xref: /OK3568_Linux_fs/kernel/tools/perf/util/cpumap.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __PERF_CPUMAP_H
3*4882a593Smuzhiyun #define __PERF_CPUMAP_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <stdio.h>
6*4882a593Smuzhiyun #include <stdbool.h>
7*4882a593Smuzhiyun #include <internal/cpumap.h>
8*4882a593Smuzhiyun #include <perf/cpumap.h>
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun struct perf_record_cpu_map_data;
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
13*4882a593Smuzhiyun struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data);
14*4882a593Smuzhiyun size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
15*4882a593Smuzhiyun size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
16*4882a593Smuzhiyun size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
17*4882a593Smuzhiyun int cpu_map__get_socket_id(int cpu);
18*4882a593Smuzhiyun int cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data);
19*4882a593Smuzhiyun int cpu_map__get_die_id(int cpu);
20*4882a593Smuzhiyun int cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data);
21*4882a593Smuzhiyun int cpu_map__get_core_id(int cpu);
22*4882a593Smuzhiyun int cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data);
23*4882a593Smuzhiyun int cpu_map__get_node_id(int cpu);
24*4882a593Smuzhiyun int cpu_map__get_node(struct perf_cpu_map *map, int idx, void *data);
25*4882a593Smuzhiyun int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct perf_cpu_map **sockp);
26*4882a593Smuzhiyun int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct perf_cpu_map **diep);
27*4882a593Smuzhiyun int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct perf_cpu_map **corep);
28*4882a593Smuzhiyun int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct perf_cpu_map **nodep);
29*4882a593Smuzhiyun const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
30*4882a593Smuzhiyun 
cpu_map__socket(struct perf_cpu_map * sock,int s)31*4882a593Smuzhiyun static inline int cpu_map__socket(struct perf_cpu_map *sock, int s)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	if (!sock || s > sock->nr || s < 0)
34*4882a593Smuzhiyun 		return 0;
35*4882a593Smuzhiyun 	return sock->map[s];
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun 
cpu_map__id_to_socket(int id)38*4882a593Smuzhiyun static inline int cpu_map__id_to_socket(int id)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	return id >> 24;
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun 
cpu_map__id_to_die(int id)43*4882a593Smuzhiyun static inline int cpu_map__id_to_die(int id)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun 	return (id >> 16) & 0xff;
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun 
cpu_map__id_to_cpu(int id)48*4882a593Smuzhiyun static inline int cpu_map__id_to_cpu(int id)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun 	return id & 0xffff;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun int cpu__setup_cpunode_map(void);
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun int cpu__max_node(void);
56*4882a593Smuzhiyun int cpu__max_cpu(void);
57*4882a593Smuzhiyun int cpu__max_present_cpu(void);
58*4882a593Smuzhiyun int cpu__get_node(int cpu);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,
61*4882a593Smuzhiyun 		       int (*f)(struct perf_cpu_map *map, int cpu, void *data),
62*4882a593Smuzhiyun 		       void *data);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
65*4882a593Smuzhiyun bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #endif /* __PERF_CPUMAP_H */
68