Skip to content

Commit 2b5cd0d

Browse files
Alexander Duyckdavem330
authored andcommitted
net: Change return type of sk_busy_loop from bool to void
checking the return value of sk_busy_loop. As there are only a few consumers of that data, and the data being checked for can be replaced with a check for !skb_queue_empty() we might as well just pull the code out of sk_busy_loop and place it in the spots that actually need it. 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 d2e64db commit 2b5cd0d

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

include/net/busy_poll.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static inline bool busy_loop_timeout(unsigned long end_time)
7474
return time_after(now, end_time);
7575
}
7676

77-
bool sk_busy_loop(struct sock *sk, int nonblock);
77+
void sk_busy_loop(struct sock *sk, int nonblock);
7878

7979
#else /* CONFIG_NET_RX_BUSY_POLL */
8080
static inline unsigned long net_busy_loop_on(void)
@@ -97,9 +97,8 @@ static inline bool busy_loop_timeout(unsigned long end_time)
9797
return true;
9898
}
9999

100-
static inline bool sk_busy_loop(struct sock *sk, int nonblock)
100+
static inline void sk_busy_loop(struct sock *sk, int nonblock)
101101
{
102-
return false;
103102
}
104103

105104
#endif /* CONFIG_NET_RX_BUSY_POLL */

net/core/datagram.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,12 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags,
256256
}
257257

258258
spin_unlock_irqrestore(&queue->lock, cpu_flags);
259-
} while (sk_can_busy_loop(sk) &&
260-
sk_busy_loop(sk, flags & MSG_DONTWAIT));
259+
260+
if (!sk_can_busy_loop(sk))
261+
break;
262+
263+
sk_busy_loop(sk, flags & MSG_DONTWAIT);
264+
} while (!skb_queue_empty(&sk->sk_receive_queue));
261265

262266
error = -EAGAIN;
263267

net/core/dev.c

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

5063-
bool sk_busy_loop(struct sock *sk, int nonblock)
5063+
void sk_busy_loop(struct sock *sk, int nonblock)
50645064
{
50655065
unsigned long end_time = !nonblock ? sk_busy_loop_end_time(sk) : 0;
50665066
int (*napi_poll)(struct napi_struct *napi, int budget);
50675067
void *have_poll_lock = NULL;
50685068
struct napi_struct *napi;
50695069
unsigned int napi_id;
5070-
int rc;
50715070

50725071
restart:
50735072
napi_id = READ_ONCE(sk->sk_napi_id);
50745073
if (napi_id < MIN_NAPI_ID)
5075-
return 0;
5074+
return;
50765075

5077-
rc = false;
50785076
napi_poll = NULL;
50795077

50805078
rcu_read_lock();
@@ -5085,7 +5083,8 @@ bool sk_busy_loop(struct sock *sk, int nonblock)
50855083

50865084
preempt_disable();
50875085
for (;;) {
5088-
rc = 0;
5086+
int work = 0;
5087+
50895088
local_bh_disable();
50905089
if (!napi_poll) {
50915090
unsigned long val = READ_ONCE(napi->state);
@@ -5103,12 +5102,12 @@ bool sk_busy_loop(struct sock *sk, int nonblock)
51035102
have_poll_lock = netpoll_poll_lock(napi);
51045103
napi_poll = napi->poll;
51055104
}
5106-
rc = napi_poll(napi, BUSY_POLL_BUDGET);
5107-
trace_napi_poll(napi, rc, BUSY_POLL_BUDGET);
5105+
work = napi_poll(napi, BUSY_POLL_BUDGET);
5106+
trace_napi_poll(napi, work, BUSY_POLL_BUDGET);
51085107
count:
5109-
if (rc > 0)
5108+
if (work > 0)
51105109
__NET_ADD_STATS(sock_net(sk),
5111-
LINUX_MIB_BUSYPOLLRXPACKETS, rc);
5110+
LINUX_MIB_BUSYPOLLRXPACKETS, work);
51125111
local_bh_enable();
51135112

51145113
if (nonblock || !skb_queue_empty(&sk->sk_receive_queue) ||
@@ -5121,20 +5120,18 @@ bool sk_busy_loop(struct sock *sk, int nonblock)
51215120
preempt_enable();
51225121
rcu_read_unlock();
51235122
cond_resched();
5124-
rc = !skb_queue_empty(&sk->sk_receive_queue);
5125-
if (rc || busy_loop_timeout(end_time))
5126-
return rc;
5123+
if (!skb_queue_empty(&sk->sk_receive_queue) ||
5124+
busy_loop_timeout(end_time))
5125+
return;
51275126
goto restart;
51285127
}
51295128
cpu_relax();
51305129
}
51315130
if (napi_poll)
51325131
busy_poll_stop(napi, have_poll_lock);
51335132
preempt_enable();
5134-
rc = !skb_queue_empty(&sk->sk_receive_queue);
51355133
out:
51365134
rcu_read_unlock();
5137-
return rc;
51385135
}
51395136
EXPORT_SYMBOL(sk_busy_loop);
51405137

net/sctp/socket.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7518,9 +7518,12 @@ struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags,
75187518
if (sk->sk_shutdown & RCV_SHUTDOWN)
75197519
break;
75207520

7521-
if (sk_can_busy_loop(sk) &&
7522-
sk_busy_loop(sk, noblock))
7523-
continue;
7521+
if (sk_can_busy_loop(sk)) {
7522+
sk_busy_loop(sk, noblock);
7523+
7524+
if (!skb_queue_empty(&sk->sk_receive_queue))
7525+
continue;
7526+
}
75247527

75257528
/* User doesn't want to wait. */
75267529
error = -EAGAIN;

0 commit comments

Comments
 (0)