Re: [PATCH 03/24] workqueue: Not all work insertion needs to wake up a worker

From: Lai Jiangshan
Date: Tue May 23 2023 - 05:55:22 EST


On Fri, May 19, 2023 at 8:17 AM Tejun Heo <tj@xxxxxxxxxx> wrote:

> + pool = pwq->pool;
> +
> /*
> * If @work was previously on a different pool, it might still be
> * running there, in which case the work needs to be queued on that
> * pool to guarantee non-reentrancy.
> */
> last_pool = get_work_pool(work);
> - if (last_pool && last_pool != pwq->pool) {
> + if (last_pool && last_pool != pool) {
> struct worker *worker;
>
> raw_spin_lock(&last_pool->lock);
> @@ -1638,13 +1636,14 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
>
> if (worker && worker->current_pwq->wq == wq) {
> pwq = worker->current_pwq;
> + pool = pwq->pool;

The code above does a "raw_spin_lock(&last_pool->lock);", and
the code next does a "raw_spin_unlock(&pool->lock);".

WARN_ON_ONCE(pool != last_pool);

can be added here and served as a comment.

> } else {
> /* meh... not running there, queue here */
> raw_spin_unlock(&last_pool->lock);
> - raw_spin_lock(&pwq->pool->lock);
> + raw_spin_lock(&pool->lock);
> }
> } else {
> - raw_spin_lock(&pwq->pool->lock);
> + raw_spin_lock(&pool->lock);
> }
>