xref: /linux/tools/perf/util/cpumap.h (revision a8cbe40fe9f4ba499cc60b8b6a6851c2c1963797)
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 
1072932371SJiri Olsa struct perf_record_cpu_map_data;
117780c25bSDon Zickus 
12315c0a1fSJiri Olsa struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
1372932371SJiri Olsa struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data);
14f854839bSJiri Olsa size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
15f854839bSJiri Olsa size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
16f854839bSJiri Olsa size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
17193b6bd3SKan Liang int cpu_map__get_socket_id(int cpu);
18f854839bSJiri Olsa int cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data);
19b74d8686SKan Liang int cpu_map__get_die_id(int cpu);
20f854839bSJiri Olsa int cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data);
21193b6bd3SKan Liang int cpu_map__get_core_id(int cpu);
22f854839bSJiri Olsa int cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data);
2386895b48SJiri Olsa int cpu_map__get_node_id(int cpu);
2486895b48SJiri Olsa int cpu_map__get_node(struct perf_cpu_map *map, int idx, void *data);
25f854839bSJiri Olsa int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct perf_cpu_map **sockp);
26f854839bSJiri Olsa int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct perf_cpu_map **diep);
27f854839bSJiri Olsa int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct perf_cpu_map **corep);
2886895b48SJiri Olsa int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct perf_cpu_map **nodep);
29f854839bSJiri Olsa const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
305ac59a8aSStephane Eranian 
31f854839bSJiri Olsa static inline int cpu_map__socket(struct perf_cpu_map *sock, int s)
325ac59a8aSStephane Eranian {
335ac59a8aSStephane Eranian 	if (!sock || s > sock->nr || s < 0)
345ac59a8aSStephane Eranian 		return 0;
355ac59a8aSStephane Eranian 	return sock->map[s];
365ac59a8aSStephane Eranian }
379ae7d335SArnaldo Carvalho de Melo 
3812c08a9fSStephane Eranian static inline int cpu_map__id_to_socket(int id)
3912c08a9fSStephane Eranian {
40db5742b6SKan Liang 	return id >> 24;
41db5742b6SKan Liang }
42db5742b6SKan Liang 
43db5742b6SKan Liang static inline int cpu_map__id_to_die(int id)
44db5742b6SKan Liang {
45db5742b6SKan Liang 	return (id >> 16) & 0xff;
4612c08a9fSStephane Eranian }
4712c08a9fSStephane Eranian 
4812c08a9fSStephane Eranian static inline int cpu_map__id_to_cpu(int id)
4912c08a9fSStephane Eranian {
5012c08a9fSStephane Eranian 	return id & 0xffff;
5112c08a9fSStephane Eranian }
5212c08a9fSStephane Eranian 
537780c25bSDon Zickus int cpu__setup_cpunode_map(void);
547780c25bSDon Zickus 
555ac76283SArnaldo Carvalho de Melo int cpu__max_node(void);
565ac76283SArnaldo Carvalho de Melo int cpu__max_cpu(void);
5792a7e127SJan Stancek int cpu__max_present_cpu(void);
585ac76283SArnaldo Carvalho de Melo int cpu__get_node(int cpu);
597780c25bSDon Zickus 
60f854839bSJiri Olsa int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,
61f854839bSJiri Olsa 		       int (*f)(struct perf_cpu_map *map, int cpu, void *data),
621fe7a300SJiri Olsa 		       void *data);
63e632aa69SJiri Olsa 
64f854839bSJiri Olsa int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
65f854839bSJiri Olsa bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
66*a8cbe40fSAndi Kleen 
67a12b51c4SPaul Mackerras #endif /* __PERF_CPUMAP_H */
68