Skip to content

Commit 8109796

Browse files
Sebastian Andrzej SiewiorPeter Zijlstra
authored andcommitted
irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support.
irq_work() triggers instantly an interrupt if supported by the architecture. Otherwise the work will be processed on the next timer tick. In worst case irq_work_sync() could spin up to a jiffy. irq_work_sync() is usually used in tear down context which is fully preemptible. Based on review irq_work_sync() is invoked from preemptible context and there is one waiter at a time. This qualifies it to use rcuwait for synchronisation. Let irq_work_sync() synchronize with rcuwait if the architecture processes irqwork via the timer tick. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent da6ff09 commit 8109796

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/linux/irq_work.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _LINUX_IRQ_WORK_H
44

55
#include <linux/smp_types.h>
6+
#include <linux/rcuwait.h>
67

78
/*
89
* An entry can be in one of four states:
@@ -16,11 +17,13 @@
1617
struct irq_work {
1718
struct __call_single_node node;
1819
void (*func)(struct irq_work *);
20+
struct rcuwait irqwait;
1921
};
2022

2123
#define __IRQ_WORK_INIT(_func, _flags) (struct irq_work){ \
2224
.node = { .u_flags = (_flags), }, \
2325
.func = (_func), \
26+
.irqwait = __RCUWAIT_INITIALIZER(irqwait), \
2427
}
2528

2629
#define IRQ_WORK_INIT(_func) __IRQ_WORK_INIT(_func, 0)

kernel/irq_work.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ void irq_work_single(void *arg)
160160
* else claimed it meanwhile.
161161
*/
162162
(void)atomic_cmpxchg(&work->node.a_flags, flags, flags & ~IRQ_WORK_BUSY);
163+
164+
if (!arch_irq_work_has_interrupt())
165+
rcuwait_wake_up(&work->irqwait);
163166
}
164167

165168
static void irq_work_run_list(struct llist_head *list)
@@ -204,6 +207,13 @@ void irq_work_tick(void)
204207
void irq_work_sync(struct irq_work *work)
205208
{
206209
lockdep_assert_irqs_enabled();
210+
might_sleep();
211+
212+
if (!arch_irq_work_has_interrupt()) {
213+
rcuwait_wait_event(&work->irqwait, !irq_work_is_busy(work),
214+
TASK_UNINTERRUPTIBLE);
215+
return;
216+
}
207217

208218
while (irq_work_is_busy(work))
209219
cpu_relax();

0 commit comments

Comments
 (0)