Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Paul Mackerras | a12b51c | 2010-03-10 20:36:09 +1100 | [diff] [blame] | 2 | #ifndef __PERF_CPUMAP_H |
| 3 | #define __PERF_CPUMAP_H |
| 4 | |
Arnaldo Carvalho de Melo | 9ae7d33 | 2012-01-19 14:07:23 -0200 | [diff] [blame] | 5 | #include <stdio.h> |
Arnaldo Carvalho de Melo | a14bb7a | 2012-09-26 12:41:14 -0300 | [diff] [blame] | 6 | #include <stdbool.h> |
Elena Reshetova | ec09a42 | 2017-02-21 17:34:56 +0200 | [diff] [blame] | 7 | #include <linux/refcount.h> |
Jiri Olsa | 959b83c | 2019-07-21 13:24:15 +0200 | [diff] [blame] | 8 | #include <internal/cpumap.h> |
Jiri Olsa | 397721e | 2019-07-21 13:24:16 +0200 | [diff] [blame] | 9 | #include <perf/cpumap.h> |
Arnaldo Carvalho de Melo | 9ae7d33 | 2012-01-19 14:07:23 -0200 | [diff] [blame] | 10 | |
Don Zickus | 7780c25 | 2014-04-07 14:55:21 -0400 | [diff] [blame] | 11 | #include "perf.h" |
| 12 | #include "util/debug.h" |
| 13 | |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 14 | struct perf_cpu_map *cpu_map__new(const char *cpu_list); |
| 15 | struct perf_cpu_map *cpu_map__empty_new(int nr); |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 16 | struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data); |
| 17 | struct perf_cpu_map *cpu_map__read(FILE *file); |
| 18 | size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); |
| 19 | size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size); |
| 20 | size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); |
Kan Liang | 193b6bd | 2015-09-01 09:58:11 -0400 | [diff] [blame] | 21 | int cpu_map__get_socket_id(int cpu); |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 22 | int cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data); |
Kan Liang | b74d868 | 2019-06-04 15:50:40 -0700 | [diff] [blame] | 23 | int cpu_map__get_die_id(int cpu); |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 24 | int cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data); |
Kan Liang | 193b6bd | 2015-09-01 09:58:11 -0400 | [diff] [blame] | 25 | int cpu_map__get_core_id(int cpu); |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 26 | int cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data); |
| 27 | int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct perf_cpu_map **sockp); |
| 28 | int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct perf_cpu_map **diep); |
| 29 | int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct perf_cpu_map **corep); |
| 30 | const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ |
Stephane Eranian | 5ac59a8 | 2013-02-06 15:46:01 +0100 | [diff] [blame] | 31 | |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 32 | static inline int cpu_map__socket(struct perf_cpu_map *sock, int s) |
Stephane Eranian | 5ac59a8 | 2013-02-06 15:46:01 +0100 | [diff] [blame] | 33 | { |
| 34 | if (!sock || s > sock->nr || s < 0) |
| 35 | return 0; |
| 36 | return sock->map[s]; |
| 37 | } |
Arnaldo Carvalho de Melo | 9ae7d33 | 2012-01-19 14:07:23 -0200 | [diff] [blame] | 38 | |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 39 | static inline int cpu_map__id_to_socket(int id) |
| 40 | { |
Kan Liang | db5742b | 2019-06-04 15:50:42 -0700 | [diff] [blame] | 41 | return id >> 24; |
| 42 | } |
| 43 | |
| 44 | static inline int cpu_map__id_to_die(int id) |
| 45 | { |
| 46 | return (id >> 16) & 0xff; |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static inline int cpu_map__id_to_cpu(int id) |
| 50 | { |
| 51 | return id & 0xffff; |
| 52 | } |
| 53 | |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 54 | static inline int cpu_map__nr(const struct perf_cpu_map *map) |
Arnaldo Carvalho de Melo | a14bb7a | 2012-09-26 12:41:14 -0300 | [diff] [blame] | 55 | { |
| 56 | return map ? map->nr : 1; |
| 57 | } |
| 58 | |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 59 | static inline bool cpu_map__empty(const struct perf_cpu_map *map) |
Arnaldo Carvalho de Melo | a14bb7a | 2012-09-26 12:41:14 -0300 | [diff] [blame] | 60 | { |
| 61 | return map ? map->map[0] == -1 : true; |
| 62 | } |
| 63 | |
Don Zickus | 7780c25 | 2014-04-07 14:55:21 -0400 | [diff] [blame] | 64 | int cpu__setup_cpunode_map(void); |
| 65 | |
Arnaldo Carvalho de Melo | 5ac7628 | 2016-01-26 15:51:46 -0300 | [diff] [blame] | 66 | int cpu__max_node(void); |
| 67 | int cpu__max_cpu(void); |
Jan Stancek | 92a7e12 | 2017-02-17 12:10:24 +0100 | [diff] [blame] | 68 | int cpu__max_present_cpu(void); |
Arnaldo Carvalho de Melo | 5ac7628 | 2016-01-26 15:51:46 -0300 | [diff] [blame] | 69 | int cpu__get_node(int cpu); |
Don Zickus | 7780c25 | 2014-04-07 14:55:21 -0400 | [diff] [blame] | 70 | |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 71 | int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res, |
| 72 | int (*f)(struct perf_cpu_map *map, int cpu, void *data), |
Jiri Olsa | 1fe7a30 | 2015-10-16 12:41:15 +0200 | [diff] [blame] | 73 | void *data); |
Jiri Olsa | e632aa6 | 2016-04-12 15:29:25 +0200 | [diff] [blame] | 74 | |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 75 | int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); |
| 76 | bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); |
| 77 | int cpu_map__idx(struct perf_cpu_map *cpus, int cpu); |
Paul Mackerras | a12b51c | 2010-03-10 20:36:09 +1100 | [diff] [blame] | 78 | #endif /* __PERF_CPUMAP_H */ |