Skip to content

Commit 5c25b5f

Browse files
author
Peter Zijlstra
committed
workqueue: Tag bound workers with KTHREAD_IS_PER_CPU
Mark the per-cpu workqueue workers as KTHREAD_IS_PER_CPU. Workqueues have unfortunate semantics in that per-cpu workers are not default flushed and parked during hotplug, however a subset does manual flush on hotplug and hard relies on them for correctness. Therefore play silly games.. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Tested-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent ac687e6 commit 5c25b5f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

kernel/workqueue.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,8 @@ static void worker_attach_to_pool(struct worker *worker,
18611861
*/
18621862
if (pool->flags & POOL_DISASSOCIATED)
18631863
worker->flags |= WORKER_UNBOUND;
1864+
else
1865+
kthread_set_per_cpu(worker->task, pool->cpu);
18641866

18651867
list_add_tail(&worker->node, &pool->workers);
18661868
worker->pool = pool;
@@ -1883,6 +1885,7 @@ static void worker_detach_from_pool(struct worker *worker)
18831885

18841886
mutex_lock(&wq_pool_attach_mutex);
18851887

1888+
kthread_set_per_cpu(worker->task, -1);
18861889
list_del(&worker->node);
18871890
worker->pool = NULL;
18881891

@@ -4919,8 +4922,10 @@ static void unbind_workers(int cpu)
49194922

49204923
raw_spin_unlock_irq(&pool->lock);
49214924

4922-
for_each_pool_worker(worker, pool)
4925+
for_each_pool_worker(worker, pool) {
4926+
kthread_set_per_cpu(worker->task, -1);
49234927
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0);
4928+
}
49244929

49254930
mutex_unlock(&wq_pool_attach_mutex);
49264931

@@ -4972,9 +4977,11 @@ static void rebind_workers(struct worker_pool *pool)
49724977
* of all workers first and then clear UNBOUND. As we're called
49734978
* from CPU_ONLINE, the following shouldn't fail.
49744979
*/
4975-
for_each_pool_worker(worker, pool)
4980+
for_each_pool_worker(worker, pool) {
4981+
kthread_set_per_cpu(worker->task, pool->cpu);
49764982
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
49774983
pool->attrs->cpumask) < 0);
4984+
}
49784985

49794986
raw_spin_lock_irq(&pool->lock);
49804987

0 commit comments

Comments
 (0)