Re: [PATCH 12/17] workqueue: Implement disable/enable for (delayed) work items

From: Lai Jiangshan
Date: Tue Feb 20 2024 - 02:22:49 EST


Hello, Tejun

On Sat, Feb 17, 2024 at 2:06 AM Tejun Heo <tj@xxxxxxxxxx> wrote:

> - A work item carries 10bit disable count in work->data while not queued.
> The access to the count is synchronized by the PENDING bit like all other
> parts of work->data.

It is 16bit disable count in the code.


> @@ -2417,7 +2437,8 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
>
> local_irq_save(irq_flags);
>
> - if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
> + if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) &&
> + !clear_pending_if_disabled(work)) {
> __queue_work(cpu, wq, work);
> ret = true;
> }
> @@ -2577,7 +2598,8 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
> /* read the comment in __queue_work() */
> local_irq_save(irq_flags);
>
> - if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
> + if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) &&
> + !clear_pending_if_disabled(work)) {
> __queue_delayed_work(cpu, wq, dwork, delay);
> ret = true;
> }

It misses the same handling at queue_work_node() and queue_rcu_work().

But it is bad idea to cancel or disable rcu work since it can be possibly
in the rcu's waiting list.

> @@ -4173,20 +4195,46 @@ bool flush_rcu_work(struct rcu_work *rwork)
> }
> EXPORT_SYMBOL(flush_rcu_work);
>

Thanks
Lai