aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
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 /arch/x86
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 'arch/x86')
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/kernel/tsc.c21
2 files changed, 10 insertions, 12 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 7fa17b5ce668..d08e061c187a 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -109,6 +109,7 @@ config X86
109 select CLOCKSOURCE_WATCHDOG 109 select CLOCKSOURCE_WATCHDOG
110 select GENERIC_CLOCKEVENTS 110 select GENERIC_CLOCKEVENTS
111 select ARCH_CLOCKSOURCE_DATA 111 select ARCH_CLOCKSOURCE_DATA
112 select CLOCKSOURCE_VALIDATE_LAST_CYCLE
112 select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC) 113 select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC)
113 select GENERIC_TIME_VSYSCALL 114 select GENERIC_TIME_VSYSCALL
114 select GENERIC_STRNCPY_FROM_USER 115 select GENERIC_STRNCPY_FROM_USER
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 57e5ce126d5a..456c0e660c43 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -951,7 +951,7 @@ core_initcall(cpufreq_tsc);
951static struct clocksource clocksource_tsc; 951static struct clocksource clocksource_tsc;
952 952
953/* 953/*
954 * We compare the TSC to the cycle_last value in the clocksource 954 * We used to compare the TSC to the cycle_last value in the clocksource
955 * structure to avoid a nasty time-warp. This can be observed in a 955 * structure to avoid a nasty time-warp. This can be observed in a
956 * very small window right after one CPU updated cycle_last under 956 * very small window right after one CPU updated cycle_last under
957 * xtime/vsyscall_gtod lock and the other CPU reads a TSC value which 957 * xtime/vsyscall_gtod lock and the other CPU reads a TSC value which
@@ -961,26 +961,23 @@ static struct clocksource clocksource_tsc;
961 * due to the unsigned delta calculation of the time keeping core 961 * due to the unsigned delta calculation of the time keeping core
962 * code, which is necessary to support wrapping clocksources like pm 962 * code, which is necessary to support wrapping clocksources like pm
963 * timer. 963 * timer.
964 *
965 * This sanity check is now done in the core timekeeping code.
966 * checking the result of read_tsc() - cycle_last for being negative.
967 * That works because CLOCKSOURCE_MASK(64) does not mask out any bit.
964 */ 968 */
965static cycle_t read_tsc(struct clocksource *cs) 969static cycle_t read_tsc(struct clocksource *cs)
966{ 970{
967 cycle_t ret = (cycle_t)get_cycles(); 971 return (cycle_t)get_cycles();
968
969 return ret >= clocksource_tsc.cycle_last ?
970 ret : clocksource_tsc.cycle_last;
971}
972
973static void resume_tsc(struct clocksource *cs)
974{
975 if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC_S3))
976 clocksource_tsc.cycle_last = 0;
977} 972}
978 973
974/*
975 * .mask MUST be CLOCKSOURCE_MASK(64). See comment above read_tsc()
976 */
979static struct clocksource clocksource_tsc = { 977static struct clocksource clocksource_tsc = {
980 .name = "tsc", 978 .name = "tsc",
981 .rating = 300, 979 .rating = 300,
982 .read = read_tsc, 980 .read = read_tsc,
983 .resume = resume_tsc,
984 .mask = CLOCKSOURCE_MASK(64), 981 .mask = CLOCKSOURCE_MASK(64),
985 .flags = CLOCK_SOURCE_IS_CONTINUOUS | 982 .flags = CLOCK_SOURCE_IS_CONTINUOUS |
986 CLOCK_SOURCE_MUST_VERIFY, 983 CLOCK_SOURCE_MUST_VERIFY,