3f75dffde7199933476ad2277a49353b36711f95
[openwrt/staging/wigyori.git] /
1 From 56364c910691f6d10ba88c964c9041b9ab777bd6 Mon Sep 17 00:00:00 2001
2 From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
3 Date: Mon, 25 Mar 2024 08:40:28 +0100
4 Subject: [PATCH 1/4] net: Remove conditional threaded-NAPI wakeup based on
5 task state.
6
7 A NAPI thread is scheduled by first setting NAPI_STATE_SCHED bit. If
8 successful (the bit was not yet set) then the NAPI_STATE_SCHED_THREADED
9 is set but only if thread's state is not TASK_INTERRUPTIBLE (is
10 TASK_RUNNING) followed by task wakeup.
11
12 If the task is idle (TASK_INTERRUPTIBLE) then the
13 NAPI_STATE_SCHED_THREADED bit is not set. The thread is no relying on
14 the bit but always leaving the wait-loop after returning from schedule()
15 because there must have been a wakeup.
16
17 The smpboot-threads implementation for per-CPU threads requires an
18 explicit condition and does not support "if we get out of schedule()
19 then there must be something to do".
20
21 Removing this optimisation simplifies the following integration.
22
23 Set NAPI_STATE_SCHED_THREADED unconditionally on wakeup and rely on it
24 in the wait path by removing the `woken' condition.
25
26 Acked-by: Jakub Kicinski <kuba@kernel.org>
27 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
28 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
29 ---
30 net/core/dev.c | 14 ++------------
31 1 file changed, 2 insertions(+), 12 deletions(-)
32
33 --- a/net/core/dev.c
34 +++ b/net/core/dev.c
35 @@ -4477,13 +4477,7 @@ static inline void ____napi_schedule(str
36 */
37 thread = READ_ONCE(napi->thread);
38 if (thread) {
39 - /* Avoid doing set_bit() if the thread is in
40 - * INTERRUPTIBLE state, cause napi_thread_wait()
41 - * makes sure to proceed with napi polling
42 - * if the thread is explicitly woken from here.
43 - */
44 - if (READ_ONCE(thread->__state) != TASK_INTERRUPTIBLE)
45 - set_bit(NAPI_STATE_SCHED_THREADED, &napi->state);
46 + set_bit(NAPI_STATE_SCHED_THREADED, &napi->state);
47 wake_up_process(thread);
48 return;
49 }
50 @@ -6639,8 +6633,6 @@ static int napi_poll(struct napi_struct
51
52 static int napi_thread_wait(struct napi_struct *napi)
53 {
54 - bool woken = false;
55 -
56 set_current_state(TASK_INTERRUPTIBLE);
57
58 while (!kthread_should_stop()) {
59 @@ -6649,15 +6641,13 @@ static int napi_thread_wait(struct napi_
60 * Testing SCHED bit is not enough because SCHED bit might be
61 * set by some other busy poll thread or by napi_disable().
62 */
63 - if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state) || woken) {
64 + if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state)) {
65 WARN_ON(!list_empty(&napi->poll_list));
66 __set_current_state(TASK_RUNNING);
67 return 0;
68 }
69
70 schedule();
71 - /* woken being true indicates this thread owns this napi. */
72 - woken = true;
73 set_current_state(TASK_INTERRUPTIBLE);
74 }
75 __set_current_state(TASK_RUNNING);