Message ID | 54BF83C9.5060300@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, 21 Jan 2015 10:47:37 +0000 Daniel Thompson <daniel.thompson@linaro.org> wrote: > > With this patchset, is it possible to call sched_clock() from within NMI > > context? I ask because the generic sched_clock() code is not NMI safe That's not good. Better not run function tracing, as that could trace functions in NMI context (I depend on that it does), and it uses sched_clock() as the default clock. -- Steve > > today. We were planning on making it NMI safe by doing something similar > > to what was done for ktime_get_mono_fast_ns() but we haven't gotten > > around to it. Mostly because no architecture that uses generic > > sched_clock() has support for NMIs right now. >
On 21/01/15 13:06, Steven Rostedt wrote: > On Wed, 21 Jan 2015 10:47:37 +0000 > Daniel Thompson <daniel.thompson@linaro.org> wrote: > > >>> With this patchset, is it possible to call sched_clock() from within NMI >>> context? I ask because the generic sched_clock() code is not NMI safe > > That's not good. Better not run function tracing, as that could trace > functions in NMI context (I depend on that it does), and it uses > sched_clock() as the default clock. I think sched_clock is unsafe as in "may sometimes give the wrong value" rather than "can lock up arbitrarily". Thus the impact is unlikely to be harmful enough to want to avoid tracing altogether. It would require special care be taken when interpreting the timestamps however. Also since update_sched_clock() is a notrace function its very hard to figure out when timestamps are at risk. Anyhow, the fix doesn't seem that hard. I can take a look. Daniel.
On 21/01/15 13:48, Daniel Thompson wrote: > On 21/01/15 13:06, Steven Rostedt wrote: >> On Wed, 21 Jan 2015 10:47:37 +0000 >> Daniel Thompson <daniel.thompson@linaro.org> wrote: >> >> >>>> With this patchset, is it possible to call sched_clock() from within NMI >>>> context? I ask because the generic sched_clock() code is not NMI safe >> >> That's not good. Better not run function tracing, as that could trace >> functions in NMI context (I depend on that it does), and it uses >> sched_clock() as the default clock. > > I think sched_clock is unsafe as in "may sometimes give the wrong value" > rather than "can lock up arbitrarily". Thus the impact is unlikely to > be harmful enough to want to avoid tracing altogether. Just to update the record... The above paragraph is wrong in every possible way. It is a livelock (and I'm working on it). > It would require special care be taken when interpreting the timestamps > however. Also since update_sched_clock() is a notrace function its very > hard to figure out when timestamps are at risk. > > Anyhow, the fix doesn't seem that hard. I can take a look. > > > Daniel. >
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 630dd2372238..fea0deeb524b 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -111,8 +111,10 @@ extern void warn_slowpath_null(const char *file, const int line); int __ret_warn_once = !!(condition); \ \ if (unlikely(__ret_warn_once)) \ - if (WARN_ON(!__warned)) \ + if (unlikely(!__warned)) { \ __warned = true; \ + __WARN(); \ + } \ unlikely(__ret_warn_once); \ }) diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 01d2d15aa662..81ea469b7e68 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -63,6 +63,8 @@ unsigned long long notrace sched_clock(void) u64 cyc; unsigned long seq; + WARN_ON_ONCE(in_nmi()); + if (cd.suspended) return cd.epoch_ns;