Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 2 | #ifndef __PERF_ENV_H |
| 3 | #define __PERF_ENV_H |
| 4 | |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 5 | #include <linux/types.h> |
Song Liu | e4378f0 | 2019-03-11 22:30:42 -0700 | [diff] [blame] | 6 | #include <linux/rbtree.h> |
Song Liu | e4378f0 | 2019-03-11 22:30:42 -0700 | [diff] [blame] | 7 | #include "rwsem.h" |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 8 | |
Arnaldo Carvalho de Melo | 87ffb6c | 2019-09-10 16:29:02 +0100 | [diff] [blame] | 9 | struct perf_cpu_map; |
| 10 | |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 11 | struct cpu_topology_map { |
| 12 | int socket_id; |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 13 | int die_id; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 14 | int core_id; |
| 15 | }; |
| 16 | |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 17 | struct cpu_cache_level { |
| 18 | u32 level; |
| 19 | u32 line_size; |
| 20 | u32 sets; |
| 21 | u32 ways; |
| 22 | char *type; |
| 23 | char *size; |
| 24 | char *map; |
| 25 | }; |
| 26 | |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 27 | struct numa_node { |
| 28 | u32 node; |
| 29 | u64 mem_total; |
| 30 | u64 mem_free; |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 31 | struct perf_cpu_map *map; |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 34 | struct memory_node { |
| 35 | u64 node; |
| 36 | u64 size; |
| 37 | unsigned long *set; |
| 38 | }; |
| 39 | |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 40 | struct perf_env { |
| 41 | char *hostname; |
| 42 | char *os_release; |
| 43 | char *version; |
| 44 | char *arch; |
| 45 | int nr_cpus_online; |
| 46 | int nr_cpus_avail; |
| 47 | char *cpu_desc; |
| 48 | char *cpuid; |
| 49 | unsigned long long total_mem; |
Kan Liang | e0838e0 | 2015-09-10 11:03:05 -0300 | [diff] [blame] | 50 | unsigned int msr_pmu_type; |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 51 | unsigned int max_branches; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 52 | |
| 53 | int nr_cmdline; |
| 54 | int nr_sibling_cores; |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 55 | int nr_sibling_dies; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 56 | int nr_sibling_threads; |
| 57 | int nr_numa_nodes; |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 58 | int nr_memory_nodes; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 59 | int nr_pmu_mappings; |
| 60 | int nr_groups; |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 61 | int nr_cpu_pmu_caps; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 62 | char *cmdline; |
| 63 | const char **cmdline_argv; |
| 64 | char *sibling_cores; |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 65 | char *sibling_dies; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 66 | char *sibling_threads; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 67 | char *pmu_mappings; |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 68 | char *cpu_pmu_caps; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 69 | struct cpu_topology_map *cpu; |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 70 | struct cpu_cache_level *caches; |
| 71 | int caches_cnt; |
Alexey Budankov | d3c8c08 | 2019-03-18 20:41:02 +0300 | [diff] [blame] | 72 | u32 comp_ratio; |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 73 | u32 comp_ver; |
| 74 | u32 comp_type; |
| 75 | u32 comp_level; |
| 76 | u32 comp_mmap_len; |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 77 | struct numa_node *numa_nodes; |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 78 | struct memory_node *memory_nodes; |
| 79 | unsigned long long memory_bsize; |
Song Liu | e4378f0 | 2019-03-11 22:30:42 -0700 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * bpf_info_lock protects bpf rbtrees. This is needed because the |
| 83 | * trees are accessed by different threads in perf-top |
| 84 | */ |
| 85 | struct { |
| 86 | struct rw_semaphore lock; |
| 87 | struct rb_root infos; |
| 88 | u32 infos_cnt; |
Song Liu | 3792cb2 | 2019-03-11 22:30:44 -0700 | [diff] [blame] | 89 | struct rb_root btfs; |
| 90 | u32 btfs_cnt; |
Song Liu | e4378f0 | 2019-03-11 22:30:42 -0700 | [diff] [blame] | 91 | } bpf_progs; |
Jiri Olsa | 389799a | 2019-08-29 13:31:48 +0200 | [diff] [blame] | 92 | |
Namhyung Kim | d1277aa | 2020-03-25 21:45:31 +0900 | [diff] [blame] | 93 | /* same reason as above (for perf-top) */ |
| 94 | struct { |
| 95 | struct rw_semaphore lock; |
| 96 | struct rb_root tree; |
| 97 | } cgroups; |
| 98 | |
Jiri Olsa | 389799a | 2019-08-29 13:31:48 +0200 | [diff] [blame] | 99 | /* For fast cpu to numa node lookup via perf_env__numa_node */ |
| 100 | int *numa_map; |
| 101 | int nr_numa_map; |
Jiri Olsa | d1e325c | 2020-08-05 11:34:40 +0200 | [diff] [blame] | 102 | |
| 103 | /* For real clock time reference. */ |
| 104 | struct { |
| 105 | u64 tod_ns; |
| 106 | u64 clockid_ns; |
Jiri Olsa | 9d88a1a1 | 2020-08-05 11:34:41 +0200 | [diff] [blame] | 107 | u64 clockid_res_ns; |
Jiri Olsa | d1e325c | 2020-08-05 11:34:40 +0200 | [diff] [blame] | 108 | int clockid; |
| 109 | /* |
| 110 | * enabled is valid for report mode, and is true if above |
| 111 | * values are set, it's set in process_clock_data |
| 112 | */ |
| 113 | bool enabled; |
| 114 | } clock; |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 115 | }; |
| 116 | |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 117 | enum perf_compress_type { |
| 118 | PERF_COMP_NONE = 0, |
| 119 | PERF_COMP_ZSTD, |
| 120 | PERF_COMP_MAX |
| 121 | }; |
| 122 | |
Song Liu | e4378f0 | 2019-03-11 22:30:42 -0700 | [diff] [blame] | 123 | struct bpf_prog_info_node; |
Song Liu | 3792cb2 | 2019-03-11 22:30:44 -0700 | [diff] [blame] | 124 | struct btf_node; |
Song Liu | e4378f0 | 2019-03-11 22:30:42 -0700 | [diff] [blame] | 125 | |
Arnaldo Carvalho de Melo | b699869 | 2015-09-08 16:58:20 -0300 | [diff] [blame] | 126 | extern struct perf_env perf_env; |
| 127 | |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 128 | void perf_env__exit(struct perf_env *env); |
| 129 | |
Arnaldo Carvalho de Melo | b699869 | 2015-09-08 16:58:20 -0300 | [diff] [blame] | 130 | int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]); |
| 131 | |
Arnaldo Carvalho de Melo | f1cedfb | 2019-09-30 11:50:15 -0300 | [diff] [blame] | 132 | int perf_env__read_cpuid(struct perf_env *env); |
Arnaldo Carvalho de Melo | aa36ddd | 2015-09-09 10:37:01 -0300 | [diff] [blame] | 133 | int perf_env__read_cpu_topology_map(struct perf_env *env); |
| 134 | |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 135 | void cpu_cache_level__free(struct cpu_cache_level *cache); |
Arnaldo Carvalho de Melo | 4e8fbc1 | 2017-12-11 14:47:49 -0300 | [diff] [blame] | 136 | |
| 137 | const char *perf_env__arch(struct perf_env *env); |
Adrian Hunter | dbbd34a | 2018-05-17 12:21:53 +0300 | [diff] [blame] | 138 | const char *perf_env__raw_arch(struct perf_env *env); |
Adrian Hunter | 9cecca3 | 2018-05-22 13:54:32 +0300 | [diff] [blame] | 139 | int perf_env__nr_cpus_avail(struct perf_env *env); |
Adrian Hunter | dbbd34a | 2018-05-17 12:21:53 +0300 | [diff] [blame] | 140 | |
Song Liu | e4378f0 | 2019-03-11 22:30:42 -0700 | [diff] [blame] | 141 | void perf_env__init(struct perf_env *env); |
| 142 | void perf_env__insert_bpf_prog_info(struct perf_env *env, |
| 143 | struct bpf_prog_info_node *info_node); |
| 144 | struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env, |
| 145 | __u32 prog_id); |
Song Liu | 3792cb2 | 2019-03-11 22:30:44 -0700 | [diff] [blame] | 146 | void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node); |
| 147 | struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id); |
Jiri Olsa | 389799a | 2019-08-29 13:31:48 +0200 | [diff] [blame] | 148 | |
| 149 | int perf_env__numa_node(struct perf_env *env, int cpu); |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 150 | #endif /* __PERF_ENV_H */ |