From b6ce063b046f68094699af3f06bb0e20e47a32f9 Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Mon, 29 Jun 2020 14:19:21 +0800 Subject: [PATCH] irqtop/lsirq: support softirq Add '-S' or '--softirq' for irqtop/lsirq, instead of interrupts, show softirqs infomation. Because there is no more description of softirq, do not show 'NAME' column by default. Signed-off-by: zhenwei pi --- include/pathnames.h | 1 + sys-utils/irq-common.c | 12 ++++++++---- sys-utils/irq-common.h | 3 ++- sys-utils/irqtop.c | 13 ++++++++++--- sys-utils/lsirq.c | 17 ++++++++++++----- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/include/pathnames.h b/include/pathnames.h index 3845d4c331..8f62337493 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -188,6 +188,7 @@ /* irqtop paths */ #define _PATH_PROC_INTERRUPTS "/proc/interrupts" +#define _PATH_PROC_SOFTIRQS "/proc/softirqs" #define _PATH_PROC_UPTIME "/proc/uptime" /* kernel command line */ diff --git a/sys-utils/irq-common.c b/sys-utils/irq-common.c index 81e8b1d2ee..3ed793740a 100644 --- a/sys-utils/irq-common.c +++ b/sys-utils/irq-common.c @@ -195,7 +195,7 @@ static char *remove_repeated_spaces(char *str) /* * irqinfo - parse the system's interrupts */ -static struct irq_stat *get_irqinfo(void) +static struct irq_stat *get_irqinfo(int softirq) { FILE *irqfile; char *line = NULL, *tmp; @@ -209,7 +209,10 @@ static struct irq_stat *get_irqinfo(void) stat->irq_info = xmalloc(sizeof(*stat->irq_info) * IRQ_INFO_LEN); stat->nr_irq_info = IRQ_INFO_LEN; - irqfile = fopen(_PATH_PROC_INTERRUPTS, "r"); + if (softirq) + irqfile = fopen(_PATH_PROC_SOFTIRQS, "r"); + else + irqfile = fopen(_PATH_PROC_INTERRUPTS, "r"); if (!irqfile) { warn(_("cannot open %s"), _PATH_PROC_INTERRUPTS); goto free_stat; @@ -368,7 +371,8 @@ void set_sort_func_by_key(struct irq_output *out, char c) struct libscols_table *get_scols_table(struct irq_output *out, struct irq_stat *prev, - struct irq_stat **xstat) + struct irq_stat **xstat, + int softirq) { struct libscols_table *table; struct irq_info *result; @@ -377,7 +381,7 @@ struct libscols_table *get_scols_table(struct irq_output *out, size_t i; /* the stats */ - stat = get_irqinfo(); + stat = get_irqinfo(softirq); if (!stat) return NULL; diff --git a/sys-utils/irq-common.h b/sys-utils/irq-common.h index 9515daf49a..f296ad06fe 100644 --- a/sys-utils/irq-common.h +++ b/sys-utils/irq-common.h @@ -56,6 +56,7 @@ void set_sort_func_by_key(struct irq_output *out, const char c); struct libscols_table *get_scols_table(struct irq_output *out, struct irq_stat *prev, - struct irq_stat **xstat); + struct irq_stat **xstat, + int softirq); #endif /* UTIL_LINUX_H_IRQ_COMMON */ diff --git a/sys-utils/irqtop.c b/sys-utils/irqtop.c index 4363fffb75..89c493e983 100644 --- a/sys-utils/irqtop.c +++ b/sys-utils/irqtop.c @@ -79,6 +79,7 @@ struct irqtop_ctl { struct irq_stat *prev_stat; unsigned int request_exit:1; + unsigned int softirq:1; }; /* user's input parser */ @@ -102,7 +103,7 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out) time_t now = time(NULL); char timestr[64], *data; - table = get_scols_table(out, ctl->prev_stat, &stat); + table = get_scols_table(out, ctl->prev_stat, &stat, ctl->softirq); if (!table) { ctl->request_exit = 1; return 1; @@ -223,6 +224,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -d, --delay delay updates\n"), stdout); fputs(_(" -o, --output define which output columns to use\n"), stdout); fputs(_(" -s, --sort specify sort column\n"), stdout); + fputs(_(" -S, --softirq show softirqs instead of interrupts\n"), stdout); fputs(USAGE_SEPARATOR, stdout); printf(USAGE_HELP_OPTIONS(22)); @@ -250,13 +252,14 @@ static void parse_args( struct irqtop_ctl *ctl, {"delay", required_argument, NULL, 'd'}, {"sort", required_argument, NULL, 's'}, {"output", required_argument, NULL, 'o'}, + {"softirq", no_argument, NULL, 'S'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {NULL, 0, NULL, 0} }; int o; - while ((o = getopt_long(argc, argv, "d:o:s:hV", longopts, NULL)) != -1) { + while ((o = getopt_long(argc, argv, "d:o:s:ShV", longopts, NULL)) != -1) { switch (o) { case 'd': { @@ -274,6 +277,9 @@ static void parse_args( struct irqtop_ctl *ctl, case 'o': outarg = optarg; break; + case 'S': + ctl->softirq = 1; + break; case 'V': print_version(EXIT_SUCCESS); case 'h': @@ -288,7 +294,8 @@ static void parse_args( struct irqtop_ctl *ctl, out->columns[out->ncolumns++] = COL_IRQ; out->columns[out->ncolumns++] = COL_TOTAL; out->columns[out->ncolumns++] = COL_DELTA; - out->columns[out->ncolumns++] = COL_NAME; + if (!ctl->softirq) + out->columns[out->ncolumns++] = COL_NAME; } /* add -o [+] to putput */ diff --git a/sys-utils/lsirq.c b/sys-utils/lsirq.c index 33fe48d257..0c7bfd83b7 100644 --- a/sys-utils/lsirq.c +++ b/sys-utils/lsirq.c @@ -38,11 +38,11 @@ #include "irq-common.h" -static int print_irq_data(struct irq_output *out) +static int print_irq_data(struct irq_output *out, int softirq) { struct libscols_table *table; - table = get_scols_table(out, NULL, NULL); + table = get_scols_table(out, NULL, NULL, softirq); if (!table) return -1; @@ -65,6 +65,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -n, --noheadings don't print headings\n"), stdout); fputs(_(" -o, --output define which output columns to use\n"), stdout); fputs(_(" -s, --sort specify sort column\n"), stdout); + fputs(_(" -S, --softirq show softirqs instead of interrupts\n"), stdout); fputs(USAGE_SEPARATOR, stdout); printf(USAGE_HELP_OPTIONS(22)); @@ -84,6 +85,7 @@ int main(int argc, char **argv) {"sort", required_argument, NULL, 's'}, {"noheadings", no_argument, NULL, 'n'}, {"output", required_argument, NULL, 'o'}, + {"softirq", no_argument, NULL, 'S'}, {"json", no_argument, NULL, 'J'}, {"pairs", no_argument, NULL, 'P'}, {"help", no_argument, NULL, 'h'}, @@ -97,10 +99,11 @@ int main(int argc, char **argv) {0} }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; + int softirq = 0; setlocale(LC_ALL, ""); - while ((c = getopt_long(argc, argv, "no:s:hJPV", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "no:s:ShJPV", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); switch (c) { @@ -119,6 +122,9 @@ int main(int argc, char **argv) case 's': set_sort_func_by_name(&out, optarg); break; + case 'S': + softirq = 1; + break; case 'V': print_version(EXIT_SUCCESS); case 'h': @@ -132,7 +138,8 @@ int main(int argc, char **argv) if (!out.ncolumns) { out.columns[out.ncolumns++] = COL_IRQ; out.columns[out.ncolumns++] = COL_TOTAL; - out.columns[out.ncolumns++] = COL_NAME; + if (!softirq) + out.columns[out.ncolumns++] = COL_NAME; } /* add -o [+] to putput */ @@ -142,5 +149,5 @@ int main(int argc, char **argv) irq_column_name_to_id) < 0) exit(EXIT_FAILURE); - return print_irq_data(&out) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + return print_irq_data(&out, softirq) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.47.3