Commit 17116969 authored by Tejun Heo's avatar Tejun Heo

workqueue: introduce for_each_pool()

With the scheduled unbound pools with custom attributes, there will be
multiple unbound pools, so it wouldn't be able to use
for_each_wq_cpu() + for_each_std_worker_pool() to iterate through all
pools.

Introduce for_each_pool() which iterates through all pools using
worker_pool_idr and use it instead of for_each_wq_cpu() +
for_each_std_worker_pool() combination in freeze_workqueues_begin().
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reviewed-by: default avatarLai Jiangshan <laijs@cn.fujitsu.com>
parent 49e3cf44
...@@ -294,6 +294,14 @@ static inline int __next_wq_cpu(int cpu, const struct cpumask *mask, ...@@ -294,6 +294,14 @@ static inline int __next_wq_cpu(int cpu, const struct cpumask *mask,
(cpu) < WORK_CPU_END; \ (cpu) < WORK_CPU_END; \
(cpu) = __next_wq_cpu((cpu), cpu_online_mask, 3)) (cpu) = __next_wq_cpu((cpu), cpu_online_mask, 3))
/**
* for_each_pool - iterate through all worker_pools in the system
* @pool: iteration cursor
* @id: integer used for iteration
*/
#define for_each_pool(pool, id) \
idr_for_each_entry(&worker_pool_idr, pool, id)
/** /**
* for_each_pwq - iterate through all pool_workqueues of the specified workqueue * for_each_pwq - iterate through all pool_workqueues of the specified workqueue
* @pwq: iteration cursor * @pwq: iteration cursor
...@@ -3586,25 +3594,24 @@ EXPORT_SYMBOL_GPL(work_on_cpu); ...@@ -3586,25 +3594,24 @@ EXPORT_SYMBOL_GPL(work_on_cpu);
*/ */
void freeze_workqueues_begin(void) void freeze_workqueues_begin(void)
{ {
unsigned int cpu; struct worker_pool *pool;
int id;
spin_lock_irq(&workqueue_lock); spin_lock_irq(&workqueue_lock);
WARN_ON_ONCE(workqueue_freezing); WARN_ON_ONCE(workqueue_freezing);
workqueue_freezing = true; workqueue_freezing = true;
for_each_wq_cpu(cpu) { for_each_pool(pool, id) {
struct worker_pool *pool;
struct workqueue_struct *wq; struct workqueue_struct *wq;
for_each_std_worker_pool(pool, cpu) {
spin_lock(&pool->lock); spin_lock(&pool->lock);
WARN_ON_ONCE(pool->flags & POOL_FREEZING); WARN_ON_ONCE(pool->flags & POOL_FREEZING);
pool->flags |= POOL_FREEZING; pool->flags |= POOL_FREEZING;
list_for_each_entry(wq, &workqueues, list) { list_for_each_entry(wq, &workqueues, list) {
struct pool_workqueue *pwq = get_pwq(cpu, wq); struct pool_workqueue *pwq = get_pwq(pool->cpu, wq);
if (pwq && pwq->pool == pool && if (pwq && pwq->pool == pool &&
(wq->flags & WQ_FREEZABLE)) (wq->flags & WQ_FREEZABLE))
...@@ -3613,7 +3620,6 @@ void freeze_workqueues_begin(void) ...@@ -3613,7 +3620,6 @@ void freeze_workqueues_begin(void)
spin_unlock(&pool->lock); spin_unlock(&pool->lock);
} }
}
spin_unlock_irq(&workqueue_lock); spin_unlock_irq(&workqueue_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