aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/timer.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-08-08 14:10:28 -0400
committerThomas Gleixner <tglx@linutronix.de>2012-08-21 10:28:31 -0400
commitc5f66e99b7cb091e3d51ae8e8156892e8feb7fa3 (patch)
treeb73b64ceabad685abd9a2bc24f0258d9dbfae367 /include/linux/timer.h
parentfc683995a6c4e604d62ab9a488ac2c1ba94fa868 (diff)
timer: Implement TIMER_IRQSAFE
Timer internals are protected with irq-safe locks but timer execution isn't, so a timer being dequeued for execution and its execution aren't atomic against IRQs. This makes it impossible to wait for its completion from IRQ handlers and difficult to shoot down a timer from IRQ handlers. This issue caused some issues for delayed_work interface. Because there's no way to reliably shoot down delayed_work->timer from IRQ handlers, __cancel_delayed_work() can't share the logic to steal the target delayed_work with cancel_delayed_work_sync(), and can only steal delayed_works which are on queued on timer. Similarly, the pending mod_delayed_work() can't be used from IRQ handlers. This patch adds a new timer flag TIMER_IRQSAFE, which makes the timer to be executed without enabling IRQ after dequeueing such that its dequeueing and execution are atomic against IRQ handlers. This makes it safe to wait for the timer's completion from IRQ handlers, for example, using del_timer_sync(). It can never be executing on the local CPU and if executing on other CPUs it won't be interrupted until done. This will enable simplifying delayed_work cancel/mod interface. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: torvalds@linux-foundation.org Cc: peterz@infradead.org Link: http://lkml.kernel.org/r/1344449428-24962-5-git-send-email-tj@kernel.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/linux/timer.h')
-rw-r--r--include/linux/timer.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 3f95c1fa615e..8c5a197e1587 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -49,18 +49,26 @@ extern struct tvec_base boot_tvec_bases;
49#endif 49#endif
50 50
51/* 51/*
52 * Note that all tvec_bases are 2 byte aligned and lower bit of 52 * Note that all tvec_bases are at least 4 byte aligned and lower two bits
53 * base in timer_list is guaranteed to be zero. Use the LSB to 53 * of base in timer_list is guaranteed to be zero. Use them for flags.
54 * indicate whether the timer is deferrable.
55 * 54 *
56 * A deferrable timer will work normally when the system is busy, but 55 * A deferrable timer will work normally when the system is busy, but
57 * will not cause a CPU to come out of idle just to service it; instead, 56 * will not cause a CPU to come out of idle just to service it; instead,
58 * the timer will be serviced when the CPU eventually wakes up with a 57 * the timer will be serviced when the CPU eventually wakes up with a
59 * subsequent non-deferrable timer. 58 * subsequent non-deferrable timer.
59 *
60 * An irqsafe timer is executed with IRQ disabled and it's safe to wait for
61 * the completion of the running instance from IRQ handlers, for example,
62 * by calling del_timer_sync().
63 *
64 * Note: The irq disabled callback execution is a special case for
65 * workqueue locking issues. It's not meant for executing random crap
66 * with interrupts disabled. Abuse is monitored!
60 */ 67 */
61#define TIMER_DEFERRABLE 0x1LU 68#define TIMER_DEFERRABLE 0x1LU
69#define TIMER_IRQSAFE 0x2LU
62 70
63#define TIMER_FLAG_MASK 0x1LU 71#define TIMER_FLAG_MASK 0x3LU
64 72
65#define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \ 73#define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \
66 .entry = { .prev = TIMER_ENTRY_STATIC }, \ 74 .entry = { .prev = TIMER_ENTRY_STATIC }, \