/* see manage_workers() for details on the two manager mutexes */
struct mutex manager_arb; /* manager arbitration */
struct mutex manager_mutex; /* manager exclusion */
- struct idr worker_idr; /* M: worker IDs and iteration */
+ struct idr worker_idr; /* M: worker IDs */
+ struct list_head workers; /* M: attached workers */
struct completion *detach_completion; /* all workers detached */
struct workqueue_attrs *attrs; /* I: worker attributes */
/**
* for_each_pool_worker - iterate through all workers of a worker_pool
* @worker: iteration cursor
- * @wi: integer used for iteration
* @pool: worker_pool to iterate workers of
*
* This must be called with @pool->manager_mutex.
* The if/else clause exists only for the lockdep assertion and can be
* ignored.
*/
-#define for_each_pool_worker(worker, wi, pool) \
- idr_for_each_entry(&(pool)->worker_idr, (worker), (wi)) \
+#define for_each_pool_worker(worker, pool) \
+ list_for_each_entry((worker), &(pool)->workers, node) \
if (({ lockdep_assert_held(&pool->manager_mutex); false; })) { } \
else
if (worker) {
INIT_LIST_HEAD(&worker->entry);
INIT_LIST_HEAD(&worker->scheduled);
+ INIT_LIST_HEAD(&worker->node);
/* on creation a worker is in !idle && prep state */
worker->flags = WORKER_PREP;
}
mutex_lock(&pool->manager_mutex);
idr_remove(&pool->worker_idr, worker->id);
- if (idr_is_empty(&pool->worker_idr))
+ list_del(&worker->node);
+ if (list_empty(&pool->workers))
detach_completion = pool->detach_completion;
mutex_unlock(&pool->manager_mutex);
/* successful, commit the pointer to idr */
idr_replace(&pool->worker_idr, worker, worker->id);
+ /* successful, attach the worker to the pool */
+ list_add_tail(&worker->node, &pool->workers);
return worker;
mutex_init(&pool->manager_arb);
mutex_init(&pool->manager_mutex);
idr_init(&pool->worker_idr);
+ INIT_LIST_HEAD(&pool->workers);
INIT_HLIST_NODE(&pool->hash_node);
pool->refcnt = 1;
spin_unlock_irq(&pool->lock);
mutex_lock(&pool->manager_mutex);
- if (!idr_is_empty(&pool->worker_idr))
+ if (!list_empty(&pool->workers))
pool->detach_completion = &detach_completion;
mutex_unlock(&pool->manager_mutex);
int cpu = smp_processor_id();
struct worker_pool *pool;
struct worker *worker;
- int wi;
for_each_cpu_worker_pool(pool, cpu) {
WARN_ON_ONCE(cpu != smp_processor_id());
* before the last CPU down must be on the cpu. After
* this, they may become diasporas.
*/
- for_each_pool_worker(worker, wi, pool)
+ for_each_pool_worker(worker, pool)
worker->flags |= WORKER_UNBOUND;
pool->flags |= POOL_DISASSOCIATED;
static void rebind_workers(struct worker_pool *pool)
{
struct worker *worker;
- int wi;
lockdep_assert_held(&pool->manager_mutex);
* of all workers first and then clear UNBOUND. As we're called
* from CPU_ONLINE, the following shouldn't fail.
*/
- for_each_pool_worker(worker, wi, pool)
+ for_each_pool_worker(worker, pool)
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
pool->attrs->cpumask) < 0);
spin_lock_irq(&pool->lock);
- for_each_pool_worker(worker, wi, pool) {
+ for_each_pool_worker(worker, pool) {
unsigned int worker_flags = worker->flags;
/*
{
static cpumask_t cpumask;
struct worker *worker;
- int wi;
lockdep_assert_held(&pool->manager_mutex);
return;
/* as we're called from CPU_ONLINE, the following shouldn't fail */
- for_each_pool_worker(worker, wi, pool)
+ for_each_pool_worker(worker, pool)
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
pool->attrs->cpumask) < 0);
}