Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 365511
b: refs/heads/master
c: 699ce09
h: refs/heads/master
i:
  365509: af6e996
  365507: 9565de6
  365503: 6d2c682
v: v3
  • Loading branch information
Tejun Heo committed Mar 13, 2013
1 parent 320c2e7 commit f519f4b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 46 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0fbd95aa8a056194933fba4ae78c50fc20f0704e
refs/heads/master: 699ce097efe8f45bc5c055e4f12cb1e271c270d9
83 changes: 38 additions & 45 deletions trunk/kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -3726,23 +3726,38 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
}

/**
* pwq_set_max_active - adjust max_active of a pwq
* pwq_adjust_max_active - update a pwq's max_active to the current setting
* @pwq: target pool_workqueue
* @max_active: new max_active value.
*
* Set @pwq->max_active to @max_active and activate delayed works if
* increased.
*
* CONTEXT:
* spin_lock_irq(pool->lock).
* If @pwq isn't freezing, set @pwq->max_active to the associated
* workqueue's saved_max_active and activate delayed work items
* accordingly. If @pwq is freezing, clear @pwq->max_active to zero.
*/
static void pwq_set_max_active(struct pool_workqueue *pwq, int max_active)
static void pwq_adjust_max_active(struct pool_workqueue *pwq)
{
pwq->max_active = max_active;
struct workqueue_struct *wq = pwq->wq;
bool freezable = wq->flags & WQ_FREEZABLE;

/* for @wq->saved_max_active */
lockdep_assert_held(&workqueue_lock);

/* fast exit for non-freezable wqs */
if (!freezable && pwq->max_active == wq->saved_max_active)
return;

spin_lock(&pwq->pool->lock);

if (!freezable || !(pwq->pool->flags & POOL_FREEZING)) {
pwq->max_active = wq->saved_max_active;

while (!list_empty(&pwq->delayed_works) &&
pwq->nr_active < pwq->max_active)
pwq_activate_first_delayed(pwq);
while (!list_empty(&pwq->delayed_works) &&
pwq->nr_active < pwq->max_active)
pwq_activate_first_delayed(pwq);
} else {
pwq->max_active = 0;
}

spin_unlock(&pwq->pool->lock);
}

static void init_and_link_pwq(struct pool_workqueue *pwq,
Expand Down Expand Up @@ -3932,15 +3947,14 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt,
goto err_destroy;

/*
* workqueue_lock protects global freeze state and workqueues
* list. Grab it, set max_active accordingly and add the new
* workqueue to workqueues list.
* workqueue_lock protects global freeze state and workqueues list.
* Grab it, adjust max_active and add the new workqueue to
* workqueues list.
*/
spin_lock_irq(&workqueue_lock);

if (workqueue_freezing && wq->flags & WQ_FREEZABLE)
for_each_pwq(pwq, wq)
pwq->max_active = 0;
for_each_pwq(pwq, wq)
pwq_adjust_max_active(pwq);

list_add(&wq->list, &workqueues);

Expand Down Expand Up @@ -4055,17 +4069,8 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)

wq->saved_max_active = max_active;

for_each_pwq(pwq, wq) {
struct worker_pool *pool = pwq->pool;

spin_lock(&pool->lock);

if (!(wq->flags & WQ_FREEZABLE) ||
!(pool->flags & POOL_FREEZING))
pwq_set_max_active(pwq, max_active);

spin_unlock(&pool->lock);
}
for_each_pwq(pwq, wq)
pwq_adjust_max_active(pwq);

spin_unlock_irq(&workqueue_lock);
}
Expand Down Expand Up @@ -4358,14 +4363,8 @@ void freeze_workqueues_begin(void)

/* suppress further executions by setting max_active to zero */
list_for_each_entry(wq, &workqueues, list) {
if (!(wq->flags & WQ_FREEZABLE))
continue;

for_each_pwq(pwq, wq) {
spin_lock(&pwq->pool->lock);
pwq->max_active = 0;
spin_unlock(&pwq->pool->lock);
}
for_each_pwq(pwq, wq)
pwq_adjust_max_active(pwq);
}

spin_unlock_irq(&workqueue_lock);
Expand Down Expand Up @@ -4445,14 +4444,8 @@ void thaw_workqueues(void)

/* restore max_active and repopulate worklist */
list_for_each_entry(wq, &workqueues, list) {
if (!(wq->flags & WQ_FREEZABLE))
continue;

for_each_pwq(pwq, wq) {
spin_lock(&pwq->pool->lock);
pwq_set_max_active(pwq, wq->saved_max_active);
spin_unlock(&pwq->pool->lock);
}
for_each_pwq(pwq, wq)
pwq_adjust_max_active(pwq);
}

/* kick workers */
Expand Down

0 comments on commit f519f4b

Please sign in to comment.