xref: /openbmc/linux/tools/perf/util/env.h (revision acd46a6b)
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 "rwsem.h"
8 
9 struct perf_cpu_map;
10 
11 struct cpu_topology_map {
12 	int	socket_id;
13 	int	die_id;
14 	int	core_id;
15 };
16 
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 
27 struct numa_node {
28 	u32		 node;
29 	u64		 mem_total;
30 	u64		 mem_free;
31 	struct perf_cpu_map	*map;
32 };
33 
34 struct memory_node {
35 	u64		 node;
36 	u64		 size;
37 	unsigned long	*set;
38 };
39 
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;
50 	unsigned int		msr_pmu_type;
51 	unsigned int		max_branches;
52 
53 	int			nr_cmdline;
54 	int			nr_sibling_cores;
55 	int			nr_sibling_dies;
56 	int			nr_sibling_threads;
57 	int			nr_numa_nodes;
58 	int			nr_memory_nodes;
59 	int			nr_pmu_mappings;
60 	int			nr_groups;
61 	int			nr_cpu_pmu_caps;
62 	char			*cmdline;
63 	const char		**cmdline_argv;
64 	char			*sibling_cores;
65 	char			*sibling_dies;
66 	char			*sibling_threads;
67 	char			*pmu_mappings;
68 	char			*cpu_pmu_caps;
69 	struct cpu_topology_map	*cpu;
70 	struct cpu_cache_level	*caches;
71 	int			 caches_cnt;
72 	u32			comp_ratio;
73 	u32			comp_ver;
74 	u32			comp_type;
75 	u32			comp_level;
76 	u32			comp_mmap_len;
77 	struct numa_node	*numa_nodes;
78 	struct memory_node	*memory_nodes;
79 	unsigned long long	 memory_bsize;
80 	u64                     clockid_res_ns;
81 
82 	/*
83 	 * bpf_info_lock protects bpf rbtrees. This is needed because the
84 	 * trees are accessed by different threads in perf-top
85 	 */
86 	struct {
87 		struct rw_semaphore	lock;
88 		struct rb_root		infos;
89 		u32			infos_cnt;
90 		struct rb_root		btfs;
91 		u32			btfs_cnt;
92 	} bpf_progs;
93 
94 	/* same reason as above (for perf-top) */
95 	struct {
96 		struct rw_semaphore	lock;
97 		struct rb_root		tree;
98 	} cgroups;
99 
100 	/* For fast cpu to numa node lookup via perf_env__numa_node */
101 	int			*numa_map;
102 	int			 nr_numa_map;
103 };
104 
105 enum perf_compress_type {
106 	PERF_COMP_NONE = 0,
107 	PERF_COMP_ZSTD,
108 	PERF_COMP_MAX
109 };
110 
111 struct bpf_prog_info_node;
112 struct btf_node;
113 
114 extern struct perf_env perf_env;
115 
116 void perf_env__exit(struct perf_env *env);
117 
118 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
119 
120 int perf_env__read_cpuid(struct perf_env *env);
121 int perf_env__read_cpu_topology_map(struct perf_env *env);
122 
123 void cpu_cache_level__free(struct cpu_cache_level *cache);
124 
125 const char *perf_env__arch(struct perf_env *env);
126 const char *perf_env__raw_arch(struct perf_env *env);
127 int perf_env__nr_cpus_avail(struct perf_env *env);
128 
129 void perf_env__init(struct perf_env *env);
130 void perf_env__insert_bpf_prog_info(struct perf_env *env,
131 				    struct bpf_prog_info_node *info_node);
132 struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
133 							__u32 prog_id);
134 void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node);
135 struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id);
136 
137 int perf_env__numa_node(struct perf_env *env, int cpu);
138 #endif /* __PERF_ENV_H */
139