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; 12*fcd83a35SJames Clark int node; 13fa265e59SJames Clark }; 14fa265e59SJames Clark 15cea6575fSJames Clark struct cpu_aggr_map { 16cea6575fSJames Clark refcount_t refcnt; 17cea6575fSJames Clark int nr; 18ff523295SJames Clark struct aggr_cpu_id map[]; 19cea6575fSJames Clark }; 20cea6575fSJames Clark 2172932371SJiri Olsa struct perf_record_cpu_map_data; 227780c25bSDon Zickus 23315c0a1fSJiri Olsa struct perf_cpu_map *perf_cpu_map__empty_new(int nr); 24cea6575fSJames Clark struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr); 25cea6575fSJames Clark 2672932371SJiri Olsa struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data); 27f854839bSJiri Olsa size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); 28f854839bSJiri Olsa size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size); 29f854839bSJiri Olsa size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); 30193b6bd3SKan Liang int cpu_map__get_socket_id(int cpu); 312760f5a1SJames Clark struct aggr_cpu_id cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data); 32b74d8686SKan Liang int cpu_map__get_die_id(int cpu); 332760f5a1SJames Clark struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data); 34193b6bd3SKan Liang int cpu_map__get_core_id(int cpu); 352760f5a1SJames Clark struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data); 3686895b48SJiri Olsa int cpu_map__get_node_id(int cpu); 372760f5a1SJames Clark struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, void *data); 38d526e1a0SJames Clark int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp); 39d526e1a0SJames Clark int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **diep); 40d526e1a0SJames Clark int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **corep); 41d526e1a0SJames Clark int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **nodep); 42f854839bSJiri Olsa const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ 435ac59a8aSStephane Eranian 44f854839bSJiri Olsa static inline int cpu_map__socket(struct perf_cpu_map *sock, int s) 455ac59a8aSStephane Eranian { 465ac59a8aSStephane Eranian if (!sock || s > sock->nr || s < 0) 475ac59a8aSStephane Eranian return 0; 485ac59a8aSStephane Eranian return sock->map[s]; 495ac59a8aSStephane Eranian } 509ae7d335SArnaldo Carvalho de Melo 5112c08a9fSStephane Eranian static inline int cpu_map__id_to_socket(int id) 5212c08a9fSStephane Eranian { 53db5742b6SKan Liang return id >> 24; 54db5742b6SKan Liang } 55db5742b6SKan Liang 56db5742b6SKan Liang static inline int cpu_map__id_to_die(int id) 57db5742b6SKan Liang { 58db5742b6SKan Liang return (id >> 16) & 0xff; 5912c08a9fSStephane Eranian } 6012c08a9fSStephane Eranian 6112c08a9fSStephane Eranian static inline int cpu_map__id_to_cpu(int id) 6212c08a9fSStephane Eranian { 6312c08a9fSStephane Eranian return id & 0xffff; 6412c08a9fSStephane Eranian } 6512c08a9fSStephane Eranian 667780c25bSDon Zickus int cpu__setup_cpunode_map(void); 677780c25bSDon Zickus 685ac76283SArnaldo Carvalho de Melo int cpu__max_node(void); 695ac76283SArnaldo Carvalho de Melo int cpu__max_cpu(void); 7092a7e127SJan Stancek int cpu__max_present_cpu(void); 715ac76283SArnaldo Carvalho de Melo int cpu__get_node(int cpu); 727780c25bSDon Zickus 73d526e1a0SJames Clark int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, 742760f5a1SJames Clark struct aggr_cpu_id (*f)(struct perf_cpu_map *map, int cpu, void *data), 751fe7a300SJiri Olsa void *data); 76e632aa69SJiri Olsa 77f854839bSJiri Olsa int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); 78f854839bSJiri Olsa bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); 79a8cbe40fSAndi Kleen 80fa265e59SJames Clark bool cpu_map__compare_aggr_cpu_id(struct aggr_cpu_id a, struct aggr_cpu_id b); 81fa265e59SJames Clark bool cpu_map__aggr_cpu_id_is_empty(struct aggr_cpu_id a); 82fa265e59SJames Clark struct aggr_cpu_id cpu_map__empty_aggr_cpu_id(void); 83fa265e59SJames Clark 84a12b51c4SPaul Mackerras #endif /* __PERF_CPUMAP_H */ 85