xref: /openbmc/linux/tools/perf/util/cpumap.h (revision 91802e73)
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 	/** CPU aggregation, note there is one CPU for each SMT thread. */
26 	int cpu;
27 };
28 
29 /** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */
30 struct cpu_aggr_map {
31 	refcount_t refcnt;
32 	/** Number of valid entries. */
33 	int nr;
34 	/** The entries. */
35 	struct aggr_cpu_id map[];
36 };
37 
38 struct perf_record_cpu_map_data;
39 
40 struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
41 
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 */
47 
48 int cpu__setup_cpunode_map(void);
49 
50 int cpu__max_node(void);
51 int cpu__max_cpu(void);
52 int cpu__max_present_cpu(void);
53 /**
54  * cpu__get_node - Returns the numa node X as read from
55  * /sys/devices/system/node/nodeX for the given CPU.
56  */
57 int cpu__get_node(int cpu);
58 /**
59  * cpu__get_socket_id - Returns the socket number as read from
60  * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given CPU.
61  */
62 int cpu__get_socket_id(int cpu);
63 /**
64  * cpu__get_die_id - Returns the die id as read from
65  * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU.
66  */
67 int cpu__get_die_id(int cpu);
68 /**
69  * cpu__get_core_id - Returns the core id as read from
70  * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU.
71  */
72 int cpu__get_core_id(int cpu);
73 
74 /**
75  * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry
76  * being empty.
77  */
78 struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr);
79 
80 typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(int cpu, void *data);
81 
82 /**
83  * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each cpu in
84  * cpus. The aggr_cpu_id is created with 'get_id' that may have a data value
85  * passed to it. The cpu_aggr_map is sorted with duplicate values removed.
86  */
87 struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus,
88 				       aggr_cpu_id_get_t get_id,
89 				       void *data);
90 
91 bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b);
92 bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a);
93 struct aggr_cpu_id aggr_cpu_id__empty(void);
94 
95 
96 /**
97  * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated with
98  * the socket for cpu. The function signature is compatible with
99  * aggr_cpu_id_get_t.
100  */
101 struct aggr_cpu_id aggr_cpu_id__socket(int cpu, void *data);
102 /**
103  * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket populated
104  * with the die and socket for cpu. The function signature is compatible with
105  * aggr_cpu_id_get_t.
106  */
107 struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data);
108 /**
109  * aggr_cpu_id__core - Create an aggr_cpu_id with the core, die and socket
110  * populated with the core, die and socket for cpu. The function signature is
111  * compatible with aggr_cpu_id_get_t.
112  */
113 struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data);
114 /**
115  * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and socket
116  * populated with the cpu, core, die and socket for cpu. The function signature
117  * is compatible with aggr_cpu_id_get_t.
118  */
119 struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data);
120 /**
121  * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for
122  * cpu. The function signature is compatible with aggr_cpu_id_get_t.
123  */
124 struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data);
125 
126 #endif /* __PERF_CPUMAP_H */
127