BPF Archive on lore.kernel.org
 help / color / Atom feed
From: Magnus Karlsson <magnus.karlsson@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: "Magnus Karlsson" <magnus.karlsson@intel.com>,
	"Björn Töpel" <bjorn.topel@intel.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Network Development" <netdev@vger.kernel.org>,
	"Jonathan Lemon" <jonathan.lemon@gmail.com>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf] xsk: improve documentation for AF_XDP
Date: Mon, 14 Oct 2019 10:03:29 +0200
Message-ID: <CAJ8uoz0CWRavNXTrEhbS3tv1mkQD+VF7t=b-0VppO4c6Am_x8Q@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQ+R3S1OpRahy78hR2hDfxaWX=peSwturK9hCeP_+9yBbQ@mail.gmail.com>

On Sat, Oct 12, 2019 at 6:52 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Oct 10, 2019 at 1:12 AM Magnus Karlsson
> <magnus.karlsson@intel.com> wrote:
> >
> > Added sections on all the bind flags, libbpf, all the setsockopts and
> > all the getsockopts. Also updated the document to reflect the latest
> > features and to correct some spelling errors.
> >
> > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
>
> thanks for the update. Overall looks good.
> Few nits below:

Will fix all your comments and send out a v2.

Thanks: Magnus

> > +What socket will then a packet arrive on? This is decided by the XDP
> > +program. Put all the sockets in the XSK_MAP and just indicate which
> > +index in the array you would like to send each packet to. A simple
> > +round-robin example of distributing packets is shown below:
> > +
> > +.. code-block:: c
> > +
> > +   #define KBUILD_MODNAME "af_xdp_example"
>
> what is this for?
> It's not a kernel module.
>
> > +   #include <uapi/linux/bpf.h>
>
> why 'uapi' ? It should use only user space headers.
>
> > +   #include "bpf_helpers.h"
> > +
> > +   #define MAX_SOCKS 16
> > +
> > +   struct bpf_map_def SEC("maps") xsks_map = {
> > +         .type = BPF_MAP_TYPE_XSKMAP,
> > +         .key_size = sizeof(int),
> > +         .value_size = sizeof(int),
> > +         .max_entries = MAX_SOCKS,
> > +   };
>
> Could you switch to BTF defined maps?
> libbpf will forever support old style as well,
> but documentation should point to the latest.
>
> > +
> > +   struct bpf_map_def SEC("maps") rr_map = {
> > +         .type = BPF_MAP_TYPE_PERCPU_ARRAY,
> > +         .key_size = sizeof(int),
> > +         .value_size = sizeof(unsigned int),
> > +         .max_entries = 1,
> > +   };
> > +
> > +   SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
> > +   {
> > +       int key = 0, idx;
> > +       unsigned int *rr;
> > +
> > +       rr = bpf_map_lookup_elem(&rr_map, &key);
> > +       if (!rr)
> > +          return XDP_ABORTED;
> > +
> > +       *rr = (*rr + 1) & (MAX_SOCKS - 1);
> > +       idx = *rr;
> > +
> > +       return bpf_redirect_map(&xsks_map, idx, 0);
> > +   }
> > +
> > +   char _license[] SEC("license") = "GPL";
>
> Above sample doesn't use gpl-only helpers. Why add above line?
>
> > +.. code-block:: c
> > +
> > +   if (xsk_ring_prod__needs_wakeup(&my_tx_ring))
> > +      sendto(xsk_socket__fd(xsk_handle), NULL, 0, MSG_DONTWAIT, NULL, 0);
> > +
> > +I.e., only use the syscall if the flag is set.
> > +
> > +We recommend that you always enable this mode as it can lead to
> > +magnitudes better performance if you run the application and the
> > +driver on the same core and somewhat better performance even if you
> > +use different cores for the application and the kernel driver, as it
> > +reduces the number of syscalls needed for the TX path.
>
> "magnitudes better performance"? Is it really at least 20 times better?
>
> > -Naive ring dequeue and enqueue could look like this::
> > +Naive ring dequeue and enqueue could look like this:
>
> lol. That's a good typo.

      reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10  8:12 Magnus Karlsson
2019-10-12 16:47 ` Alexei Starovoitov
2019-10-14  8:03   ` Magnus Karlsson [this message]

Reply instructions:

You may reply publically 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='CAJ8uoz0CWRavNXTrEhbS3tv1mkQD+VF7t=b-0VppO4c6Am_x8Q@mail.gmail.com' \
    --to=magnus.karlsson@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jonathan.lemon@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    /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

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git