]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask
authorIan Rogers <irogers@google.com>
Wed, 3 Dec 2025 21:47:02 +0000 (13:47 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 4 Dec 2025 08:36:14 +0000 (00:36 -0800)
If the perf_cpu_map is empty or is just the any CPU value, then early
return. Don't process the "any" CPU when creating the bitmap.

Tested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/cpumap.c

index 89570397a4b350d738a31d62e4bea8fa13c9a13c..a80845038a5ebcf6fa08bab26628642b5da57199 100644 (file)
@@ -684,16 +684,21 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size)
        unsigned char *bitmap;
        struct perf_cpu c, last_cpu = perf_cpu_map__max(map);
 
-       if (buf == NULL)
+       if (buf == NULL || size == 0)
                return 0;
 
+       if (last_cpu.cpu < 0) {
+               buf[0] = '\0';
+               return 0;
+       }
+
        bitmap = zalloc(last_cpu.cpu / 8 + 1);
        if (bitmap == NULL) {
                buf[0] = '\0';
                return 0;
        }
 
-       perf_cpu_map__for_each_cpu(c, idx, map)
+       perf_cpu_map__for_each_cpu_skip_any(c, idx, map)
                bitmap[c.cpu / 8] |= 1 << (c.cpu % 8);
 
        for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) {