workqueue: convert worker_pool->worker_ida to idr and implement for_each_pool_worker()
authorTejun Heo <tj@kernel.org>
Tue, 19 Mar 2013 20:45:21 +0000 (13:45 -0700)
committerTejun Heo <tj@kernel.org>
Tue, 19 Mar 2013 20:45:21 +0000 (13:45 -0700)
commit822d8405d13931062d653e0c2cc0199ed801b072
tree388738869c771c58d20bc24d25729fabc0aab171
parent14a40ffccd6163bbcd1d6f32b28a88ffe6149fc6
workqueue: convert worker_pool->worker_ida to idr and implement for_each_pool_worker()

Make worker_ida an idr - worker_idr and use it to implement
for_each_pool_worker() which will be used to simplify worker rebinding
on CPU_ONLINE.

pool->worker_idr is protected by both pool->manager_mutex and
pool->lock so that it can be iterated while holding either lock.

* create_worker() allocates ID without installing worker pointer and
  installs the pointer later using idr_replace().  This is because
  worker ID is needed when creating the actual task to name it and the
  new worker shouldn't be visible to iterations before fully
  initialized.

* In destroy_worker(), ID removal is moved before kthread_stop().
  This is again to guarantee that only fully working workers are
  visible to for_each_pool_worker().

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>
kernel/workqueue.c