[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAM9d7cibDFdua2=SXBL2yNBFD7dYGs0H+ZOL_rhEzzjrP5ReLQ@mail.gmail.com>
Date: Mon, 21 Jun 2021 18:43:29 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Song Liu <songliubraving@...com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Jiri Olsa <jolsa@...hat.com>, Ingo Molnar <mingo@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
Andi Kleen <ak@...ux.intel.com>,
Ian Rogers <irogers@...gle.com>,
Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCHSET v2 0/3] perf stat: Enable BPF counters with --for-each-cgroup
Hi Song,
On Wed, Jun 16, 2021 at 11:33 PM Song Liu <songliubraving@...com> wrote:
>
>
>
> > On Jun 16, 2021, at 3:32 PM, Peter Zijlstra <peterz@...radead.org> wrote:
> >
> > 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?
>
> I think we can solve this with bpf_get_current_ancestor_cgroup_id and
> a bounded loop. Like:
>
> /* get diff_reading, which is reading - prev_reading */
>
> for (i = 0; i < 10 /* at most 10 levels */; i++) {
> __u64 cgroup_id = bpf_get_current_ancestor_cgroup_id(i);
> if (!cgroup_id)
> break;
> /* add diff_reading to cgroup_id */
> }
OK, but I'm not sure 0 id is guaranteed.
>
> >
> >>>> * 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.
>
> We can create a raw_tp BPF program just for BPF_PROG_TEST_RUN (now also called
> BPF_PROG_RUN). The program should be the same as current on_switch program.
> We don't have to attach the program, just use BPF_PROG_RUN to trigger it.
>
> Would something like this work?
Oh, I think it'd work. Thanks for the suggestion!
Thanks,
Namhyung
Powered by blists - more mailing lists