blob: 271a90b326c4181db284a863c6709a1eea09fe6b [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>
Jiri Olsac60da222016-07-04 14:16:20 +02007#include "cpumap.h"
Song Liue4378f02019-03-11 22:30:42 -07008#include "rwsem.h"
Jiri Olsa720e98b2016-02-16 16:01:43 +01009
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030010struct cpu_topology_map {
11 int socket_id;
12 int core_id;
13};
14
Jiri Olsa720e98b2016-02-16 16:01:43 +010015struct cpu_cache_level {
16 u32 level;
17 u32 line_size;
18 u32 sets;
19 u32 ways;
20 char *type;
21 char *size;
22 char *map;
23};
24
Jiri Olsac60da222016-07-04 14:16:20 +020025struct numa_node {
26 u32 node;
27 u64 mem_total;
28 u64 mem_free;
29 struct cpu_map *map;
30};
31
Jiri Olsae2091ce2018-03-07 16:50:08 +010032struct memory_node {
33 u64 node;
34 u64 size;
35 unsigned long *set;
36};
37
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030038struct perf_env {
39 char *hostname;
40 char *os_release;
41 char *version;
42 char *arch;
43 int nr_cpus_online;
44 int nr_cpus_avail;
45 char *cpu_desc;
46 char *cpuid;
47 unsigned long long total_mem;
Kan Liange0838e02015-09-10 11:03:05 -030048 unsigned int msr_pmu_type;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030049
50 int nr_cmdline;
51 int nr_sibling_cores;
52 int nr_sibling_threads;
53 int nr_numa_nodes;
Jiri Olsae2091ce2018-03-07 16:50:08 +010054 int nr_memory_nodes;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030055 int nr_pmu_mappings;
56 int nr_groups;
57 char *cmdline;
58 const char **cmdline_argv;
59 char *sibling_cores;
60 char *sibling_threads;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030061 char *pmu_mappings;
62 struct cpu_topology_map *cpu;
Jiri Olsa720e98b2016-02-16 16:01:43 +010063 struct cpu_cache_level *caches;
64 int caches_cnt;
Alexey Budankovd3c8c082019-03-18 20:41:02 +030065 u32 comp_ratio;
Alexey Budankov42e1fd82019-03-18 20:41:33 +030066 u32 comp_ver;
67 u32 comp_type;
68 u32 comp_level;
69 u32 comp_mmap_len;
Jiri Olsac60da222016-07-04 14:16:20 +020070 struct numa_node *numa_nodes;
Jiri Olsae2091ce2018-03-07 16:50:08 +010071 struct memory_node *memory_nodes;
72 unsigned long long memory_bsize;
Alexey Budankovcf790512018-10-09 17:36:24 +030073 u64 clockid_res_ns;
Song Liue4378f02019-03-11 22:30:42 -070074
75 /*
76 * bpf_info_lock protects bpf rbtrees. This is needed because the
77 * trees are accessed by different threads in perf-top
78 */
79 struct {
80 struct rw_semaphore lock;
81 struct rb_root infos;
82 u32 infos_cnt;
Song Liu3792cb22019-03-11 22:30:44 -070083 struct rb_root btfs;
84 u32 btfs_cnt;
Song Liue4378f02019-03-11 22:30:42 -070085 } bpf_progs;
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030086};
87
Alexey Budankov42e1fd82019-03-18 20:41:33 +030088enum perf_compress_type {
89 PERF_COMP_NONE = 0,
90 PERF_COMP_ZSTD,
91 PERF_COMP_MAX
92};
93
Song Liue4378f02019-03-11 22:30:42 -070094struct bpf_prog_info_node;
Song Liu3792cb22019-03-11 22:30:44 -070095struct btf_node;
Song Liue4378f02019-03-11 22:30:42 -070096
Arnaldo Carvalho de Melob6998692015-09-08 16:58:20 -030097extern struct perf_env perf_env;
98
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030099void perf_env__exit(struct perf_env *env);
100
Arnaldo Carvalho de Melob6998692015-09-08 16:58:20 -0300101int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
102
Arnaldo Carvalho de Meloaa36ddd2015-09-09 10:37:01 -0300103int perf_env__read_cpu_topology_map(struct perf_env *env);
104
Jiri Olsa720e98b2016-02-16 16:01:43 +0100105void cpu_cache_level__free(struct cpu_cache_level *cache);
Arnaldo Carvalho de Melo4e8fbc12017-12-11 14:47:49 -0300106
107const char *perf_env__arch(struct perf_env *env);
Adrian Hunterdbbd34a2018-05-17 12:21:53 +0300108const char *perf_env__raw_arch(struct perf_env *env);
Adrian Hunter9cecca32018-05-22 13:54:32 +0300109int perf_env__nr_cpus_avail(struct perf_env *env);
Adrian Hunterdbbd34a2018-05-17 12:21:53 +0300110
Song Liue4378f02019-03-11 22:30:42 -0700111void perf_env__init(struct perf_env *env);
112void perf_env__insert_bpf_prog_info(struct perf_env *env,
113 struct bpf_prog_info_node *info_node);
114struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
115 __u32 prog_id);
Song Liu3792cb22019-03-11 22:30:44 -0700116void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node);
117struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id);
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -0300118#endif /* __PERF_ENV_H */