600-v6.10-net-Remove-conditional-threaded-NAPI-wakeup-based-on.patch 2.7 KB

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