Re: [PATCH v3 3/7] perf evsel: Add iterator to iterate over events ordered by CPU

Jiri Olsa
2019-10-30T10:05:58Z

On Fri, Oct 25, 2019 at 11:14:13AM -0700, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> Add some common code that is needed to iterate over all events
> in CPU order. Used in followon patches
>
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
>
> ---
>
> v2: Add cpumap__for_each_cpu macro to factor out some common code
> ---
> tools/perf/util/cpumap.h | 8 ++++++++
> tools/perf/util/evlist.c | 33 +++++++++++++++++++++++++++++++++
> tools/perf/util/evlist.h | 4 ++++
> tools/perf/util/evsel.h | 1 +
> 4 files changed, 46 insertions(+)
>
> diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
> index 2553bef1279d..a9b13d72fd29 100644
> --- a/tools/perf/util/cpumap.h
> +++ b/tools/perf/util/cpumap.h
> @@ -60,4 +60,12 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,
>
> int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
> bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
> +
> +#define __cpumap__for_each_cpu(cpus, index, cpu, maxcpu)\
> + for ((index) = 0; \
> + (cpu) = (index) < (maxcpu) ? (cpus)->map[index] : -1, (index) < (maxcpu); \
> + (index)++)
> +#define cpumap__for_each_cpu(cpus, index, cpu) \
> + __cpumap__for_each_cpu(cpus, index, cpu, (cpus)->nr)

there's perf_cpu_map__for_each_cpu macro in libperf

jirka