Skip to content

Commit 7db6b04

Browse files
ssamudraladavem330
authored andcommitted
net: Commonize busy polling code to focus on napi_id instead of socket
Move the core functionality in sk_busy_loop() to napi_busy_loop() and make it independent of sk. This enables re-using this function in epoll busy loop implementation. Signed-off-by: Sridhar Samudrala <sridhar.samudrala@intel.com> Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3705671 commit 7db6b04

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

include/net/busy_poll.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ static inline bool sk_can_busy_loop(const struct sock *sk)
5151
return sk->sk_ll_usec && !signal_pending(current);
5252
}
5353

54-
void sk_busy_loop(struct sock *sk, int nonblock);
54+
bool sk_busy_loop_end(void *p, unsigned long start_time);
55+
56+
void napi_busy_loop(unsigned int napi_id,
57+
bool (*loop_end)(void *, unsigned long),
58+
void *loop_end_arg);
5559

5660
#else /* CONFIG_NET_RX_BUSY_POLL */
5761
static inline unsigned long net_busy_loop_on(void)
@@ -64,10 +68,6 @@ static inline bool sk_can_busy_loop(struct sock *sk)
6468
return false;
6569
}
6670

67-
static inline void sk_busy_loop(struct sock *sk, int nonblock)
68-
{
69-
}
70-
7171
#endif /* CONFIG_NET_RX_BUSY_POLL */
7272

7373
static inline unsigned long busy_loop_current_time(void)
@@ -111,6 +111,16 @@ static inline bool sk_busy_loop_timeout(struct sock *sk,
111111
return true;
112112
}
113113

114+
static inline void sk_busy_loop(struct sock *sk, int nonblock)
115+
{
116+
#ifdef CONFIG_NET_RX_BUSY_POLL
117+
unsigned int napi_id = READ_ONCE(sk->sk_napi_id);
118+
119+
if (napi_id >= MIN_NAPI_ID)
120+
napi_busy_loop(napi_id, nonblock ? NULL : sk_busy_loop_end, sk);
121+
#endif
122+
}
123+
114124
/* used in the NIC receive handler to mark the skb */
115125
static inline void skb_mark_napi_id(struct sk_buff *skb,
116126
struct napi_struct *napi)

net/core/dev.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5060,19 +5060,16 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock)
50605060
do_softirq();
50615061
}
50625062

5063-
void sk_busy_loop(struct sock *sk, int nonblock)
5063+
void napi_busy_loop(unsigned int napi_id,
5064+
bool (*loop_end)(void *, unsigned long),
5065+
void *loop_end_arg)
50645066
{
5065-
unsigned long start_time = nonblock ? 0 : busy_loop_current_time();
5067+
unsigned long start_time = loop_end ? busy_loop_current_time() : 0;
50665068
int (*napi_poll)(struct napi_struct *napi, int budget);
50675069
void *have_poll_lock = NULL;
50685070
struct napi_struct *napi;
5069-
unsigned int napi_id;
50705071

50715072
restart:
5072-
napi_id = READ_ONCE(sk->sk_napi_id);
5073-
if (napi_id < MIN_NAPI_ID)
5074-
return;
5075-
50765073
napi_poll = NULL;
50775074

50785075
rcu_read_lock();
@@ -5106,12 +5103,11 @@ void sk_busy_loop(struct sock *sk, int nonblock)
51065103
trace_napi_poll(napi, work, BUSY_POLL_BUDGET);
51075104
count:
51085105
if (work > 0)
5109-
__NET_ADD_STATS(sock_net(sk),
5106+
__NET_ADD_STATS(dev_net(napi->dev),
51105107
LINUX_MIB_BUSYPOLLRXPACKETS, work);
51115108
local_bh_enable();
51125109

5113-
if (nonblock || !skb_queue_empty(&sk->sk_receive_queue) ||
5114-
sk_busy_loop_timeout(sk, start_time))
5110+
if (!loop_end || loop_end(loop_end_arg, start_time))
51155111
break;
51165112

51175113
if (unlikely(need_resched())) {
@@ -5120,8 +5116,7 @@ void sk_busy_loop(struct sock *sk, int nonblock)
51205116
preempt_enable();
51215117
rcu_read_unlock();
51225118
cond_resched();
5123-
if (!skb_queue_empty(&sk->sk_receive_queue) ||
5124-
sk_busy_loop_timeout(sk, start_time))
5119+
if (loop_end(loop_end_arg, start_time))
51255120
return;
51265121
goto restart;
51275122
}
@@ -5133,7 +5128,7 @@ void sk_busy_loop(struct sock *sk, int nonblock)
51335128
out:
51345129
rcu_read_unlock();
51355130
}
5136-
EXPORT_SYMBOL(sk_busy_loop);
5131+
EXPORT_SYMBOL(napi_busy_loop);
51375132

51385133
#endif /* CONFIG_NET_RX_BUSY_POLL */
51395134

net/core/sock.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,3 +3237,14 @@ static int __init proto_init(void)
32373237
subsys_initcall(proto_init);
32383238

32393239
#endif /* PROC_FS */
3240+
3241+
#ifdef CONFIG_NET_RX_BUSY_POLL
3242+
bool sk_busy_loop_end(void *p, unsigned long start_time)
3243+
{
3244+
struct sock *sk = p;
3245+
3246+
return !skb_queue_empty(&sk->sk_receive_queue) ||
3247+
sk_busy_loop_timeout(sk, start_time);
3248+
}
3249+
EXPORT_SYMBOL(sk_busy_loop_end);
3250+
#endif /* CONFIG_NET_RX_BUSY_POLL */

0 commit comments

Comments
 (0)