bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Magnus Karlsson <magnus.karlsson@gmail.com>
To: "Björn Töpel" <bjorn.topel@gmail.com>
Cc: "Network Development" <netdev@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>, "Björn Töpel" <bjorn.topel@intel.com>,
	"Karlsson, Magnus" <magnus.karlsson@intel.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Fijalkowski, Maciej" <maciej.fijalkowski@intel.com>,
	"Samudrala, Sridhar" <sridhar.samudrala@intel.com>,
	"Brandeburg, Jesse" <jesse.brandeburg@intel.com>,
	"Zhang, Qi Z" <qi.z.zhang@intel.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jonathan Lemon" <jonathan.lemon@gmail.com>,
	"Maxim Mikityanskiy" <maximmi@nvidia.com>
Subject: Re: [PATCH bpf-next v3 09/10] samples/bpf: add busy-poll support to xdpsock
Date: Wed, 25 Nov 2020 09:19:26 +0100	[thread overview]
Message-ID: <CAJ8uoz3BmTUX8vENTjX5QseTJ4ftP8KgHypiieQHsQ1Lzso8Xg@mail.gmail.com> (raw)
In-Reply-To: <20201119083024.119566-10-bjorn.topel@gmail.com>

On Thu, Nov 19, 2020 at 9:33 AM Björn Töpel <bjorn.topel@gmail.com> wrote:
>
> From: Björn Töpel <bjorn.topel@intel.com>
>
> Add a new option to xdpsock, 'B', for busy-polling. This option will
> also set the batching size, 'b' option, to the busy-poll budget.
>
> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
> ---
>  samples/bpf/xdpsock_user.c | 40 +++++++++++++++++++++++++++++++-------
>  1 file changed, 33 insertions(+), 7 deletions(-)

Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>

> diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
> index 24aa7511c4c8..cb1eaee8a32b 100644
> --- a/samples/bpf/xdpsock_user.c
> +++ b/samples/bpf/xdpsock_user.c
> @@ -95,6 +95,7 @@ static int opt_timeout = 1000;
>  static bool opt_need_wakeup = true;
>  static u32 opt_num_xsks = 1;
>  static u32 prog_id;
> +static bool opt_busy_poll;
>
>  struct xsk_ring_stats {
>         unsigned long rx_npkts;
> @@ -911,6 +912,7 @@ static struct option long_options[] = {
>         {"quiet", no_argument, 0, 'Q'},
>         {"app-stats", no_argument, 0, 'a'},
>         {"irq-string", no_argument, 0, 'I'},
> +       {"busy-poll", no_argument, 0, 'B'},
>         {0, 0, 0, 0}
>  };
>
> @@ -949,6 +951,7 @@ static void usage(const char *prog)
>                 "  -Q, --quiet          Do not display any stats.\n"
>                 "  -a, --app-stats      Display application (syscall) statistics.\n"
>                 "  -I, --irq-string     Display driver interrupt statistics for interface associated with irq-string.\n"
> +               "  -B, --busy-poll      Busy poll.\n"
>                 "\n";
>         fprintf(stderr, str, prog, XSK_UMEM__DEFAULT_FRAME_SIZE,
>                 opt_batch_size, MIN_PKT_SIZE, MIN_PKT_SIZE,
> @@ -964,7 +967,7 @@ static void parse_command_line(int argc, char **argv)
>         opterr = 0;
>
>         for (;;) {
> -               c = getopt_long(argc, argv, "Frtli:q:pSNn:czf:muMd:b:C:s:P:xQaI:",
> +               c = getopt_long(argc, argv, "Frtli:q:pSNn:czf:muMd:b:C:s:P:xQaI:B",
>                                 long_options, &option_index);
>                 if (c == -1)
>                         break;
> @@ -1062,7 +1065,9 @@ static void parse_command_line(int argc, char **argv)
>                                 fprintf(stderr, "ERROR: Failed to get irqs for %s\n", opt_irq_str);
>                                 usage(basename(argv[0]));
>                         }
> -
> +                       break;
> +               case 'B':
> +                       opt_busy_poll = 1;
>                         break;
>                 default:
>                         usage(basename(argv[0]));
> @@ -1131,7 +1136,7 @@ static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk)
>                 while (ret != rcvd) {
>                         if (ret < 0)
>                                 exit_with_error(-ret);
> -                       if (xsk_ring_prod__needs_wakeup(&umem->fq)) {
> +                       if (opt_busy_poll || xsk_ring_prod__needs_wakeup(&umem->fq)) {
>                                 xsk->app_stats.fill_fail_polls++;
>                                 recvfrom(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, NULL);
>                         }
> @@ -1177,7 +1182,7 @@ static void rx_drop(struct xsk_socket_info *xsk)
>
>         rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx);
>         if (!rcvd) {
> -               if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
> +               if (opt_busy_poll || xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
>                         xsk->app_stats.rx_empty_polls++;
>                         recvfrom(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, NULL);
>                 }
> @@ -1188,7 +1193,7 @@ static void rx_drop(struct xsk_socket_info *xsk)
>         while (ret != rcvd) {
>                 if (ret < 0)
>                         exit_with_error(-ret);
> -               if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
> +               if (opt_busy_poll || xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
>                         xsk->app_stats.fill_fail_polls++;
>                         recvfrom(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, NULL);
>                 }
> @@ -1340,7 +1345,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
>
>         rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx);
>         if (!rcvd) {
> -               if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
> +               if (opt_busy_poll || xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
>                         xsk->app_stats.rx_empty_polls++;
>                         recvfrom(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, NULL);
>                 }
> @@ -1353,7 +1358,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
>                 if (ret < 0)
>                         exit_with_error(-ret);
>                 complete_tx_l2fwd(xsk);
> -               if (xsk_ring_prod__needs_wakeup(&xsk->tx)) {
> +               if (opt_busy_poll || xsk_ring_prod__needs_wakeup(&xsk->tx)) {
>                         xsk->app_stats.tx_wakeup_sendtos++;
>                         kick_tx(xsk);
>                 }
> @@ -1458,6 +1463,24 @@ static void enter_xsks_into_map(struct bpf_object *obj)
>         }
>  }
>
> +static void apply_setsockopt(struct xsk_socket_info *xsk)
> +{
> +       int sock_opt;
> +
> +       if (!opt_busy_poll)
> +               return;
> +
> +       sock_opt = 1;
> +       if (setsockopt(xsk_socket__fd(xsk->xsk), SOL_SOCKET, SO_PREFER_BUSY_POLL,
> +                      (void *)&sock_opt, sizeof(sock_opt)) < 0)
> +               exit_with_error(errno);
> +
> +       sock_opt = 20;
> +       if (setsockopt(xsk_socket__fd(xsk->xsk), SOL_SOCKET, SO_BUSY_POLL,
> +                      (void *)&sock_opt, sizeof(sock_opt)) < 0)
> +               exit_with_error(errno);
> +}
> +
>  int main(int argc, char **argv)
>  {
>         struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
> @@ -1499,6 +1522,9 @@ int main(int argc, char **argv)
>         for (i = 0; i < opt_num_xsks; i++)
>                 xsks[num_socks++] = xsk_configure_socket(umem, rx, tx);
>
> +       for (i = 0; i < opt_num_xsks; i++)
> +               apply_setsockopt(xsks[i]);
> +
>         if (opt_bench == BENCH_TXONLY) {
>                 gen_eth_hdr_data();
>
> --
> 2.27.0
>

  reply	other threads:[~2020-11-25  8:19 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19  8:30 [PATCH bpf-next v3 00/10] Introduce preferred busy-polling Björn Töpel
2020-11-19  8:30 ` [PATCH bpf-next v3 01/10] net: introduce " Björn Töpel
2020-11-24  0:04   ` Jakub Kicinski
2020-11-24  7:58     ` Björn Töpel
2020-11-24  0:11   ` Jakub Kicinski
2020-11-24  8:47     ` Björn Töpel
2020-11-24 16:21   ` Jakub Kicinski
2020-11-19  8:30 ` [PATCH bpf-next v3 02/10] net: add SO_BUSY_POLL_BUDGET socket option Björn Töpel
2020-11-24 16:21   ` Jakub Kicinski
2020-11-19  8:30 ` [PATCH bpf-next v3 03/10] xsk: add support for recvmsg() Björn Töpel
2020-11-25  6:55   ` Magnus Karlsson
2020-11-19  8:30 ` [PATCH bpf-next v3 04/10] xsk: check need wakeup flag in sendmsg() Björn Töpel
2020-11-25  7:16   ` Magnus Karlsson
2020-11-19  8:30 ` [PATCH bpf-next v3 05/10] xsk: add busy-poll support for {recv,send}msg() Björn Töpel
2020-11-25  7:58   ` Magnus Karlsson
2020-11-19  8:30 ` [PATCH bpf-next v3 06/10] xsk: propagate napi_id to XDP socket Rx path Björn Töpel
2020-11-25 14:47   ` Magnus Karlsson
2020-11-25 21:14   ` Michael S. Tsirkin
2021-09-29 18:33   ` kernel test robot
2021-09-30  6:04     ` Magnus Karlsson
2021-10-02  2:07       ` [kbuild-all] " Philip Li
2021-11-05 20:17   ` kernel test robot
2020-11-19  8:30 ` [PATCH bpf-next v3 07/10] samples/bpf: use recvfrom() in xdpsock/rxdrop Björn Töpel
2020-11-25  7:59   ` Magnus Karlsson
2020-11-19  8:30 ` [PATCH bpf-next v3 08/10] samples/bpf: use recvfrom() in xdpsock/l2fwd Björn Töpel
2020-11-25  8:00   ` Magnus Karlsson
2020-11-19  8:30 ` [PATCH bpf-next v3 09/10] samples/bpf: add busy-poll support to xdpsock Björn Töpel
2020-11-25  8:19   ` Magnus Karlsson [this message]
2020-11-19  8:30 ` [PATCH bpf-next v3 10/10] samples/bpf: add option to set the busy-poll budget Björn Töpel
2020-11-25  8:23   ` Magnus Karlsson
2020-11-23 13:31 ` [PATCH bpf-next v3 00/10] Introduce preferred busy-polling Björn Töpel
2020-11-23 23:54   ` Jakub Kicinski
2020-11-24  0:14 ` Jakub Kicinski

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=CAJ8uoz3BmTUX8vENTjX5QseTJ4ftP8KgHypiieQHsQ1Lzso8Xg@mail.gmail.com \
    --to=magnus.karlsson@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@gmail.com \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=edumazet@google.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=kuba@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=maximmi@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=qi.z.zhang@intel.com \
    --cc=sridhar.samudrala@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;
as well as URLs for NNTP newsgroup(s).