netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Magnus Karlsson <magnus.karlsson@intel.com>
Cc: "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: Sat, 12 Oct 2019 09:47:12 -0700	[thread overview]
Message-ID: <CAADnVQ+R3S1OpRahy78hR2hDfxaWX=peSwturK9hCeP_+9yBbQ@mail.gmail.com> (raw)
In-Reply-To: <1570695134-660-1-git-send-email-magnus.karlsson@intel.com>

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:

> +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	other threads:[~2019-10-12 16:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10  8:12 [PATCH bpf] xsk: improve documentation for AF_XDP Magnus Karlsson
2019-10-12 16:47 ` Alexei Starovoitov [this message]
2019-10-14  8:03   ` 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='CAADnVQ+R3S1OpRahy78hR2hDfxaWX=peSwturK9hCeP_+9yBbQ@mail.gmail.com' \
    --to=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
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).