Commit 793777bc authored by Valentin Schneider's avatar Valentin Schneider Committed by Tejun Heo

workqueue: Factorize unbind/rebind_workers() logic

Later patches will reuse this code, move it into reusable functions.
Signed-off-by: default avatarValentin Schneider <vschneid@redhat.com>
Reviewed-by: default avatarLai Jiangshan <jiangshanlai@gmail.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 99c621ef
...@@ -1976,6 +1976,23 @@ static struct worker *create_worker(struct worker_pool *pool) ...@@ -1976,6 +1976,23 @@ static struct worker *create_worker(struct worker_pool *pool)
return NULL; return NULL;
} }
static void unbind_worker(struct worker *worker)
{
lockdep_assert_held(&wq_pool_attach_mutex);
kthread_set_per_cpu(worker->task, -1);
if (cpumask_intersects(wq_unbound_cpumask, cpu_active_mask))
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, wq_unbound_cpumask) < 0);
else
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0);
}
static void rebind_worker(struct worker *worker, struct worker_pool *pool)
{
kthread_set_per_cpu(worker->task, pool->cpu);
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask) < 0);
}
/** /**
* destroy_worker - destroy a workqueue worker * destroy_worker - destroy a workqueue worker
* @worker: worker to be destroyed * @worker: worker to be destroyed
...@@ -5051,13 +5068,8 @@ static void unbind_workers(int cpu) ...@@ -5051,13 +5068,8 @@ static void unbind_workers(int cpu)
raw_spin_unlock_irq(&pool->lock); raw_spin_unlock_irq(&pool->lock);
for_each_pool_worker(worker, pool) { for_each_pool_worker(worker, pool)
kthread_set_per_cpu(worker->task, -1); unbind_worker(worker);
if (cpumask_intersects(wq_unbound_cpumask, cpu_active_mask))
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, wq_unbound_cpumask) < 0);
else
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0);
}
mutex_unlock(&wq_pool_attach_mutex); mutex_unlock(&wq_pool_attach_mutex);
} }
...@@ -5082,11 +5094,8 @@ static void rebind_workers(struct worker_pool *pool) ...@@ -5082,11 +5094,8 @@ static void rebind_workers(struct worker_pool *pool)
* of all workers first and then clear UNBOUND. As we're called * of all workers first and then clear UNBOUND. As we're called
* from CPU_ONLINE, the following shouldn't fail. * from CPU_ONLINE, the following shouldn't fail.
*/ */
for_each_pool_worker(worker, pool) { for_each_pool_worker(worker, pool)
kthread_set_per_cpu(worker->task, pool->cpu); rebind_worker(worker, pool);
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
pool->attrs->cpumask) < 0);
}
raw_spin_lock_irq(&pool->lock); raw_spin_lock_irq(&pool->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment