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);
169 static int bpf_program_profiler__load(struct evsel *evsel, struct target *target)
189 ret = bpf_program_profiler_load_one(evsel, prog_id);
191 bpf_program_profiler__destroy(evsel);
201 static int bpf_program_profiler__enable(struct evsel *evsel)
206 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
210 bpf_program_profiler__destroy(evsel);
217 static int bpf_program_profiler__disable(struct evsel *evsel)
221 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
228 static int bpf_program_profiler__read(struct evsel *evsel)
241 if (list_empty(&evsel->bpf_counter_list))
244 perf_cpu_map__for_each_idx(idx, evsel__cpus(evsel)) {
245 counts = perf_counts(evsel->counts, idx, 0);
250 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
263 idx = perf_cpu_map__idx(evsel__cpus(evsel),
267 counts = perf_counts(evsel->counts, idx, 0);
276 static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu_map_idx,
283 list_for_each_entry(counter, &evsel->bpf_counter_list, list) {
365 static int bperf_check_target(struct evsel *evsel,
370 if (evsel->core.leader->nr_members > 1) {
381 *filter_entry_cnt = perf_cpu_map__nr(evsel__cpus(evsel));
384 *filter_entry_cnt = perf_thread_map__nr(evsel->core.threads);
385 } else if (target->pid || evsel->evlist->workload.pid != -1) {
387 *filter_entry_cnt = perf_thread_map__nr(evsel->core.threads);
398 static int bperf_reload_leader_program(struct evsel *evsel, int attr_map_fd,
428 err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, entry, BPF_ANY);
431 evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry->link_id);
432 assert(evsel->bperf_leader_link_fd >= 0);
438 evsel->leader_skel = skel;
439 evsel__open_per_cpu(evsel, all_cpu_map, -1);
447 static int bperf__load(struct evsel *evsel, struct target *target)
454 if (bperf_check_target(evsel, target, &filter_type, &filter_entry_cnt))
463 evsel->bperf_leader_prog_fd = -1;
464 evsel->bperf_leader_link_fd = -1;
478 err = bpf_map_lookup_elem(attr_map_fd, &evsel->core.attr, &entry);
480 err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, &entry, BPF_ANY);
485 evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry.link_id);
486 if (evsel->bperf_leader_link_fd < 0 &&
487 bperf_reload_leader_program(evsel, attr_map_fd, &entry)) {
496 evsel->bperf_leader_prog_fd = bpf_prog_get_fd_by_id(
497 bpf_link_get_prog_id(evsel->bperf_leader_link_fd));
498 assert(evsel->bperf_leader_prog_fd >= 0);
507 err = bperf_trigger_reading(evsel->bperf_leader_prog_fd, 0);
515 evsel->follower_skel = bperf_follower_bpf__open();
516 if (!evsel->follower_skel) {
523 bpf_program__set_attach_target(evsel->follower_skel->progs.fexit_XXX,
524 evsel->bperf_leader_prog_fd, "on_switch");
527 bpf_map__reuse_fd(evsel->follower_skel->maps.diff_readings, diff_map_fd);
530 bpf_map__set_max_entries(evsel->follower_skel->maps.accum_readings,
533 bpf_map__set_max_entries(evsel->follower_skel->maps.filter,
535 err = bperf_follower_bpf__load(evsel->follower_skel);
538 bperf_follower_bpf__destroy(evsel->follower_skel);
539 evsel->follower_skel = NULL;
549 key = perf_thread_map__pid(evsel->core.threads, i);
551 key = perf_cpu_map__cpu(evsel->core.cpus, i).cpu;
555 filter_map_fd = bpf_map__fd(evsel->follower_skel->maps.filter);
559 evsel->follower_skel->bss->type = filter_type;
561 err = bperf_follower_bpf__attach(evsel->follower_skel);
564 if (err && evsel->bperf_leader_link_fd >= 0)
565 close(evsel->bperf_leader_link_fd);
566 if (err && evsel->bperf_leader_prog_fd >= 0)
567 close(evsel->bperf_leader_prog_fd);
577 static int bperf__install_pe(struct evsel *evsel, int cpu_map_idx, int fd)
579 struct bperf_leader_bpf *skel = evsel->leader_skel;
589 static int bperf_sync_counters(struct evsel *evsel)
596 bperf_trigger_reading(evsel->bperf_leader_prog_fd, cpu);
601 static int bperf__enable(struct evsel *evsel)
603 evsel->follower_skel->bss->enabled = 1;
607 static int bperf__disable(struct evsel *evsel)
609 evsel->follower_skel->bss->enabled = 0;
613 static int bperf__read(struct evsel *evsel)
615 struct bperf_follower_bpf *skel = evsel->follower_skel;
623 bperf_sync_counters(evsel);
633 switch (evsel->follower_skel->bss->type) {
637 perf_cpu_map__for_each_cpu(entry, j, evsel__cpus(evsel)) {
638 counts = perf_counts(evsel->counts, j, 0);
645 cpu = perf_cpu_map__cpu(evsel__cpus(evsel), i).cpu;
647 counts = perf_counts(evsel->counts, i, 0);
654 counts = perf_counts(evsel->counts, 0, i);
673 static int bperf__destroy(struct evsel *evsel)
675 bperf_follower_bpf__destroy(evsel->follower_skel);
676 close(evsel->bperf_leader_prog_fd);
677 close(evsel->bperf_leader_link_fd);
767 static inline bool bpf_counter_skip(struct evsel *evsel)
769 return evsel->bpf_counter_ops == NULL;
772 int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd)
774 if (bpf_counter_skip(evsel))
776 return evsel->bpf_counter_ops->install_pe(evsel, cpu_map_idx, fd);
779 int bpf_counter__load(struct evsel *evsel, struct target *target)
782 evsel->bpf_counter_ops = &bpf_program_profiler_ops;
784 evsel->bpf_counter_ops = &bperf_cgrp_ops;
785 else if (target->use_bpf || evsel->bpf_counter ||
786 evsel__match_bpf_counter_events(evsel->name))
787 evsel->bpf_counter_ops = &bperf_ops;
789 if (evsel->bpf_counter_ops)
790 return evsel->bpf_counter_ops->load(evsel, target);
794 int bpf_counter__enable(struct evsel *evsel)
796 if (bpf_counter_skip(evsel))
798 return evsel->bpf_counter_ops->enable(evsel);
801 int bpf_counter__disable(struct evsel *evsel)
803 if (bpf_counter_skip(evsel))
805 return evsel->bpf_counter_ops->disable(evsel);
808 int bpf_counter__read(struct evsel *evsel)
810 if (bpf_counter_skip(evsel))
812 return evsel->bpf_counter_ops->read(evsel);
815 void bpf_counter__destroy(struct evsel *evsel)
817 if (bpf_counter_skip(evsel))
819 evsel->bpf_counter_ops->destroy(evsel);
820 evsel->bpf_counter_ops = NULL;
821 evsel->bpf_skel = NULL;