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_cpu_map; 15 16 LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); 17 LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void); 18 LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); 19 LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); 20 LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); 21 LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, 22 struct perf_cpu_map *other); 23 LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); 24 LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx); 25 LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); 26 LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); 27 LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map); 28 LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_cpu cpu); 29 30 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ 31 for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ 32 (idx) < perf_cpu_map__nr(cpus); \ 33 (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx)) 34 35 #define perf_cpu_map__for_each_idx(idx, cpus) \ 36 for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++) 37 38 #endif /* __LIBPERF_CPUMAP_H */ 39