Skip to content

Commit 30d1c4d

Browse files
olsajiriacmel
authored andcommitted
libperf: Fix perf_cpu_map__for_each_cpu macro
Tzvetomir Stoyanov reported an issue with using macro perf_cpu_map__for_each_cpu using private perf_cpu object. The issue is caused by recent change that wrapped cpu in struct perf_cpu to distinguish it from cpu indexes. We need to make struct perf_cpu public. Add a simple test for using the perf_cpu_map__for_each_cpu macro. Fixes: 6d18804 ("perf cpumap: Give CPUs their own type") Reported-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20220215153713.31395-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9de0736 commit 30d1c4d

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

tools/lib/perf/include/internal/cpumap.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
#define __LIBPERF_INTERNAL_CPUMAP_H
44

55
#include <linux/refcount.h>
6-
7-
/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
8-
struct perf_cpu {
9-
int cpu;
10-
};
6+
#include <perf/cpumap.h>
117

128
/**
139
* A sized, reference counted, sorted array of integers representing CPU

tools/lib/perf/include/perf/cpumap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include <stdio.h>
88
#include <stdbool.h>
99

10+
/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
11+
struct perf_cpu {
12+
int cpu;
13+
};
14+
1015
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
1116
LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
1217
LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);

tools/lib/perf/libperf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ LIBPERF_0.0.1 {
22
global:
33
libperf_init;
44
perf_cpu_map__dummy_new;
5+
perf_cpu_map__default_new;
56
perf_cpu_map__get;
67
perf_cpu_map__put;
78
perf_cpu_map__new;

tools/lib/perf/tests/test-cpumap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static int libperf_print(enum libperf_print_level level,
1414
int test_cpumap(int argc, char **argv)
1515
{
1616
struct perf_cpu_map *cpus;
17+
struct perf_cpu cpu;
18+
int idx;
1719

1820
__T_START;
1921

@@ -27,6 +29,15 @@ int test_cpumap(int argc, char **argv)
2729
perf_cpu_map__put(cpus);
2830
perf_cpu_map__put(cpus);
2931

32+
cpus = perf_cpu_map__default_new();
33+
if (!cpus)
34+
return -1;
35+
36+
perf_cpu_map__for_each_cpu(cpu, idx, cpus)
37+
__T("wrong cpu number", cpu.cpu != -1);
38+
39+
perf_cpu_map__put(cpus);
40+
3041
__T_END;
3142
return tests_failed == 0 ? 0 : -1;
3243
}

0 commit comments

Comments
 (0)