diff mbox series

perf stat: Get a perf cgroup more portably in BPF

Message ID 20220922033349.2908447-1-namhyung@kernel.org (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series perf stat: Get a perf cgroup more portably in BPF | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Namhyung Kim Sept. 22, 2022, 3:33 a.m. UTC
The perf_event_cgrp_id can be different on other configurations.
To be more portable as CO-RE, it needs to get the cgroup subsys id
using the bpf_core_enum_value() helper.

Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/bpf_skel/bperf_cgroup.bpf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ian Rogers Sept. 22, 2022, 3:53 a.m. UTC | #1
On Wed, Sep 21, 2022 at 8:33 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> The perf_event_cgrp_id can be different on other configurations.
> To be more portable as CO-RE, it needs to get the cgroup subsys id
> using the bpf_core_enum_value() helper.
>
> Suggested-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/util/bpf_skel/bperf_cgroup.bpf.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
> index c72f8ad96f75..35a8e38d3ee3 100644
> --- a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
> +++ b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
> @@ -57,8 +57,10 @@ static inline int get_cgroup_v1_idx(__u32 *cgrps, int size)
>         __u32 *elem;
>         int level;
>         int cnt;
> +       int perf_id;
>
> -       cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_event_cgrp_id], cgroup);
> +       perf_id = bpf_core_enum_value(enum cgroup_subsys_id, perf_event_cgrp_id);
> +       cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_id], cgroup);

LGTM, do we need the same fix in off cpu?
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/util/bpf_skel/off_cpu.bpf.c?h=perf/core#n123

Thanks,
Ian

>         level = BPF_CORE_READ(cgrp, level);
>
>         for (cnt = 0; i < MAX_LEVELS; i++) {
> --
> 2.37.3.968.ga6b4b080e4-goog
>
Namhyung Kim Sept. 22, 2022, 4:18 a.m. UTC | #2
Hi Ian,

On Wed, Sep 21, 2022 at 8:54 PM Ian Rogers <irogers@google.com> wrote:
>
> On Wed, Sep 21, 2022 at 8:33 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > The perf_event_cgrp_id can be different on other configurations.
> > To be more portable as CO-RE, it needs to get the cgroup subsys id
> > using the bpf_core_enum_value() helper.
> >
> > Suggested-by: Ian Rogers <irogers@google.com>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> >  tools/perf/util/bpf_skel/bperf_cgroup.bpf.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
> > index c72f8ad96f75..35a8e38d3ee3 100644
> > --- a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
> > +++ b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
> > @@ -57,8 +57,10 @@ static inline int get_cgroup_v1_idx(__u32 *cgrps, int size)
> >         __u32 *elem;
> >         int level;
> >         int cnt;
> > +       int perf_id;
> >
> > -       cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_event_cgrp_id], cgroup);
> > +       perf_id = bpf_core_enum_value(enum cgroup_subsys_id, perf_event_cgrp_id);
> > +       cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_id], cgroup);
>
> LGTM, do we need the same fix in off cpu?
> https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/util/bpf_skel/off_cpu.bpf.c?h=perf/core#n123

Right, will send v2.

Thanks,
Namhyung
diff mbox series

Patch

diff --git a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
index c72f8ad96f75..35a8e38d3ee3 100644
--- a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
+++ b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c
@@ -57,8 +57,10 @@  static inline int get_cgroup_v1_idx(__u32 *cgrps, int size)
 	__u32 *elem;
 	int level;
 	int cnt;
+	int perf_id;
 
-	cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_event_cgrp_id], cgroup);
+	perf_id = bpf_core_enum_value(enum cgroup_subsys_id, perf_event_cgrp_id);
+	cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_id], cgroup);
 	level = BPF_CORE_READ(cgrp, level);
 
 	for (cnt = 0; i < MAX_LEVELS; i++) {