wifi: mt76: use wait_event_interruptible in worker thread for PREEMPT_RT
Subsystems (2)
PATCH 1/1 wifi: mt76: use wait_event_interruptible in worker thread for PREEMPT_RT
The mt76 worker thread uses a manual set_current_state(TASK_INTERRUPTIBLE) / schedule() loop. On PREEMPT_RT kernels, this pattern triggers:
BUG: scheduling while atomic: mt76-usb-rx phy/2852/0x00000002
The manual task state manipulation interacts poorly with RT's preemption model, where different locking and state transition semantics apply.
Replace the open-coded sleep loop with wait_event_interruptible() on a new wait_queue_head embedded in struct mt76_worker. The schedule point becomes an RT-safe wait_event that properly handles the task state transitions. Update mt76_worker_schedule() to use wake_up() to signal the wait queue.
This follows the standard kernel pattern for kthread wait loops and eliminates the need for manual set_current_state() calls entirely.
--- drivers/net/wireless/mediatek/mt76/util.c | 8 ++++---- drivers/net/wireless/mediatek/mt76/util.h | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/util.c +4 -4
@@ -111,20 +111,20 @@ int __mt76_worker_fn(void *ptr)struct mt76_worker *w = ptr;while (!kthread_should_stop ()) { -set_current_state (TASK_INTERRUPTIBLE ); -if (kthread_should_park ()) {kthread_parkme ();continue ; }if (!test_and_clear_bit (MT76_WORKER_SCHEDULED , &w->state)) { -schedule (); +wait_event_interruptible (w->wq, +test_bit (MT76_WORKER_SCHEDULED , &w->state) || +kthread_should_stop () || +kthread_should_park ());continue ; }set_bit (MT76_WORKER_RUNNING , &w->state); -set_current_state (TASK_RUNNING ); w->fn (w);cond_resched ();clear_bit (MT76_WORKER_RUNNING , &w->state);
drivers/net/wireless/mediatek/mt76/util.h +4 -1
@@ -9,12 +9,14 @@#include <linux/skbuff.h> #include <linux/bitops.h> #include <linux/bitfield.h> +#include <linux/wait.h> #include <net/mac80211.h> struct mt76_worker {struct task_struct *task;void (*fn)(struct mt76_worker *); +wait_queue_head_t wq;unsigned long state; };
@@ -63,6 +65,7 @@ mt76_worker_setup(struct ieee80211_hw *hw, struct mt76_worker *w,if (fn) w->fn = fn; +init_waitqueue_head (&w->wq); w->task =kthread_run (__mt76_worker_fn, w,"mt76-%s %s" , name, dev_name);
@@ -82,7 +85,7 @@ static inline void mt76_worker_schedule(struct mt76_worker *w)if (!test_and_set_bit (MT76_WORKER_SCHEDULED , &w->state) && !test_bit (MT76_WORKER_RUNNING , &w->state)) -wake_up_process (w->task); +wake_up (&w->wq); }static inline void mt76_worker_disable (struct mt76_worker *w)
Signature · 1 line
2.43.0