1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBPERF_INTERNAL_CPUMAP_H
3 #define __LIBPERF_INTERNAL_CPUMAP_H
4 
5 #include <linux/refcount.h>
6 #include <perf/cpumap.h>
7 #include <internal/rc_check.h>
8 
9 /**
10  * A sized, reference counted, sorted array of integers representing CPU
11  * numbers. This is commonly used to capture which CPUs a PMU is associated
12  * with. The indices into the cpumap are frequently used as they avoid having
13  * gaps if CPU numbers were used. For events associated with a pid, rather than
14  * a CPU, a single dummy map with an entry of -1 is used.
15  */
16 DECLARE_RC_STRUCT(perf_cpu_map) {
17 	refcount_t	refcnt;
18 	/** Length of the map array. */
19 	int		nr;
20 	/** The CPU values. */
21 	struct perf_cpu	map[];
22 };
23 
24 #ifndef MAX_NR_CPUS
25 #define MAX_NR_CPUS	2048
26 #endif
27 
28 struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus);
29 int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu);
30 bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b);
31 
32 void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus);
33 
34 static inline refcount_t *perf_cpu_map__refcnt(struct perf_cpu_map *map)
35 {
36 	return &RC_CHK_ACCESS(map)->refcnt;
37 }
38 #endif /* __LIBPERF_INTERNAL_CPUMAP_H */
39