Lines Matching refs:evsel
19 #include "evsel.h"
48 static int bpf_program_profiler__destroy(struct evsel *evsel)
53 &evsel->bpf_counter_list, list) {
58 assert(list_empty(&evsel->bpf_counter_list));
102 static int bpf_program_profiler_load_one(struct evsel *evsel, u32 prog_id)
128 skel->rodata->num_cpu = evsel__nr_cpus(evsel);
130 bpf_map__set_max_entries(skel->maps.events, evsel__nr_cpus(evsel));
157 list_add(&counter->list, &evsel->bpf_counter_list);
167 static int bpf_program_profiler__load(struct evsel *evsel, struct target *target)
186 ret = bpf_program_profiler_load_one(evsel, prog_id);
188 bpf_program_profiler__destroy(evsel);
198 static int bpf_program_profiler__enable(struct evsel *evsel)
203 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
207 bpf_program_profiler__destroy(evsel);
214 static int bpf_program_profiler__disable(struct evsel *evsel)
218 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
225 static int bpf_program_profiler__read(struct evsel *evsel)
238 if (list_empty(&evsel->bpf_counter_list))
241 perf_cpu_map__for_each_idx(idx, evsel__cpus(evsel)) {
242 counts = perf_counts(evsel->counts, idx, 0);
247 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
260 idx = perf_cpu_map__idx(evsel__cpus(evsel),
264 counts = perf_counts(evsel->counts, idx, 0);
273 static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu_map_idx,
280 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
362 static int bperf_check_target(struct evsel *evsel,
367 if (evsel->core.leader->nr_members > 1) {
378 *filter_entry_cnt = perf_cpu_map__nr(evsel__cpus(evsel));
381 *filter_entry_cnt = perf_thread_map__nr(evsel->core.threads);
382 } else if (target->pid || evsel->evlist->workload.pid != -1) {
384 *filter_entry_cnt = perf_thread_map__nr(evsel->core.threads);
395 static int bperf_reload_leader_program(struct evsel *evsel, int attr_map_fd,
425 err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, entry, BPF_ANY);
428 evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry->link_id);
429 assert(evsel->bperf_leader_link_fd >= 0);
435 evsel->leader_skel = skel;
436 evsel__open_per_cpu(evsel, all_cpu_map, -1);
444 static int bperf__load(struct evsel *evsel, struct target *target)
451 if (bperf_check_target(evsel, target, &filter_type, &filter_entry_cnt))
460 evsel->bperf_leader_prog_fd = -1;
461 evsel->bperf_leader_link_fd = -1;
475 err = bpf_map_lookup_elem(attr_map_fd, &evsel->core.attr, &entry);
477 err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, &entry, BPF_ANY);
482 evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry.link_id);
483 if (evsel->bperf_leader_link_fd < 0 &&
484 bperf_reload_leader_program(evsel, attr_map_fd, &entry)) {
493 evsel->bperf_leader_prog_fd = bpf_prog_get_fd_by_id(
494 bpf_link_get_prog_id(evsel->bperf_leader_link_fd));
495 assert(evsel->bperf_leader_prog_fd >= 0);
504 err = bperf_trigger_reading(evsel->bperf_leader_prog_fd, 0);
512 evsel->follower_skel = bperf_follower_bpf__open();
513 if (!evsel->follower_skel) {
520 bpf_program__set_attach_target(evsel->follower_skel->progs.fexit_XXX,
521 evsel->bperf_leader_prog_fd, "on_switch");
524 bpf_map__reuse_fd(evsel->follower_skel->maps.diff_readings, diff_map_fd);
527 bpf_map__set_max_entries(evsel->follower_skel->maps.accum_readings,
530 bpf_map__set_max_entries(evsel->follower_skel->maps.filter,
532 err = bperf_follower_bpf__load(evsel->follower_skel);
535 bperf_follower_bpf__destroy(evsel->follower_skel);
536 evsel->follower_skel = NULL;
546 key = perf_thread_map__pid(evsel->core.threads, i);
548 key = perf_cpu_map__cpu(evsel->core.cpus, i).cpu;
552 filter_map_fd = bpf_map__fd(evsel->follower_skel->maps.filter);
556 evsel->follower_skel->bss->type = filter_type;
558 err = bperf_follower_bpf__attach(evsel->follower_skel);
561 if (err && evsel->bperf_leader_link_fd >= 0)
562 close(evsel->bperf_leader_link_fd);
563 if (err && evsel->bperf_leader_prog_fd >= 0)
564 close(evsel->bperf_leader_prog_fd);
574 static int bperf__install_pe(struct evsel *evsel, int cpu_map_idx, int fd)
576 struct bperf_leader_bpf *skel = evsel->leader_skel;
586 static int bperf_sync_counters(struct evsel *evsel)
593 bperf_trigger_reading(evsel->bperf_leader_prog_fd, cpu);
598 static int bperf__enable(struct evsel *evsel)
600 evsel->follower_skel->bss->enabled = 1;
604 static int bperf__disable(struct evsel *evsel)
606 evsel->follower_skel->bss->enabled = 0;
610 static int bperf__read(struct evsel *evsel)
612 struct bperf_follower_bpf *skel = evsel->follower_skel;
620 bperf_sync_counters(evsel);
630 switch (evsel->follower_skel->bss->type) {
634 perf_cpu_map__for_each_cpu(entry, j, evsel__cpus(evsel)) {
635 counts = perf_counts(evsel->counts, j, 0);
642 cpu = perf_cpu_map__cpu(evsel__cpus(evsel), i).cpu;
644 counts = perf_counts(evsel->counts, i, 0);
651 counts = perf_counts(evsel->counts, 0, i);
670 static int bperf__destroy(struct evsel *evsel)
672 bperf_follower_bpf__destroy(evsel->follower_skel);
673 close(evsel->bperf_leader_prog_fd);
674 close(evsel->bperf_leader_link_fd);
764 static inline bool bpf_counter_skip(struct evsel *evsel)
766 return evsel->bpf_counter_ops == NULL;
769 int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd)
771 if (bpf_counter_skip(evsel))
773 return evsel->bpf_counter_ops->install_pe(evsel, cpu_map_idx, fd);
776 int bpf_counter__load(struct evsel *evsel, struct target *target)
779 evsel->bpf_counter_ops = &bpf_program_profiler_ops;
781 evsel->bpf_counter_ops = &bperf_cgrp_ops;
782 else if (target->use_bpf || evsel->bpf_counter ||
783 evsel__match_bpf_counter_events(evsel->name))
784 evsel->bpf_counter_ops = &bperf_ops;
786 if (evsel->bpf_counter_ops)
787 return evsel->bpf_counter_ops->load(evsel, target);
791 int bpf_counter__enable(struct evsel *evsel)
793 if (bpf_counter_skip(evsel))
795 return evsel->bpf_counter_ops->enable(evsel);
798 int bpf_counter__disable(struct evsel *evsel)
800 if (bpf_counter_skip(evsel))
802 return evsel->bpf_counter_ops->disable(evsel);
805 int bpf_counter__read(struct evsel *evsel)
807 if (bpf_counter_skip(evsel))
809 return evsel->bpf_counter_ops->read(evsel);
812 void bpf_counter__destroy(struct evsel *evsel)
814 if (bpf_counter_skip(evsel))
816 evsel->bpf_counter_ops->destroy(evsel);
817 evsel->bpf_counter_ops = NULL;
818 evsel->bpf_skel = NULL;