Skip to content

Commit 6409c4d

Browse files
author
Ingo Molnar
committed
sched: sched_clock() improvement: use in_nmi()
make sure we dont execute more complex sched_clock() code in NMI context. Acked-by: Peter Zijlstra <[email protected]> Acked-by: Steven Rostedt <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent af39241 commit 6409c4d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/sched_clock.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/spinlock.h>
3030
#include <linux/ktime.h>
3131
#include <linux/module.h>
32+
#include <linux/hardirq.h>
3233

3334
/*
3435
* Scheduler clock - returns current time in nanosec units.
@@ -151,6 +152,13 @@ u64 sched_clock_cpu(int cpu)
151152
struct sched_clock_data *scd = cpu_sdc(cpu);
152153
u64 now, clock, this_clock, remote_clock;
153154

155+
/*
156+
* Normally this is not called in NMI context - but if it is,
157+
* trying to do any locking here is totally lethal.
158+
*/
159+
if (unlikely(in_nmi()))
160+
return scd->clock;
161+
154162
if (unlikely(!sched_clock_running))
155163
return 0ull;
156164

0 commit comments

Comments
 (0)