GNU Linux-libre 5.19-rc6-gnu
[releases.git] / tools / lib / perf / include / perf / cpumap.h
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 <perf/cpumap.h>
7 #include <stdio.h>
8 #include <stdbool.h>
9
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
15 LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
16 LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
17 LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
18 LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file);
19 LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
20 LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig,
21                                                      struct perf_cpu_map *other);
22 LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
23 LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
24 LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
25 LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map);
26 LIBPERF_API struct perf_cpu perf_cpu_map__max(struct perf_cpu_map *map);
27 LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_cpu cpu);
28
29 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus)              \
30         for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx);   \
31              (idx) < perf_cpu_map__nr(cpus);                    \
32              (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx))
33
34 #define perf_cpu_map__for_each_idx(idx, cpus)                           \
35         for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++)
36
37 #endif /* __LIBPERF_CPUMAP_H */