1 /* SPDX-License-Identifier: GPL-2.0 */ << 2 #ifndef __PERF_CPUMAP_H 1 #ifndef __PERF_CPUMAP_H 3 #define __PERF_CPUMAP_H 2 #define __PERF_CPUMAP_H 4 3 5 #include <stdbool.h> << 6 #include <stdio.h> 4 #include <stdio.h> 7 #include <perf/cpumap.h> !! 5 #include <stdbool.h> >> 6 #include <linux/atomic.h> 8 7 9 /** Identify where counts are aggregated, -1 i !! 8 #include "perf.h" 10 struct aggr_cpu_id { !! 9 #include "util/debug.h" 11 /** A value in the range 0 to number o << 12 int thread_idx; << 13 /** The numa node X as read from /sys/ << 14 int node; << 15 /** << 16 * The socket number as read from << 17 * /sys/devices/system/cpu/cpuX/topolo << 18 */ << 19 int socket; << 20 /** The die id as read from /sys/devic << 21 int die; << 22 /** The cluster id as read from /sys/d << 23 int cluster; << 24 /** The cache level as read from /sys/ << 25 int cache_lvl; << 26 /** << 27 * The cache instance ID, which is the << 28 * /sys/devices/system/cpu/cpuX/cache/ << 29 */ << 30 int cache; << 31 /** The core id as read from /sys/devi << 32 int core; << 33 /** CPU aggregation, note there is one << 34 struct perf_cpu cpu; << 35 }; << 36 10 37 /** A collection of aggr_cpu_id values, the "b !! 11 struct cpu_map { 38 struct cpu_aggr_map { !! 12 atomic_t refcnt; 39 /** Number of valid entries. */ << 40 int nr; 13 int nr; 41 /** The entries. */ !! 14 int map[]; 42 struct aggr_cpu_id map[]; << 43 }; 15 }; 44 16 45 #define cpu_aggr_map__for_each_idx(idx, aggr_m !! 17 struct cpu_map *cpu_map__new(const char *cpu_list); 46 for ((idx) = 0; (idx) < aggr_map->nr; !! 18 struct cpu_map *cpu_map__empty_new(int nr); >> 19 struct cpu_map *cpu_map__dummy_new(void); >> 20 struct cpu_map *cpu_map__read(FILE *file); >> 21 size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); >> 22 int cpu_map__get_socket_id(int cpu); >> 23 int cpu_map__get_socket(struct cpu_map *map, int idx, void *data); >> 24 int cpu_map__get_core_id(int cpu); >> 25 int cpu_map__get_core(struct cpu_map *map, int idx, void *data); >> 26 int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp); >> 27 int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep); >> 28 >> 29 struct cpu_map *cpu_map__get(struct cpu_map *map); >> 30 void cpu_map__put(struct cpu_map *map); >> 31 >> 32 static inline int cpu_map__socket(struct cpu_map *sock, int s) >> 33 { >> 34 if (!sock || s > sock->nr || s < 0) >> 35 return 0; >> 36 return sock->map[s]; >> 37 } >> 38 >> 39 static inline int cpu_map__id_to_socket(int id) >> 40 { >> 41 return id >> 16; >> 42 } 47 43 48 struct perf_record_cpu_map_data; !! 44 static inline int cpu_map__id_to_cpu(int id) >> 45 { >> 46 return id & 0xffff; >> 47 } 49 48 50 bool perf_record_cpu_map_data__test_bit(int i, !! 49 static inline int cpu_map__nr(const struct cpu_map *map) >> 50 { >> 51 return map ? map->nr : 1; >> 52 } 51 53 52 struct perf_cpu_map *perf_cpu_map__empty_new(i !! 54 static inline bool cpu_map__empty(const struct cpu_map *map) >> 55 { >> 56 return map ? map->map[0] == -1 : true; >> 57 } 53 58 54 struct perf_cpu_map *cpu_map__new_data(const s !! 59 int max_cpu_num; 55 size_t cpu_map__snprint(struct perf_cpu_map *m !! 60 int max_node_num; 56 size_t cpu_map__snprint_mask(struct perf_cpu_m !! 61 int *cpunode_map; 57 size_t cpu_map__fprintf(struct perf_cpu_map *m << 58 struct perf_cpu_map *cpu_map__online(void); /* << 59 62 60 int cpu__setup_cpunode_map(void); 63 int cpu__setup_cpunode_map(void); 61 64 62 int cpu__max_node(void); !! 65 static inline int cpu__max_node(void) 63 struct perf_cpu cpu__max_cpu(void); !! 66 { 64 struct perf_cpu cpu__max_present_cpu(void); !! 67 if (unlikely(!max_node_num)) 65 !! 68 pr_debug("cpu_map not initialized\n"); 66 /** !! 69 67 * cpu_map__is_dummy - Events associated with !! 70 return max_node_num; 68 */ !! 71 } 69 static inline bool cpu_map__is_dummy(const str !! 72 70 { !! 73 static inline int cpu__max_cpu(void) 71 return perf_cpu_map__nr(cpus) == 1 && !! 74 { 72 } !! 75 if (unlikely(!max_cpu_num)) 73 !! 76 pr_debug("cpu_map not initialized\n"); 74 /** !! 77 75 * cpu__get_node - Returns the numa node X as !! 78 return max_cpu_num; 76 * /sys/devices/system/node/nodeX for the give !! 79 } 77 */ !! 80 78 int cpu__get_node(struct perf_cpu cpu); !! 81 static inline int cpu__get_node(int cpu) 79 /** !! 82 { 80 * cpu__get_socket_id - Returns the socket num !! 83 if (unlikely(cpunode_map == NULL)) { 81 * /sys/devices/system/cpu/cpuX/topology/physi !! 84 pr_debug("cpu_map not initialized\n"); 82 */ !! 85 return -1; 83 int cpu__get_socket_id(struct perf_cpu cpu); !! 86 } 84 /** !! 87 85 * cpu__get_die_id - Returns the die id as rea !! 88 return cpunode_map[cpu]; 86 * /sys/devices/system/cpu/cpuX/topology/die_i !! 89 } 87 */ !! 90 88 int cpu__get_die_id(struct perf_cpu cpu); !! 91 int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, 89 /** !! 92 int (*f)(struct cpu_map *map, int cpu, void *data), 90 * cpu__get_cluster_id - Returns the cluster i !! 93 void *data); 91 * /sys/devices/system/cpu/cpuX/topology/clust << 92 */ << 93 int cpu__get_cluster_id(struct perf_cpu cpu); << 94 /** << 95 * cpu__get_core_id - Returns the core id as r << 96 * /sys/devices/system/cpu/cpuX/topology/core_ << 97 */ << 98 int cpu__get_core_id(struct perf_cpu cpu); << 99 << 100 /** << 101 * cpu_aggr_map__empty_new - Create a cpu_aggr << 102 * being empty. << 103 */ << 104 struct cpu_aggr_map *cpu_aggr_map__empty_new(i << 105 << 106 typedef struct aggr_cpu_id (*aggr_cpu_id_get_t << 107 << 108 /** << 109 * cpu_aggr_map__new - Create a cpu_aggr_map w << 110 * cpus. The aggr_cpu_id is created with 'get_ << 111 * passed to it. The cpu_aggr_map is sorted wi << 112 */ << 113 struct cpu_aggr_map *cpu_aggr_map__new(const s << 114 aggr_cp << 115 void *d << 116 << 117 bool aggr_cpu_id__equal(const struct aggr_cpu_ << 118 bool aggr_cpu_id__is_empty(const struct aggr_c << 119 struct aggr_cpu_id aggr_cpu_id__empty(void); << 120 << 121 << 122 /** << 123 * aggr_cpu_id__socket - Create an aggr_cpu_id << 124 * the socket for cpu. The function signature << 125 * aggr_cpu_id_get_t. << 126 */ << 127 struct aggr_cpu_id aggr_cpu_id__socket(struct << 128 /** << 129 * aggr_cpu_id__die - Create an aggr_cpu_id wi << 130 * with the die and socket for cpu. The functi << 131 * aggr_cpu_id_get_t. << 132 */ << 133 struct aggr_cpu_id aggr_cpu_id__die(struct per << 134 /** << 135 * aggr_cpu_id__cluster - Create an aggr_cpu_i << 136 * populated with the cluster, die and socket << 137 * is compatible with aggr_cpu_id_get_t. << 138 */ << 139 struct aggr_cpu_id aggr_cpu_id__cluster(struct << 140 /** << 141 * aggr_cpu_id__core - Create an aggr_cpu_id w << 142 * socket populated with the core, die and soc << 143 * signature is compatible with aggr_cpu_id_ge << 144 */ << 145 struct aggr_cpu_id aggr_cpu_id__core(struct pe << 146 /** << 147 * aggr_cpu_id__core - Create an aggr_cpu_id w << 148 * populated with the cpu, core, die and socke << 149 * is compatible with aggr_cpu_id_get_t. << 150 */ << 151 struct aggr_cpu_id aggr_cpu_id__cpu(struct per << 152 /** << 153 * aggr_cpu_id__node - Create an aggr_cpu_id w << 154 * cpu. The function signature is compatible w << 155 */ << 156 struct aggr_cpu_id aggr_cpu_id__node(struct pe << 157 /** << 158 * aggr_cpu_id__global - Create an aggr_cpu_id << 159 * The function signature is compatible with a << 160 */ << 161 struct aggr_cpu_id aggr_cpu_id__global(struct << 162 #endif /* __PERF_CPUMAP_H */ 94 #endif /* __PERF_CPUMAP_H */ 163 95
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.