]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsirq: add option to limit cpus
authorRobin Jarry <robin@jarry.cc>
Tue, 5 Nov 2024 10:02:38 +0000 (11:02 +0100)
committerRobin Jarry <robin@jarry.cc>
Wed, 6 Nov 2024 10:06:12 +0000 (11:06 +0100)
For consistency with irqtop, add a --cpu-list lsirq option to specify
a list of CPUs for which to display interrupt counters.

get_scols_table() already supports a cpu_set_t argument. Simply parse
the argument and pass it down.

Signed-off-by: Robin Jarry <robin@jarry.cc>
bash-completion/lsirq
sys-utils/lsirq.1.adoc
sys-utils/lsirq.c

index d4dd19efa3c383fe2a2b7eb6e744011e8f8a163c..4c3c9f04fa2bbb2fd51f828533d5133f15f7727d 100644 (file)
@@ -25,6 +25,9 @@ _lsirq_module()
                '-t'|'--threshold')
                        return 0
                        ;;
+               '-C'|'--cpu-list')
+                       return 0
+                       ;;
                '-h'|'--help'|'-V'|'--version')
                        return 0
                        ;;
@@ -36,6 +39,7 @@ _lsirq_module()
                --softirq
                --sort
                --threshold
+               --cpu-list
                --help
                --version"
        COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
index 8839af0e6b5ee6408a26061e0d16b8b8190699b4..02aea16b31fcc9368fe65cf9929b840235fdfa9a 100644 (file)
@@ -43,6 +43,9 @@ Show softirqs information.
 *-t*, *--threshold* _min_::
 Only show IRQs with counters above the specified threshold. Human readable values are supported (e.g. 1.2K).
 
+*-C*, *--cpu-list* _list_::
+Only show interrupt counters on the specified CPU list.
+
 include::man-common/help-version.adoc[]
 
 == AUTHORS
index 6a2536068d680a936496e5194d89d56990a56a20..e31addaf595ec57e43a085555638be66719cf368 100644 (file)
 #include "irq-common.h"
 
 static int print_irq_data(struct irq_output *out,
-                         int softirq, unsigned long threshold)
+                         int softirq, unsigned long threshold,
+                         size_t setsize, cpu_set_t *cpuset)
 {
        struct libscols_table *table;
 
-       table = get_scols_table(out, NULL, NULL, softirq, threshold, 0, NULL);
+       table = get_scols_table(out, NULL, NULL, softirq, threshold, setsize, cpuset);
        if (!table)
                return -1;
 
@@ -62,6 +63,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -s, --sort <column>  specify sort column\n"), stdout);
        fputs(_(" -S, --softirq        show softirqs instead of interrupts\n"), stdout);
        fputs(_(" -t, --threshold <N>  only IRQs with counters above <N>\n"), stdout);
+       fputs(_(" -C, --cpu-list <list> only show counters for these CPUs\n"), stdout);
        fputs(USAGE_SEPARATOR, stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(22));
 
@@ -82,6 +84,7 @@ int main(int argc, char **argv)
                {"noheadings", no_argument, NULL, 'n'},
                {"output", required_argument, NULL, 'o'},
                {"threshold", required_argument, NULL, 't'},
+               {"cpu-list", required_argument, NULL, 'C'},
                {"softirq", no_argument, NULL, 'S'},
                {"json", no_argument, NULL, 'J'},
                {"pairs", no_argument, NULL, 'P'},
@@ -97,11 +100,13 @@ int main(int argc, char **argv)
        };
        int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
        uintmax_t threshold = 0;
+       cpu_set_t *cpuset = NULL;
+       size_t setsize = 0;
        int softirq = 0;
 
        setlocale(LC_ALL, "");
 
-       while ((c = getopt_long(argc, argv, "no:s:t:ShJPV", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "no:s:t:C:ShJPV", longopts, NULL)) != -1) {
                err_exclusive_options(c, longopts, excl, excl_st);
 
                switch (c) {
@@ -126,6 +131,23 @@ int main(int argc, char **argv)
                case 't':
                        threshold = strtosize_or_err(optarg, _("error: --threshold"));
                        break;
+               case 'C': {
+                       int ncpus = get_max_number_of_cpus();
+                       if (ncpus <= 0)
+                               errx(EXIT_FAILURE, _("cannot determine NR_CPUS; aborting"));
+
+                       if (cpuset != NULL)
+                               cpuset_free(cpuset);
+
+                       cpuset = cpuset_alloc(ncpus, &setsize, NULL);
+                       if (!cpuset)
+                               err(EXIT_FAILURE, _("cpuset_alloc failed"));
+
+                       if (cpulist_parse(optarg, cpuset, setsize, 0))
+                               errx(EXIT_FAILURE, _("failed to parse CPU list: %s"),
+                                       optarg);
+                       break;
+               }
                case 'V':
                        print_version(EXIT_SUCCESS);
                case 'h':
@@ -149,7 +171,7 @@ int main(int argc, char **argv)
                                irq_column_name_to_id) < 0)
                exit(EXIT_FAILURE);
 
-       if (print_irq_data(&out, softirq, threshold) < 0)
+       if (print_irq_data(&out, softirq, threshold, setsize, cpuset) < 0)
                return EXIT_FAILURE;
 
        return EXIT_SUCCESS;