1a12b51c4SPaul Mackerras #ifndef __PERF_CPUMAP_H 2a12b51c4SPaul Mackerras #define __PERF_CPUMAP_H 3a12b51c4SPaul Mackerras 49ae7d335SArnaldo Carvalho de Melo #include <stdio.h> 5a14bb7a6SArnaldo Carvalho de Melo #include <stdbool.h> 6f30a79b0SJiri Olsa #include <linux/atomic.h> 79ae7d335SArnaldo Carvalho de Melo 87780c25bSDon Zickus #include "perf.h" 97780c25bSDon Zickus #include "util/debug.h" 107780c25bSDon Zickus 1160d567e2SArnaldo Carvalho de Melo struct cpu_map { 12f30a79b0SJiri Olsa atomic_t refcnt; 1360d567e2SArnaldo Carvalho de Melo int nr; 1460d567e2SArnaldo Carvalho de Melo int map[]; 1560d567e2SArnaldo Carvalho de Melo }; 1660d567e2SArnaldo Carvalho de Melo 1760d567e2SArnaldo Carvalho de Melo struct cpu_map *cpu_map__new(const char *cpu_list); 1860d567e2SArnaldo Carvalho de Melo struct cpu_map *cpu_map__dummy_new(void); 197ae92e74SYan, Zheng struct cpu_map *cpu_map__read(FILE *file); 209ae7d335SArnaldo Carvalho de Melo size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); 21193b6bd3SKan Liang int cpu_map__get_socket_id(int cpu); 22*1fe7a300SJiri Olsa int cpu_map__get_socket(struct cpu_map *map, int idx, void *data); 23193b6bd3SKan Liang int cpu_map__get_core_id(int cpu); 24*1fe7a300SJiri Olsa int cpu_map__get_core(struct cpu_map *map, int idx, void *data); 255ac59a8aSStephane Eranian int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp); 2612c08a9fSStephane Eranian int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep); 275ac59a8aSStephane Eranian 28f30a79b0SJiri Olsa struct cpu_map *cpu_map__get(struct cpu_map *map); 29f30a79b0SJiri Olsa void cpu_map__put(struct cpu_map *map); 30f30a79b0SJiri Olsa 315ac59a8aSStephane Eranian static inline int cpu_map__socket(struct 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 { 4012c08a9fSStephane Eranian return id >> 16; 4112c08a9fSStephane Eranian } 4212c08a9fSStephane Eranian 4312c08a9fSStephane Eranian static inline int cpu_map__id_to_cpu(int id) 4412c08a9fSStephane Eranian { 4512c08a9fSStephane Eranian return id & 0xffff; 4612c08a9fSStephane Eranian } 4712c08a9fSStephane Eranian 48a14bb7a6SArnaldo Carvalho de Melo static inline int cpu_map__nr(const struct cpu_map *map) 49a14bb7a6SArnaldo Carvalho de Melo { 50a14bb7a6SArnaldo Carvalho de Melo return map ? map->nr : 1; 51a14bb7a6SArnaldo Carvalho de Melo } 52a14bb7a6SArnaldo Carvalho de Melo 53ec1e7e43SSukadev Bhattiprolu static inline bool cpu_map__empty(const struct cpu_map *map) 54a14bb7a6SArnaldo Carvalho de Melo { 55a14bb7a6SArnaldo Carvalho de Melo return map ? map->map[0] == -1 : true; 56a14bb7a6SArnaldo Carvalho de Melo } 57a14bb7a6SArnaldo Carvalho de Melo 587780c25bSDon Zickus int max_cpu_num; 597780c25bSDon Zickus int max_node_num; 607780c25bSDon Zickus int *cpunode_map; 617780c25bSDon Zickus 627780c25bSDon Zickus int cpu__setup_cpunode_map(void); 637780c25bSDon Zickus 647780c25bSDon Zickus static inline int cpu__max_node(void) 657780c25bSDon Zickus { 667780c25bSDon Zickus if (unlikely(!max_node_num)) 677780c25bSDon Zickus pr_debug("cpu_map not initialized\n"); 687780c25bSDon Zickus 697780c25bSDon Zickus return max_node_num; 707780c25bSDon Zickus } 717780c25bSDon Zickus 727780c25bSDon Zickus static inline int cpu__max_cpu(void) 737780c25bSDon Zickus { 747780c25bSDon Zickus if (unlikely(!max_cpu_num)) 757780c25bSDon Zickus pr_debug("cpu_map not initialized\n"); 767780c25bSDon Zickus 777780c25bSDon Zickus return max_cpu_num; 787780c25bSDon Zickus } 797780c25bSDon Zickus 807780c25bSDon Zickus static inline int cpu__get_node(int cpu) 817780c25bSDon Zickus { 827780c25bSDon Zickus if (unlikely(cpunode_map == NULL)) { 837780c25bSDon Zickus pr_debug("cpu_map not initialized\n"); 847780c25bSDon Zickus return -1; 857780c25bSDon Zickus } 867780c25bSDon Zickus 877780c25bSDon Zickus return cpunode_map[cpu]; 887780c25bSDon Zickus } 897780c25bSDon Zickus 90f1cbb8f3SJiri Olsa int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, 91*1fe7a300SJiri Olsa int (*f)(struct cpu_map *map, int cpu, void *data), 92*1fe7a300SJiri Olsa void *data); 93a12b51c4SPaul Mackerras #endif /* __PERF_CPUMAP_H */ 94