Skip to content

Commit da30ba2

Browse files
imran-knhtejun
authored andcommitted
workqueue: warn if delayed_work is queued to an offlined cpu.
delayed_work submitted to an offlined cpu, will not get executed, after the specified delay if the cpu remains offline. If the cpu never comes online the work will never get executed. checking for online cpu in __queue_delayed_work, does not sound like a good idea because to do this reliably we need hotplug lock and since work may be submitted from atomic contexts, we would have to use cpus_read_trylock. But if trylock fails we would queue the work on any cpu and this may not be optimal because our intended cpu might still be online. Putting a WARN_ON_ONCE for an already offlined cpu, will indicate users of queue_delayed_work_on, if they are (wrongly) trying to queue delayed_work on offlined cpu. Also indicate the problem of using offlined cpu with queue_delayed_work_on, in its description. Signed-off-by: Imran Khan <imran.f.khan@oracle.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent d57212f commit da30ba2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

kernel/workqueue.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,7 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
25082508
return;
25092509
}
25102510

2511+
WARN_ON_ONCE(cpu != WORK_CPU_UNBOUND && !cpu_online(cpu));
25112512
dwork->wq = wq;
25122513
dwork->cpu = cpu;
25132514
timer->expires = jiffies + delay;
@@ -2533,6 +2534,12 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
25332534
* @dwork: work to queue
25342535
* @delay: number of jiffies to wait before queueing
25352536
*
2537+
* We queue the delayed_work to a specific CPU, for non-zero delays the
2538+
* caller must ensure it is online and can't go away. Callers that fail
2539+
* to ensure this, may get @dwork->timer queued to an offlined CPU and
2540+
* this will prevent queueing of @dwork->work unless the offlined CPU
2541+
* becomes online again.
2542+
*
25362543
* Return: %false if @work was already on a queue, %true otherwise. If
25372544
* @delay is zero and @dwork is idle, it will be scheduled for immediate
25382545
* execution.

0 commit comments

Comments
 (0)