aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2014-07-16 17:05:12 -0400
committerJohn Stultz <john.stultz@linaro.org>2014-07-23 18:01:51 -0400
commit09ec54429c6d10f87d1f084de53ae2c1c3a81108 (patch)
tree842749293edd755e8bb12e1433c2f9df7dd842cf /kernel
parent3a97837784acbf9fed699fc04d1799b0eb742fdf (diff)
clocksource: Move cycle_last validation to core code
The only user of the cycle_last validation is the x86 TSC. In order to provide NMI safe accessor functions for clock monotonic and monotonic_raw we need to do that in the core. We can't do the TSC specific if (now < cycle_last) now = cycle_last; for the other wrapping around clocksources, but TSC has CLOCKSOURCE_MASK(64) which actually does not mask out anything so if now is less than cycle_last the subtraction will give a negative result. So we can check for that in clocksource_delta() and return 0 for that case. Implement and enable it for x86 Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/time/Kconfig5
-rw-r--r--kernel/time/timekeeping_internal.h9
2 files changed, 14 insertions, 0 deletions
diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig
index feccfd888732..d626dc98e8df 100644
--- a/kernel/time/Kconfig
+++ b/kernel/time/Kconfig
@@ -12,6 +12,11 @@ config CLOCKSOURCE_WATCHDOG
12config ARCH_CLOCKSOURCE_DATA 12config ARCH_CLOCKSOURCE_DATA
13 bool 13 bool
14 14
15# Clocksources require validation of the clocksource against the last
16# cycle update - x86/TSC misfeature
17config CLOCKSOURCE_VALIDATE_LAST_CYCLE
18 bool
19
15# Timekeeping vsyscall support 20# Timekeeping vsyscall support
16config GENERIC_TIME_VSYSCALL 21config GENERIC_TIME_VSYSCALL
17 bool 22 bool
diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h
index 05dfa6b25dc4..4ea005a7f9da 100644
--- a/kernel/time/timekeeping_internal.h
+++ b/kernel/time/timekeeping_internal.h
@@ -12,9 +12,18 @@ extern void tk_debug_account_sleep_time(struct timespec64 *t);
12#define tk_debug_account_sleep_time(x) 12#define tk_debug_account_sleep_time(x)
13#endif 13#endif
14 14
15#ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE
16static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask)
17{
18 cycle_t ret = (now - last) & mask;
19
20 return (s64) ret > 0 ? ret : 0;
21}
22#else
15static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask) 23static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask)
16{ 24{
17 return (now - last) & mask; 25 return (now - last) & mask;
18} 26}
27#endif
19 28
20#endif /* _TIMEKEEPING_INTERNAL_H */ 29#endif /* _TIMEKEEPING_INTERNAL_H */