1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_CPUMAP_H
3 #define __PERF_CPUMAP_H
7 #include <internal/cpumap.h>
8 #include <perf/cpumap.h>
10 /** Identify where counts are aggregated, -1 implies not to aggregate. */
12 /** A value in the range 0 to number of threads. */
14 /** The numa node X as read from /sys/devices/system/node/nodeX. */
17 * The socket number as read from
18 * /sys/devices/system/cpu/cpuX/topology/physical_package_id.
21 /** The die id as read from /sys/devices/system/cpu/cpuX/topology/die_id. */
23 /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */
25 /** CPU aggregation, note there is one CPU for each SMT thread. */
29 /** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */
32 /** Number of valid entries. */
35 struct aggr_cpu_id map[];
38 struct perf_record_cpu_map_data;
40 struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
42 struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data);
43 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
44 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
45 size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
46 const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
48 int cpu__setup_cpunode_map(void);
50 int cpu__max_node(void);
51 struct perf_cpu cpu__max_cpu(void);
52 struct perf_cpu cpu__max_present_cpu(void);
55 * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, use a single dummy map with an entry of -1.
57 static inline bool cpu_map__is_dummy(struct perf_cpu_map *cpus)
59 return perf_cpu_map__nr(cpus) == 1 && perf_cpu_map__cpu(cpus, 0).cpu == -1;
63 * cpu__get_node - Returns the numa node X as read from
64 * /sys/devices/system/node/nodeX for the given CPU.
66 int cpu__get_node(struct perf_cpu cpu);
68 * cpu__get_socket_id - Returns the socket number as read from
69 * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given CPU.
71 int cpu__get_socket_id(struct perf_cpu cpu);
73 * cpu__get_die_id - Returns the die id as read from
74 * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU.
76 int cpu__get_die_id(struct perf_cpu cpu);
78 * cpu__get_core_id - Returns the core id as read from
79 * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU.
81 int cpu__get_core_id(struct perf_cpu cpu);
84 * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry
87 struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr);
89 typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data);
92 * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each cpu in
93 * cpus. The aggr_cpu_id is created with 'get_id' that may have a data value
94 * passed to it. The cpu_aggr_map is sorted with duplicate values removed.
96 struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus,
97 aggr_cpu_id_get_t get_id,
100 bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b);
101 bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a);
102 struct aggr_cpu_id aggr_cpu_id__empty(void);
106 * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated with
107 * the socket for cpu. The function signature is compatible with
110 struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data);
112 * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket populated
113 * with the die and socket for cpu. The function signature is compatible with
116 struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data);
118 * aggr_cpu_id__core - Create an aggr_cpu_id with the core, die and socket
119 * populated with the core, die and socket for cpu. The function signature is
120 * compatible with aggr_cpu_id_get_t.
122 struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data);
124 * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and socket
125 * populated with the cpu, core, die and socket for cpu. The function signature
126 * is compatible with aggr_cpu_id_get_t.
128 struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data);
130 * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for
131 * cpu. The function signature is compatible with aggr_cpu_id_get_t.
133 struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data);
135 #endif /* __PERF_CPUMAP_H */