Skip to content

Commit dcd4259

Browse files
Frederic Weisbeckerpaulmckrcu
authored andcommitted
timer: Add timer_curr_running()
This commit adds a timer_curr_running() function that verifies that the current code is running in the context of the specified timer's handler. Cc: Josh Triplett <josh@joshtriplett.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Lai Jiangshan <jiangshanlai@gmail.com> Cc: Joel Fernandes <joel@joelfernandes.org> Cc: Neeraj Upadhyay <neeraju@codeaurora.org> Cc: Thomas Gleixner <tglx@linutronix.de> Tested-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 43759fe commit dcd4259

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎include/linux/timer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ extern int try_to_del_timer_sync(struct timer_list *timer);
192192

193193
#define del_singleshot_timer_sync(t) del_timer_sync(t)
194194

195+
extern bool timer_curr_running(struct timer_list *timer);
196+
195197
extern void init_timers(void);
196198
struct hrtimer;
197199
extern enum hrtimer_restart it_real_fn(struct hrtimer *);

‎kernel/time/timer.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,19 @@ int try_to_del_timer_sync(struct timer_list *timer)
12371237
}
12381238
EXPORT_SYMBOL(try_to_del_timer_sync);
12391239

1240+
bool timer_curr_running(struct timer_list *timer)
1241+
{
1242+
int i;
1243+
1244+
for (i = 0; i < NR_BASES; i++) {
1245+
struct timer_base *base = this_cpu_ptr(&timer_bases[i]);
1246+
if (base->running_timer == timer)
1247+
return true;
1248+
}
1249+
1250+
return false;
1251+
}
1252+
12401253
#ifdef CONFIG_PREEMPT_RT
12411254
static __init void timer_base_init_expiry_lock(struct timer_base *base)
12421255
{

0 commit comments

Comments
 (0)