History

workqueue: make GCWQ_FREEZING a pool flag

Make GCWQ_FREEZING a pool flag POOL_FREEZING. This patch doesn't change locking - FREEZING on both pools of a CPU are set or clear together while holding gcwq->lock. It shouldn't cause any functional difference. This leaves gcwq->flags w/o any flags. Removed. While at it, convert BUG_ON()s in freeze_workqueue_begin() and thaw_workqueues() to WARN_ON_ONCE(). This is part of an effort to remove global_cwq and make worker_pool the top level abstraction, which in turn will help implementing worker pools with user-specified attributes.

Tejun Heo committed 13 years ago

Commit 35b6bb61 parent 24647571 file · +15 −13Browse files

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

Unified · Split

kernel/workqueue.c+15−13
@@ -46,11 +46,6 @@ · 45 unmodified lines
4646 #include "workqueue_internal.h"
4747
4848 enum {
49− /*
50− * global_cwq flags
51− */
52− GCWQ_FREEZING = 1 << 1, /* freeze in progress */
53−
5449 /*
5550 * worker_pool flags
5651 *
@@ -70,6 +65,7 @@ enum { · 13 unmodified lines
7065 POOL_MANAGE_WORKERS = 1 << 0, /* need to manage workers */
7166 POOL_MANAGING_WORKERS = 1 << 1, /* managing workers */
7267 POOL_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */
68+ POOL_FREEZING = 1 << 3, /* freeze in progress */
7369
7470 /* worker flags */
7571 WORKER_STARTED = 1 << 0, /* started */
@@ -152,7 +148,6 @@ struct worker_pool { · 76 unmodified lines
152148 struct global_cwq {
153149 spinlock_t lock; /* the gcwq lock */
154150 unsigned int cpu; /* I: the associated cpu */
155− unsigned int flags; /* L: GCWQ_* flags */
156151
157152 /* workers are chained either in busy_hash or pool idle_list */
158153 DECLARE_HASHTABLE(busy_hash, BUSY_WORKER_HASH_ORDER);
@@ -3380,13 +3375,15 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active) · 3221 unmodified lines
33803375 wq->saved_max_active = max_active;
33813376
33823377 for_each_cwq_cpu(cpu, wq) {
3383− struct global_cwq *gcwq = get_gcwq(cpu);
3378+ struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3379+ struct worker_pool *pool = cwq->pool;
3380+ struct global_cwq *gcwq = pool->gcwq;
33843381
33853382 spin_lock_irq(&gcwq->lock);
33863383
33873384 if (!(wq->flags & WQ_FREEZABLE) ||
3388− !(gcwq->flags & GCWQ_FREEZING))
3389− cwq_set_max_active(get_cwq(gcwq->cpu, wq), max_active);
3385+ !(pool->flags & POOL_FREEZING))
3386+ cwq_set_max_active(cwq, max_active);
33903387
33913388 spin_unlock_irq(&gcwq->lock);
33923389 }
@@ -3676,12 +3673,15 @@ void freeze_workqueues_begin(void) · 283 unmodified lines
36763673
36773674 for_each_gcwq_cpu(cpu) {
36783675 struct global_cwq *gcwq = get_gcwq(cpu);
3676+ struct worker_pool *pool;
36793677 struct workqueue_struct *wq;
36803678
36813679 spin_lock_irq(&gcwq->lock);
36823680
3683− BUG_ON(gcwq->flags & GCWQ_FREEZING);
3684− gcwq->flags |= GCWQ_FREEZING;
3681+ for_each_worker_pool(pool, gcwq) {
3682+ WARN_ON_ONCE(pool->flags & POOL_FREEZING);
3683+ pool->flags |= POOL_FREEZING;
3684+ }
36853685
36863686 list_for_each_entry(wq, &workqueues, list) {
36873687 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
@@ -3767,8 +3767,10 @@ void thaw_workqueues(void) · 79 unmodified lines
37673767
37683768 spin_lock_irq(&gcwq->lock);
37693769
3770− BUG_ON(!(gcwq->flags & GCWQ_FREEZING));
3771− gcwq->flags &= ~GCWQ_FREEZING;
3770+ for_each_worker_pool(pool, gcwq) {
3771+ WARN_ON_ONCE(!(pool->flags & POOL_FREEZING));
3772+ pool->flags &= ~POOL_FREEZING;
3773+ }
37723774
37733775 list_for_each_entry(wq, &workqueues, list) {
37743776 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);