13ce311afSJiri Olsa /* SPDX-License-Identifier: GPL-2.0 */
23ce311afSJiri Olsa #ifndef __LIBPERF_INTERNAL_CPUMAP_H
33ce311afSJiri Olsa #define __LIBPERF_INTERNAL_CPUMAP_H
43ce311afSJiri Olsa 
53ce311afSJiri Olsa #include <linux/refcount.h>
630d1c4d9SJiri Olsa #include <perf/cpumap.h>
7*da885a0eSIan Rogers #include <internal/rc_check.h>
86d18804bSIan Rogers 
9818ab78cSIan Rogers /**
10818ab78cSIan Rogers  * A sized, reference counted, sorted array of integers representing CPU
11818ab78cSIan Rogers  * numbers. This is commonly used to capture which CPUs a PMU is associated
12818ab78cSIan Rogers  * with. The indices into the cpumap are frequently used as they avoid having
13818ab78cSIan Rogers  * gaps if CPU numbers were used. For events associated with a pid, rather than
14818ab78cSIan Rogers  * a CPU, a single dummy map with an entry of -1 is used.
15818ab78cSIan Rogers  */
DECLARE_RC_STRUCT(perf_cpu_map)16*da885a0eSIan Rogers DECLARE_RC_STRUCT(perf_cpu_map) {
173ce311afSJiri Olsa 	refcount_t	refcnt;
18818ab78cSIan Rogers 	/** Length of the map array. */
193ce311afSJiri Olsa 	int		nr;
20818ab78cSIan Rogers 	/** The CPU values. */
216d18804bSIan Rogers 	struct perf_cpu	map[];
223ce311afSJiri Olsa };
233ce311afSJiri Olsa 
243ce311afSJiri Olsa #ifndef MAX_NR_CPUS
253ce311afSJiri Olsa #define MAX_NR_CPUS	2048
263ce311afSJiri Olsa #endif
273ce311afSJiri Olsa 
281f94479eSIan Rogers struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus);
296d18804bSIan Rogers int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu);
30c3ad8d23SIan Rogers bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b);
313ce311afSJiri Olsa 
32b2778514SArnaldo Carvalho de Melo void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus);
33b2778514SArnaldo Carvalho de Melo 
perf_cpu_map__refcnt(struct perf_cpu_map * map)344121234aSArnaldo Carvalho de Melo static inline refcount_t *perf_cpu_map__refcnt(struct perf_cpu_map *map)
354121234aSArnaldo Carvalho de Melo {
36*da885a0eSIan Rogers 	return &RC_CHK_ACCESS(map)->refcnt;
374121234aSArnaldo Carvalho de Melo }
383ce311afSJiri Olsa #endif /* __LIBPERF_INTERNAL_CPUMAP_H */
39