xref: /openbmc/linux/tools/perf/util/cpumap.h (revision b2f10cd4)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2a12b51c4SPaul Mackerras #ifndef __PERF_CPUMAP_H
3a12b51c4SPaul Mackerras #define __PERF_CPUMAP_H
4a12b51c4SPaul Mackerras 
537be5858SArnaldo Carvalho de Melo #include <stdbool.h>
69ae7d335SArnaldo Carvalho de Melo #include <stdio.h>
7959b83c7SJiri Olsa #include <internal/cpumap.h>
8397721e0SJiri Olsa #include <perf/cpumap.h>
99ae7d335SArnaldo Carvalho de Melo 
1049679da3SIan Rogers /** Identify where counts are aggregated, -1 implies not to aggregate. */
11fa265e59SJames Clark struct aggr_cpu_id {
1249679da3SIan Rogers 	/** A value in the range 0 to number of threads. */
138d4852b4SJames Clark 	int thread;
1449679da3SIan Rogers 	/** The numa node X as read from /sys/devices/system/node/nodeX. */
15fcd83a35SJames Clark 	int node;
1649679da3SIan Rogers 	/**
1749679da3SIan Rogers 	 * The socket number as read from
1849679da3SIan Rogers 	 * /sys/devices/system/cpu/cpuX/topology/physical_package_id.
1949679da3SIan Rogers 	 */
201a270cb6SJames Clark 	int socket;
2149679da3SIan Rogers 	/** The die id as read from /sys/devices/system/cpu/cpuX/topology/die_id. */
22ba2ee166SJames Clark 	int die;
2349679da3SIan Rogers 	/** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */
24b9933817SJames Clark 	int core;
2534794913SIan Rogers 	/** CPU aggregation, note there is one CPU for each SMT thread. */
266d18804bSIan Rogers 	struct perf_cpu cpu;
27fa265e59SJames Clark };
28fa265e59SJames Clark 
2992aad5c3SIan Rogers /** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */
30cea6575fSJames Clark struct cpu_aggr_map {
31cea6575fSJames Clark 	refcount_t refcnt;
3292aad5c3SIan Rogers 	/** Number of valid entries. */
33cea6575fSJames Clark 	int nr;
3492aad5c3SIan Rogers 	/** The entries. */
35ff523295SJames Clark 	struct aggr_cpu_id map[];
36cea6575fSJames Clark };
37cea6575fSJames Clark 
3872932371SJiri Olsa struct perf_record_cpu_map_data;
397780c25bSDon Zickus 
40*b2f10cd4SIan Rogers bool perf_record_cpu_map_data__test_bit(int i, const struct perf_record_cpu_map_data *data);
41*b2f10cd4SIan Rogers 
42315c0a1fSJiri Olsa struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
43cea6575fSJames Clark 
44*b2f10cd4SIan Rogers struct perf_cpu_map *cpu_map__new_data(const struct perf_record_cpu_map_data *data);
45f854839bSJiri Olsa size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
46f854839bSJiri Olsa size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
47f854839bSJiri Olsa size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
48f854839bSJiri Olsa const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
495ac59a8aSStephane Eranian 
507780c25bSDon Zickus int cpu__setup_cpunode_map(void);
517780c25bSDon Zickus 
525ac76283SArnaldo Carvalho de Melo int cpu__max_node(void);
536d18804bSIan Rogers struct perf_cpu cpu__max_cpu(void);
546d18804bSIan Rogers struct perf_cpu cpu__max_present_cpu(void);
5537be5858SArnaldo Carvalho de Melo 
5637be5858SArnaldo Carvalho de Melo /**
5737be5858SArnaldo Carvalho de Melo  * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, use a single dummy map with an entry of -1.
5837be5858SArnaldo Carvalho de Melo  */
5937be5858SArnaldo Carvalho de Melo static inline bool cpu_map__is_dummy(struct perf_cpu_map *cpus)
6037be5858SArnaldo Carvalho de Melo {
6144028699SIan Rogers 	return perf_cpu_map__nr(cpus) == 1 && perf_cpu_map__cpu(cpus, 0).cpu == -1;
6237be5858SArnaldo Carvalho de Melo }
6337be5858SArnaldo Carvalho de Melo 
64194a3a20SIan Rogers /**
65194a3a20SIan Rogers  * cpu__get_node - Returns the numa node X as read from
66194a3a20SIan Rogers  * /sys/devices/system/node/nodeX for the given CPU.
67194a3a20SIan Rogers  */
686d18804bSIan Rogers int cpu__get_node(struct perf_cpu cpu);
694e90e5ccSIan Rogers /**
704e90e5ccSIan Rogers  * cpu__get_socket_id - Returns the socket number as read from
714e90e5ccSIan Rogers  * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given CPU.
724e90e5ccSIan Rogers  */
736d18804bSIan Rogers int cpu__get_socket_id(struct perf_cpu cpu);
744e90e5ccSIan Rogers /**
754e90e5ccSIan Rogers  * cpu__get_die_id - Returns the die id as read from
764e90e5ccSIan Rogers  * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU.
774e90e5ccSIan Rogers  */
786d18804bSIan Rogers int cpu__get_die_id(struct perf_cpu cpu);
794e90e5ccSIan Rogers /**
804e90e5ccSIan Rogers  * cpu__get_core_id - Returns the core id as read from
814e90e5ccSIan Rogers  * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU.
824e90e5ccSIan Rogers  */
836d18804bSIan Rogers int cpu__get_core_id(struct perf_cpu cpu);
844e90e5ccSIan Rogers 
8592aad5c3SIan Rogers /**
8692aad5c3SIan Rogers  * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry
8792aad5c3SIan Rogers  * being empty.
8892aad5c3SIan Rogers  */
8992aad5c3SIan Rogers struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr);
9092aad5c3SIan Rogers 
916d18804bSIan Rogers typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data);
927780c25bSDon Zickus 
935f50e15cSIan Rogers /**
945f50e15cSIan Rogers  * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each cpu in
955f50e15cSIan Rogers  * cpus. The aggr_cpu_id is created with 'get_id' that may have a data value
965f50e15cSIan Rogers  * passed to it. The cpu_aggr_map is sorted with duplicate values removed.
975f50e15cSIan Rogers  */
985f50e15cSIan Rogers struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus,
995f50e15cSIan Rogers 				       aggr_cpu_id_get_t get_id,
1001fe7a300SJiri Olsa 				       void *data);
101e632aa69SJiri Olsa 
1023ac23d19SIan Rogers bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b);
10351b826faSIan Rogers bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a);
10451b826faSIan Rogers struct aggr_cpu_id aggr_cpu_id__empty(void);
105fa265e59SJames Clark 
106973aeb3cSIan Rogers 
107973aeb3cSIan Rogers /**
108973aeb3cSIan Rogers  * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated with
109973aeb3cSIan Rogers  * the socket for cpu. The function signature is compatible with
110973aeb3cSIan Rogers  * aggr_cpu_id_get_t.
111973aeb3cSIan Rogers  */
1126d18804bSIan Rogers struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data);
113973aeb3cSIan Rogers /**
114973aeb3cSIan Rogers  * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket populated
115973aeb3cSIan Rogers  * with the die and socket for cpu. The function signature is compatible with
116973aeb3cSIan Rogers  * aggr_cpu_id_get_t.
117973aeb3cSIan Rogers  */
1186d18804bSIan Rogers struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data);
119973aeb3cSIan Rogers /**
120973aeb3cSIan Rogers  * aggr_cpu_id__core - Create an aggr_cpu_id with the core, die and socket
121973aeb3cSIan Rogers  * populated with the core, die and socket for cpu. The function signature is
122973aeb3cSIan Rogers  * compatible with aggr_cpu_id_get_t.
123973aeb3cSIan Rogers  */
1246d18804bSIan Rogers struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data);
125973aeb3cSIan Rogers /**
12634794913SIan Rogers  * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and socket
12734794913SIan Rogers  * populated with the cpu, core, die and socket for cpu. The function signature
12834794913SIan Rogers  * is compatible with aggr_cpu_id_get_t.
12934794913SIan Rogers  */
1306d18804bSIan Rogers struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data);
13134794913SIan Rogers /**
132973aeb3cSIan Rogers  * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for
133973aeb3cSIan Rogers  * cpu. The function signature is compatible with aggr_cpu_id_get_t.
134973aeb3cSIan Rogers  */
1356d18804bSIan Rogers struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data);
136973aeb3cSIan Rogers 
137a12b51c4SPaul Mackerras #endif /* __PERF_CPUMAP_H */
138