Skip to content

Commit e2de90b

Browse files
captain5050namhyung
authored andcommitted
perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask
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>
1 parent a0a4173 commit e2de90b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/perf/util/cpumap.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,16 +684,21 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size)
684684
unsigned char *bitmap;
685685
struct perf_cpu c, last_cpu = perf_cpu_map__max(map);
686686

687-
if (buf == NULL)
687+
if (buf == NULL || size == 0)
688688
return 0;
689689

690+
if (last_cpu.cpu < 0) {
691+
buf[0] = '\0';
692+
return 0;
693+
}
694+
690695
bitmap = zalloc(last_cpu.cpu / 8 + 1);
691696
if (bitmap == NULL) {
692697
buf[0] = '\0';
693698
return 0;
694699
}
695700

696-
perf_cpu_map__for_each_cpu(c, idx, map)
701+
perf_cpu_map__for_each_cpu_skip_any(c, idx, map)
697702
bitmap[c.cpu / 8] |= 1 << (c.cpu % 8);
698703

699704
for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) {

0 commit comments

Comments
 (0)