162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __LIBPERF_INTERNAL_CPUMAP_H
362306a36Sopenharmony_ci#define __LIBPERF_INTERNAL_CPUMAP_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/refcount.h>
662306a36Sopenharmony_ci#include <perf/cpumap.h>
762306a36Sopenharmony_ci#include <internal/rc_check.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/**
1062306a36Sopenharmony_ci * A sized, reference counted, sorted array of integers representing CPU
1162306a36Sopenharmony_ci * numbers. This is commonly used to capture which CPUs a PMU is associated
1262306a36Sopenharmony_ci * with. The indices into the cpumap are frequently used as they avoid having
1362306a36Sopenharmony_ci * gaps if CPU numbers were used. For events associated with a pid, rather than
1462306a36Sopenharmony_ci * a CPU, a single dummy map with an entry of -1 is used.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ciDECLARE_RC_STRUCT(perf_cpu_map) {
1762306a36Sopenharmony_ci	refcount_t	refcnt;
1862306a36Sopenharmony_ci	/** Length of the map array. */
1962306a36Sopenharmony_ci	int		nr;
2062306a36Sopenharmony_ci	/** The CPU values. */
2162306a36Sopenharmony_ci	struct perf_cpu	map[];
2262306a36Sopenharmony_ci};
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#ifndef MAX_NR_CPUS
2562306a36Sopenharmony_ci#define MAX_NR_CPUS	2048
2662306a36Sopenharmony_ci#endif
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_cistruct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus);
2962306a36Sopenharmony_ciint perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu);
3062306a36Sopenharmony_cibool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b);
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_civoid perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus);
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistatic inline refcount_t *perf_cpu_map__refcnt(struct perf_cpu_map *map)
3562306a36Sopenharmony_ci{
3662306a36Sopenharmony_ci	return &RC_CHK_ACCESS(map)->refcnt;
3762306a36Sopenharmony_ci}
3862306a36Sopenharmony_ci#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
39