Lines Matching +full:local +full:- +full:cap +full:- +full:size
1 // SPDX-License-Identifier: GPL-2.0
18 #include "bpf-event.h"
19 #include "bpf-utils.h"
25 __u32 prog_id = info_node->info_linear->info.id; in perf_env__insert_bpf_prog_info()
30 down_write(&env->bpf_progs.lock); in perf_env__insert_bpf_prog_info()
31 p = &env->bpf_progs.infos.rb_node; in perf_env__insert_bpf_prog_info()
36 if (prog_id < node->info_linear->info.id) { in perf_env__insert_bpf_prog_info()
37 p = &(*p)->rb_left; in perf_env__insert_bpf_prog_info()
38 } else if (prog_id > node->info_linear->info.id) { in perf_env__insert_bpf_prog_info()
39 p = &(*p)->rb_right; in perf_env__insert_bpf_prog_info()
46 rb_link_node(&info_node->rb_node, parent, p); in perf_env__insert_bpf_prog_info()
47 rb_insert_color(&info_node->rb_node, &env->bpf_progs.infos); in perf_env__insert_bpf_prog_info()
48 env->bpf_progs.infos_cnt++; in perf_env__insert_bpf_prog_info()
50 up_write(&env->bpf_progs.lock); in perf_env__insert_bpf_prog_info()
59 down_read(&env->bpf_progs.lock); in perf_env__find_bpf_prog_info()
60 n = env->bpf_progs.infos.rb_node; in perf_env__find_bpf_prog_info()
64 if (prog_id < node->info_linear->info.id) in perf_env__find_bpf_prog_info()
65 n = n->rb_left; in perf_env__find_bpf_prog_info()
66 else if (prog_id > node->info_linear->info.id) in perf_env__find_bpf_prog_info()
67 n = n->rb_right; in perf_env__find_bpf_prog_info()
74 up_read(&env->bpf_progs.lock); in perf_env__find_bpf_prog_info()
81 __u32 btf_id = btf_node->id; in perf_env__insert_btf()
86 down_write(&env->bpf_progs.lock); in perf_env__insert_btf()
87 p = &env->bpf_progs.btfs.rb_node; in perf_env__insert_btf()
92 if (btf_id < node->id) { in perf_env__insert_btf()
93 p = &(*p)->rb_left; in perf_env__insert_btf()
94 } else if (btf_id > node->id) { in perf_env__insert_btf()
95 p = &(*p)->rb_right; in perf_env__insert_btf()
103 rb_link_node(&btf_node->rb_node, parent, p); in perf_env__insert_btf()
104 rb_insert_color(&btf_node->rb_node, &env->bpf_progs.btfs); in perf_env__insert_btf()
105 env->bpf_progs.btfs_cnt++; in perf_env__insert_btf()
107 up_write(&env->bpf_progs.lock); in perf_env__insert_btf()
116 down_read(&env->bpf_progs.lock); in perf_env__find_btf()
117 n = env->bpf_progs.btfs.rb_node; in perf_env__find_btf()
121 if (btf_id < node->id) in perf_env__find_btf()
122 n = n->rb_left; in perf_env__find_btf()
123 else if (btf_id > node->id) in perf_env__find_btf()
124 n = n->rb_right; in perf_env__find_btf()
131 up_read(&env->bpf_progs.lock); in perf_env__find_btf()
141 down_write(&env->bpf_progs.lock); in perf_env__purge_bpf()
143 root = &env->bpf_progs.infos; in perf_env__purge_bpf()
150 next = rb_next(&node->rb_node); in perf_env__purge_bpf()
151 rb_erase(&node->rb_node, root); in perf_env__purge_bpf()
152 free(node->info_linear); in perf_env__purge_bpf()
156 env->bpf_progs.infos_cnt = 0; in perf_env__purge_bpf()
158 root = &env->bpf_progs.btfs; in perf_env__purge_bpf()
165 next = rb_next(&node->rb_node); in perf_env__purge_bpf()
166 rb_erase(&node->rb_node, root); in perf_env__purge_bpf()
170 env->bpf_progs.btfs_cnt = 0; in perf_env__purge_bpf()
172 up_write(&env->bpf_progs.lock); in perf_env__purge_bpf()
186 zfree(&env->hostname); in perf_env__exit()
187 zfree(&env->os_release); in perf_env__exit()
188 zfree(&env->version); in perf_env__exit()
189 zfree(&env->arch); in perf_env__exit()
190 zfree(&env->cpu_desc); in perf_env__exit()
191 zfree(&env->cpuid); in perf_env__exit()
192 zfree(&env->cmdline); in perf_env__exit()
193 zfree(&env->cmdline_argv); in perf_env__exit()
194 zfree(&env->sibling_dies); in perf_env__exit()
195 zfree(&env->sibling_cores); in perf_env__exit()
196 zfree(&env->sibling_threads); in perf_env__exit()
197 zfree(&env->pmu_mappings); in perf_env__exit()
198 zfree(&env->cpu); in perf_env__exit()
199 for (i = 0; i < env->nr_cpu_pmu_caps; i++) in perf_env__exit()
200 zfree(&env->cpu_pmu_caps[i]); in perf_env__exit()
201 zfree(&env->cpu_pmu_caps); in perf_env__exit()
202 zfree(&env->numa_map); in perf_env__exit()
204 for (i = 0; i < env->nr_numa_nodes; i++) in perf_env__exit()
205 perf_cpu_map__put(env->numa_nodes[i].map); in perf_env__exit()
206 zfree(&env->numa_nodes); in perf_env__exit()
208 for (i = 0; i < env->caches_cnt; i++) in perf_env__exit()
209 cpu_cache_level__free(&env->caches[i]); in perf_env__exit()
210 zfree(&env->caches); in perf_env__exit()
212 for (i = 0; i < env->nr_memory_nodes; i++) in perf_env__exit()
213 zfree(&env->memory_nodes[i].set); in perf_env__exit()
214 zfree(&env->memory_nodes); in perf_env__exit()
216 for (i = 0; i < env->nr_hybrid_nodes; i++) { in perf_env__exit()
217 zfree(&env->hybrid_nodes[i].pmu_name); in perf_env__exit()
218 zfree(&env->hybrid_nodes[i].cpus); in perf_env__exit()
220 zfree(&env->hybrid_nodes); in perf_env__exit()
222 for (i = 0; i < env->nr_pmus_with_caps; i++) { in perf_env__exit()
223 for (j = 0; j < env->pmu_caps[i].nr_caps; j++) in perf_env__exit()
224 zfree(&env->pmu_caps[i].caps[j]); in perf_env__exit()
225 zfree(&env->pmu_caps[i].caps); in perf_env__exit()
226 zfree(&env->pmu_caps[i].pmu_name); in perf_env__exit()
228 zfree(&env->pmu_caps); in perf_env__exit()
234 env->bpf_progs.infos = RB_ROOT; in perf_env__init()
235 env->bpf_progs.btfs = RB_ROOT; in perf_env__init()
236 init_rwsem(&env->bpf_progs.lock); in perf_env__init()
238 env->kernel_is_64_bit = -1; in perf_env__init()
249 env->kernel_is_64_bit = 1; in perf_env__init_kernel_mode()
251 env->kernel_is_64_bit = 0; in perf_env__init_kernel_mode()
256 if (env->kernel_is_64_bit == -1) in perf_env__kernel_is_64_bit()
259 return env->kernel_is_64_bit; in perf_env__kernel_is_64_bit()
267 env->cmdline_argv = calloc(argc, sizeof(char *)); in perf_env__set_cmdline()
268 if (env->cmdline_argv == NULL) in perf_env__set_cmdline()
276 env->cmdline_argv[i] = argv[i]; in perf_env__set_cmdline()
277 if (env->cmdline_argv[i] == NULL) in perf_env__set_cmdline()
281 env->nr_cmdline = argc; in perf_env__set_cmdline()
285 zfree(&env->cmdline_argv); in perf_env__set_cmdline()
287 return -ENOMEM; in perf_env__set_cmdline()
294 if (env->cpu != NULL) in perf_env__read_cpu_topology_map()
297 if (env->nr_cpus_avail == 0) in perf_env__read_cpu_topology_map()
298 env->nr_cpus_avail = cpu__max_present_cpu().cpu; in perf_env__read_cpu_topology_map()
300 nr_cpus = env->nr_cpus_avail; in perf_env__read_cpu_topology_map()
301 if (nr_cpus == -1) in perf_env__read_cpu_topology_map()
302 return -EINVAL; in perf_env__read_cpu_topology_map()
304 env->cpu = calloc(nr_cpus, sizeof(env->cpu[0])); in perf_env__read_cpu_topology_map()
305 if (env->cpu == NULL) in perf_env__read_cpu_topology_map()
306 return -ENOMEM; in perf_env__read_cpu_topology_map()
311 env->cpu[idx].core_id = cpu__get_core_id(cpu); in perf_env__read_cpu_topology_map()
312 env->cpu[idx].socket_id = cpu__get_socket_id(cpu); in perf_env__read_cpu_topology_map()
313 env->cpu[idx].die_id = cpu__get_die_id(cpu); in perf_env__read_cpu_topology_map()
316 env->nr_cpus_avail = nr_cpus; in perf_env__read_cpu_topology_map()
327 if (!pmu->name) in perf_env__read_pmu_mappings()
333 return -ENOENT; in perf_env__read_pmu_mappings()
335 env->nr_pmu_mappings = pmu_num; in perf_env__read_pmu_mappings()
338 return -ENOMEM; in perf_env__read_pmu_mappings()
341 if (!pmu->name) in perf_env__read_pmu_mappings()
343 if (strbuf_addf(&sb, "%u:%s", pmu->type, pmu->name) < 0) in perf_env__read_pmu_mappings()
350 env->pmu_mappings = strbuf_detach(&sb, NULL); in perf_env__read_pmu_mappings()
356 return -1; in perf_env__read_pmu_mappings()
367 free(env->cpuid); in perf_env__read_cpuid()
368 env->cpuid = strdup(cpuid); in perf_env__read_cpuid()
369 if (env->cpuid == NULL) in perf_env__read_cpuid()
378 if (env->arch) in perf_env__read_arch()
382 env->arch = strdup(uts.machine); in perf_env__read_arch()
384 return env->arch ? 0 : -ENOMEM; in perf_env__read_arch()
389 if (env->nr_cpus_avail == 0) in perf_env__read_nr_cpus_avail()
390 env->nr_cpus_avail = cpu__max_present_cpu().cpu; in perf_env__read_nr_cpus_avail()
392 return env->nr_cpus_avail ? 0 : -ENOENT; in perf_env__read_nr_cpus_avail()
397 return env && !perf_env__read_arch(env) ? env->arch : "unknown"; in perf_env__raw_arch()
402 return env && !perf_env__read_nr_cpus_avail(env) ? env->nr_cpus_avail : 0; in perf_env__nr_cpus_avail()
407 zfree(&cache->type); in cpu_cache_level__free()
408 zfree(&cache->map); in cpu_cache_level__free()
409 zfree(&cache->size); in cpu_cache_level__free()
446 if (!env || !env->arch) { /* Assume local operation */ in perf_env__arch()
452 arch_name = env->arch; in perf_env__arch()
461 if (!env || !env->cpuid) { /* Assume local operation */ in perf_env__cpuid()
467 return env->cpuid; in perf_env__cpuid()
474 if (!env || !env->nr_pmu_mappings) { /* Assume local operation */ in perf_env__nr_pmu_mappings()
480 return env->nr_pmu_mappings; in perf_env__nr_pmu_mappings()
487 if (!env || !env->pmu_mappings) { /* Assume local operation */ in perf_env__pmu_mappings()
493 return env->pmu_mappings; in perf_env__pmu_mappings()
498 if (!env->nr_numa_map) { in perf_env__numa_node()
502 for (i = 0; i < env->nr_numa_nodes; i++) { in perf_env__numa_node()
503 nn = &env->numa_nodes[i]; in perf_env__numa_node()
504 nr = max(nr, perf_cpu_map__max(nn->map).cpu); in perf_env__numa_node()
511 * it for missing cpus, which return node -1 in perf_env__numa_node()
513 env->numa_map = malloc(nr * sizeof(int)); in perf_env__numa_node()
514 if (!env->numa_map) in perf_env__numa_node()
515 return -1; in perf_env__numa_node()
518 env->numa_map[i] = -1; in perf_env__numa_node()
520 env->nr_numa_map = nr; in perf_env__numa_node()
522 for (i = 0; i < env->nr_numa_nodes; i++) { in perf_env__numa_node()
526 nn = &env->numa_nodes[i]; in perf_env__numa_node()
527 perf_cpu_map__for_each_cpu(tmp, j, nn->map) in perf_env__numa_node()
528 env->numa_map[tmp.cpu] = i; in perf_env__numa_node()
532 return cpu.cpu >= 0 && cpu.cpu < env->nr_numa_map ? env->numa_map[cpu.cpu] : -1; in perf_env__numa_node()
536 const char *cap) in perf_env__find_pmu_cap() argument
543 if (!pmu_name || !cap) in perf_env__find_pmu_cap()
546 cap_size = strlen(cap); in perf_env__find_pmu_cap()
551 memcpy(cap_eq, cap, cap_size); in perf_env__find_pmu_cap()
555 for (i = 0; i < env->nr_cpu_pmu_caps; i++) { in perf_env__find_pmu_cap()
556 if (!strncmp(env->cpu_pmu_caps[i], cap_eq, cap_size + 1)) { in perf_env__find_pmu_cap()
558 return &env->cpu_pmu_caps[i][cap_size + 1]; in perf_env__find_pmu_cap()
564 for (i = 0; i < env->nr_pmus_with_caps; i++) { in perf_env__find_pmu_cap()
565 if (strcmp(env->pmu_caps[i].pmu_name, pmu_name)) in perf_env__find_pmu_cap()
568 ptr = env->pmu_caps[i].caps; in perf_env__find_pmu_cap()
570 for (j = 0; j < env->pmu_caps[i].nr_caps; j++) { in perf_env__find_pmu_cap()