xref: /openbmc/linux/tools/lib/perf/include/perf/cpumap.h (revision 916ce34a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBPERF_CPUMAP_H
3 #define __LIBPERF_CPUMAP_H
4 
5 #include <perf/core.h>
6 #include <stdio.h>
7 #include <stdbool.h>
8 
9 /** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
10 struct perf_cpu {
11 	int cpu;
12 };
13 
14 struct perf_cache {
15 	int cache_lvl;
16 	int cache;
17 };
18 
19 struct perf_cpu_map;
20 
21 /**
22  * perf_cpu_map__dummy_new - a map with a singular "any CPU"/dummy -1 value.
23  */
24 LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
25 LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
26 LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
27 LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file);
28 LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
29 LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig,
30 						     struct perf_cpu_map *other);
31 LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig,
32 							 struct perf_cpu_map *other);
33 LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
34 LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
35 LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
36 /**
37  * perf_cpu_map__empty - is map either empty or the "any CPU"/dummy value.
38  */
39 LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map);
40 LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map);
41 LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_cpu cpu);
42 LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs,
43 				     const struct perf_cpu_map *rhs);
44 /**
45  * perf_cpu_map__any_cpu - Does the map contain the "any CPU"/dummy -1 value?
46  */
47 LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map);
48 
49 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus)		\
50 	for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx);	\
51 	     (idx) < perf_cpu_map__nr(cpus);			\
52 	     (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx))
53 
54 #define perf_cpu_map__for_each_idx(idx, cpus)				\
55 	for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++)
56 
57 #endif /* __LIBPERF_CPUMAP_H */
58