Skip to content

Commit 2c8bd58

Browse files
a-darwishKAGA-KOKO
authored andcommitted
time/sched_clock: Expire timer in hardirq context
To minimize latency, PREEMPT_RT kernels expires hrtimers in preemptible softirq context by default. This can be overriden by marking the timer's expiry with HRTIMER_MODE_HARD. sched_clock_timer is missing this annotation: if its callback is preempted and the duration of the preemption exceeds the wrap around time of the underlying clocksource, sched clock will get out of sync. Mark the sched_clock_timer for expiry in hard interrupt context. Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20200309181529.26558-1-a.darwish@linutronix.de
1 parent 048495e commit 2c8bd58

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎kernel/time/sched_clock.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
208208

209209
if (sched_clock_timer.function != NULL) {
210210
/* update timeout for clock wrap */
211-
hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL);
211+
hrtimer_start(&sched_clock_timer, cd.wrap_kt,
212+
HRTIMER_MODE_REL_HARD);
212213
}
213214

214215
r = rate;
@@ -254,9 +255,9 @@ void __init generic_sched_clock_init(void)
254255
* Start the timer to keep sched_clock() properly updated and
255256
* sets the initial epoch.
256257
*/
257-
hrtimer_init(&sched_clock_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
258+
hrtimer_init(&sched_clock_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
258259
sched_clock_timer.function = sched_clock_poll;
259-
hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL);
260+
hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL_HARD);
260261
}
261262

262263
/*
@@ -293,7 +294,7 @@ void sched_clock_resume(void)
293294
struct clock_read_data *rd = &cd.read_data[0];
294295

295296
rd->epoch_cyc = cd.actual_read_sched_clock();
296-
hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL);
297+
hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL_HARD);
297298
rd->read_sched_clock = cd.actual_read_sched_clock;
298299
}
299300

0 commit comments

Comments
 (0)