xref: /linux/tools/perf/util/env.h (revision 366efbff58092fac48421fa34018bb34c326088e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_ENV_H
3 #define __PERF_ENV_H
4 
5 #include <linux/types.h>
6 #include <linux/rbtree.h>
7 #include "cpumap.h"
8 #include "rwsem.h"
9 
10 struct perf_cpu_map;
11 
12 struct cpu_topology_map {
13 	int	socket_id;
14 	int	die_id;
15 	int	core_id;
16 };
17 
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 
28 struct numa_node {
29 	u32		 node;
30 	u64		 mem_total;
31 	u64		 mem_free;
32 	struct perf_cpu_map	*map;
33 };
34 
35 struct memory_node {
36 	u64		 node;
37 	u64		 size;
38 	unsigned long	*set;
39 };
40 
41 struct hybrid_node {
42 	char	*pmu_name;
43 	char	*cpus;
44 };
45 
46 struct pmu_caps {
47 	int		nr_caps;
48 	unsigned int    max_branches;
49 	unsigned int	br_cntr_nr;
50 	unsigned int	br_cntr_width;
51 
52 	char            **caps;
53 	char            *pmu_name;
54 };
55 
56 struct perf_env {
57 	char			*hostname;
58 	char			*os_release;
59 	char			*version;
60 	char			*arch;
61 	int			nr_cpus_online;
62 	int			nr_cpus_avail;
63 	char			*cpu_desc;
64 	char			*cpuid;
65 	unsigned long long	total_mem;
66 	unsigned int		msr_pmu_type;
67 	unsigned int		max_branches;
68 	unsigned int		br_cntr_nr;
69 	unsigned int		br_cntr_width;
70 	int			kernel_is_64_bit;
71 
72 	int			nr_cmdline;
73 	int			nr_sibling_cores;
74 	int			nr_sibling_dies;
75 	int			nr_sibling_threads;
76 	int			nr_numa_nodes;
77 	int			nr_memory_nodes;
78 	int			nr_pmu_mappings;
79 	int			nr_groups;
80 	int			nr_cpu_pmu_caps;
81 	int			nr_hybrid_nodes;
82 	int			nr_pmus_with_caps;
83 	char			*cmdline;
84 	const char		**cmdline_argv;
85 	char			*sibling_cores;
86 	char			*sibling_dies;
87 	char			*sibling_threads;
88 	char			*pmu_mappings;
89 	char			**cpu_pmu_caps;
90 	struct cpu_topology_map	*cpu;
91 	struct cpu_cache_level	*caches;
92 	int			 caches_cnt;
93 	u32			comp_ratio;
94 	u32			comp_ver;
95 	u32			comp_type;
96 	u32			comp_level;
97 	u32			comp_mmap_len;
98 	struct numa_node	*numa_nodes;
99 	struct memory_node	*memory_nodes;
100 	unsigned long long	 memory_bsize;
101 	struct hybrid_node	*hybrid_nodes;
102 	struct pmu_caps		*pmu_caps;
103 #ifdef HAVE_LIBBPF_SUPPORT
104 	/*
105 	 * bpf_info_lock protects bpf rbtrees. This is needed because the
106 	 * trees are accessed by different threads in perf-top
107 	 */
108 	struct {
109 		struct rw_semaphore	lock;
110 		struct rb_root		infos;
111 		u32			infos_cnt;
112 		struct rb_root		btfs;
113 		u32			btfs_cnt;
114 	} bpf_progs;
115 #endif // HAVE_LIBBPF_SUPPORT
116 	/* same reason as above (for perf-top) */
117 	struct {
118 		struct rw_semaphore	lock;
119 		struct rb_root		tree;
120 	} cgroups;
121 
122 	/* For fast cpu to numa node lookup via perf_env__numa_node */
123 	int			*numa_map;
124 	int			 nr_numa_map;
125 
126 	/* For real clock time reference. */
127 	struct {
128 		u64	tod_ns;
129 		u64	clockid_ns;
130 		u64     clockid_res_ns;
131 		int	clockid;
132 		/*
133 		 * enabled is valid for report mode, and is true if above
134 		 * values are set, it's set in process_clock_data
135 		 */
136 		bool	enabled;
137 	} clock;
138 };
139 
140 enum perf_compress_type {
141 	PERF_COMP_NONE = 0,
142 	PERF_COMP_ZSTD,
143 	PERF_COMP_MAX
144 };
145 
146 struct bpf_prog_info_node;
147 struct btf_node;
148 
149 extern struct perf_env perf_env;
150 
151 void perf_env__exit(struct perf_env *env);
152 
153 int perf_env__kernel_is_64_bit(struct perf_env *env);
154 
155 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
156 
157 int perf_env__read_cpuid(struct perf_env *env);
158 int perf_env__read_pmu_mappings(struct perf_env *env);
159 int perf_env__nr_pmu_mappings(struct perf_env *env);
160 const char *perf_env__pmu_mappings(struct perf_env *env);
161 
162 int perf_env__read_cpu_topology_map(struct perf_env *env);
163 
164 void cpu_cache_level__free(struct cpu_cache_level *cache);
165 
166 const char *perf_env__arch(struct perf_env *env);
167 const char *perf_env__cpuid(struct perf_env *env);
168 const char *perf_env__raw_arch(struct perf_env *env);
169 int perf_env__nr_cpus_avail(struct perf_env *env);
170 
171 void perf_env__init(struct perf_env *env);
172 void perf_env__insert_bpf_prog_info(struct perf_env *env,
173 				    struct bpf_prog_info_node *info_node);
174 struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
175 							__u32 prog_id);
176 bool perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node);
177 struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id);
178 
179 int perf_env__numa_node(struct perf_env *env, struct perf_cpu cpu);
180 char *perf_env__find_pmu_cap(struct perf_env *env, const char *pmu_name,
181 			     const char *cap);
182 
183 bool perf_env__has_pmu_mapping(struct perf_env *env, const char *pmu_name);
184 #endif /* __PERF_ENV_H */
185