Skip to content

Commit b4e8ae5

Browse files
Stefan Roeschkuba-moo
authored andcommitted
net: add napi_busy_loop_rcu()
This adds the napi_busy_loop_rcu() function. This function assumes that the calling function is already holding the rcu read lock and napi_busy_loop() does not need to take the rcu read lock. Add a NAPI_F_NO_SCHED flag, which tells __napi_busy_loop() to abort if we need to reschedule rather than drop the RCU read lock and reschedule. Signed-off-by: Stefan Roesch <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 13d381b commit b4e8ae5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/net/busy_poll.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ void napi_busy_loop(unsigned int napi_id,
4848
bool (*loop_end)(void *, unsigned long),
4949
void *loop_end_arg, bool prefer_busy_poll, u16 budget);
5050

51+
void napi_busy_loop_rcu(unsigned int napi_id,
52+
bool (*loop_end)(void *, unsigned long),
53+
void *loop_end_arg, bool prefer_busy_poll, u16 budget);
54+
5155
#else /* CONFIG_NET_RX_BUSY_POLL */
5256
static inline unsigned long net_busy_loop_on(void)
5357
{

net/core/dev.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,6 +6179,7 @@ static void __busy_poll_stop(struct napi_struct *napi, bool skip_schedule)
61796179

61806180
enum {
61816181
NAPI_F_PREFER_BUSY_POLL = 1,
6182+
NAPI_F_END_ON_RESCHED = 2,
61826183
};
61836184

61846185
static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock,
@@ -6285,6 +6286,8 @@ static void __napi_busy_loop(unsigned int napi_id,
62856286
break;
62866287

62876288
if (unlikely(need_resched())) {
6289+
if (flags & NAPI_F_END_ON_RESCHED)
6290+
break;
62886291
if (napi_poll)
62896292
busy_poll_stop(napi, have_poll_lock, flags, budget);
62906293
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
@@ -6304,6 +6307,18 @@ static void __napi_busy_loop(unsigned int napi_id,
63046307
preempt_enable();
63056308
}
63066309

6310+
void napi_busy_loop_rcu(unsigned int napi_id,
6311+
bool (*loop_end)(void *, unsigned long),
6312+
void *loop_end_arg, bool prefer_busy_poll, u16 budget)
6313+
{
6314+
unsigned flags = NAPI_F_END_ON_RESCHED;
6315+
6316+
if (prefer_busy_poll)
6317+
flags |= NAPI_F_PREFER_BUSY_POLL;
6318+
6319+
__napi_busy_loop(napi_id, loop_end, loop_end_arg, flags, budget);
6320+
}
6321+
63076322
void napi_busy_loop(unsigned int napi_id,
63086323
bool (*loop_end)(void *, unsigned long),
63096324
void *loop_end_arg, bool prefer_busy_poll, u16 budget)

0 commit comments

Comments
 (0)