770-net-introduce-napi_is_scheduled-helper.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 7f3eb2174512fe6c9c0f062e96eccb0d3cc6d5cd Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Wed, 18 Oct 2023 14:35:47 +0200
  4. Subject: [PATCH] net: introduce napi_is_scheduled helper
  5. We currently have napi_if_scheduled_mark_missed that can be used to
  6. check if napi is scheduled but that does more thing than simply checking
  7. it and return a bool. Some driver already implement custom function to
  8. check if napi is scheduled.
  9. Drop these custom function and introduce napi_is_scheduled that simply
  10. check if napi is scheduled atomically.
  11. Update any driver and code that implement a similar check and instead
  12. use this new helper.
  13. Signed-off-by: Christian Marangi <[email protected]>
  14. Signed-off-by: Paolo Abeni <[email protected]>
  15. ---
  16. drivers/net/ethernet/chelsio/cxgb3/sge.c | 8 --------
  17. drivers/net/wireless/realtek/rtw89/core.c | 2 +-
  18. include/linux/netdevice.h | 23 +++++++++++++++++++++++
  19. net/core/dev.c | 2 +-
  20. 4 files changed, 25 insertions(+), 10 deletions(-)
  21. --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
  22. +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
  23. @@ -2501,14 +2501,6 @@ static int napi_rx_handler(struct napi_s
  24. return work_done;
  25. }
  26. -/*
  27. - * Returns true if the device is already scheduled for polling.
  28. - */
  29. -static inline int napi_is_scheduled(struct napi_struct *napi)
  30. -{
  31. - return test_bit(NAPI_STATE_SCHED, &napi->state);
  32. -}
  33. -
  34. /**
  35. * process_pure_responses - process pure responses from a response queue
  36. * @adap: the adapter
  37. --- a/drivers/net/wireless/realtek/rtw89/core.c
  38. +++ b/drivers/net/wireless/realtek/rtw89/core.c
  39. @@ -1744,7 +1744,7 @@ static void rtw89_core_rx_to_mac80211(st
  40. struct napi_struct *napi = &rtwdev->napi;
  41. /* In low power mode, napi isn't scheduled. Receive it to netif. */
  42. - if (unlikely(!test_bit(NAPI_STATE_SCHED, &napi->state)))
  43. + if (unlikely(!napi_is_scheduled(napi)))
  44. napi = NULL;
  45. rtw89_core_hw_to_sband_rate(rx_status);
  46. --- a/include/linux/netdevice.h
  47. +++ b/include/linux/netdevice.h
  48. @@ -480,6 +480,29 @@ static inline bool napi_prefer_busy_poll
  49. return test_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state);
  50. }
  51. +/**
  52. + * napi_is_scheduled - test if NAPI is scheduled
  53. + * @n: NAPI context
  54. + *
  55. + * This check is "best-effort". With no locking implemented,
  56. + * a NAPI can be scheduled or terminate right after this check
  57. + * and produce not precise results.
  58. + *
  59. + * NAPI_STATE_SCHED is an internal state, napi_is_scheduled
  60. + * should not be used normally and napi_schedule should be
  61. + * used instead.
  62. + *
  63. + * Use only if the driver really needs to check if a NAPI
  64. + * is scheduled for example in the context of delayed timer
  65. + * that can be skipped if a NAPI is already scheduled.
  66. + *
  67. + * Return True if NAPI is scheduled, False otherwise.
  68. + */
  69. +static inline bool napi_is_scheduled(struct napi_struct *n)
  70. +{
  71. + return test_bit(NAPI_STATE_SCHED, &n->state);
  72. +}
  73. +
  74. bool napi_schedule_prep(struct napi_struct *n);
  75. /**
  76. --- a/net/core/dev.c
  77. +++ b/net/core/dev.c
  78. @@ -6555,7 +6555,7 @@ static int __napi_poll(struct napi_struc
  79. * accidentally calling ->poll() when NAPI is not scheduled.
  80. */
  81. work = 0;
  82. - if (test_bit(NAPI_STATE_SCHED, &n->state)) {
  83. + if (napi_is_scheduled(n)) {
  84. work = n->poll(n, weight);
  85. trace_napi_poll(n, work, weight);
  86. }