Re: [PATCH] perf stat: Fix aggregation of cgroup events
From: Arnaldo Carvalho de Melo
Date: Fri Nov 06 2026 - 17:00:28 EST
On Wed, Oct 14, 2026 at 11:14:06AM -0700, Namhyung Kim wrote:
> On Fri, Oct 02, 2026 at 10:13:29AM -0700, Chun-Tse Shao wrote:
> > On Thu, Oct 1, 2026 at 10:48 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > >
> > > I got a report that perf stat with BPF and cgroup is broken with
> > > aggregation like per-socket or node. On my machine, running the
> > > following command shows the problem.
> > >
> > > $ sudo perf stat -a --bpf-counters --per-socket -e cycles \
> > > --for-each-cgroup /user.slice,/system.slice sleep 1
> > >
> > > Performance counter stats for 'system wide':
> > >
> > > S0 12 <not counted> cpu_atom/cycles/ user.slice
> > > S0 16 <not counted> cpu_core/cycles/ user.slice
> > > S0 12 <not counted> cpu_atom/cycles/ system.slice
> > > S0 16 <not counted> cpu_core/cycles/ system.slice
> > >
> > > 1.002798147 seconds time elapsed
> > >
> > > That's because there's a logic to make the whole event failed if result
> > > from any CPU looks bad when aggregation is enabled. Normally it
> > > considers bad when an event has no enabled and running time. But it's
> > > possible for a cgroup event to have no chance to run on some CPU during
> > > the window and then it will have 0 enabled and running time. Let's not
> > > treat them as errors.
> > >
> > > After the fix, the same command produces:
> > >
> > > Performance counter stats for 'system wide':
> > >
> > > S0 12 5,094,112 cpu_atom/cycles/ user.slice
> > > S0 16 28,075,944 cpu_core/cycles/ user.slice
> > > S0 12 1,516,568 cpu_atom/cycles/ system.slice
> > > S0 16 5,569,575 cpu_core/cycles/ system.slice
> > >
> > > 1.003231856 seconds time elapsed
> > >
> > > Reported-by: Chun-Tse Shao <ctshao@xxxxxxxxxx>
> > > Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> >
> > Tested-by: Chun-Tse Shao <ctshao@xxxxxxxxxx>
>
> Thanks for the test!
>
> Arnaldo, can you please take this?
>
applied,
- Arnaldo
> Thanks,
> Namhyung