From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Magnus Karlsson <magnus.karlsson@gmail.com>
Cc: "Magnus Karlsson" <magnus.karlsson@intel.com>,
"Björn Töpel" <bjorn.topel@intel.com>,
ast@kernel.org, "Daniel Borkmann" <daniel@iogearbox.net>,
"Network Development" <netdev@vger.kernel.org>,
"Jakub Kicinski" <jakub.kicinski@netronome.com>,
"Björn Töpel" <bjorn.topel@gmail.com>,
"Zhang, Qi Z" <qi.z.zhang@intel.com>,
"Jesper Dangaard Brouer" <brouer@redhat.com>
Subject: Re: [PATCH bpf-next v2 1/2] libbpf: add support for using AF_XDP sockets
Date: Tue, 18 Dec 2018 10:53:11 -0800 [thread overview]
Message-ID: <20181218185309.dog3dpdd5pt3nejy@ast-mbp> (raw)
In-Reply-To: <CAJ8uoz3XMPxkcX1KDeJLbbgOSfmse6cJ-Sr0rtCaH=KpwnQbQg@mail.gmail.com>
On Mon, Dec 17, 2018 at 10:12:33AM +0100, Magnus Karlsson wrote:
> On Fri, Dec 14, 2018 at 9:25 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Wed, Dec 12, 2018 at 02:09:48PM +0100, Magnus Karlsson wrote:
> > > This commit adds AF_XDP support to libbpf. The main reason for
> > > this is to facilitate writing applications that use AF_XDP by offering
> > > higher-level APIs that hide many of the details of the AF_XDP
> > > uapi. This is in the same vein as libbpf facilitates XDP adoption by
> > > offering easy-to-use higher level interfaces of XDP
> > > functionality. Hopefully this will facilitate adoption of AF_XDP, make
> > > applications using it simpler and smaller, and finally also make it
> > > possible for applications to benefit from optimizations in the AF_XDP
> > > user space access code. Previously, people just copied and pasted the
> > > code from the sample application into their application, which is not
> > > desirable.
> > >
> > > The interface is composed of two parts:
> > >
> > > * Low-level access interface to the four rings and the packet
> > > * High-level control plane interface for creating and setting
> > > up umems and af_xdp sockets.
> > >
> > > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> > ...
> > > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > > index 5f68d7b..da99203 100644
> > > --- a/tools/lib/bpf/libbpf.h
> > > +++ b/tools/lib/bpf/libbpf.h
> >
> > may be instead of lib/bpf/libbpf.h the xsk stuff should go to lib/bpf/xsk.h ?
>
> Yes. Good idea.
>
> > > @@ -15,6 +15,7 @@
> > > #include <stdbool.h>
> > > #include <sys/types.h> // for size_t
> > > #include <linux/bpf.h>
> > > +#include <linux/if_xdp.h>
> > >
> > > #ifdef __cplusplus
> > > extern "C" {
> > > @@ -355,6 +356,98 @@ LIBBPF_API const struct bpf_line_info *
> > > bpf_prog_linfo__lfind(const struct bpf_prog_linfo *prog_linfo,
> > > __u32 insn_off, __u32 nr_skip);
> > >
> > > +/* Do not access these members directly. Use the functions below. */
> > > +struct xsk_prod_ring {
> > > + __u32 cached_prod;
> > > + __u32 cached_cons;
> > > + __u32 mask;
> > > + __u32 size;
> > > + __u32 *producer;
> > > + __u32 *consumer;
> > > + void *ring;
> > > +};
> > > +
> > > +/* Do not access these members directly. Use the functions below. */
> > > +struct xsk_cons_ring {
> > > + __u32 cached_prod;
> > > + __u32 cached_cons;
> > > + __u32 mask;
> > > + __u32 size;
> > > + __u32 *producer;
> > > + __u32 *consumer;
> > > + void *ring;
> > > +};
> >
> > xsk_prod_ring and xsk_cons_ring have exactly the same members,
> > but they're two different structs? why?
> > May be have one 'struct xsk_ring' ?
>
> They operate on the same ring but represents either the producer or
> the consumer of that same ring. The reason for this is that I want to
> make sure that the user gets a compile time error if he or she tries
> to use for example the function xsk__reserve_prod when user space is a
> consumer of that ring (and the same kind of argument for
> xsk__submit_prod, xsk__peek_cons, and xsk__release_cons). If we move
> to a xsk_ring, we lose this compile time check, or is there another
> better way of doing this in C without getting double definitions or
> using hard to read #defines? The only benefit I see with going to
> xsk_ring is that we get rid of two small inline functions and one
> struct definition in the header file, but the code size will be the
> same. Personally I prefer compile time error checking. But let me know
> what to proceed with.
how about the following?
struct xsk_ring {...};
struct xsk_prod {
struct xsk_ring r;
};
struct xsk_cons {
struct xsk_ring r;
};
and compiler will warn when xsk_prod is used instead of xsk_cons.
The methods can be called xsk_prod__* and xsk_cons__*
Also do 'producer' and 'consumer' names really fit?
Typically producer and consumer are two sides of the single ring.
next prev parent reply other threads:[~2018-12-18 18:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-12 13:09 [PATCH bpf-next v2 0/2] libbpf: adding AF_XDP support Magnus Karlsson
2018-12-12 13:09 ` [PATCH bpf-next v2 1/2] libbpf: add support for using AF_XDP sockets Magnus Karlsson
2018-12-13 6:23 ` Alexei Starovoitov
2018-12-13 9:06 ` Magnus Karlsson
2018-12-13 15:48 ` Daniel Borkmann
2018-12-14 20:23 ` Alexei Starovoitov
2018-12-17 9:12 ` Magnus Karlsson
2018-12-18 18:53 ` Alexei Starovoitov [this message]
2018-12-12 13:09 ` [PATCH bpf-next v2 2/2] samples/bpf: convert xdpsock to use libbpf for AF_XDP access Magnus Karlsson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181218185309.dog3dpdd5pt3nejy@ast-mbp \
--to=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bjorn.topel@gmail.com \
--cc=bjorn.topel@intel.com \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=jakub.kicinski@netronome.com \
--cc=magnus.karlsson@gmail.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=qi.z.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox