Skip to content

Commit

Permalink
workqueue: Restrict affinity change to rescuer
Browse files Browse the repository at this point in the history
create_worker() will already set the right affinity using
kthread_bind_mask(), this means only the rescuer will need to change
it's affinity.

Howveer, while in cpu-hot-unplug a regular task is not allowed to run
on online&&!active as it would be pushed away quite agressively. We
need KTHREAD_IS_PER_CPU to survive in that environment.

Therefore set the affinity after getting that magic flag.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Tested-by: Valentin Schneider <valentin.schneider@arm.com>
Link: https://lkml.kernel.org/r/20210121103506.826629830@infradead.org
  • Loading branch information
Peter Zijlstra committed Jan 22, 2021
1 parent 5c25b5f commit 640f17c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1848,12 +1848,6 @@ static void worker_attach_to_pool(struct worker *worker,
{
mutex_lock(&wq_pool_attach_mutex);

/*
* set_cpus_allowed_ptr() will fail if the cpumask doesn't have any
* online CPUs. It'll be re-applied when any of the CPUs come up.
*/
set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask);

/*
* The wq_pool_attach_mutex ensures %POOL_DISASSOCIATED remains
* stable across this function. See the comments above the flag
Expand All @@ -1864,6 +1858,9 @@ static void worker_attach_to_pool(struct worker *worker,
else
kthread_set_per_cpu(worker->task, pool->cpu);

if (worker->rescue_wq)
set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask);

list_add_tail(&worker->node, &pool->workers);
worker->pool = pool;

Expand Down

0 comments on commit 640f17c

Please sign in to comment.