]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
irqtop/lsirq: support softirq
authorzhenwei pi <pizhenwei@bytedance.com>
Mon, 29 Jun 2020 06:19:21 +0000 (14:19 +0800)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Jul 2020 10:23:56 +0000 (12:23 +0200)
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 <pizhenwei@bytedance.com>
include/pathnames.h
sys-utils/irq-common.c
sys-utils/irq-common.h
sys-utils/irqtop.c
sys-utils/lsirq.c

index 3845d4c3319da23954a5660564e5a6d64ac67516..8f62337493105cce87b7ee022e881567d4aed422 100644 (file)
 
 /* irqtop paths */
 #define _PATH_PROC_INTERRUPTS  "/proc/interrupts"
+#define _PATH_PROC_SOFTIRQS    "/proc/softirqs"
 #define _PATH_PROC_UPTIME      "/proc/uptime"
 
 /* kernel command line */
index 81e8b1d2eee4fd70df682ac6adc2d61cebadc724..3ed793740a98e9804bef2f3568059f5fe7032b24 100644 (file)
@@ -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;
 
index 9515daf49aad9d74ab47ccf0fe9e816571e75291..f296ad06fe961fa2bee1f3af55b1aa724f52f75c 100644 (file)
@@ -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 */
index 4363fffb75d15e905a7ab43c447674da419c12df..89c493e9831cfcab5f94b457d77e0907616c033e 100644 (file)
@@ -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 <secs>   delay updates\n"), stdout);
        fputs(_(" -o, --output <list>  define which output columns to use\n"), stdout);
        fputs(_(" -s, --sort <column>  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 [+]<list> to putput */
index 33fe48d257c920f4c8e634d6fe30b23a0f99aa8b..0c7bfd83b79bef10d5c3706b0169ef387d7aaf67 100644 (file)
 
 #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 <list>  define which output columns to use\n"), stdout);
        fputs(_(" -s, --sort <column>  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 [+]<list> 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;
 }