Skip to content

Commit adaad27

Browse files
committed
Merge branch 'for-io_uring-add-napi-busy-polling-support' of git://git.kernel.org/pub/scm/linux/kernel/git/kuba/linux into for-6.9/io_uring
Pull netdev side of the io_uring napi support. * 'for-io_uring-add-napi-busy-polling-support' of git://git.kernel.org/pub/scm/linux/kernel/git/kuba/linux: net: add napi_busy_loop_rcu() net: split off __napi_busy_poll from napi_busy_poll
2 parents b4bb190 + b4e8ae5 commit adaad27

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
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: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6177,8 +6177,13 @@ static void __busy_poll_stop(struct napi_struct *napi, bool skip_schedule)
61776177
clear_bit(NAPI_STATE_SCHED, &napi->state);
61786178
}
61796179

6180-
static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bool prefer_busy_poll,
6181-
u16 budget)
6180+
enum {
6181+
NAPI_F_PREFER_BUSY_POLL = 1,
6182+
NAPI_F_END_ON_RESCHED = 2,
6183+
};
6184+
6185+
static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock,
6186+
unsigned flags, u16 budget)
61826187
{
61836188
bool skip_schedule = false;
61846189
unsigned long timeout;
@@ -6198,7 +6203,7 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bool
61986203

61996204
local_bh_disable();
62006205

6201-
if (prefer_busy_poll) {
6206+
if (flags & NAPI_F_PREFER_BUSY_POLL) {
62026207
napi->defer_hard_irqs_count = READ_ONCE(napi->dev->napi_defer_hard_irqs);
62036208
timeout = READ_ONCE(napi->dev->gro_flush_timeout);
62046209
if (napi->defer_hard_irqs_count && timeout) {
@@ -6222,23 +6227,23 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bool
62226227
local_bh_enable();
62236228
}
62246229

6225-
void napi_busy_loop(unsigned int napi_id,
6226-
bool (*loop_end)(void *, unsigned long),
6227-
void *loop_end_arg, bool prefer_busy_poll, u16 budget)
6230+
static void __napi_busy_loop(unsigned int napi_id,
6231+
bool (*loop_end)(void *, unsigned long),
6232+
void *loop_end_arg, unsigned flags, u16 budget)
62286233
{
62296234
unsigned long start_time = loop_end ? busy_loop_current_time() : 0;
62306235
int (*napi_poll)(struct napi_struct *napi, int budget);
62316236
void *have_poll_lock = NULL;
62326237
struct napi_struct *napi;
62336238

6239+
WARN_ON_ONCE(!rcu_read_lock_held());
6240+
62346241
restart:
62356242
napi_poll = NULL;
62366243

6237-
rcu_read_lock();
6238-
62396244
napi = napi_by_id(napi_id);
62406245
if (!napi)
6241-
goto out;
6246+
return;
62426247

62436248
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
62446249
preempt_disable();
@@ -6254,14 +6259,14 @@ void napi_busy_loop(unsigned int napi_id,
62546259
*/
62556260
if (val & (NAPIF_STATE_DISABLE | NAPIF_STATE_SCHED |
62566261
NAPIF_STATE_IN_BUSY_POLL)) {
6257-
if (prefer_busy_poll)
6262+
if (flags & NAPI_F_PREFER_BUSY_POLL)
62586263
set_bit(NAPI_STATE_PREFER_BUSY_POLL, &napi->state);
62596264
goto count;
62606265
}
62616266
if (cmpxchg(&napi->state, val,
62626267
val | NAPIF_STATE_IN_BUSY_POLL |
62636268
NAPIF_STATE_SCHED) != val) {
6264-
if (prefer_busy_poll)
6269+
if (flags & NAPI_F_PREFER_BUSY_POLL)
62656270
set_bit(NAPI_STATE_PREFER_BUSY_POLL, &napi->state);
62666271
goto count;
62676272
}
@@ -6281,23 +6286,47 @@ void napi_busy_loop(unsigned int napi_id,
62816286
break;
62826287

62836288
if (unlikely(need_resched())) {
6289+
if (flags & NAPI_F_END_ON_RESCHED)
6290+
break;
62846291
if (napi_poll)
6285-
busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
6292+
busy_poll_stop(napi, have_poll_lock, flags, budget);
62866293
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
62876294
preempt_enable();
62886295
rcu_read_unlock();
62896296
cond_resched();
6297+
rcu_read_lock();
62906298
if (loop_end(loop_end_arg, start_time))
62916299
return;
62926300
goto restart;
62936301
}
62946302
cpu_relax();
62956303
}
62966304
if (napi_poll)
6297-
busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
6305+
busy_poll_stop(napi, have_poll_lock, flags, budget);
62986306
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
62996307
preempt_enable();
6300-
out:
6308+
}
6309+
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+
6322+
void napi_busy_loop(unsigned int napi_id,
6323+
bool (*loop_end)(void *, unsigned long),
6324+
void *loop_end_arg, bool prefer_busy_poll, u16 budget)
6325+
{
6326+
unsigned flags = prefer_busy_poll ? NAPI_F_PREFER_BUSY_POLL : 0;
6327+
6328+
rcu_read_lock();
6329+
__napi_busy_loop(napi_id, loop_end, loop_end_arg, flags, budget);
63016330
rcu_read_unlock();
63026331
}
63036332
EXPORT_SYMBOL(napi_busy_loop);

0 commit comments

Comments
 (0)