Merge tag 'at24-fixes-for-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / tools / perf / util / env.h
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 hybrid_node {
41         char    *pmu_name;
42         char    *cpus;
43 };
44
45 struct 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
52 struct 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;
62         unsigned int            msr_pmu_type;
63         unsigned int            max_branches;
64
65         int                     nr_cmdline;
66         int                     nr_sibling_cores;
67         int                     nr_sibling_dies;
68         int                     nr_sibling_threads;
69         int                     nr_numa_nodes;
70         int                     nr_memory_nodes;
71         int                     nr_pmu_mappings;
72         int                     nr_groups;
73         int                     nr_cpu_pmu_caps;
74         int                     nr_hybrid_nodes;
75         int                     nr_hybrid_cpc_nodes;
76         char                    *cmdline;
77         const char              **cmdline_argv;
78         char                    *sibling_cores;
79         char                    *sibling_dies;
80         char                    *sibling_threads;
81         char                    *pmu_mappings;
82         char                    *cpu_pmu_caps;
83         struct cpu_topology_map *cpu;
84         struct cpu_cache_level  *caches;
85         int                      caches_cnt;
86         u32                     comp_ratio;
87         u32                     comp_ver;
88         u32                     comp_type;
89         u32                     comp_level;
90         u32                     comp_mmap_len;
91         struct numa_node        *numa_nodes;
92         struct memory_node      *memory_nodes;
93         unsigned long long       memory_bsize;
94         struct hybrid_node      *hybrid_nodes;
95         struct hybrid_cpc_node  *hybrid_cpc_nodes;
96 #ifdef HAVE_LIBBPF_SUPPORT
97         /*
98          * bpf_info_lock protects bpf rbtrees. This is needed because the
99          * trees are accessed by different threads in perf-top
100          */
101         struct {
102                 struct rw_semaphore     lock;
103                 struct rb_root          infos;
104                 u32                     infos_cnt;
105                 struct rb_root          btfs;
106                 u32                     btfs_cnt;
107         } bpf_progs;
108 #endif // HAVE_LIBBPF_SUPPORT
109         /* same reason as above (for perf-top) */
110         struct {
111                 struct rw_semaphore     lock;
112                 struct rb_root          tree;
113         } cgroups;
114
115         /* For fast cpu to numa node lookup via perf_env__numa_node */
116         int                     *numa_map;
117         int                      nr_numa_map;
118
119         /* For real clock time reference. */
120         struct {
121                 u64     tod_ns;
122                 u64     clockid_ns;
123                 u64     clockid_res_ns;
124                 int     clockid;
125                 /*
126                  * enabled is valid for report mode, and is true if above
127                  * values are set, it's set in process_clock_data
128                  */
129                 bool    enabled;
130         } clock;
131 };
132
133 enum perf_compress_type {
134         PERF_COMP_NONE = 0,
135         PERF_COMP_ZSTD,
136         PERF_COMP_MAX
137 };
138
139 struct bpf_prog_info_node;
140 struct btf_node;
141
142 extern struct perf_env perf_env;
143
144 void perf_env__exit(struct perf_env *env);
145
146 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
147
148 int perf_env__read_cpuid(struct perf_env *env);
149 int perf_env__read_cpu_topology_map(struct perf_env *env);
150
151 void cpu_cache_level__free(struct cpu_cache_level *cache);
152
153 const char *perf_env__arch(struct perf_env *env);
154 const char *perf_env__raw_arch(struct perf_env *env);
155 int perf_env__nr_cpus_avail(struct perf_env *env);
156
157 void perf_env__init(struct perf_env *env);
158 void perf_env__insert_bpf_prog_info(struct perf_env *env,
159                                     struct bpf_prog_info_node *info_node);
160 struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
161                                                         __u32 prog_id);
162 void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node);
163 struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id);
164
165 int perf_env__numa_node(struct perf_env *env, int cpu);
166 #endif /* __PERF_ENV_H */