mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-21 06:01:23 +00:00
workqueue: remove the confusing POOL_FREEZING
Currently, the global freezing state is propagated to worker_pools via POOL_FREEZING and then to each workqueue; however, the middle step - propagation through worker_pools - can be skipped as long as one or more max_active adjustments happens for each workqueue after the update to the global state is visible. The global workqueue freezing state and the max_active adjustments during workqueue creation and [un]freezing are serialized with wq_pool_mutex, so it's trivial to guarantee that max_actives stay in sync with global freezing state. POOL_FREEZING is unnecessary and makes the code more confusing and complicates freeze_workqueues_begin() and thaw_workqueues() by requiring them to walk through all pools. Remove POOL_FREEZING and use workqueue_freezing directly instead. tj: Description and comment updates. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
parent
1037de36ed
commit
74b414ead1
1 changed files with 7 additions and 25 deletions
|
@ -69,7 +69,6 @@ enum {
|
||||||
* worker_attach_to_pool() is in progress.
|
* worker_attach_to_pool() is in progress.
|
||||||
*/
|
*/
|
||||||
POOL_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */
|
POOL_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */
|
||||||
POOL_FREEZING = 1 << 3, /* freeze in progress */
|
|
||||||
|
|
||||||
/* worker flags */
|
/* worker flags */
|
||||||
WORKER_DIE = 1 << 1, /* die die die */
|
WORKER_DIE = 1 << 1, /* die die die */
|
||||||
|
@ -3533,9 +3532,6 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs)
|
||||||
if (!pool || init_worker_pool(pool) < 0)
|
if (!pool || init_worker_pool(pool) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (workqueue_freezing)
|
|
||||||
pool->flags |= POOL_FREEZING;
|
|
||||||
|
|
||||||
lockdep_set_subclass(&pool->lock, 1); /* see put_pwq() */
|
lockdep_set_subclass(&pool->lock, 1); /* see put_pwq() */
|
||||||
copy_workqueue_attrs(pool->attrs, attrs);
|
copy_workqueue_attrs(pool->attrs, attrs);
|
||||||
|
|
||||||
|
@ -3642,7 +3638,12 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)
|
||||||
|
|
||||||
spin_lock_irq(&pwq->pool->lock);
|
spin_lock_irq(&pwq->pool->lock);
|
||||||
|
|
||||||
if (!freezable || !(pwq->pool->flags & POOL_FREEZING)) {
|
/*
|
||||||
|
* During [un]freezing, the caller is responsible for ensuring that
|
||||||
|
* this function is called at least once after @workqueue_freezing
|
||||||
|
* is updated and visible.
|
||||||
|
*/
|
||||||
|
if (!freezable || !workqueue_freezing) {
|
||||||
pwq->max_active = wq->saved_max_active;
|
pwq->max_active = wq->saved_max_active;
|
||||||
|
|
||||||
while (!list_empty(&pwq->delayed_works) &&
|
while (!list_empty(&pwq->delayed_works) &&
|
||||||
|
@ -4751,24 +4752,14 @@ EXPORT_SYMBOL_GPL(work_on_cpu);
|
||||||
*/
|
*/
|
||||||
void freeze_workqueues_begin(void)
|
void freeze_workqueues_begin(void)
|
||||||
{
|
{
|
||||||
struct worker_pool *pool;
|
|
||||||
struct workqueue_struct *wq;
|
struct workqueue_struct *wq;
|
||||||
struct pool_workqueue *pwq;
|
struct pool_workqueue *pwq;
|
||||||
int pi;
|
|
||||||
|
|
||||||
mutex_lock(&wq_pool_mutex);
|
mutex_lock(&wq_pool_mutex);
|
||||||
|
|
||||||
WARN_ON_ONCE(workqueue_freezing);
|
WARN_ON_ONCE(workqueue_freezing);
|
||||||
workqueue_freezing = true;
|
workqueue_freezing = true;
|
||||||
|
|
||||||
/* set FREEZING */
|
|
||||||
for_each_pool(pool, pi) {
|
|
||||||
spin_lock_irq(&pool->lock);
|
|
||||||
WARN_ON_ONCE(pool->flags & POOL_FREEZING);
|
|
||||||
pool->flags |= POOL_FREEZING;
|
|
||||||
spin_unlock_irq(&pool->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
list_for_each_entry(wq, &workqueues, list) {
|
list_for_each_entry(wq, &workqueues, list) {
|
||||||
mutex_lock(&wq->mutex);
|
mutex_lock(&wq->mutex);
|
||||||
for_each_pwq(pwq, wq)
|
for_each_pwq(pwq, wq)
|
||||||
|
@ -4838,21 +4829,13 @@ void thaw_workqueues(void)
|
||||||
{
|
{
|
||||||
struct workqueue_struct *wq;
|
struct workqueue_struct *wq;
|
||||||
struct pool_workqueue *pwq;
|
struct pool_workqueue *pwq;
|
||||||
struct worker_pool *pool;
|
|
||||||
int pi;
|
|
||||||
|
|
||||||
mutex_lock(&wq_pool_mutex);
|
mutex_lock(&wq_pool_mutex);
|
||||||
|
|
||||||
if (!workqueue_freezing)
|
if (!workqueue_freezing)
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
/* clear FREEZING */
|
workqueue_freezing = false;
|
||||||
for_each_pool(pool, pi) {
|
|
||||||
spin_lock_irq(&pool->lock);
|
|
||||||
WARN_ON_ONCE(!(pool->flags & POOL_FREEZING));
|
|
||||||
pool->flags &= ~POOL_FREEZING;
|
|
||||||
spin_unlock_irq(&pool->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* restore max_active and repopulate worklist */
|
/* restore max_active and repopulate worklist */
|
||||||
list_for_each_entry(wq, &workqueues, list) {
|
list_for_each_entry(wq, &workqueues, list) {
|
||||||
|
@ -4862,7 +4845,6 @@ void thaw_workqueues(void)
|
||||||
mutex_unlock(&wq->mutex);
|
mutex_unlock(&wq->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
workqueue_freezing = false;
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&wq_pool_mutex);
|
mutex_unlock(&wq_pool_mutex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue