Re: [PATCH wq/for-6.9 v5 2/4] workqueue: Enable unbound cpumask update on ordered workqueues

From: Tejun Heo
Date: Thu Feb 08 2024 - 12:42:39 EST


Hello,

Generally looks good to me. Minor nits below:

On Thu, Feb 08, 2024 at 11:10:12AM -0500, Waiman Long wrote:
> +static void unplug_oldest_pwq(struct workqueue_struct *wq)
> +{
> + struct pool_workqueue *pwq;
> + unsigned long flags;
> +
> + lockdep_assert_held(&wq->mutex);
> +
> + pwq = list_first_entry_or_null(&wq->pwqs, struct pool_workqueue,
> + pwqs_node);
> + if (WARN_ON_ONCE(!pwq))
> + return;
> + raw_spin_lock_irqsave(&pwq->pool->lock, flags);

Can we do raw_spin_lock_irq() instead?

> @@ -4740,6 +4784,13 @@ static void pwq_release_workfn(struct kthread_work *work)
> mutex_lock(&wq->mutex);
> list_del_rcu(&pwq->pwqs_node);
> is_last = list_empty(&wq->pwqs);
> +
> + /*
> + * For ordered workqueue with a plugged dfl_pwq, restart it now.
> + */
> + if (!is_last && (wq->flags & __WQ_ORDERED))
> + unplug_oldest_pwq(wq);

I'm not so sure about is_last test here. unplug_oldest_pwq() is testing for
NULL anyway, so maybe just drop this test here and drop WARN_ON_ONCE()
there?

> @@ -4966,6 +5017,15 @@ apply_wqattrs_prepare(struct workqueue_struct *wq,
> cpumask_copy(new_attrs->__pod_cpumask, new_attrs->cpumask);
> ctx->attrs = new_attrs;
>
> + /*
> + * For initialized ordered workqueues, there is only one pwq (dfl_pwq).
> + * Set the plugged flag of ctx->dfl_pwq to suspend execution of newly
> + * queued work items until execution of older work items in the old
> + * pwq's have completed.
> + */
> + if (!list_empty(&wq->pwqs) && (wq->flags & __WQ_ORDERED))
> + ctx->dfl_pwq->plugged = true;

Can we test __WQ_ORDERED first?

Thanks.

--
tejun