History

workqueue: rename wq_mutex to wq_pool_mutex

wq->flush_mutex will be renamed to wq->mutex and cover all fields specific to each workqueue and eventually replace pwq_lock, which will make locking simpler and easier to understand. Rename wq_mutex to wq_pool_mutex to avoid confusion with wq->mutex. After the scheduled changes, wq_pool_mutex won't be protecting anything specific to each workqueue instance anyway. This patch is pure rename. tj: s/wqs_mutex/wq_pool_mutex/. Rewrote description.

Lai Jiangshan committed 13 years ago

Commit 68e13a61 parent 519e3c11 file · +55 −54Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+55−54
@@ -123,9 +123,9 @@ enum { · 122 unmodified lines
123123 * MG: pool->manager_mutex and pool->lock protected. Writes require both
124124 * locks. Reads can happen under either lock.
125125 *
126− * WQ: wq_mutex protected.
126+ * PL: wq_pool_mutex protected.
127127 *
128− * WR: wq_mutex protected for writes. Sched-RCU protected for reads.
128+ * PR: wq_pool_mutex protected for writes. Sched-RCU protected for reads.
129129 *
130130 * PW: pwq_lock protected.
131131 *
@@ -163,8 +163,8 @@ struct worker_pool { · 31 unmodified lines
163163 struct idr worker_idr; /* MG: worker IDs and iteration */
164164
165165 struct workqueue_attrs *attrs; /* I: worker attributes */
166− struct hlist_node hash_node; /* WQ: unbound_pool_hash node */
167− int refcnt; /* WQ: refcnt for unbound pools */
166+ struct hlist_node hash_node; /* PL: unbound_pool_hash node */
167+ int refcnt; /* PL: refcnt for unbound pools */
168168
169169 /*
170170 * The current concurrency level. As it's likely to be accessed
@@ -226,10 +226,10 @@ struct wq_device; · 55 unmodified lines
226226 * the appropriate worker_pool through its pool_workqueues.
227227 */
228228 struct workqueue_struct {
229− unsigned int flags; /* WQ: WQ_* flags */
229+ unsigned int flags; /* PL: WQ_* flags */
230230 struct pool_workqueue __percpu *cpu_pwqs; /* I: per-cpu pwq's */
231231 struct list_head pwqs; /* FR: all pwqs of this wq */
232− struct list_head list; /* WQ: list of all workqueues */
232+ struct list_head list; /* PL: list of all workqueues */
233233
234234 struct mutex flush_mutex; /* protects wq flushing */
235235 int work_color; /* F: current work color */
@@ -242,7 +242,7 @@ struct workqueue_struct { · 6 unmodified lines
242242 struct list_head maydays; /* MD: pwqs requesting rescue */
243243 struct worker *rescuer; /* I: rescue worker */
244244
245− int nr_drainers; /* WQ: drain in progress */
245+ int nr_drainers; /* PL: drain in progress */
246246 int saved_max_active; /* PW: saved pwq max_active */
247247
248248 #ifdef CONFIG_SYSFS
@@ -256,20 +256,20 @@ struct workqueue_struct { · 7 unmodified lines
256256
257257 static struct kmem_cache *pwq_cache;
258258
259−static DEFINE_MUTEX(wq_mutex); /* protects workqueues and pools */
259+static DEFINE_MUTEX(wq_pool_mutex); /* protects pools and workqueues list */
260260 static DEFINE_SPINLOCK(pwq_lock); /* protects pool_workqueues */
261261 static DEFINE_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */
262262
263−static LIST_HEAD(workqueues); /* WQ: list of all workqueues */
264−static bool workqueue_freezing; /* WQ: have wqs started freezing? */
263+static LIST_HEAD(workqueues); /* PL: list of all workqueues */
264+static bool workqueue_freezing; /* PL: have wqs started freezing? */
265265
266266 /* the per-cpu worker pools */
267267 static DEFINE_PER_CPU_SHARED_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS],
268268 cpu_worker_pools);
269269
270−static DEFINE_IDR(worker_pool_idr); /* WR: idr of all pools */
270+static DEFINE_IDR(worker_pool_idr); /* PR: idr of all pools */
271271
272−/* WQ: hash of all unbound pools keyed by pool->attrs */
272+/* PL: hash of all unbound pools keyed by pool->attrs */
273273 static DEFINE_HASHTABLE(unbound_pool_hash, UNBOUND_POOL_HASH_ORDER);
274274
275275 /* I: attributes used when instantiating standard unbound pools on demand */
@@ -293,10 +293,10 @@ static void copy_workqueue_attrs(struct workqueue_attrs *to, · 17 unmodified lines
293293 #define CREATE_TRACE_POINTS
294294 #include <trace/events/workqueue.h>
295295
296−#define assert_rcu_or_wq_mutex() \
296+#define assert_rcu_or_pool_mutex() \
297297 rcu_lockdep_assert(rcu_read_lock_sched_held() || \
298− lockdep_is_held(&wq_mutex), \
299− "sched RCU or wq_mutex should be held")
298+ lockdep_is_held(&wq_pool_mutex), \
299+ "sched RCU or wq_pool_mutex should be held")
300300
301301 #define assert_rcu_or_pwq_lock() \
302302 rcu_lockdep_assert(rcu_read_lock_sched_held() || \
@@ -323,16 +323,16 @@ static void copy_workqueue_attrs(struct workqueue_attrs *to, · 20 unmodified lines
323323 * @pool: iteration cursor
324324 * @pi: integer used for iteration
325325 *
326− * This must be called either with wq_mutex held or sched RCU read locked.
327− * If the pool needs to be used beyond the locking in effect, the caller is
328− * responsible for guaranteeing that the pool stays online.
326+ * This must be called either with wq_pool_mutex held or sched RCU read
327+ * locked. If the pool needs to be used beyond the locking in effect, the
328+ * caller is responsible for guaranteeing that the pool stays online.
329329 *
330330 * The if/else clause exists only for the lockdep assertion and can be
331331 * ignored.
332332 */
333333 #define for_each_pool(pool, pi) \
334334 idr_for_each_entry(&worker_pool_idr, pool, pi) \
335− if (({ assert_rcu_or_wq_mutex(); false; })) { } \
335+ if (({ assert_rcu_or_pool_mutex(); false; })) { } \
336336 else
337337
338338 /**
@@ -489,7 +489,7 @@ static int worker_pool_assign_id(struct worker_pool *pool) · 150 unmodified lines
489489 {
490490 int ret;
491491
492− lockdep_assert_held(&wq_mutex);
492+ lockdep_assert_held(&wq_pool_mutex);
493493
494494 do {
495495 if (!idr_pre_get(&worker_pool_idr, GFP_KERNEL))
@@ -607,9 +607,9 @@ static struct pool_workqueue *get_work_pwq(struct work_struct *work) · 111 unmodified lines
607607 *
608608 * Return the worker_pool @work was last associated with. %NULL if none.
609609 *
610− * Pools are created and destroyed under wq_mutex, and allows read access
611− * under sched-RCU read lock. As such, this function should be called
612− * under wq_mutex or with preemption disabled.
610+ * Pools are created and destroyed under wq_pool_mutex, and allows read
611+ * access under sched-RCU read lock. As such, this function should be
612+ * called under wq_pool_mutex or with preemption disabled.
613613 *
614614 * All fields of the returned pool are accessible as long as the above
615615 * mentioned locking is in effect. If the returned pool needs to be used
@@ -621,7 +621,7 @@ static struct worker_pool *get_work_pool(struct work_struct *work) · 5 unmodified lines
621621 unsigned long data = atomic_long_read(&work->data);
622622 int pool_id;
623623
624− assert_rcu_or_wq_mutex();
624+ assert_rcu_or_pool_mutex();
625625
626626 if (data & WORK_STRUCT_PWQ)
627627 return ((struct pool_workqueue *)
@@ -2684,10 +2684,10 @@ void drain_workqueue(struct workqueue_struct *wq) · 2056 unmodified lines
26842684 * hotter than drain_workqueue() and already looks at @wq->flags.
26852685 * Use __WQ_DRAINING so that queue doesn't have to check nr_drainers.
26862686 */
2687− mutex_lock(&wq_mutex);
2687+ mutex_lock(&wq_pool_mutex);
26882688 if (!wq->nr_drainers++)
26892689 wq->flags |= __WQ_DRAINING;
2690− mutex_unlock(&wq_mutex);
2690+ mutex_unlock(&wq_pool_mutex);
26912691 reflush:
26922692 flush_workqueue(wq);
26932693
@@ -2714,10 +2714,10 @@ reflush: · 20 unmodified lines
27142714
27152715 local_irq_enable();
27162716
2717− mutex_lock(&wq_mutex);
2717+ mutex_lock(&wq_pool_mutex);
27182718 if (!--wq->nr_drainers)
27192719 wq->flags &= ~__WQ_DRAINING;
2720− mutex_unlock(&wq_mutex);
2720+ mutex_unlock(&wq_pool_mutex);
27212721 }
27222722 EXPORT_SYMBOL_GPL(drain_workqueue);
27232723
@@ -3430,16 +3430,16 @@ static void put_unbound_pool(struct worker_pool *pool) · 706 unmodified lines
34303430 {
34313431 struct worker *worker;
34323432
3433− mutex_lock(&wq_mutex);
3433+ mutex_lock(&wq_pool_mutex);
34343434 if (--pool->refcnt) {
3435− mutex_unlock(&wq_mutex);
3435+ mutex_unlock(&wq_pool_mutex);
34363436 return;
34373437 }
34383438
34393439 /* sanity checks */
34403440 if (WARN_ON(!(pool->flags & POOL_DISASSOCIATED)) ||
34413441 WARN_ON(!list_empty(&pool->worklist))) {
3442− mutex_unlock(&wq_mutex);
3442+ mutex_unlock(&wq_pool_mutex);
34433443 return;
34443444 }
34453445
@@ -3448,7 +3448,7 @@ static void put_unbound_pool(struct worker_pool *pool) · 2 unmodified lines
34483448 idr_remove(&worker_pool_idr, pool->id);
34493449 hash_del(&pool->hash_node);
34503450
3451− mutex_unlock(&wq_mutex);
3451+ mutex_unlock(&wq_pool_mutex);
34523452
34533453 /*
34543454 * Become the manager and destroy all workers. Grabbing
@@ -3489,7 +3489,7 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 34 unmodified lines
34893489 u32 hash = wqattrs_hash(attrs);
34903490 struct worker_pool *pool;
34913491
3492− mutex_lock(&wq_mutex);
3492+ mutex_lock(&wq_pool_mutex);
34933493
34943494 /* do we already have a matching pool? */
34953495 hash_for_each_possible(unbound_pool_hash, pool, hash_node, hash) {
@@ -3520,10 +3520,10 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 24 unmodified lines
35203520 /* install */
35213521 hash_add(unbound_pool_hash, &pool->hash_node, hash);
35223522 out_unlock:
3523− mutex_unlock(&wq_mutex);
3523+ mutex_unlock(&wq_pool_mutex);
35243524 return pool;
35253525 fail:
3526− mutex_unlock(&wq_mutex);
3526+ mutex_unlock(&wq_pool_mutex);
35273527 if (pool)
35283528 put_unbound_pool(pool);
35293529 return NULL;
@@ -3803,10 +3803,11 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt, · 273 unmodified lines
38033803 goto err_destroy;
38043804
38053805 /*
3806− * wq_mutex protects global freeze state and workqueues list. Grab
3807− * it, adjust max_active and add the new @wq to workqueues list.
3806+ * wq_pool_mutex protects global freeze state and workqueues list.
3807+ * Grab it, adjust max_active and add the new @wq to workqueues
3808+ * list.
38083809 */
3809− mutex_lock(&wq_mutex);
3810+ mutex_lock(&wq_pool_mutex);
38103811
38113812 spin_lock_irq(&pwq_lock);
38123813 for_each_pwq(pwq, wq)
@@ -3815,7 +3816,7 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt, · 2 unmodified lines
38153816
38163817 list_add(&wq->list, &workqueues);
38173818
3818− mutex_unlock(&wq_mutex);
3819+ mutex_unlock(&wq_pool_mutex);
38193820
38203821 return wq;
38213822
@@ -3866,9 +3867,9 @@ void destroy_workqueue(struct workqueue_struct *wq) · 44 unmodified lines
38663867 * wq list is used to freeze wq, remove from list after
38673868 * flushing is complete in case freeze races us.
38683869 */
3869− mutex_lock(&wq_mutex);
3870+ mutex_lock(&wq_pool_mutex);
38703871 list_del_init(&wq->list);
3871− mutex_unlock(&wq_mutex);
3872+ mutex_unlock(&wq_pool_mutex);
38723873
38733874 workqueue_sysfs_unregister(wq);
38743875
@@ -4198,7 +4199,7 @@ static int __cpuinit workqueue_cpu_up_callback(struct notifier_block *nfb, · 323 unmodified lines
41984199
41994200 case CPU_DOWN_FAILED:
42004201 case CPU_ONLINE:
4201− mutex_lock(&wq_mutex);
4202+ mutex_lock(&wq_pool_mutex);
42024203
42034204 for_each_pool(pool, pi) {
42044205 mutex_lock(&pool->manager_mutex);
@@ -4216,7 +4217,7 @@ static int __cpuinit workqueue_cpu_up_callback(struct notifier_block *nfb, · 11 unmodified lines
42164217 mutex_unlock(&pool->manager_mutex);
42174218 }
42184219
4219− mutex_unlock(&wq_mutex);
4220+ mutex_unlock(&wq_pool_mutex);
42204221 break;
42214222 }
42224223 return NOTIFY_OK;
@@ -4292,7 +4293,7 @@ EXPORT_SYMBOL_GPL(work_on_cpu); · 69 unmodified lines
42924293 * pool->worklist.
42934294 *
42944295 * CONTEXT:
4295− * Grabs and releases wq_mutex, pwq_lock and pool->lock's.
4296+ * Grabs and releases wq_pool_mutex, pwq_lock and pool->lock's.
42964297 */
42974298 void freeze_workqueues_begin(void)
42984299 {
@@ -4301,7 +4302,7 @@ void freeze_workqueues_begin(void) · 2 unmodified lines
43014302 struct pool_workqueue *pwq;
43024303 int pi;
43034304
4304− mutex_lock(&wq_mutex);
4305+ mutex_lock(&wq_pool_mutex);
43054306
43064307 WARN_ON_ONCE(workqueue_freezing);
43074308 workqueue_freezing = true;
@@ -4322,7 +4323,7 @@ void freeze_workqueues_begin(void) · 14 unmodified lines
43224323 }
43234324 spin_unlock_irq(&pwq_lock);
43244325
4325− mutex_unlock(&wq_mutex);
4326+ mutex_unlock(&wq_pool_mutex);
43264327 }
43274328
43284329 /**
@@ -4332,7 +4333,7 @@ void freeze_workqueues_begin(void) · 3 unmodified lines
43324333 * between freeze_workqueues_begin() and thaw_workqueues().
43334334 *
43344335 * CONTEXT:
4335− * Grabs and releases wq_mutex.
4336+ * Grabs and releases wq_pool_mutex.
43364337 *
43374338 * RETURNS:
43384339 * %true if some freezable workqueues are still busy. %false if freezing
@@ -4344,7 +4345,7 @@ bool freeze_workqueues_busy(void) · 5 unmodified lines
43444345 struct workqueue_struct *wq;
43454346 struct pool_workqueue *pwq;
43464347
4347− mutex_lock(&wq_mutex);
4348+ mutex_lock(&wq_pool_mutex);
43484349
43494350 WARN_ON_ONCE(!workqueue_freezing);
43504351
@@ -4367,7 +4368,7 @@ bool freeze_workqueues_busy(void) · 16 unmodified lines
43674368 rcu_read_unlock_sched();
43684369 }
43694370 out_unlock:
4370− mutex_unlock(&wq_mutex);
4371+ mutex_unlock(&wq_pool_mutex);
43714372 return busy;
43724373 }
43734374
@@ -4378,7 +4379,7 @@ out_unlock: · 4 unmodified lines
43784379 * frozen works are transferred to their respective pool worklists.
43794380 *
43804381 * CONTEXT:
4381− * Grabs and releases wq_mutex, pwq_lock and pool->lock's.
4382+ * Grabs and releases wq_pool_mutex, pwq_lock and pool->lock's.
43824383 */
43834384 void thaw_workqueues(void)
43844385 {
@@ -4387,7 +4388,7 @@ void thaw_workqueues(void) · 2 unmodified lines
43874388 struct worker_pool *pool;
43884389 int pi;
43894390
4390− mutex_lock(&wq_mutex);
4391+ mutex_lock(&wq_pool_mutex);
43914392
43924393 if (!workqueue_freezing)
43934394 goto out_unlock;
@@ -4410,7 +4411,7 @@ void thaw_workqueues(void) · 16 unmodified lines
44104411
44114412 workqueue_freezing = false;
44124413 out_unlock:
4413− mutex_unlock(&wq_mutex);
4414+ mutex_unlock(&wq_pool_mutex);
44144415 }
44154416 #endif /* CONFIG_FREEZER */
44164417
@@ -4442,9 +4443,9 @@ static int __init init_workqueues(void) · 25 unmodified lines
44424443 pool->attrs->nice = std_nice[i++];
44434444
44444445 /* alloc pool ID */
4445− mutex_lock(&wq_mutex);
4446+ mutex_lock(&wq_pool_mutex);
44464447 BUG_ON(worker_pool_assign_id(pool));
4447− mutex_unlock(&wq_mutex);
4448+ mutex_unlock(&wq_pool_mutex);
44484449 }
44494450 }
44504451