netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] xsk: Bring back busy polling support in XDP_COPY
@ 2025-03-25  4:43 Samiullah Khawaja
  2025-03-25 16:24 ` Samiullah Khawaja
  2025-03-25 16:37 ` Stanislav Fomichev
  0 siblings, 2 replies; 3+ messages in thread
From: Samiullah Khawaja @ 2025-03-25  4:43 UTC (permalink / raw)
  To: Jakub Kicinski, David S . Miller , Eric Dumazet, Paolo Abeni,
	almasrymina, willemb, jdamato, mkarsten
  Cc: netdev, skhawaja

Commit 5ef44b3cb43b ("xsk: Bring back busy polling support") fixed the
busy polling support in xsk for XDP_ZEROCOPY after it was broken in
commit 86e25f40aa1e ("net: napi: Add napi_config"). The busy polling
support with XDP_COPY remained broken since the napi_id setup in
xsk_rcv_check was removed.

Bring back the setup of napi_id for XDP_COPY so socket level SO_BUSYPOLL
can be used to poll the underlying napi.

Tested using AF_XDP support in virtio-net by running the xsk_rr AF_XDP
benchmarking tool shared here:
https://lore.kernel.org/all/20250320163523.3501305-1-skhawaja@google.com/T/

Enabled socket busy polling using following commands in qemu,

```
sudo ethtool -L eth0 combined 1
sudo ethtool -G eth0 rx 1024
echo 400 | sudo tee /proc/sys/net/core/busy_read
echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs
echo 15000   | sudo tee /sys/class/net/eth0/gro_flush_timeout
```

Fixes: 5ef44b3cb43b ("xsk: Bring back busy polling support")
Fixes: 86e25f40aa1e ("net: napi: Add napi_config")
Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
---
 net/xdp/xsk.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index e5d104ce7b82..de8bf97b2cb9 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -310,6 +310,18 @@ static bool xsk_is_bound(struct xdp_sock *xs)
 	return false;
 }
 
+static void __xsk_mark_napi_id_once(struct sock *sk, struct net_device *dev, u32 qid)
+{
+	struct netdev_rx_queue *rxq;
+
+	if (qid >= dev->real_num_rx_queues)
+		return;
+
+	rxq = __netif_get_rx_queue(dev, qid);
+	if (rxq->napi)
+		__sk_mark_napi_id_once(sk, rxq->napi->napi_id);
+}
+
 static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
 {
 	if (!xsk_is_bound(xs))
@@ -323,6 +335,7 @@ static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
 		return -ENOSPC;
 	}
 
+	__xsk_mark_napi_id_once(&xs->sk, xs->dev, xs->queue_id);
 	return 0;
 }
 
@@ -1300,13 +1313,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 	xs->queue_id = qid;
 	xp_add_xsk(xs->pool, xs);
 
-	if (xs->zc && qid < dev->real_num_rx_queues) {
-		struct netdev_rx_queue *rxq;
-
-		rxq = __netif_get_rx_queue(dev, qid);
-		if (rxq->napi)
-			__sk_mark_napi_id_once(sk, rxq->napi->napi_id);
-	}
+	if (xs->zc)
+		__xsk_mark_napi_id_once(sk, dev, qid);
 
 out_unlock:
 	if (err) {
-- 
2.49.0.395.g12beb8f557-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] xsk: Bring back busy polling support in XDP_COPY
  2025-03-25  4:43 [PATCH net-next] xsk: Bring back busy polling support in XDP_COPY Samiullah Khawaja
@ 2025-03-25 16:24 ` Samiullah Khawaja
  2025-03-25 16:37 ` Stanislav Fomichev
  1 sibling, 0 replies; 3+ messages in thread
From: Samiullah Khawaja @ 2025-03-25 16:24 UTC (permalink / raw)
  To: Jakub Kicinski, David S . Miller, Eric Dumazet, Paolo Abeni,
	almasrymina, willemb, jdamato, mkarsten
  Cc: netdev

On Mon, Mar 24, 2025 at 9:43 PM Samiullah Khawaja <skhawaja@google.com> wrote:
>
> Commit 5ef44b3cb43b ("xsk: Bring back busy polling support") fixed the
> busy polling support in xsk for XDP_ZEROCOPY after it was broken in
> commit 86e25f40aa1e ("net: napi: Add napi_config"). The busy polling
> support with XDP_COPY remained broken since the napi_id setup in
> xsk_rcv_check was removed.
>
> Bring back the setup of napi_id for XDP_COPY so socket level SO_BUSYPOLL
> can be used to poll the underlying napi.
>
> Tested using AF_XDP support in virtio-net by running the xsk_rr AF_XDP
> benchmarking tool shared here:
> https://lore.kernel.org/all/20250320163523.3501305-1-skhawaja@google.com/T/
>
> Enabled socket busy polling using following commands in qemu,
>
> ```
> sudo ethtool -L eth0 combined 1
> sudo ethtool -G eth0 rx 1024
> echo 400 | sudo tee /proc/sys/net/core/busy_read
> echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs
> echo 15000   | sudo tee /sys/class/net/eth0/gro_flush_timeout
> ```
>
> Fixes: 5ef44b3cb43b ("xsk: Bring back busy polling support")
> Fixes: 86e25f40aa1e ("net: napi: Add napi_config")
> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
> ---
>  net/xdp/xsk.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index e5d104ce7b82..de8bf97b2cb9 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -310,6 +310,18 @@ static bool xsk_is_bound(struct xdp_sock *xs)
>         return false;
>  }
>
> +static void __xsk_mark_napi_id_once(struct sock *sk, struct net_device *dev, u32 qid)
> +{
> +       struct netdev_rx_queue *rxq;
> +
> +       if (qid >= dev->real_num_rx_queues)
> +               return;
> +
> +       rxq = __netif_get_rx_queue(dev, qid);
> +       if (rxq->napi)
> +               __sk_mark_napi_id_once(sk, rxq->napi->napi_id);
> +}
> +
>  static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>  {
>         if (!xsk_is_bound(xs))
> @@ -323,6 +335,7 @@ static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>                 return -ENOSPC;
>         }
>
> +       __xsk_mark_napi_id_once(&xs->sk, xs->dev, xs->queue_id);
>         return 0;
>  }
>
> @@ -1300,13 +1313,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
>         xs->queue_id = qid;
>         xp_add_xsk(xs->pool, xs);
>
> -       if (xs->zc && qid < dev->real_num_rx_queues) {
> -               struct netdev_rx_queue *rxq;
> -
> -               rxq = __netif_get_rx_queue(dev, qid);
> -               if (rxq->napi)
> -                       __sk_mark_napi_id_once(sk, rxq->napi->napi_id);
> -       }
> +       if (xs->zc)
> +               __xsk_mark_napi_id_once(sk, dev, qid);
>
>  out_unlock:
>         if (err) {
> --
> 2.49.0.395.g12beb8f557-goog
>

The original commit 5ef44b3cb43b ("xsk: Bring back busy polling
support") has landed in 6.13 so I will revise this and resend it to
the net. Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] xsk: Bring back busy polling support in XDP_COPY
  2025-03-25  4:43 [PATCH net-next] xsk: Bring back busy polling support in XDP_COPY Samiullah Khawaja
  2025-03-25 16:24 ` Samiullah Khawaja
@ 2025-03-25 16:37 ` Stanislav Fomichev
  1 sibling, 0 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2025-03-25 16:37 UTC (permalink / raw)
  To: Samiullah Khawaja
  Cc: Jakub Kicinski, David S . Miller , Eric Dumazet, Paolo Abeni,
	almasrymina, willemb, jdamato, mkarsten, netdev

On 03/25, Samiullah Khawaja wrote:
> Commit 5ef44b3cb43b ("xsk: Bring back busy polling support") fixed the
> busy polling support in xsk for XDP_ZEROCOPY after it was broken in
> commit 86e25f40aa1e ("net: napi: Add napi_config"). The busy polling
> support with XDP_COPY remained broken since the napi_id setup in
> xsk_rcv_check was removed.
> 
> Bring back the setup of napi_id for XDP_COPY so socket level SO_BUSYPOLL
> can be used to poll the underlying napi.
> 
> Tested using AF_XDP support in virtio-net by running the xsk_rr AF_XDP
> benchmarking tool shared here:
> https://lore.kernel.org/all/20250320163523.3501305-1-skhawaja@google.com/T/
> 
> Enabled socket busy polling using following commands in qemu,
> 
> ```
> sudo ethtool -L eth0 combined 1
> sudo ethtool -G eth0 rx 1024
> echo 400 | sudo tee /proc/sys/net/core/busy_read
> echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs
> echo 15000   | sudo tee /sys/class/net/eth0/gro_flush_timeout
> ```
> 
> Fixes: 5ef44b3cb43b ("xsk: Bring back busy polling support")
> Fixes: 86e25f40aa1e ("net: napi: Add napi_config")
> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
> ---
>  net/xdp/xsk.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index e5d104ce7b82..de8bf97b2cb9 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -310,6 +310,18 @@ static bool xsk_is_bound(struct xdp_sock *xs)
>  	return false;
>  }
>  
> +static void __xsk_mark_napi_id_once(struct sock *sk, struct net_device *dev, u32 qid)
> +{
> +	struct netdev_rx_queue *rxq;
> +
> +	if (qid >= dev->real_num_rx_queues)
> +		return;
> +
> +	rxq = __netif_get_rx_queue(dev, qid);
> +	if (rxq->napi)
> +		__sk_mark_napi_id_once(sk, rxq->napi->napi_id);
> +}
> +
>  static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>  {
>  	if (!xsk_is_bound(xs))
> @@ -323,6 +335,7 @@ static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>  		return -ENOSPC;
>  	}

[..]

> +	__xsk_mark_napi_id_once(&xs->sk, xs->dev, xs->queue_id);
>  	return 0;
>  }

Can we move this part to a different place? __xsk_rcv maybe? So it
doesn't trigger for the zc case where napi is resolved at bind time.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-25 16:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25  4:43 [PATCH net-next] xsk: Bring back busy polling support in XDP_COPY Samiullah Khawaja
2025-03-25 16:24 ` Samiullah Khawaja
2025-03-25 16:37 ` Stanislav Fomichev

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).