Skip to content

Commit e68b6e5

Browse files
edumazetdavem330
authored andcommitted
udp: enable busy polling for all sockets
UDP busy polling is restricted to connected UDP sockets. This is because sk_busy_loop() only takes care of one NAPI context. There are cases where it could be extended. 1) Some hosts receive traffic on a single NIC, with one RX queue. 2) Some applications use SO_REUSEPORT and associated BPF filter to split the incoming traffic on one UDP socket per RX queue/thread/cpu 3) Some UDP sockets are used to send/receive traffic for one flow, but they do not bother with connect() This patch records the napi_id of first received skb, giving more reach to busy polling. Tested: lpaa23:~# echo 70 >/proc/sys/net/core/busy_read lpaa24:~# echo 70 >/proc/sys/net/core/busy_read lpaa23:~# for f in `seq 1 10`; do ./super_netperf 1 -H lpaa24 -t UDP_RR -l 5; done Before patch : 27867 28870 37324 41060 41215 36764 36838 44455 41282 43843 After patch : 73920 73213 70147 74845 71697 68315 68028 75219 70082 73707 Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fcd2b0d commit e68b6e5

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

‎include/net/busy_poll.h‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ static inline void skb_mark_napi_id(struct sk_buff *skb,
8080
skb->napi_id = napi->napi_id;
8181
}
8282

83-
/* used in the protocol hanlder to propagate the napi_id to the socket */
84-
static inline void sk_mark_napi_id(struct sock *sk, struct sk_buff *skb)
85-
{
86-
sk->sk_napi_id = skb->napi_id;
87-
}
8883

8984
#else /* CONFIG_NET_RX_BUSY_POLL */
9085
static inline unsigned long net_busy_loop_on(void)
@@ -107,10 +102,6 @@ static inline void skb_mark_napi_id(struct sk_buff *skb,
107102
{
108103
}
109104

110-
static inline void sk_mark_napi_id(struct sock *sk, struct sk_buff *skb)
111-
{
112-
}
113-
114105
static inline bool busy_loop_timeout(unsigned long end_time)
115106
{
116107
return true;
@@ -122,4 +113,23 @@ static inline bool sk_busy_loop(struct sock *sk, int nonblock)
122113
}
123114

124115
#endif /* CONFIG_NET_RX_BUSY_POLL */
116+
117+
/* used in the protocol hanlder to propagate the napi_id to the socket */
118+
static inline void sk_mark_napi_id(struct sock *sk, const struct sk_buff *skb)
119+
{
120+
#ifdef CONFIG_NET_RX_BUSY_POLL
121+
sk->sk_napi_id = skb->napi_id;
122+
#endif
123+
}
124+
125+
/* variant used for unconnected sockets */
126+
static inline void sk_mark_napi_id_once(struct sock *sk,
127+
const struct sk_buff *skb)
128+
{
129+
#ifdef CONFIG_NET_RX_BUSY_POLL
130+
if (!sk->sk_napi_id)
131+
sk->sk_napi_id = skb->napi_id;
132+
#endif
133+
}
134+
125135
#endif /* _LINUX_NET_BUSY_POLL_H */

‎net/ipv4/udp.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,8 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
15691569
sock_rps_save_rxhash(sk, skb);
15701570
sk_mark_napi_id(sk, skb);
15711571
sk_incoming_cpu_update(sk);
1572+
} else {
1573+
sk_mark_napi_id_once(sk, skb);
15721574
}
15731575

15741576
rc = __udp_enqueue_schedule_skb(sk, skb);

‎net/ipv6/udp.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ static int __udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
519519
sock_rps_save_rxhash(sk, skb);
520520
sk_mark_napi_id(sk, skb);
521521
sk_incoming_cpu_update(sk);
522+
} else {
523+
sk_mark_napi_id_once(sk, skb);
522524
}
523525

524526
rc = __udp_enqueue_schedule_skb(sk, skb);

0 commit comments

Comments
 (0)