Skip to content

Commit 793777b

Browse files
valschneiderhtejun
authored andcommitted
workqueue: Factorize unbind/rebind_workers() logic
Later patches will reuse this code, move it into reusable functions. Signed-off-by: Valentin Schneider <[email protected]> Reviewed-by: Lai Jiangshan <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 99c621e commit 793777b

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

kernel/workqueue.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,23 @@ static struct worker *create_worker(struct worker_pool *pool)
19761976
return NULL;
19771977
}
19781978

1979+
static void unbind_worker(struct worker *worker)
1980+
{
1981+
lockdep_assert_held(&wq_pool_attach_mutex);
1982+
1983+
kthread_set_per_cpu(worker->task, -1);
1984+
if (cpumask_intersects(wq_unbound_cpumask, cpu_active_mask))
1985+
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, wq_unbound_cpumask) < 0);
1986+
else
1987+
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0);
1988+
}
1989+
1990+
static void rebind_worker(struct worker *worker, struct worker_pool *pool)
1991+
{
1992+
kthread_set_per_cpu(worker->task, pool->cpu);
1993+
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask) < 0);
1994+
}
1995+
19791996
/**
19801997
* destroy_worker - destroy a workqueue worker
19811998
* @worker: worker to be destroyed
@@ -5051,13 +5068,8 @@ static void unbind_workers(int cpu)
50515068

50525069
raw_spin_unlock_irq(&pool->lock);
50535070

5054-
for_each_pool_worker(worker, pool) {
5055-
kthread_set_per_cpu(worker->task, -1);
5056-
if (cpumask_intersects(wq_unbound_cpumask, cpu_active_mask))
5057-
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, wq_unbound_cpumask) < 0);
5058-
else
5059-
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0);
5060-
}
5071+
for_each_pool_worker(worker, pool)
5072+
unbind_worker(worker);
50615073

50625074
mutex_unlock(&wq_pool_attach_mutex);
50635075
}
@@ -5082,11 +5094,8 @@ static void rebind_workers(struct worker_pool *pool)
50825094
* of all workers first and then clear UNBOUND. As we're called
50835095
* from CPU_ONLINE, the following shouldn't fail.
50845096
*/
5085-
for_each_pool_worker(worker, pool) {
5086-
kthread_set_per_cpu(worker->task, pool->cpu);
5087-
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
5088-
pool->attrs->cpumask) < 0);
5089-
}
5097+
for_each_pool_worker(worker, pool)
5098+
rebind_worker(worker, pool);
50905099

50915100
raw_spin_lock_irq(&pool->lock);
50925101

0 commit comments

Comments
 (0)