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 <linux/refcount.h> 8 #include <internal/cpumap.h> 9 #include <perf/cpumap.h> 10 11 #include "perf.h" 12 #include "util/debug.h" 13 14 struct perf_cpu_map *cpu_map__empty_new(int nr); 15 struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data); 16 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); 17 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size); 18 size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); 19 int cpu_map__get_socket_id(int cpu); 20 int cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data); 21 int cpu_map__get_die_id(int cpu); 22 int cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data); 23 int cpu_map__get_core_id(int cpu); 24 int cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data); 25 int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct perf_cpu_map **sockp); 26 int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct perf_cpu_map **diep); 27 int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct perf_cpu_map **corep); 28 const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ 29 30 static inline int cpu_map__socket(struct perf_cpu_map *sock, int s) 31 { 32 if (!sock || s > sock->nr || s < 0) 33 return 0; 34 return sock->map[s]; 35 } 36 37 static inline int cpu_map__id_to_socket(int id) 38 { 39 return id >> 24; 40 } 41 42 static inline int cpu_map__id_to_die(int id) 43 { 44 return (id >> 16) & 0xff; 45 } 46 47 static inline int cpu_map__id_to_cpu(int id) 48 { 49 return id & 0xffff; 50 } 51 52 static inline int cpu_map__nr(const struct perf_cpu_map *map) 53 { 54 return map ? map->nr : 1; 55 } 56 57 static inline bool cpu_map__empty(const struct perf_cpu_map *map) 58 { 59 return map ? map->map[0] == -1 : true; 60 } 61 62 int cpu__setup_cpunode_map(void); 63 64 int cpu__max_node(void); 65 int cpu__max_cpu(void); 66 int cpu__max_present_cpu(void); 67 int cpu__get_node(int cpu); 68 69 int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res, 70 int (*f)(struct perf_cpu_map *map, int cpu, void *data), 71 void *data); 72 73 int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); 74 bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); 75 int cpu_map__idx(struct perf_cpu_map *cpus, int cpu); 76 #endif /* __PERF_CPUMAP_H */ 77