bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] samples: bpf: refactor xdp_sample_pkts_kern with BTF-defined map
@ 2020-09-05 15:41 Daniel T. Lee
       [not found] ` <5f562f6a.1c69fb81.b9e0.0669SMTPIN_ADDED_BROKEN@mx.google.com>
  2020-09-08 23:24 ` Andrii Nakryiko
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel T. Lee @ 2020-09-05 15:41 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov; +Cc: Andrii Nakryiko, netdev, bpf

Most of the samples were converted to use the new BTF-defined MAP as
they moved to libbbpf, but some of the samples were missing.

Instead of using the previous BPF MAP definition, this commit refactors
xdp_sample_pkts_kern MAP definition with the new BTF-defined MAP format.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
---
 samples/bpf/xdp_sample_pkts_kern.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/samples/bpf/xdp_sample_pkts_kern.c b/samples/bpf/xdp_sample_pkts_kern.c
index 33377289e2a8..b15172b7d455 100644
--- a/samples/bpf/xdp_sample_pkts_kern.c
+++ b/samples/bpf/xdp_sample_pkts_kern.c
@@ -7,12 +7,12 @@
 #define SAMPLE_SIZE 64ul
 #define MAX_CPUS 128
 
-struct bpf_map_def SEC("maps") my_map = {
-	.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
-	.key_size = sizeof(int),
-	.value_size = sizeof(u32),
-	.max_entries = MAX_CPUS,
-};
+struct {
+	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+	__uint(key_size, sizeof(int));
+	__uint(value_size, sizeof(u32));
+	__uint(max_entries, MAX_CPUS);
+} my_map SEC(".maps");
 
 SEC("xdp_sample")
 int xdp_sample_prog(struct xdp_md *ctx)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] samples: bpf: refactor xdp_sample_pkts_kern with BTF-defined map
       [not found] ` <5f562f6a.1c69fb81.b9e0.0669SMTPIN_ADDED_BROKEN@mx.google.com>
@ 2020-09-07 16:58   ` Daniel T. Lee
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel T. Lee @ 2020-09-07 16:58 UTC (permalink / raw)
  To: Michal Rostecki
  Cc: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko, netdev, bpf

On Mon, Sep 7, 2020 at 10:02 PM Michal Rostecki <mrostecki@opensuse.org> wrote:
>
> Daniel T. Lee writes:
> > Most of the samples were converted to use the new BTF-defined MAP as
> > they moved to libbbpf, but some of the samples were missing.
> >
> > Instead of using the previous BPF MAP definition, this commit refactors
> > xdp_sample_pkts_kern MAP definition with the new BTF-defined MAP format.
> >
> > Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
> > ---
> >  samples/bpf/xdp_sample_pkts_kern.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
>
> I see that samples/bpf/ibumad_kern.c and samples/bpf/xdp_monitor_kern.c
> still have old style BPF map definitions. Maybe you could change them as
> well?


Thanks for the review!

Actually, I'm well aware that there are some samples left with old style map
definitions, But those examples should be transferred from bpf_load to
libbbpf, not just bpf map changes.

I'm also planning to refactor those patches in the future.
For now I've just refactored this file, but if you think this patch
size is small,
I'll send it with other changes.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] samples: bpf: refactor xdp_sample_pkts_kern with BTF-defined map
  2020-09-08 23:24 ` Andrii Nakryiko
@ 2020-09-08 17:38   ` Daniel T. Lee
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel T. Lee @ 2020-09-08 17:38 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: Daniel Borkmann, Alexei Starovoitov, Networking, bpf

On Wed, Sep 9, 2020 at 8:24 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sat, Sep 5, 2020 at 8:41 AM Daniel T. Lee <danieltimlee@gmail.com> wrote:
> >
> > Most of the samples were converted to use the new BTF-defined MAP as
> > they moved to libbbpf, but some of the samples were missing.
> >
> > Instead of using the previous BPF MAP definition, this commit refactors
> > xdp_sample_pkts_kern MAP definition with the new BTF-defined MAP format.
> >
> > Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
> > ---
> >  samples/bpf/xdp_sample_pkts_kern.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/samples/bpf/xdp_sample_pkts_kern.c b/samples/bpf/xdp_sample_pkts_kern.c
> > index 33377289e2a8..b15172b7d455 100644
> > --- a/samples/bpf/xdp_sample_pkts_kern.c
> > +++ b/samples/bpf/xdp_sample_pkts_kern.c
> > @@ -7,12 +7,12 @@
> >  #define SAMPLE_SIZE 64ul
> >  #define MAX_CPUS 128
> >
> > -struct bpf_map_def SEC("maps") my_map = {
> > -       .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
> > -       .key_size = sizeof(int),
> > -       .value_size = sizeof(u32),
> > -       .max_entries = MAX_CPUS,
> > -};
> > +struct {
> > +       __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
> > +       __uint(key_size, sizeof(int));
> > +       __uint(value_size, sizeof(u32));
> > +       __uint(max_entries, MAX_CPUS);
>
> if you drop max_entries property, libbpf will set it to the maximum
> configured number of CPUs on the host, which is what you probably
> want. Do you might sending v2 without MAX_CPUS (check if macro is
> still used anywhere else). Thanks!
>

Thanks for your time and effort for the review.

I'll check and send the next version of patch.


> > +} my_map SEC(".maps");
> >
> >  SEC("xdp_sample")
> >  int xdp_sample_prog(struct xdp_md *ctx)
> > --
> > 2.25.1
> >

-- 
Best,
Daniel T. Lee

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] samples: bpf: refactor xdp_sample_pkts_kern with BTF-defined map
  2020-09-05 15:41 [PATCH bpf-next] samples: bpf: refactor xdp_sample_pkts_kern with BTF-defined map Daniel T. Lee
       [not found] ` <5f562f6a.1c69fb81.b9e0.0669SMTPIN_ADDED_BROKEN@mx.google.com>
@ 2020-09-08 23:24 ` Andrii Nakryiko
  2020-09-08 17:38   ` Daniel T. Lee
  1 sibling, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2020-09-08 23:24 UTC (permalink / raw)
  To: Daniel T. Lee; +Cc: Daniel Borkmann, Alexei Starovoitov, Networking, bpf

On Sat, Sep 5, 2020 at 8:41 AM Daniel T. Lee <danieltimlee@gmail.com> wrote:
>
> Most of the samples were converted to use the new BTF-defined MAP as
> they moved to libbbpf, but some of the samples were missing.
>
> Instead of using the previous BPF MAP definition, this commit refactors
> xdp_sample_pkts_kern MAP definition with the new BTF-defined MAP format.
>
> Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
> ---
>  samples/bpf/xdp_sample_pkts_kern.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/samples/bpf/xdp_sample_pkts_kern.c b/samples/bpf/xdp_sample_pkts_kern.c
> index 33377289e2a8..b15172b7d455 100644
> --- a/samples/bpf/xdp_sample_pkts_kern.c
> +++ b/samples/bpf/xdp_sample_pkts_kern.c
> @@ -7,12 +7,12 @@
>  #define SAMPLE_SIZE 64ul
>  #define MAX_CPUS 128
>
> -struct bpf_map_def SEC("maps") my_map = {
> -       .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
> -       .key_size = sizeof(int),
> -       .value_size = sizeof(u32),
> -       .max_entries = MAX_CPUS,
> -};
> +struct {
> +       __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
> +       __uint(key_size, sizeof(int));
> +       __uint(value_size, sizeof(u32));
> +       __uint(max_entries, MAX_CPUS);

if you drop max_entries property, libbpf will set it to the maximum
configured number of CPUs on the host, which is what you probably
want. Do you might sending v2 without MAX_CPUS (check if macro is
still used anywhere else). Thanks!

> +} my_map SEC(".maps");
>
>  SEC("xdp_sample")
>  int xdp_sample_prog(struct xdp_md *ctx)
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-09  2:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 15:41 [PATCH bpf-next] samples: bpf: refactor xdp_sample_pkts_kern with BTF-defined map Daniel T. Lee
     [not found] ` <5f562f6a.1c69fb81.b9e0.0669SMTPIN_ADDED_BROKEN@mx.google.com>
2020-09-07 16:58   ` Daniel T. Lee
2020-09-08 23:24 ` Andrii Nakryiko
2020-09-08 17:38   ` Daniel T. Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).