cpumap.h 1.1 KB

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