diff mbox series

[v1,2/2] perf bpf filter: Support pre-5.16 kernels

Message ID 20230408055208.1283832-2-irogers@google.com (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series [v1,1/2] perf lock contention: Support pre-5.14 kernels | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ian Rogers April 8, 2023, 5:52 a.m. UTC
The mem_hops bits were added in 5.16 with no prior equivalent.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/bpf_skel/sample_filter.bpf.c | 28 ++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

Comments

Namhyung Kim April 10, 2023, 3:34 p.m. UTC | #1
On Fri, Apr 7, 2023 at 10:52 PM Ian Rogers <irogers@google.com> wrote:
>
> The mem_hops bits were added in 5.16 with no prior equivalent.
>
> Signed-off-by: Ian Rogers <irogers@google.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/bpf_skel/sample_filter.bpf.c | 28 ++++++++++++++++++--
>  1 file changed, 26 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c b/tools/perf/util/bpf_skel/sample_filter.bpf.c
> index 57e3c67d6d37..cffe493af1ed 100644
> --- a/tools/perf/util/bpf_skel/sample_filter.bpf.c
> +++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c
> @@ -24,6 +24,24 @@ struct perf_sample_data___new {
>         __u64 sample_flags;
>  } __attribute__((preserve_access_index));
>
> +/* new kernel perf_mem_data_src definition */
> +union perf_mem_data_src__new {
> +       __u64 val;
> +       struct {
> +               __u64   mem_op:5,       /* type of opcode */
> +                       mem_lvl:14,     /* memory hierarchy level */
> +                       mem_snoop:5,    /* snoop mode */
> +                       mem_lock:2,     /* lock instr */
> +                       mem_dtlb:7,     /* tlb access */
> +                       mem_lvl_num:4,  /* memory hierarchy level number */
> +                       mem_remote:1,   /* remote */
> +                       mem_snoopx:2,   /* snoop mode, ext */
> +                       mem_blk:3,      /* access blocked */
> +                       mem_hops:3,     /* hop level */
> +                       mem_rsvd:18;
> +       };
> +};
> +
>  /* helper function to return the given perf sample data */
>  static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
>                                     struct perf_bpf_filter_entry *entry)
> @@ -89,8 +107,14 @@ static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
>                         return kctx->data->data_src.mem_dtlb;
>                 if (entry->part == 7)
>                         return kctx->data->data_src.mem_blk;
> -               if (entry->part == 8)
> -                       return kctx->data->data_src.mem_hops;
> +               if (entry->part == 8) {
> +                       union perf_mem_data_src__new *data = (void *)&kctx->data->data_src;
> +
> +                       if (bpf_core_field_exists(data->mem_hops))
> +                               return data->mem_hops;
> +
> +                       return 0;
> +               }
>                 /* return the whole word */
>                 return kctx->data->data_src.val;
>         default:
> --
> 2.40.0.577.gac1e443424-goog
>
Arnaldo Carvalho de Melo April 10, 2023, 10:12 p.m. UTC | #2
Em Mon, Apr 10, 2023 at 08:34:34AM -0700, Namhyung Kim escreveu:
> On Fri, Apr 7, 2023 at 10:52 PM Ian Rogers <irogers@google.com> wrote:
> >
> > The mem_hops bits were added in 5.16 with no prior equivalent.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Both applied, thanks,

- Arnaldo
 
> Thanks,
> Namhyung
> 
> 
> > ---
> >  tools/perf/util/bpf_skel/sample_filter.bpf.c | 28 ++++++++++++++++++--
> >  1 file changed, 26 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c b/tools/perf/util/bpf_skel/sample_filter.bpf.c
> > index 57e3c67d6d37..cffe493af1ed 100644
> > --- a/tools/perf/util/bpf_skel/sample_filter.bpf.c
> > +++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c
> > @@ -24,6 +24,24 @@ struct perf_sample_data___new {
> >         __u64 sample_flags;
> >  } __attribute__((preserve_access_index));
> >
> > +/* new kernel perf_mem_data_src definition */
> > +union perf_mem_data_src__new {
> > +       __u64 val;
> > +       struct {
> > +               __u64   mem_op:5,       /* type of opcode */
> > +                       mem_lvl:14,     /* memory hierarchy level */
> > +                       mem_snoop:5,    /* snoop mode */
> > +                       mem_lock:2,     /* lock instr */
> > +                       mem_dtlb:7,     /* tlb access */
> > +                       mem_lvl_num:4,  /* memory hierarchy level number */
> > +                       mem_remote:1,   /* remote */
> > +                       mem_snoopx:2,   /* snoop mode, ext */
> > +                       mem_blk:3,      /* access blocked */
> > +                       mem_hops:3,     /* hop level */
> > +                       mem_rsvd:18;
> > +       };
> > +};
> > +
> >  /* helper function to return the given perf sample data */
> >  static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
> >                                     struct perf_bpf_filter_entry *entry)
> > @@ -89,8 +107,14 @@ static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
> >                         return kctx->data->data_src.mem_dtlb;
> >                 if (entry->part == 7)
> >                         return kctx->data->data_src.mem_blk;
> > -               if (entry->part == 8)
> > -                       return kctx->data->data_src.mem_hops;
> > +               if (entry->part == 8) {
> > +                       union perf_mem_data_src__new *data = (void *)&kctx->data->data_src;
> > +
> > +                       if (bpf_core_field_exists(data->mem_hops))
> > +                               return data->mem_hops;
> > +
> > +                       return 0;
> > +               }
> >                 /* return the whole word */
> >                 return kctx->data->data_src.val;
> >         default:
> > --
> > 2.40.0.577.gac1e443424-goog
> >
diff mbox series

Patch

diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c b/tools/perf/util/bpf_skel/sample_filter.bpf.c
index 57e3c67d6d37..cffe493af1ed 100644
--- a/tools/perf/util/bpf_skel/sample_filter.bpf.c
+++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c
@@ -24,6 +24,24 @@  struct perf_sample_data___new {
 	__u64 sample_flags;
 } __attribute__((preserve_access_index));
 
+/* new kernel perf_mem_data_src definition */
+union perf_mem_data_src__new {
+	__u64 val;
+	struct {
+		__u64   mem_op:5,	/* type of opcode */
+			mem_lvl:14,	/* memory hierarchy level */
+			mem_snoop:5,	/* snoop mode */
+			mem_lock:2,	/* lock instr */
+			mem_dtlb:7,	/* tlb access */
+			mem_lvl_num:4,	/* memory hierarchy level number */
+			mem_remote:1,   /* remote */
+			mem_snoopx:2,	/* snoop mode, ext */
+			mem_blk:3,	/* access blocked */
+			mem_hops:3,	/* hop level */
+			mem_rsvd:18;
+	};
+};
+
 /* helper function to return the given perf sample data */
 static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
 				    struct perf_bpf_filter_entry *entry)
@@ -89,8 +107,14 @@  static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
 			return kctx->data->data_src.mem_dtlb;
 		if (entry->part == 7)
 			return kctx->data->data_src.mem_blk;
-		if (entry->part == 8)
-			return kctx->data->data_src.mem_hops;
+		if (entry->part == 8) {
+			union perf_mem_data_src__new *data = (void *)&kctx->data->data_src;
+
+			if (bpf_core_field_exists(data->mem_hops))
+				return data->mem_hops;
+
+			return 0;
+		}
 		/* return the whole word */
 		return kctx->data->data_src.val;
 	default: