Lines Matching refs:evsel
48 static int bpf_program_profiler__destroy(struct evsel *evsel) in bpf_program_profiler__destroy() argument
53 &evsel->bpf_counter_list, list) { in bpf_program_profiler__destroy()
58 assert(list_empty(&evsel->bpf_counter_list)); in bpf_program_profiler__destroy()
102 static int bpf_program_profiler_load_one(struct evsel *evsel, u32 prog_id) in bpf_program_profiler_load_one() argument
128 skel->rodata->num_cpu = evsel__nr_cpus(evsel); in bpf_program_profiler_load_one()
130 bpf_map__set_max_entries(skel->maps.events, evsel__nr_cpus(evsel)); in bpf_program_profiler_load_one()
157 list_add(&counter->list, &evsel->bpf_counter_list); in bpf_program_profiler_load_one()
169 static int bpf_program_profiler__load(struct evsel *evsel, struct target *target) in bpf_program_profiler__load() argument
189 ret = bpf_program_profiler_load_one(evsel, prog_id); in bpf_program_profiler__load()
191 bpf_program_profiler__destroy(evsel); in bpf_program_profiler__load()
201 static int bpf_program_profiler__enable(struct evsel *evsel) in bpf_program_profiler__enable() argument
206 list_for_each_entry(counter, &evsel->bpf_counter_list, list) { in bpf_program_profiler__enable()
210 bpf_program_profiler__destroy(evsel); in bpf_program_profiler__enable()
217 static int bpf_program_profiler__disable(struct evsel *evsel) in bpf_program_profiler__disable() argument
221 list_for_each_entry(counter, &evsel->bpf_counter_list, list) { in bpf_program_profiler__disable()
228 static int bpf_program_profiler__read(struct evsel *evsel) in bpf_program_profiler__read() argument
241 if (list_empty(&evsel->bpf_counter_list)) in bpf_program_profiler__read()
244 perf_cpu_map__for_each_idx(idx, evsel__cpus(evsel)) { in bpf_program_profiler__read()
245 counts = perf_counts(evsel->counts, idx, 0); in bpf_program_profiler__read()
250 list_for_each_entry(counter, &evsel->bpf_counter_list, list) { in bpf_program_profiler__read()
263 idx = perf_cpu_map__idx(evsel__cpus(evsel), in bpf_program_profiler__read()
267 counts = perf_counts(evsel->counts, idx, 0); in bpf_program_profiler__read()
276 static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu_map_idx, in bpf_program_profiler__install_pe() argument
283 list_for_each_entry(counter, &evsel->bpf_counter_list, list) { in bpf_program_profiler__install_pe()
365 static int bperf_check_target(struct evsel *evsel, in bperf_check_target() argument
370 if (evsel->core.leader->nr_members > 1) { in bperf_check_target()
381 *filter_entry_cnt = perf_cpu_map__nr(evsel__cpus(evsel)); in bperf_check_target()
384 *filter_entry_cnt = perf_thread_map__nr(evsel->core.threads); in bperf_check_target()
385 } else if (target->pid || evsel->evlist->workload.pid != -1) { in bperf_check_target()
387 *filter_entry_cnt = perf_thread_map__nr(evsel->core.threads); in bperf_check_target()
399 static int bperf_reload_leader_program(struct evsel *evsel, int attr_map_fd, in bperf_reload_leader_program() argument
429 err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, entry, BPF_ANY); in bperf_reload_leader_program()
432 evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry->link_id); in bperf_reload_leader_program()
433 assert(evsel->bperf_leader_link_fd >= 0); in bperf_reload_leader_program()
439 evsel->leader_skel = skel; in bperf_reload_leader_program()
440 evsel__open_per_cpu(evsel, all_cpu_map, -1); in bperf_reload_leader_program()
468 static int bperf__load(struct evsel *evsel, struct target *target) in bperf__load() argument
475 if (bperf_check_target(evsel, target, &filter_type, &filter_entry_cnt)) in bperf__load()
484 evsel->bperf_leader_prog_fd = -1; in bperf__load()
485 evsel->bperf_leader_link_fd = -1; in bperf__load()
499 err = bpf_map_lookup_elem(attr_map_fd, &evsel->core.attr, &entry); in bperf__load()
501 err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, &entry, BPF_ANY); in bperf__load()
506 evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry.link_id); in bperf__load()
507 if (evsel->bperf_leader_link_fd < 0 && in bperf__load()
508 bperf_reload_leader_program(evsel, attr_map_fd, &entry)) { in bperf__load()
517 evsel->bperf_leader_prog_fd = bpf_prog_get_fd_by_id( in bperf__load()
518 bpf_link_get_prog_id(evsel->bperf_leader_link_fd)); in bperf__load()
519 assert(evsel->bperf_leader_prog_fd >= 0); in bperf__load()
528 err = bperf_trigger_reading(evsel->bperf_leader_prog_fd, 0); in bperf__load()
536 evsel->follower_skel = bperf_follower_bpf__open(); in bperf__load()
537 if (!evsel->follower_skel) { in bperf__load()
544 bpf_program__set_attach_target(evsel->follower_skel->progs.fexit_XXX, in bperf__load()
545 evsel->bperf_leader_prog_fd, "on_switch"); in bperf__load()
548 bpf_map__reuse_fd(evsel->follower_skel->maps.diff_readings, diff_map_fd); in bperf__load()
551 bpf_map__set_max_entries(evsel->follower_skel->maps.accum_readings, in bperf__load()
553 err = bperf_follower_bpf__load(evsel->follower_skel); in bperf__load()
556 bperf_follower_bpf__destroy(evsel->follower_skel); in bperf__load()
557 evsel->follower_skel = NULL; in bperf__load()
568 key = perf_thread_map__pid(evsel->core.threads, i); in bperf__load()
570 key = perf_cpu_map__cpu(evsel->core.cpus, i).cpu; in bperf__load()
574 filter_map_fd = bpf_map__fd(evsel->follower_skel->maps.filter); in bperf__load()
578 evsel->follower_skel->bss->type = filter_type; in bperf__load()
579 evsel->follower_skel->bss->inherit = target->inherit; in bperf__load()
581 err = bperf_attach_follower_program(evsel->follower_skel, filter_type, in bperf__load()
585 if (err && evsel->bperf_leader_link_fd >= 0) in bperf__load()
586 close(evsel->bperf_leader_link_fd); in bperf__load()
587 if (err && evsel->bperf_leader_prog_fd >= 0) in bperf__load()
588 close(evsel->bperf_leader_prog_fd); in bperf__load()
598 static int bperf__install_pe(struct evsel *evsel, int cpu_map_idx, int fd) in bperf__install_pe() argument
600 struct bperf_leader_bpf *skel = evsel->leader_skel; in bperf__install_pe()
610 static int bperf_sync_counters(struct evsel *evsel) in bperf_sync_counters() argument
617 bperf_trigger_reading(evsel->bperf_leader_prog_fd, cpu); in bperf_sync_counters()
622 static int bperf__enable(struct evsel *evsel) in bperf__enable() argument
624 evsel->follower_skel->bss->enabled = 1; in bperf__enable()
628 static int bperf__disable(struct evsel *evsel) in bperf__disable() argument
630 evsel->follower_skel->bss->enabled = 0; in bperf__disable()
634 static int bperf__read(struct evsel *evsel) in bperf__read() argument
636 struct bperf_follower_bpf *skel = evsel->follower_skel; in bperf__read()
644 bperf_sync_counters(evsel); in bperf__read()
654 switch (evsel->follower_skel->bss->type) { in bperf__read()
658 perf_cpu_map__for_each_cpu(entry, j, evsel__cpus(evsel)) { in bperf__read()
659 counts = perf_counts(evsel->counts, j, 0); in bperf__read()
666 cpu = perf_cpu_map__cpu(evsel__cpus(evsel), i).cpu; in bperf__read()
668 counts = perf_counts(evsel->counts, i, 0); in bperf__read()
675 counts = perf_counts(evsel->counts, 0, i); in bperf__read()
694 static int bperf__destroy(struct evsel *evsel) in bperf__destroy() argument
696 bperf_follower_bpf__destroy(evsel->follower_skel); in bperf__destroy()
697 close(evsel->bperf_leader_prog_fd); in bperf__destroy()
698 close(evsel->bperf_leader_link_fd); in bperf__destroy()
788 static inline bool bpf_counter_skip(struct evsel *evsel) in bpf_counter_skip() argument
790 return evsel->bpf_counter_ops == NULL; in bpf_counter_skip()
793 int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd) in bpf_counter__install_pe() argument
795 if (bpf_counter_skip(evsel)) in bpf_counter__install_pe()
797 return evsel->bpf_counter_ops->install_pe(evsel, cpu_map_idx, fd); in bpf_counter__install_pe()
800 int bpf_counter__load(struct evsel *evsel, struct target *target) in bpf_counter__load() argument
803 evsel->bpf_counter_ops = &bpf_program_profiler_ops; in bpf_counter__load()
805 evsel->bpf_counter_ops = &bperf_cgrp_ops; in bpf_counter__load()
806 else if (target->use_bpf || evsel->bpf_counter || in bpf_counter__load()
807 evsel__match_bpf_counter_events(evsel->name)) in bpf_counter__load()
808 evsel->bpf_counter_ops = &bperf_ops; in bpf_counter__load()
810 if (evsel->bpf_counter_ops) in bpf_counter__load()
811 return evsel->bpf_counter_ops->load(evsel, target); in bpf_counter__load()
815 int bpf_counter__enable(struct evsel *evsel) in bpf_counter__enable() argument
817 if (bpf_counter_skip(evsel)) in bpf_counter__enable()
819 return evsel->bpf_counter_ops->enable(evsel); in bpf_counter__enable()
822 int bpf_counter__disable(struct evsel *evsel) in bpf_counter__disable() argument
824 if (bpf_counter_skip(evsel)) in bpf_counter__disable()
826 return evsel->bpf_counter_ops->disable(evsel); in bpf_counter__disable()
829 int bpf_counter__read(struct evsel *evsel) in bpf_counter__read() argument
831 if (bpf_counter_skip(evsel)) in bpf_counter__read()
833 return evsel->bpf_counter_ops->read(evsel); in bpf_counter__read()
836 void bpf_counter__destroy(struct evsel *evsel) in bpf_counter__destroy() argument
838 if (bpf_counter_skip(evsel)) in bpf_counter__destroy()
840 evsel->bpf_counter_ops->destroy(evsel); in bpf_counter__destroy()
841 evsel->bpf_counter_ops = NULL; in bpf_counter__destroy()
842 evsel->bpf_skel = NULL; in bpf_counter__destroy()