Skip to content

Commit

Permalink
sched: sched_clock() improvement: use in_nmi()
Browse files Browse the repository at this point in the history
make sure we dont execute more complex sched_clock() code in NMI context.

Acked-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ingo Molnar committed Feb 26, 2009
1 parent af39241 commit 6409c4d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kernel/sched_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <linux/spinlock.h>
#include <linux/ktime.h>
#include <linux/module.h>
#include <linux/hardirq.h>

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

/*
* Normally this is not called in NMI context - but if it is,
* trying to do any locking here is totally lethal.
*/
if (unlikely(in_nmi()))
return scd->clock;

if (unlikely(!sched_clock_running))
return 0ull;

Expand Down

0 comments on commit 6409c4d

Please sign in to comment.