1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __PERF_CPUMAP_H 3 #define __PERF_CPUMAP_H 4 5 #include <stdio.h> 6 #include <stdbool.h> 7 #include <internal/cpumap.h> 8 #include <perf/cpumap.h> 9 10 /** Identify where counts are aggregated, -1 implies not to aggregate. */ 11 struct aggr_cpu_id { 12 /** A value in the range 0 to number of threads. */ 13 int thread; 14 /** The numa node X as read from /sys/devices/system/node/nodeX. */ 15 int node; 16 /** 17 * The socket number as read from 18 * /sys/devices/system/cpu/cpuX/topology/physical_package_id. 19 */ 20 int socket; 21 /** The die id as read from /sys/devices/system/cpu/cpuX/topology/die_id. */ 22 int die; 23 /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */ 24 int core; 25 }; 26 27 struct cpu_aggr_map { 28 refcount_t refcnt; 29 int nr; 30 struct aggr_cpu_id map[]; 31 }; 32 33 struct perf_record_cpu_map_data; 34 35 struct perf_cpu_map *perf_cpu_map__empty_new(int nr); 36 struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr); 37 38 struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data); 39 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); 40 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size); 41 size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); 42 int cpu_map__get_socket_id(int cpu); 43 struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data); 44 int cpu_map__get_die_id(int cpu); 45 struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); 46 int cpu_map__get_core_id(int cpu); 47 struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); 48 int cpu_map__get_node_id(int cpu); 49 struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); 50 int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp); 51 int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **diep); 52 int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **corep); 53 int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **nodep); 54 const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ 55 56 int cpu__setup_cpunode_map(void); 57 58 int cpu__max_node(void); 59 int cpu__max_cpu(void); 60 int cpu__max_present_cpu(void); 61 int cpu__get_node(int cpu); 62 63 int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, 64 struct aggr_cpu_id (*f)(int cpu, void *data), 65 void *data); 66 67 int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); 68 bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); 69 70 bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b); 71 bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a); 72 struct aggr_cpu_id aggr_cpu_id__empty(void); 73 74 #endif /* __PERF_CPUMAP_H */ 75