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 cpu_topology_map { 11 int socket_id; 12 int die_id; 13 int core_id; 14 }; 15 16 struct cpu_cache_level { 17 u32 level; 18 u32 line_size; 19 u32 sets; 20 u32 ways; 21 char *type; 22 char *size; 23 char *map; 24 }; 25 26 struct numa_node { 27 u32 node; 28 u64 mem_total; 29 u64 mem_free; 30 struct cpu_map *map; 31 }; 32 33 struct memory_node { 34 u64 node; 35 u64 size; 36 unsigned long *set; 37 }; 38 39 struct perf_env { 40 char *hostname; 41 char *os_release; 42 char *version; 43 char *arch; 44 int nr_cpus_online; 45 int nr_cpus_avail; 46 char *cpu_desc; 47 char *cpuid; 48 unsigned long long total_mem; 49 unsigned int msr_pmu_type; 50 51 int nr_cmdline; 52 int nr_sibling_cores; 53 int nr_sibling_dies; 54 int nr_sibling_threads; 55 int nr_numa_nodes; 56 int nr_memory_nodes; 57 int nr_pmu_mappings; 58 int nr_groups; 59 char *cmdline; 60 const char **cmdline_argv; 61 char *sibling_cores; 62 char *sibling_dies; 63 char *sibling_threads; 64 char *pmu_mappings; 65 struct cpu_topology_map *cpu; 66 struct cpu_cache_level *caches; 67 int caches_cnt; 68 u32 comp_ratio; 69 u32 comp_ver; 70 u32 comp_type; 71 u32 comp_level; 72 u32 comp_mmap_len; 73 struct numa_node *numa_nodes; 74 struct memory_node *memory_nodes; 75 unsigned long long memory_bsize; 76 u64 clockid_res_ns; 77 78 /* 79 * bpf_info_lock protects bpf rbtrees. This is needed because the 80 * trees are accessed by different threads in perf-top 81 */ 82 struct { 83 struct rw_semaphore lock; 84 struct rb_root infos; 85 u32 infos_cnt; 86 struct rb_root btfs; 87 u32 btfs_cnt; 88 } bpf_progs; 89 }; 90 91 enum perf_compress_type { 92 PERF_COMP_NONE = 0, 93 PERF_COMP_ZSTD, 94 PERF_COMP_MAX 95 }; 96 97 struct bpf_prog_info_node; 98 struct btf_node; 99 100 extern struct perf_env perf_env; 101 102 void perf_env__exit(struct perf_env *env); 103 104 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]); 105 106 int perf_env__read_cpu_topology_map(struct perf_env *env); 107 108 void cpu_cache_level__free(struct cpu_cache_level *cache); 109 110 const char *perf_env__arch(struct perf_env *env); 111 const char *perf_env__raw_arch(struct perf_env *env); 112 int perf_env__nr_cpus_avail(struct perf_env *env); 113 114 void perf_env__init(struct perf_env *env); 115 void perf_env__insert_bpf_prog_info(struct perf_env *env, 116 struct bpf_prog_info_node *info_node); 117 struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env, 118 __u32 prog_id); 119 void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node); 120 struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id); 121 #endif /* __PERF_ENV_H */ 122