diff options
author | Tejun Heo <tj@kernel.org> | 2024-01-29 08:11:24 -1000 |
---|---|---|
committer | Sasha Levin <sashal@kernel.org> | 2024-03-26 18:16:25 -0400 |
commit | 70abdc2f6c906ffea699f6e0e08fcbd9437e6bcc (patch) | |
tree | c683fec9385cc7b43c08ea92c094de80636f4971 /kernel/workqueue.c | |
parent | 0c4ce23e6323e52d0590e78825cd3c63323d7a52 (diff) | |
download | linux-stable-70abdc2f6c906ffea699f6e0e08fcbd9437e6bcc.tar.gz linux-stable-70abdc2f6c906ffea699f6e0e08fcbd9437e6bcc.tar.bz2 linux-stable-70abdc2f6c906ffea699f6e0e08fcbd9437e6bcc.zip |
workqueue: Factor out pwq_is_empty()
[ Upstream commit afa87ce85379e2d93863fce595afdb5771a84004 ]
"!pwq->nr_active && list_empty(&pwq->inactive_works)" test is repeated
multiple times. Let's factor it out into pwq_is_empty().
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Lai Jiangshan <jiangshanlai@gmail.com>
Stable-dep-of: 5797b1c18919 ("workqueue: Implement system-wide nr_active enforcement for unbound workqueues")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r-- | kernel/workqueue.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 8ee754dd319d..6d0f64b5918b 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1456,6 +1456,11 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq) } } +static bool pwq_is_empty(struct pool_workqueue *pwq) +{ + return !pwq->nr_active && list_empty(&pwq->inactive_works); +} + static void pwq_activate_inactive_work(struct work_struct *work) { struct pool_workqueue *pwq = get_work_pwq(work); @@ -3325,7 +3330,7 @@ reflush: bool drained; raw_spin_lock_irq(&pwq->pool->lock); - drained = !pwq->nr_active && list_empty(&pwq->inactive_works); + drained = pwq_is_empty(pwq); raw_spin_unlock_irq(&pwq->pool->lock); if (drained) @@ -4772,7 +4777,7 @@ static bool pwq_busy(struct pool_workqueue *pwq) if ((pwq != pwq->wq->dfl_pwq) && (pwq->refcnt > 1)) return true; - if (pwq->nr_active || !list_empty(&pwq->inactive_works)) + if (!pwq_is_empty(pwq)) return true; return false; @@ -5210,7 +5215,7 @@ void show_one_workqueue(struct workqueue_struct *wq) unsigned long flags; for_each_pwq(pwq, wq) { - if (pwq->nr_active || !list_empty(&pwq->inactive_works)) { + if (!pwq_is_empty(pwq)) { idle = false; break; } @@ -5222,7 +5227,7 @@ void show_one_workqueue(struct workqueue_struct *wq) for_each_pwq(pwq, wq) { raw_spin_lock_irqsave(&pwq->pool->lock, flags); - if (pwq->nr_active || !list_empty(&pwq->inactive_works)) { + if (!pwq_is_empty(pwq)) { /* * Defer printing to avoid deadlocks in console * drivers that queue work while holding locks |