Re: [PATCHSET v2 0/3] perf stat: Enable BPF counters with --for-each-cgroup

From: Peter Zijlstra
Date: Wed Jun 16 2021 - 18:34:38 EST


On Wed, Jun 16, 2021 at 09:33:42AM -0700, Namhyung Kim wrote:

> > That seems unfortunate; there's no bpf helper to iterate cgroup
> > hierarchy?
>
> I couldn't find one..

Song, is that something that would make sense to have?

> > > * there's no reliable way to trigger running the BPF program
> >
> > You can't attach to the PERF_COUNT_SW_CGROUP_SWITCHES event?
>
> I did it. But the BPF test run seems not to work with perf_event.
> So it needs to trigger a cgroup switch manually..

AFAICT it should be possible to set a bpf prog on a software event.
perf_event_set_bpf_prog() will take the first branch
(!perf_event_is_tracing()) and call perf_event_set_bpf_handler().

That should then result in running the bpf program every time the event
would generate a sample.

So if you configure the event to sample on every single event, it should
then run your program every time.

This is all from looking at the code, because I really can't operate any
of that for real. I suspect Song can help out.

The alternative is to attach a BPF program to the sched_switch
tracepoint and do the cgroup filter in BPF.