Skip to content

Commit

Permalink
workqueue: Remove schedule() in unbind_workers()
Browse files Browse the repository at this point in the history
The commit 6d25be5 ("sched/core, workqueues: Distangle worker
accounting from rq lock") changed the schedule callbacks for workqueue
and moved the schedule callback from the wakeup code to at end of
schedule() in the worker's process context.

It means that the callback wq_worker_running() is guaranteed that
it sees the %WORKER_UNBOUND flag after scheduled since unbind_workers()
is running on the same CPU that all the pool's workers bound to.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Lai Jiangshan authored and Tejun Heo committed Dec 9, 2021
1 parent 11b45b0 commit b4ac938
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -4979,6 +4979,9 @@ static void unbind_workers(int cpu)
* We've blocked all attach/detach operations. Make all workers
* unbound and set DISASSOCIATED. Before this, all workers
* must be on the cpu. After this, they may become diasporas.
* And the preemption disabled section in their sched callbacks
* are guaranteed to see WORKER_UNBOUND since the code here
* is on the same cpu.
*/
for_each_pool_worker(worker, pool)
worker->flags |= WORKER_UNBOUND;
Expand All @@ -4994,14 +4997,6 @@ static void unbind_workers(int cpu)

mutex_unlock(&wq_pool_attach_mutex);

/*
* Call schedule() so that we cross rq->lock and thus can
* guarantee sched callbacks see the %WORKER_UNBOUND flag.
* This is necessary as scheduler callbacks may be invoked
* from other cpus.
*/
schedule();

/*
* Sched callbacks are disabled now. Zap nr_running.
* After this, nr_running stays zero and need_more_worker()
Expand Down

0 comments on commit b4ac938

Please sign in to comment.