xref: /linux/tools/perf/util/cpumap.h (revision d526e1a033e03ec4515b1800f99d99a35c7ea790)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2a12b51c4SPaul Mackerras #ifndef __PERF_CPUMAP_H
3a12b51c4SPaul Mackerras #define __PERF_CPUMAP_H
4a12b51c4SPaul Mackerras 
59ae7d335SArnaldo Carvalho de Melo #include <stdio.h>
6a14bb7a6SArnaldo Carvalho de Melo #include <stdbool.h>
7959b83c7SJiri Olsa #include <internal/cpumap.h>
8397721e0SJiri Olsa #include <perf/cpumap.h>
99ae7d335SArnaldo Carvalho de Melo 
10fa265e59SJames Clark struct aggr_cpu_id {
11fa265e59SJames Clark 	int id;
12fa265e59SJames Clark };
13fa265e59SJames Clark 
14cea6575fSJames Clark struct cpu_aggr_map {
15cea6575fSJames Clark 	refcount_t refcnt;
16cea6575fSJames Clark 	int nr;
17cea6575fSJames Clark 	int map[];
18cea6575fSJames Clark };
19cea6575fSJames Clark 
2072932371SJiri Olsa struct perf_record_cpu_map_data;
217780c25bSDon Zickus 
22315c0a1fSJiri Olsa struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
23cea6575fSJames Clark struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr);
24cea6575fSJames Clark 
2572932371SJiri Olsa struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data);
26f854839bSJiri Olsa size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
27f854839bSJiri Olsa size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
28f854839bSJiri Olsa size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
29193b6bd3SKan Liang int cpu_map__get_socket_id(int cpu);
302760f5a1SJames Clark struct aggr_cpu_id cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data);
31b74d8686SKan Liang int cpu_map__get_die_id(int cpu);
322760f5a1SJames Clark struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data);
33193b6bd3SKan Liang int cpu_map__get_core_id(int cpu);
342760f5a1SJames Clark struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data);
3586895b48SJiri Olsa int cpu_map__get_node_id(int cpu);
362760f5a1SJames Clark struct aggr_cpu_id  cpu_map__get_node(struct perf_cpu_map *map, int idx, void *data);
37*d526e1a0SJames Clark int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp);
38*d526e1a0SJames Clark int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **diep);
39*d526e1a0SJames Clark int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **corep);
40*d526e1a0SJames Clark int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **nodep);
41f854839bSJiri Olsa const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
425ac59a8aSStephane Eranian 
43f854839bSJiri Olsa static inline int cpu_map__socket(struct perf_cpu_map *sock, int s)
445ac59a8aSStephane Eranian {
455ac59a8aSStephane Eranian 	if (!sock || s > sock->nr || s < 0)
465ac59a8aSStephane Eranian 		return 0;
475ac59a8aSStephane Eranian 	return sock->map[s];
485ac59a8aSStephane Eranian }
499ae7d335SArnaldo Carvalho de Melo 
5012c08a9fSStephane Eranian static inline int cpu_map__id_to_socket(int id)
5112c08a9fSStephane Eranian {
52db5742b6SKan Liang 	return id >> 24;
53db5742b6SKan Liang }
54db5742b6SKan Liang 
55db5742b6SKan Liang static inline int cpu_map__id_to_die(int id)
56db5742b6SKan Liang {
57db5742b6SKan Liang 	return (id >> 16) & 0xff;
5812c08a9fSStephane Eranian }
5912c08a9fSStephane Eranian 
6012c08a9fSStephane Eranian static inline int cpu_map__id_to_cpu(int id)
6112c08a9fSStephane Eranian {
6212c08a9fSStephane Eranian 	return id & 0xffff;
6312c08a9fSStephane Eranian }
6412c08a9fSStephane Eranian 
657780c25bSDon Zickus int cpu__setup_cpunode_map(void);
667780c25bSDon Zickus 
675ac76283SArnaldo Carvalho de Melo int cpu__max_node(void);
685ac76283SArnaldo Carvalho de Melo int cpu__max_cpu(void);
6992a7e127SJan Stancek int cpu__max_present_cpu(void);
705ac76283SArnaldo Carvalho de Melo int cpu__get_node(int cpu);
717780c25bSDon Zickus 
72*d526e1a0SJames Clark int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res,
732760f5a1SJames Clark 		       struct aggr_cpu_id (*f)(struct perf_cpu_map *map, int cpu, void *data),
741fe7a300SJiri Olsa 		       void *data);
75e632aa69SJiri Olsa 
76f854839bSJiri Olsa int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
77f854839bSJiri Olsa bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
78a8cbe40fSAndi Kleen 
79fa265e59SJames Clark bool cpu_map__compare_aggr_cpu_id(struct aggr_cpu_id a, struct aggr_cpu_id b);
80fa265e59SJames Clark bool cpu_map__aggr_cpu_id_is_empty(struct aggr_cpu_id a);
81fa265e59SJames Clark struct aggr_cpu_id cpu_map__empty_aggr_cpu_id(void);
82fa265e59SJames Clark 
83a12b51c4SPaul Mackerras #endif /* __PERF_CPUMAP_H */
84