netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Magnus Karlsson <magnus.karlsson@gmail.com>
To: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Cc: Magnus Karlsson <magnus.karlsson@intel.com>,
	bpf <bpf@vger.kernel.org>,
	Network Development <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf 2/2] libbpf: remove dependency on barrier.h in xsk.h
Date: Wed, 4 Sep 2019 12:25:13 +0200	[thread overview]
Message-ID: <CAJ8uoz3jhr+VUmtjotW07mnDkYLgOYYO2HpV9hOv3i8B4=Z_CQ@mail.gmail.com> (raw)
In-Reply-To: <xunyftlc7dn8.fsf@redhat.com>

On Wed, Sep 4, 2019 at 8:56 AM Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
>
> Hi, Magnus!
>
> >>>>> On Wed, 4 Sep 2019 08:39:24 +0200, Magnus Karlsson  wrote:
>
>  > On Wed, Sep 4, 2019 at 7:32 AM Yauheni Kaliuta
>  > <yauheni.kaliuta@redhat.com> wrote:
>  >>
>  >> Hi, Magnus!
>  >>
>  >> >>>>> On Tue,  9 Apr 2019 08:44:13 +0200, Magnus Karlsson  wrote:
>  >>
>  >> > The use of smp_rmb() and smp_wmb() creates a Linux header dependency
>  >> > on barrier.h that is uneccessary in most parts. This patch implements
>  >> > the two small defines that are needed from barrier.h. As a bonus, the
>  >> > new implementations are faster than the default ones as they default
>  >> > to sfence and lfence for x86, while we only need a compiler barrier in
>  >> > our case. Just as it is when the same ring access code is compiled in
>  >> > the kernel.
>  >>
>  >> > Fixes: 1cad07884239 ("libbpf: add support for using AF_XDP sockets")
>  >> > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
>  >> > ---
>  >> >  tools/lib/bpf/xsk.h | 19 +++++++++++++++++--
>  >> >  1 file changed, 17 insertions(+), 2 deletions(-)
>  >>
>  >> > diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h
>  >> > index 3638147..317b44f 100644
>  >> > --- a/tools/lib/bpf/xsk.h
>  >> > +++ b/tools/lib/bpf/xsk.h
>  >> > @@ -39,6 +39,21 @@ DEFINE_XSK_RING(xsk_ring_cons);
>  >> >  struct xsk_umem;
>  >> >  struct xsk_socket;
>  >>
>  >> > +#if !defined bpf_smp_rmb && !defined bpf_smp_wmb
>  >> > +# if defined(__i386__) || defined(__x86_64__)
>  >> > +#  define bpf_smp_rmb() asm volatile("" : : : "memory")
>  >> > +#  define bpf_smp_wmb() asm volatile("" : : : "memory")
>  >> > +# elif defined(__aarch64__)
>  >> > +#  define bpf_smp_rmb() asm volatile("dmb ishld" : : : "memory")
>  >> > +#  define bpf_smp_wmb() asm volatile("dmb ishst" : : : "memory")
>  >> > +# elif defined(__arm__)
>  >> > +#  define bpf_smp_rmb() asm volatile("dmb ish" : : : "memory")
>  >> > +#  define bpf_smp_wmb() asm volatile("dmb ishst" : : : "memory")
>  >> > +# else
>  >> > +#  error Architecture not supported by the XDP socket code in libbpf.
>  >> > +# endif
>  >> > +#endif
>  >> > +
>  >>
>  >> What about other architectures then?
>
>  > AF_XDP has not been tested on anything else, as far as I
>  > know. But contributions that extend it to more archs are very
>  > welcome.
>
> Well, I'll may be try to fetch something from barrier.h's (since
> I cannot consider myself as a specialist in the area), but at the
> moment the patch breaks the build on that arches.

Do you have a specific architecture in mind and do you have some
board/server (of that architecture) you could test AF_XDP on?

>  > /Magnus
>
>  >>
>  >> >  static inline __u64 *xsk_ring_prod__fill_addr(struct xsk_ring_prod *fill,
>  >> >                                            __u32 idx)
>  >> >  {
>  >> > @@ -119,7 +134,7 @@ static inline void xsk_ring_prod__submit(struct xsk_ring_prod *prod, size_t nb)
>  >> >      /* Make sure everything has been written to the ring before signalling
>  >> >       * this to the kernel.
>  >> >       */
>  >> > -    smp_wmb();
>  >> > +    bpf_smp_wmb();
>  >>
>  >> >      *prod->producer += nb;
>  >> >  }
>  >> > @@ -133,7 +148,7 @@ static inline size_t xsk_ring_cons__peek(struct xsk_ring_cons *cons,
>  >> >              /* Make sure we do not speculatively read the data before
>  >> >               * we have received the packet buffers from the ring.
>  >> >               */
>  >> > -            smp_rmb();
>  >> > +            bpf_smp_rmb();
>  >>
>  >> >              *idx = cons->cached_cons;
>  cons-> cached_cons += entries;
>  >> > --
>  >> > 2.7.4
>  >>
>  >>
>  >> --
>  >> WBR,
>  >> Yauheni Kaliuta
>
> --
> WBR,
> Yauheni Kaliuta

  reply	other threads:[~2019-09-04 10:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09  6:44 [PATCH bpf 0/2] libbpf: remove two dependencies on Linux kernel headers and improve performance as a bonus Magnus Karlsson
2019-04-09  6:44 ` [PATCH bpf 1/2] libbpf: remove likely/unlikely in xsk.h Magnus Karlsson
2019-04-09  6:44 ` [PATCH bpf 2/2] libbpf: remove dependency on barrier.h " Magnus Karlsson
2019-04-09  9:10   ` Daniel Borkmann
2019-04-09 11:29     ` Magnus Karlsson
2019-04-09 22:28       ` Georg Müller
2019-04-09 22:46         ` Daniel Borkmann
2019-09-04  5:32   ` Yauheni Kaliuta
2019-09-04  6:39     ` Magnus Karlsson
2019-09-04  6:56       ` Yauheni Kaliuta
2019-09-04 10:25         ` Magnus Karlsson [this message]
2019-09-04 12:19           ` Yauheni Kaliuta
2019-09-04 12:21             ` 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='CAJ8uoz3jhr+VUmtjotW07mnDkYLgOYYO2HpV9hOv3i8B4=Z_CQ@mail.gmail.com' \
    --to=magnus.karlsson@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=yauheni.kaliuta@redhat.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;
as well as URLs for NNTP newsgroup(s).