Skip to content

Commit ecc68ee

Browse files
erthalionacmel
authored andcommitted
perf stat: Separate bperf from bpf_profiler
It seems that perf stat -b <prog id> doesn't produce any results: $ perf stat -e cycles -b 4 -I 10000 -vvv Control descriptor is not initialized cycles: 0 0 0 time counts unit events 10.007641640 <not supported> cycles Looks like this happens because fentry/fexit progs are getting loaded, but the corresponding perf event is not enabled and not added into the events bpf map. I think there is some mixing up between two type of bpf support, one for bperf and one for bpf_profiler. Both are identified via evsel__is_bpf, based on which perf events are enabled, but for the latter (bpf_profiler) a perf event is required. Using evsel__is_bperf to check only bperf produces expected results: $ perf stat -e cycles -b 4 -I 10000 -vvv Control descriptor is not initialized ------------------------------------------------------------ perf_event_attr: size 136 sample_type IDENTIFIER read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING disabled 1 exclude_guest 1 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 3 ------------------------------------------------------------ [...perf_event_attr for other CPUs...] ------------------------------------------------------------ cycles: 309426 169009 169009 time counts unit events 10.010091271 309426 cycles The final numbers correspond (at least in the level of magnitude) to the same metric obtained via bpftool. Fixes: 112cb56 ("perf stat: Introduce config stat.bpf-counter-events") Reviewed-by: Song Liu <song@kernel.org> Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com> Tested-by: Song Liu <song@kernel.org> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20230412182316.11628-1-9erthalion6@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 1f85d01 commit ecc68ee

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tools/perf/builtin-stat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
712712
counter->reset_group = false;
713713
if (bpf_counter__load(counter, &target))
714714
return -1;
715-
if (!evsel__is_bpf(counter))
715+
if (!(evsel__is_bperf(counter)))
716716
all_counters_use_bpf = false;
717717
}
718718

@@ -728,7 +728,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
728728

729729
if (counter->reset_group || counter->errored)
730730
continue;
731-
if (evsel__is_bpf(counter))
731+
if (evsel__is_bperf(counter))
732732
continue;
733733
try_again:
734734
if (create_perf_stat_counter(counter, &stat_config, &target,

tools/perf/util/evsel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ static inline bool evsel__is_bpf(struct evsel *evsel)
269269
return evsel->bpf_counter_ops != NULL;
270270
}
271271

272+
static inline bool evsel__is_bperf(struct evsel *evsel)
273+
{
274+
return evsel->bpf_counter_ops != NULL && list_empty(&evsel->bpf_counter_list);
275+
}
276+
272277
#define EVSEL__MAX_ALIASES 8
273278

274279
extern const char *const evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES];

0 commit comments

Comments
 (0)