workqueue: introduce queue_delayed_work_on_offline_safe
PATCH v3 1/1 workqueue: introduce queue_delayed_work_on_offline_safe
Currently users of queue_delayed_work_on, need to ensure that specified cpu is and remains online. The failure to do so may result in delayed_work getting queued on an offlined cpu and hence never getting executed.
The current users of queue_delayed_work_on, seem to ensure the above mentioned criteria but for those, unknown amongst current users or new users, who can't confirm to this we need another interface.
So introduce queue_delayed_work_on_offline_safe, which is a wrapper around queue_delayed_work_on to ensure that the specified cpu is and remains online.
---
v2 --> v3:
- Corrected a couple of typos spotted by Haakon
- Collected Acked-by, from Haakon
v1 --> v2:
- Remove RFC tag
- For cases where dwork can't be put on specified CPU, let caller decide the next CPU to try with.
include/linux/workqueue.h | 3 +++ kernel/workqueue.c | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
include/linux/workqueue.h +3 -0
@@ -589,6 +589,9 @@ extern bool queue_work_node(int node, struct workqueue_struct *wq, struct work_struct *work);extern bool queue_delayed_work_on (int cpu,struct workqueue_struct *wq,struct delayed_work *work,unsigned long delay); +extern bool queue_delayed_work_on_offline_safe (int cpu, +struct workqueue_struct *wq,struct delayed_work *work, +unsigned long delay,bool *online);extern bool mod_delayed_work_on (int cpu,struct workqueue_struct *wq,struct delayed_work *dwork,unsigned long delay);extern bool queue_rcu_work (struct workqueue_struct *wq,struct rcu_work *rwork);
kernel/workqueue.c +42 -0
48 lines not on this page · raw message
base-commit: 5bc55a333a2f7316b58edc7573e8e893f7acb532
Signature · 1 line
2.34.1
Tejun Heo
maintainerQuoted 10 lines · Imran Khan
Currently users of
queue_delayed_work_on, need to ensure that specified cpu is and remains online. The failure to do so may result indelayed_workgetting queued on an offlined cpu and hence never getting executed.The current users of
queue_delayed_work_on, seem to ensure the above mentioned criteria but for those, unknown amongst current users or new users, who can't confirm to this we need another interface.
Quoted 6 lines
So introduce
queue_delayed_work_on_offline_safe, which is a wrapper aroundqueue_delayed_work_onto ensure that the specified cpu is and remains online.Signed-off-by Imran Khan <[email protected]>Acked-by Haakon Bugge <[email protected]>
So, idk, do we really need this? Can't we just add a debug warning which triggers when CPU goes down with delayed works queued on it?
Thanks.
Signature · 1 line
tejun
Hello Tejun,
Thanks for getting back on this.
Quoted 15 lines · Tejun Heo
Quoted 14 lines · Imran Khan
Currently users of
queue_delayed_work_on, need to ensure that specified cpu is and remains online. The failure to do so may result indelayed_workgetting queued on an offlined cpu and hence never getting executed.The current users of
queue_delayed_work_on, seem to ensure the above mentioned criteria but for those, unknown amongst current users or new users, who can't confirm to this we need another interface.So introduce
queue_delayed_work_on_offline_safe, which is a wrapper aroundqueue_delayed_work_onto ensure that the specified cpu is and remains online.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Imran Khan <[email protected]>Acked-by Haakon Bugge <[email protected]>So, idk, do we really need this? Can't we just add a debug warning which triggers when CPU goes down with delayed works queued on it?
Actually, we are good for cases where a CPU goes offline with delayed works queued on it, because the associated timers will migrate to other cpu (BP).
The problem is for the cases where a CPU is already offline or in the middle of being offlined and past timers_dead_cpu callback. In such a scenario if someone puts a delayed work on this CPU, we have problem. The WARN_ON_ONCE in [1] can indicate this but the dwork's timer would still end up on the offlined cpu and will not be migrated (since CPU was past timer_dead state , when dwork was queued).
One way to avoid this is that we ask callers to do the needful (hotplug lock, hotplug callbacks) and ensure dwork does not end up on such offlined CPU. The other way (as attempted in this patch) would be to give such users an interface, that can ensure that dwork never ends on on offlined CPU.
Thanks,
Imran
[1]: https://lore.kernel.org/all/[email protected]/
Quoted 2 lines
Thanks.
Tejun Heo
maintainerOn Wed, Feb 05, 2025 at 11:54:20AM +1100, [email protected] wrote:
...
Quoted 11 lines
The problem is for the cases where a CPU is already offline or in the middle of being offlined and past
timers_dead_cpucallback. In such a scenario if someone puts a delayed work on this CPU, we have problem. TheWARN_ON_ONCEin [1] can indicate this but the dwork's timer would still end up on the offlined cpu and will not be migrated (since CPU was pasttimer_deadstate , when dwork was queued).One way to avoid this is that we ask callers to do the needful (hotplug lock, hotplug callbacks) and ensure dwork does not end up on such offlined CPU. The other way (as attempted in this patch) would be to give such users an interface, that can ensure that dwork never ends on on offlined CPU.
I don't think introducing a new interface makes sense here. Either the WARN is enough or we can follow what queue_work_on() does and ensure that the delayed work item gets executed *somewhere*.
Thanks.
Signature · 1 line
tejun