Re: [PATCH v1 2/2] perf bpf_counter: Fix handling of cpumap fixing hybrid
From: Ian Rogers
Date: Mon Oct 06 2025 - 17:21:00 EST
On Mon, Oct 6, 2025 at 12:57 PM Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
>
> On Mon, Oct 06, 2025 at 09:18:22AM -0700, Ian Rogers wrote:
> > On Wed, Oct 1, 2025 at 11:12 AM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> > >
> > > Don't open evsels on all CPUs, open them just on the CPUs they
> > > support. This avoids opening say an e-core event on a p-core and
> > > getting a failure - achieve this by getting rid of the "all_cpu_map".
> > >
> > > In install_pe functions don't use the cpu_map_idx as a CPU number,
> > > translate the cpu_map_idx, which is a dense index into the cpu_map
> > > skipping holes at the beginning, to a proper CPU number.
> > >
> > > Before:
> > > ```
> > > $ perf stat --bpf-counters -a -e cycles,instructions -- sleep 1
> > >
> > > Performance counter stats for 'system wide':
> > >
> > > <not supported> cpu_atom/cycles/
> > > 566,270,672 cpu_core/cycles/
> > > <not supported> cpu_atom/instructions/
> > > 572,792,836 cpu_core/instructions/ # 1.01 insn per cycle
> > >
> > > 1.001595384 seconds time elapsed
> > > ```
> > >
> > > After:
> > > ```
> > > $ perf stat --bpf-counters -a -e cycles,instructions -- sleep 1
> > >
> > > Performance counter stats for 'system wide':
> > >
> > > 443,299,201 cpu_atom/cycles/
> > > 1,233,919,737 cpu_core/cycles/
> > > 213,634,112 cpu_atom/instructions/ # 0.48 insn per cycle
> > > 2,758,965,527 cpu_core/instructions/ # 2.24 insn per cycle
> > >
> > > 1.001699485 seconds time elapsed
> > > ```
> > >
> > > Fixes: 7fac83aaf2ee ("perf stat: Introduce 'bperf' to share hardware PMCs with BPF")
> > > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> >
> > +Thomas Falcon
> >
> > I think it'd be nice to get this quite major fix for
> > --bpf-counters/bperf for hybrid architectures into v6.18 and stable
> > builds. Thomas would it be possible for you to give a Tested-by tag
> > using the reproduction in the commit message?
>
> Its even already in linux-next:
>
> ⬢ [acme@toolbx perf-tools-next]$ git log -5 --oneline linux-next/master tools/perf/util/bpf_counter.c
> b91917c0c6fa6df9 perf bpf_counter: Fix handling of cpumap fixing hybrid
> 8c519a825b4add85 perf bpf_counter: Move header declarations into C code
> 07dc3a6de33098b0 perf stat: Support inherit events during fork() for bperf
> effe957c6bb70cac libperf cpumap: Replace usage of perf_cpu_map__new(NULL) with perf_cpu_map__new_online_cpus()
> b84b3f47921568a8 perf bpf_counter: Fix a few memory leaks
> ⬢ [acme@toolbx perf-tools-next]$
Oh, thanks! Sorry for missing it. Thanks Thomas for the tag!
Ian