Skip to content

Commit 13d381b

Browse files
Stefan Roeschkuba-moo
authored andcommitted
net: split off __napi_busy_poll from napi_busy_poll
This splits off the key part of the napi_busy_poll function into its own function, __napi_busy_poll, and changes the prefer_busy_poll bool to be flag based to allow passing in more flags in the future. This is done in preparation for an additional napi_busy_poll() function, that doesn't take the rcu_read_lock(). The new function is introduced in the next patch. 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 54be6c6 commit 13d381b

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

net/core/dev.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6177,8 +6177,12 @@ 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+
};
6183+
6184+
static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock,
6185+
unsigned flags, u16 budget)
61826186
{
61836187
bool skip_schedule = false;
61846188
unsigned long timeout;
@@ -6198,7 +6202,7 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bool
61986202

61996203
local_bh_disable();
62006204

6201-
if (prefer_busy_poll) {
6205+
if (flags & NAPI_F_PREFER_BUSY_POLL) {
62026206
napi->defer_hard_irqs_count = READ_ONCE(napi->dev->napi_defer_hard_irqs);
62036207
timeout = READ_ONCE(napi->dev->gro_flush_timeout);
62046208
if (napi->defer_hard_irqs_count && timeout) {
@@ -6222,23 +6226,23 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bool
62226226
local_bh_enable();
62236227
}
62246228

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)
6229+
static void __napi_busy_loop(unsigned int napi_id,
6230+
bool (*loop_end)(void *, unsigned long),
6231+
void *loop_end_arg, unsigned flags, u16 budget)
62286232
{
62296233
unsigned long start_time = loop_end ? busy_loop_current_time() : 0;
62306234
int (*napi_poll)(struct napi_struct *napi, int budget);
62316235
void *have_poll_lock = NULL;
62326236
struct napi_struct *napi;
62336237

6238+
WARN_ON_ONCE(!rcu_read_lock_held());
6239+
62346240
restart:
62356241
napi_poll = NULL;
62366242

6237-
rcu_read_lock();
6238-
62396243
napi = napi_by_id(napi_id);
62406244
if (!napi)
6241-
goto out;
6245+
return;
62426246

62436247
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
62446248
preempt_disable();
@@ -6254,14 +6258,14 @@ void napi_busy_loop(unsigned int napi_id,
62546258
*/
62556259
if (val & (NAPIF_STATE_DISABLE | NAPIF_STATE_SCHED |
62566260
NAPIF_STATE_IN_BUSY_POLL)) {
6257-
if (prefer_busy_poll)
6261+
if (flags & NAPI_F_PREFER_BUSY_POLL)
62586262
set_bit(NAPI_STATE_PREFER_BUSY_POLL, &napi->state);
62596263
goto count;
62606264
}
62616265
if (cmpxchg(&napi->state, val,
62626266
val | NAPIF_STATE_IN_BUSY_POLL |
62636267
NAPIF_STATE_SCHED) != val) {
6264-
if (prefer_busy_poll)
6268+
if (flags & NAPI_F_PREFER_BUSY_POLL)
62656269
set_bit(NAPI_STATE_PREFER_BUSY_POLL, &napi->state);
62666270
goto count;
62676271
}
@@ -6282,22 +6286,32 @@ void napi_busy_loop(unsigned int napi_id,
62826286

62836287
if (unlikely(need_resched())) {
62846288
if (napi_poll)
6285-
busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
6289+
busy_poll_stop(napi, have_poll_lock, flags, budget);
62866290
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
62876291
preempt_enable();
62886292
rcu_read_unlock();
62896293
cond_resched();
6294+
rcu_read_lock();
62906295
if (loop_end(loop_end_arg, start_time))
62916296
return;
62926297
goto restart;
62936298
}
62946299
cpu_relax();
62956300
}
62966301
if (napi_poll)
6297-
busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
6302+
busy_poll_stop(napi, have_poll_lock, flags, budget);
62986303
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
62996304
preempt_enable();
6300-
out:
6305+
}
6306+
6307+
void napi_busy_loop(unsigned int napi_id,
6308+
bool (*loop_end)(void *, unsigned long),
6309+
void *loop_end_arg, bool prefer_busy_poll, u16 budget)
6310+
{
6311+
unsigned flags = prefer_busy_poll ? NAPI_F_PREFER_BUSY_POLL : 0;
6312+
6313+
rcu_read_lock();
6314+
__napi_busy_loop(napi_id, loop_end, loop_end_arg, flags, budget);
63016315
rcu_read_unlock();
63026316
}
63036317
EXPORT_SYMBOL(napi_busy_loop);

0 commit comments

Comments
 (0)