blob: 1383876f72b3773628b690145b012489643423d6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -03002#ifndef __PERF_ENV_H
3#define __PERF_ENV_H
4
Jiri Olsa720e98b2016-02-16 16:01:43 +01005#include <linux/types.h>
Song Liue4378f02019-03-11 22:30:42 -07006#include <linux/rbtree.h>
Song Liue4378f02019-03-11 22:30:42 -07007#include "rwsem.h"
Jiri Olsa720e98b2016-02-16 16:01:43 +01008
Arnaldo Carvalho de Melo87ffb6c2019-09-10 16:29:02 +01009struct perf_cpu_map;
10
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030011struct cpu_topology_map {
12 int socket_id;
Kan Liangacae8b32019-06-04 15:50:41 -070013 int die_id;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030014 int core_id;
15};
16
Jiri Olsa720e98b2016-02-16 16:01:43 +010017struct 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 Olsac60da222016-07-04 14:16:20 +020027struct numa_node {
28 u32 node;
29 u64 mem_total;
30 u64 mem_free;
Jiri Olsaf8548392019-07-21 13:23:49 +020031 struct perf_cpu_map *map;
Jiri Olsac60da222016-07-04 14:16:20 +020032};
33
Jiri Olsae2091ce2018-03-07 16:50:08 +010034struct memory_node {
35 u64 node;
36 u64 size;
37 unsigned long *set;
38};
39
Jin Yaof7d74ce2021-05-14 20:29:47 +080040struct hybrid_node {
41 char *pmu_name;
42 char *cpus;
43};
44
Jin Yaoe1190832021-05-14 20:29:48 +080045struct hybrid_cpc_node {
46 int nr_cpu_pmu_caps;
47 unsigned int max_branches;
48 char *cpu_pmu_caps;
49 char *pmu_name;
50};
51
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030052struct perf_env {
53 char *hostname;
54 char *os_release;
55 char *version;
56 char *arch;
57 int nr_cpus_online;
58 int nr_cpus_avail;
59 char *cpu_desc;
60 char *cpuid;
61 unsigned long long total_mem;
Kan Liange0838e02015-09-10 11:03:05 -030062 unsigned int msr_pmu_type;
Kan Liang6f91ea22020-03-19 13:25:02 -070063 unsigned int max_branches;
Leo Yan7c0223e2021-08-09 19:27:25 +080064 int kernel_is_64_bit;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030065
66 int nr_cmdline;
67 int nr_sibling_cores;
Kan Liangacae8b32019-06-04 15:50:41 -070068 int nr_sibling_dies;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030069 int nr_sibling_threads;
70 int nr_numa_nodes;
Jiri Olsae2091ce2018-03-07 16:50:08 +010071 int nr_memory_nodes;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030072 int nr_pmu_mappings;
73 int nr_groups;
Kan Liang6f91ea22020-03-19 13:25:02 -070074 int nr_cpu_pmu_caps;
Jin Yaof7d74ce2021-05-14 20:29:47 +080075 int nr_hybrid_nodes;
Jin Yaoe1190832021-05-14 20:29:48 +080076 int nr_hybrid_cpc_nodes;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030077 char *cmdline;
78 const char **cmdline_argv;
79 char *sibling_cores;
Kan Liangacae8b32019-06-04 15:50:41 -070080 char *sibling_dies;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030081 char *sibling_threads;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030082 char *pmu_mappings;
Kan Liang6f91ea22020-03-19 13:25:02 -070083 char *cpu_pmu_caps;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030084 struct cpu_topology_map *cpu;
Jiri Olsa720e98b2016-02-16 16:01:43 +010085 struct cpu_cache_level *caches;
86 int caches_cnt;
Alexey Budankovd3c8c082019-03-18 20:41:02 +030087 u32 comp_ratio;
Alexey Budankov42e1fd82019-03-18 20:41:33 +030088 u32 comp_ver;
89 u32 comp_type;
90 u32 comp_level;
91 u32 comp_mmap_len;
Jiri Olsac60da222016-07-04 14:16:20 +020092 struct numa_node *numa_nodes;
Jiri Olsae2091ce2018-03-07 16:50:08 +010093 struct memory_node *memory_nodes;
94 unsigned long long memory_bsize;
Jin Yaof7d74ce2021-05-14 20:29:47 +080095 struct hybrid_node *hybrid_nodes;
Jin Yaoe1190832021-05-14 20:29:48 +080096 struct hybrid_cpc_node *hybrid_cpc_nodes;
Arnaldo Carvalho de Meloef0580e2020-10-20 15:57:21 -030097#ifdef HAVE_LIBBPF_SUPPORT
Song Liue4378f02019-03-11 22:30:42 -070098 /*
99 * bpf_info_lock protects bpf rbtrees. This is needed because the
100 * trees are accessed by different threads in perf-top
101 */
102 struct {
103 struct rw_semaphore lock;
104 struct rb_root infos;
105 u32 infos_cnt;
Song Liu3792cb22019-03-11 22:30:44 -0700106 struct rb_root btfs;
107 u32 btfs_cnt;
Song Liue4378f02019-03-11 22:30:42 -0700108 } bpf_progs;
Arnaldo Carvalho de Meloef0580e2020-10-20 15:57:21 -0300109#endif // HAVE_LIBBPF_SUPPORT
Namhyung Kimd1277aa2020-03-25 21:45:31 +0900110 /* same reason as above (for perf-top) */
111 struct {
112 struct rw_semaphore lock;
113 struct rb_root tree;
114 } cgroups;
115
Jiri Olsa389799a2019-08-29 13:31:48 +0200116 /* For fast cpu to numa node lookup via perf_env__numa_node */
117 int *numa_map;
118 int nr_numa_map;
Jiri Olsad1e325c2020-08-05 11:34:40 +0200119
120 /* For real clock time reference. */
121 struct {
122 u64 tod_ns;
123 u64 clockid_ns;
Jiri Olsa9d88a1a12020-08-05 11:34:41 +0200124 u64 clockid_res_ns;
Jiri Olsad1e325c2020-08-05 11:34:40 +0200125 int clockid;
126 /*
127 * enabled is valid for report mode, and is true if above
128 * values are set, it's set in process_clock_data
129 */
130 bool enabled;
131 } clock;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -0300132};
133
Alexey Budankov42e1fd82019-03-18 20:41:33 +0300134enum perf_compress_type {
135 PERF_COMP_NONE = 0,
136 PERF_COMP_ZSTD,
137 PERF_COMP_MAX
138};
139
Song Liue4378f02019-03-11 22:30:42 -0700140struct bpf_prog_info_node;
Song Liu3792cb22019-03-11 22:30:44 -0700141struct btf_node;
Song Liue4378f02019-03-11 22:30:42 -0700142
Arnaldo Carvalho de Melob6998692015-09-08 16:58:20 -0300143extern struct perf_env perf_env;
144
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -0300145void perf_env__exit(struct perf_env *env);
146
Leo Yan7c0223e2021-08-09 19:27:25 +0800147int perf_env__kernel_is_64_bit(struct perf_env *env);
148
Arnaldo Carvalho de Melob6998692015-09-08 16:58:20 -0300149int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
150
Arnaldo Carvalho de Melof1cedfb2019-09-30 11:50:15 -0300151int perf_env__read_cpuid(struct perf_env *env);
Kim Phillips9fe88952021-08-17 17:15:07 -0500152int perf_env__read_pmu_mappings(struct perf_env *env);
153int perf_env__nr_pmu_mappings(struct perf_env *env);
154const char *perf_env__pmu_mappings(struct perf_env *env);
155
Arnaldo Carvalho de Meloaa36ddd2015-09-09 10:37:01 -0300156int perf_env__read_cpu_topology_map(struct perf_env *env);
157
Jiri Olsa720e98b2016-02-16 16:01:43 +0100158void cpu_cache_level__free(struct cpu_cache_level *cache);
Arnaldo Carvalho de Melo4e8fbc12017-12-11 14:47:49 -0300159
160const char *perf_env__arch(struct perf_env *env);
Kim Phillips9fe88952021-08-17 17:15:07 -0500161const char *perf_env__cpuid(struct perf_env *env);
Adrian Hunterdbbd34a2018-05-17 12:21:53 +0300162const char *perf_env__raw_arch(struct perf_env *env);
Adrian Hunter9cecca32018-05-22 13:54:32 +0300163int perf_env__nr_cpus_avail(struct perf_env *env);
Adrian Hunterdbbd34a2018-05-17 12:21:53 +0300164
Song Liue4378f02019-03-11 22:30:42 -0700165void perf_env__init(struct perf_env *env);
166void perf_env__insert_bpf_prog_info(struct perf_env *env,
167 struct bpf_prog_info_node *info_node);
168struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
169 __u32 prog_id);
Song Liu3792cb22019-03-11 22:30:44 -0700170void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node);
171struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id);
Jiri Olsa389799a2019-08-29 13:31:48 +0200172
173int perf_env__numa_node(struct perf_env *env, int cpu);
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -0300174#endif /* __PERF_ENV_H */