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