Commit 30d1c4d9 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

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: 6d18804b ("perf cpumap: Give CPUs their own type")
Reported-by: default avatarTzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9de07369
...@@ -3,11 +3,7 @@ ...@@ -3,11 +3,7 @@
#define __LIBPERF_INTERNAL_CPUMAP_H #define __LIBPERF_INTERNAL_CPUMAP_H
#include <linux/refcount.h> #include <linux/refcount.h>
#include <perf/cpumap.h>
/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
struct perf_cpu {
int cpu;
};
/** /**
* A sized, reference counted, sorted array of integers representing CPU * A sized, reference counted, sorted array of integers representing CPU
......
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
struct perf_cpu {
int cpu;
};
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
......
...@@ -2,6 +2,7 @@ LIBPERF_0.0.1 { ...@@ -2,6 +2,7 @@ LIBPERF_0.0.1 {
global: global:
libperf_init; libperf_init;
perf_cpu_map__dummy_new; perf_cpu_map__dummy_new;
perf_cpu_map__default_new;
perf_cpu_map__get; perf_cpu_map__get;
perf_cpu_map__put; perf_cpu_map__put;
perf_cpu_map__new; perf_cpu_map__new;
......
...@@ -14,6 +14,8 @@ static int libperf_print(enum libperf_print_level level, ...@@ -14,6 +14,8 @@ static int libperf_print(enum libperf_print_level level,
int test_cpumap(int argc, char **argv) int test_cpumap(int argc, char **argv)
{ {
struct perf_cpu_map *cpus; struct perf_cpu_map *cpus;
struct perf_cpu cpu;
int idx;
__T_START; __T_START;
...@@ -27,6 +29,15 @@ int test_cpumap(int argc, char **argv) ...@@ -27,6 +29,15 @@ int test_cpumap(int argc, char **argv)
perf_cpu_map__put(cpus); perf_cpu_map__put(cpus);
perf_cpu_map__put(cpus); perf_cpu_map__put(cpus);
cpus = perf_cpu_map__default_new();
if (!cpus)
return -1;
perf_cpu_map__for_each_cpu(cpu, idx, cpus)
__T("wrong cpu number", cpu.cpu != -1);
perf_cpu_map__put(cpus);
__T_END; __T_END;
return tests_failed == 0 ? 0 : -1; return tests_failed == 0 ? 0 : -1;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment