Lines Matching full:env
4 #include "env.h"
25 void perf_env__insert_bpf_prog_info(struct perf_env *env, in perf_env__insert_bpf_prog_info() argument
28 down_write(&env->bpf_progs.lock); in perf_env__insert_bpf_prog_info()
29 __perf_env__insert_bpf_prog_info(env, info_node); in perf_env__insert_bpf_prog_info()
30 up_write(&env->bpf_progs.lock); in perf_env__insert_bpf_prog_info()
33 void __perf_env__insert_bpf_prog_info(struct perf_env *env, struct bpf_prog_info_node *info_node) in __perf_env__insert_bpf_prog_info() argument
40 p = &env->bpf_progs.infos.rb_node; in __perf_env__insert_bpf_prog_info()
56 rb_insert_color(&info_node->rb_node, &env->bpf_progs.infos); in __perf_env__insert_bpf_prog_info()
57 env->bpf_progs.infos_cnt++; in __perf_env__insert_bpf_prog_info()
60 struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env, in perf_env__find_bpf_prog_info() argument
66 down_read(&env->bpf_progs.lock); in perf_env__find_bpf_prog_info()
67 n = env->bpf_progs.infos.rb_node; in perf_env__find_bpf_prog_info()
81 up_read(&env->bpf_progs.lock); in perf_env__find_bpf_prog_info()
85 bool perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node) in perf_env__insert_btf() argument
89 down_write(&env->bpf_progs.lock); in perf_env__insert_btf()
90 ret = __perf_env__insert_btf(env, btf_node); in perf_env__insert_btf()
91 up_write(&env->bpf_progs.lock); in perf_env__insert_btf()
95 bool __perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node) in __perf_env__insert_btf() argument
102 p = &env->bpf_progs.btfs.rb_node; in __perf_env__insert_btf()
118 rb_insert_color(&btf_node->rb_node, &env->bpf_progs.btfs); in __perf_env__insert_btf()
119 env->bpf_progs.btfs_cnt++; in __perf_env__insert_btf()
123 struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id) in perf_env__find_btf() argument
127 down_read(&env->bpf_progs.lock); in perf_env__find_btf()
128 res = __perf_env__find_btf(env, btf_id); in perf_env__find_btf()
129 up_read(&env->bpf_progs.lock); in perf_env__find_btf()
133 struct btf_node *__perf_env__find_btf(struct perf_env *env, __u32 btf_id) in __perf_env__find_btf() argument
138 n = env->bpf_progs.btfs.rb_node; in __perf_env__find_btf()
153 static void perf_env__purge_bpf(struct perf_env *env) in perf_env__purge_bpf() argument
158 down_write(&env->bpf_progs.lock); in perf_env__purge_bpf()
160 root = &env->bpf_progs.infos; in perf_env__purge_bpf()
173 env->bpf_progs.infos_cnt = 0; in perf_env__purge_bpf()
175 root = &env->bpf_progs.btfs; in perf_env__purge_bpf()
187 env->bpf_progs.btfs_cnt = 0; in perf_env__purge_bpf()
189 up_write(&env->bpf_progs.lock); in perf_env__purge_bpf()
192 static void perf_env__purge_bpf(struct perf_env *env __maybe_unused) in perf_env__purge_bpf()
197 void perf_env__exit(struct perf_env *env) in perf_env__exit() argument
201 perf_env__purge_bpf(env); in perf_env__exit()
202 perf_env__purge_cgroups(env); in perf_env__exit()
203 zfree(&env->hostname); in perf_env__exit()
204 zfree(&env->os_release); in perf_env__exit()
205 zfree(&env->version); in perf_env__exit()
206 zfree(&env->arch); in perf_env__exit()
207 zfree(&env->cpu_desc); in perf_env__exit()
208 zfree(&env->cpuid); in perf_env__exit()
209 zfree(&env->cmdline); in perf_env__exit()
210 zfree(&env->cmdline_argv); in perf_env__exit()
211 zfree(&env->sibling_dies); in perf_env__exit()
212 zfree(&env->sibling_cores); in perf_env__exit()
213 zfree(&env->sibling_threads); in perf_env__exit()
214 zfree(&env->pmu_mappings); in perf_env__exit()
215 zfree(&env->cpu); in perf_env__exit()
216 for (i = 0; i < env->nr_cpu_pmu_caps; i++) in perf_env__exit()
217 zfree(&env->cpu_pmu_caps[i]); in perf_env__exit()
218 zfree(&env->cpu_pmu_caps); in perf_env__exit()
219 zfree(&env->numa_map); in perf_env__exit()
221 for (i = 0; i < env->nr_numa_nodes; i++) in perf_env__exit()
222 perf_cpu_map__put(env->numa_nodes[i].map); in perf_env__exit()
223 zfree(&env->numa_nodes); in perf_env__exit()
225 for (i = 0; i < env->caches_cnt; i++) in perf_env__exit()
226 cpu_cache_level__free(&env->caches[i]); in perf_env__exit()
227 zfree(&env->caches); in perf_env__exit()
229 for (i = 0; i < env->nr_memory_nodes; i++) in perf_env__exit()
230 zfree(&env->memory_nodes[i].set); in perf_env__exit()
231 zfree(&env->memory_nodes); in perf_env__exit()
233 for (i = 0; i < env->nr_hybrid_nodes; i++) { in perf_env__exit()
234 zfree(&env->hybrid_nodes[i].pmu_name); in perf_env__exit()
235 zfree(&env->hybrid_nodes[i].cpus); in perf_env__exit()
237 zfree(&env->hybrid_nodes); in perf_env__exit()
239 for (i = 0; i < env->nr_pmus_with_caps; i++) { in perf_env__exit()
240 for (j = 0; j < env->pmu_caps[i].nr_caps; j++) in perf_env__exit()
241 zfree(&env->pmu_caps[i].caps[j]); in perf_env__exit()
242 zfree(&env->pmu_caps[i].caps); in perf_env__exit()
243 zfree(&env->pmu_caps[i].pmu_name); in perf_env__exit()
245 zfree(&env->pmu_caps); in perf_env__exit()
248 void perf_env__init(struct perf_env *env) in perf_env__init() argument
251 env->bpf_progs.infos = RB_ROOT; in perf_env__init()
252 env->bpf_progs.btfs = RB_ROOT; in perf_env__init()
253 init_rwsem(&env->bpf_progs.lock); in perf_env__init()
255 env->kernel_is_64_bit = -1; in perf_env__init()
258 static void perf_env__init_kernel_mode(struct perf_env *env) in perf_env__init_kernel_mode() argument
260 const char *arch = perf_env__raw_arch(env); in perf_env__init_kernel_mode()
266 env->kernel_is_64_bit = 1; in perf_env__init_kernel_mode()
268 env->kernel_is_64_bit = 0; in perf_env__init_kernel_mode()
271 int perf_env__kernel_is_64_bit(struct perf_env *env) in perf_env__kernel_is_64_bit() argument
273 if (env->kernel_is_64_bit == -1) in perf_env__kernel_is_64_bit()
274 perf_env__init_kernel_mode(env); in perf_env__kernel_is_64_bit()
276 return env->kernel_is_64_bit; in perf_env__kernel_is_64_bit()
279 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) in perf_env__set_cmdline() argument
284 env->cmdline_argv = calloc(argc, sizeof(char *)); in perf_env__set_cmdline()
285 if (env->cmdline_argv == NULL) in perf_env__set_cmdline()
293 env->cmdline_argv[i] = argv[i]; in perf_env__set_cmdline()
294 if (env->cmdline_argv[i] == NULL) in perf_env__set_cmdline()
298 env->nr_cmdline = argc; in perf_env__set_cmdline()
302 zfree(&env->cmdline_argv); in perf_env__set_cmdline()
307 int perf_env__read_cpu_topology_map(struct perf_env *env) in perf_env__read_cpu_topology_map() argument
311 if (env->cpu != NULL) in perf_env__read_cpu_topology_map()
314 if (env->nr_cpus_avail == 0) in perf_env__read_cpu_topology_map()
315 env->nr_cpus_avail = cpu__max_present_cpu().cpu; in perf_env__read_cpu_topology_map()
317 nr_cpus = env->nr_cpus_avail; in perf_env__read_cpu_topology_map()
321 env->cpu = calloc(nr_cpus, sizeof(env->cpu[0])); in perf_env__read_cpu_topology_map()
322 if (env->cpu == NULL) in perf_env__read_cpu_topology_map()
328 env->cpu[idx].core_id = cpu__get_core_id(cpu); in perf_env__read_cpu_topology_map()
329 env->cpu[idx].socket_id = cpu__get_socket_id(cpu); in perf_env__read_cpu_topology_map()
330 env->cpu[idx].die_id = cpu__get_die_id(cpu); in perf_env__read_cpu_topology_map()
333 env->nr_cpus_avail = nr_cpus; in perf_env__read_cpu_topology_map()
337 int perf_env__read_pmu_mappings(struct perf_env *env) in perf_env__read_pmu_mappings() argument
350 env->nr_pmu_mappings = pmu_num; in perf_env__read_pmu_mappings()
363 env->pmu_mappings = strbuf_detach(&sb, NULL); in perf_env__read_pmu_mappings()
372 int perf_env__read_cpuid(struct perf_env *env) in perf_env__read_cpuid() argument
380 free(env->cpuid); in perf_env__read_cpuid()
381 env->cpuid = strdup(cpuid); in perf_env__read_cpuid()
382 if (env->cpuid == NULL) in perf_env__read_cpuid()
387 static int perf_env__read_arch(struct perf_env *env) in perf_env__read_arch() argument
391 if (env->arch) in perf_env__read_arch()
395 env->arch = strdup(uts.machine); in perf_env__read_arch()
397 return env->arch ? 0 : -ENOMEM; in perf_env__read_arch()
400 static int perf_env__read_nr_cpus_avail(struct perf_env *env) in perf_env__read_nr_cpus_avail() argument
402 if (env->nr_cpus_avail == 0) in perf_env__read_nr_cpus_avail()
403 env->nr_cpus_avail = cpu__max_present_cpu().cpu; in perf_env__read_nr_cpus_avail()
405 return env->nr_cpus_avail ? 0 : -ENOENT; in perf_env__read_nr_cpus_avail()
408 const char *perf_env__raw_arch(struct perf_env *env) in perf_env__raw_arch() argument
410 return env && !perf_env__read_arch(env) ? env->arch : "unknown"; in perf_env__raw_arch()
413 int perf_env__nr_cpus_avail(struct perf_env *env) in perf_env__nr_cpus_avail() argument
415 return env && !perf_env__read_nr_cpus_avail(env) ? env->nr_cpus_avail : 0; in perf_env__nr_cpus_avail()
457 const char *perf_env__arch(struct perf_env *env) in perf_env__arch() argument
461 if (!env || !env->arch) { /* Assume local operation */ in perf_env__arch()
467 arch_name = env->arch; in perf_env__arch()
472 const char *perf_env__arch_strerrno(struct perf_env *env __maybe_unused, int err __maybe_unused) in perf_env__arch_strerrno()
475 if (env->arch_strerrno == NULL) in perf_env__arch_strerrno()
476 env->arch_strerrno = arch_syscalls__strerrno_function(perf_env__arch(env)); in perf_env__arch_strerrno()
478 return env->arch_strerrno ? env->arch_strerrno(err) : "no arch specific strerrno function"; in perf_env__arch_strerrno()
484 const char *perf_env__cpuid(struct perf_env *env) in perf_env__cpuid() argument
488 if (!env->cpuid) { /* Assume local operation */ in perf_env__cpuid()
489 status = perf_env__read_cpuid(env); in perf_env__cpuid()
494 return env->cpuid; in perf_env__cpuid()
497 int perf_env__nr_pmu_mappings(struct perf_env *env) in perf_env__nr_pmu_mappings() argument
501 if (!env->nr_pmu_mappings) { /* Assume local operation */ in perf_env__nr_pmu_mappings()
502 status = perf_env__read_pmu_mappings(env); in perf_env__nr_pmu_mappings()
507 return env->nr_pmu_mappings; in perf_env__nr_pmu_mappings()
510 const char *perf_env__pmu_mappings(struct perf_env *env) in perf_env__pmu_mappings() argument
514 if (!env->pmu_mappings) { /* Assume local operation */ in perf_env__pmu_mappings()
515 status = perf_env__read_pmu_mappings(env); in perf_env__pmu_mappings()
520 return env->pmu_mappings; in perf_env__pmu_mappings()
523 int perf_env__numa_node(struct perf_env *env, struct perf_cpu cpu) in perf_env__numa_node() argument
525 if (!env->nr_numa_map) { in perf_env__numa_node()
529 for (i = 0; i < env->nr_numa_nodes; i++) { in perf_env__numa_node()
530 nn = &env->numa_nodes[i]; in perf_env__numa_node()
540 env->numa_map = malloc(nr * sizeof(int)); in perf_env__numa_node()
541 if (!env->numa_map) in perf_env__numa_node()
545 env->numa_map[i] = -1; in perf_env__numa_node()
547 env->nr_numa_map = nr; in perf_env__numa_node()
549 for (i = 0; i < env->nr_numa_nodes; i++) { in perf_env__numa_node()
553 nn = &env->numa_nodes[i]; in perf_env__numa_node()
555 env->numa_map[tmp.cpu] = i; in perf_env__numa_node()
559 return cpu.cpu >= 0 && cpu.cpu < env->nr_numa_map ? env->numa_map[cpu.cpu] : -1; in perf_env__numa_node()
562 bool perf_env__has_pmu_mapping(struct perf_env *env, const char *pmu_name) in perf_env__has_pmu_mapping() argument
564 char *pmu_mapping = env->pmu_mappings, *colon; in perf_env__has_pmu_mapping()
566 for (int i = 0; i < env->nr_pmu_mappings; ++i) { in perf_env__has_pmu_mapping()
580 char *perf_env__find_pmu_cap(struct perf_env *env, const char *pmu_name, in perf_env__find_pmu_cap() argument
600 for (i = 0; i < env->nr_cpu_pmu_caps; i++) { in perf_env__find_pmu_cap()
601 if (!strncmp(env->cpu_pmu_caps[i], cap_eq, cap_size + 1)) { in perf_env__find_pmu_cap()
603 return &env->cpu_pmu_caps[i][cap_size + 1]; in perf_env__find_pmu_cap()
609 for (i = 0; i < env->nr_pmus_with_caps; i++) { in perf_env__find_pmu_cap()
610 if (strcmp(env->pmu_caps[i].pmu_name, pmu_name)) in perf_env__find_pmu_cap()
613 ptr = env->pmu_caps[i].caps; in perf_env__find_pmu_cap()
615 for (j = 0; j < env->pmu_caps[i].nr_caps; j++) { in perf_env__find_pmu_cap()
628 void perf_env__find_br_cntr_info(struct perf_env *env, in perf_env__find_br_cntr_info() argument
633 *nr = env->cpu_pmu_caps ? env->br_cntr_nr : in perf_env__find_br_cntr_info()
634 env->pmu_caps->br_cntr_nr; in perf_env__find_br_cntr_info()
638 *width = env->cpu_pmu_caps ? env->br_cntr_width : in perf_env__find_br_cntr_info()
639 env->pmu_caps->br_cntr_width; in perf_env__find_br_cntr_info()