Skip to content

Commit a073195

Browse files
Björn Töpelborkmann
authored andcommitted
xsk: Add busy-poll support for {recv,send}msg()
Wire-up XDP socket busy-poll support for recvmsg() and sendmsg(). If the XDP socket prefers busy-polling, make sure that no wakeup/IPI is performed. Signed-off-by: Björn Töpel <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Magnus Karlsson <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e392081 commit a073195

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

net/xdp/xsk.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/netdevice.h>
2424
#include <linux/rculist.h>
2525
#include <net/xdp_sock_drv.h>
26+
#include <net/busy_poll.h>
2627
#include <net/xdp.h>
2728

2829
#include "xsk_queue.h"
@@ -517,6 +518,17 @@ static int __xsk_sendmsg(struct sock *sk)
517518
return xs->zc ? xsk_zc_xmit(xs) : xsk_generic_xmit(sk);
518519
}
519520

521+
static bool xsk_no_wakeup(struct sock *sk)
522+
{
523+
#ifdef CONFIG_NET_RX_BUSY_POLL
524+
/* Prefer busy-polling, skip the wakeup. */
525+
return READ_ONCE(sk->sk_prefer_busy_poll) && READ_ONCE(sk->sk_ll_usec) &&
526+
READ_ONCE(sk->sk_napi_id) >= MIN_NAPI_ID;
527+
#else
528+
return false;
529+
#endif
530+
}
531+
520532
static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
521533
{
522534
bool need_wait = !(m->msg_flags & MSG_DONTWAIT);
@@ -529,6 +541,12 @@ static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
529541
if (unlikely(need_wait))
530542
return -EOPNOTSUPP;
531543

544+
if (sk_can_busy_loop(sk))
545+
sk_busy_loop(sk, 1); /* only support non-blocking sockets */
546+
547+
if (xsk_no_wakeup(sk))
548+
return 0;
549+
532550
pool = xs->pool;
533551
if (pool->cached_need_wakeup & XDP_WAKEUP_TX)
534552
return __xsk_sendmsg(sk);
@@ -550,6 +568,12 @@ static int xsk_recvmsg(struct socket *sock, struct msghdr *m, size_t len, int fl
550568
if (unlikely(need_wait))
551569
return -EOPNOTSUPP;
552570

571+
if (sk_can_busy_loop(sk))
572+
sk_busy_loop(sk, 1); /* only support non-blocking sockets */
573+
574+
if (xsk_no_wakeup(sk))
575+
return 0;
576+
553577
if (xs->pool->cached_need_wakeup & XDP_WAKEUP_RX && xs->zc)
554578
return xsk_wakeup(xs, XDP_WAKEUP_RX);
555579
return 0;

0 commit comments

Comments
 (0)