1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_CPUMAP_H
3 #define __PERF_CPUMAP_H
8 #include <internal/cpumap.h>
9 #include <perf/cpumap.h>
11 /** Identify where counts are aggregated, -1 implies not to aggregate. */
13 /** A value in the range 0 to number of threads. */
15 /** The numa node X as read from /sys/devices/system/node/nodeX. */
18 * The socket number as read from
19 * /sys/devices/system/cpu/cpuX/topology/physical_package_id.
22 /** The die id as read from /sys/devices/system/cpu/cpuX/topology/die_id. */
24 /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */
26 /** CPU aggregation, note there is one CPU for each SMT thread. */
30 /** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */
33 /** Number of valid entries. */
36 struct aggr_cpu_id map[];
39 struct perf_record_cpu_map_data;
41 struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
43 struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data);
44 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
45 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
46 size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
47 const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
49 int cpu__setup_cpunode_map(void);
51 int cpu__max_node(void);
52 struct perf_cpu cpu__max_cpu(void);
53 struct perf_cpu cpu__max_present_cpu(void);
56 * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, use a single dummy map with an entry of -1.
58 static inline bool cpu_map__is_dummy(struct perf_cpu_map *cpus)
60 return cpus->nr == 1 && cpus->map[0].cpu == -1;
64 * cpu__get_node - Returns the numa node X as read from
65 * /sys/devices/system/node/nodeX for the given CPU.
67 int cpu__get_node(struct perf_cpu cpu);
69 * cpu__get_socket_id - Returns the socket number as read from
70 * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given CPU.
72 int cpu__get_socket_id(struct perf_cpu cpu);
74 * cpu__get_die_id - Returns the die id as read from
75 * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU.
77 int cpu__get_die_id(struct perf_cpu cpu);
79 * cpu__get_core_id - Returns the core id as read from
80 * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU.
82 int cpu__get_core_id(struct perf_cpu cpu);
85 * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry
88 struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr);
90 typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data);
93 * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each cpu in
94 * cpus. The aggr_cpu_id is created with 'get_id' that may have a data value
95 * passed to it. The cpu_aggr_map is sorted with duplicate values removed.
97 struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus,
98 aggr_cpu_id_get_t get_id,
101 bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b);
102 bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a);
103 struct aggr_cpu_id aggr_cpu_id__empty(void);
107 * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated with
108 * the socket for cpu. The function signature is compatible with
111 struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data);
113 * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket populated
114 * with the die and socket for cpu. The function signature is compatible with
117 struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data);
119 * aggr_cpu_id__core - Create an aggr_cpu_id with the core, die and socket
120 * populated with the core, die and socket for cpu. The function signature is
121 * compatible with aggr_cpu_id_get_t.
123 struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data);
125 * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and socket
126 * populated with the cpu, core, die and socket for cpu. The function signature
127 * is compatible with aggr_cpu_id_get_t.
129 struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data);
131 * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for
132 * cpu. The function signature is compatible with aggr_cpu_id_get_t.
134 struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data);
136 #endif /* __PERF_CPUMAP_H */