OpenCloudOS-Kernel/kernel/time
Thomas Gleixner d8bb6f4c16 x86: tsc prevent time going backwards
We already catch most of the TSC problems by sanity checks, but there
is a subtle bug which has been in the code forever. This can cause
time jumps in the range of hours.

This was reported in:
     http://lkml.org/lkml/2007/8/23/96
and
     http://lkml.org/lkml/2008/3/31/23

I was able to reproduce the problem with a gettimeofday loop test on a
dual core and a quad core machine which both have sychronized
TSCs. The TSCs seems not to be perfectly in sync though, but the
kernel is not able to detect the slight delta in the sync check. Still
there exists an extremly small window where this delta can be observed
with a real big time jump. So far I was only able to reproduce this
with the vsyscall gettimeofday implementation, but in theory this
might be observable with the syscall based version as well.

CPU 0 updates the clock source variables under xtime/vyscall lock and
CPU1, where the TSC is slighty behind CPU0, is reading the time right
after the seqlock was unlocked.

The clocksource reference data was updated with the TSC from CPU0 and
the value which is read from TSC on CPU1 is less than the reference
data. This results in a huge delta value due to the unsigned
subtraction of the TSC value and the reference value. This algorithm
can not be changed due to the support of wrapping clock sources like
pm timer.

The huge delta is converted to nanoseconds and added to xtime, which
is then observable by the caller. The next gettimeofday call on CPU1
will show the correct time again as now the TSC has advanced above the
reference value.

To prevent this TSC specific wreckage we need to compare the TSC value
against the reference value and return the latter when it is larger
than the actual TSC value.

I pondered to mark the TSC unstable when the readout is smaller than
the reference value, but this would render an otherwise good and fast
clocksource unusable without a real good reason.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-04-19 19:19:55 +02:00
..
Kconfig clockevents: Allow build w/o run-tine usage for migration purposes 2007-10-12 23:04:05 +02:00
Makefile clockevents: Allow build w/o run-tine usage for migration purposes 2007-10-12 23:04:05 +02:00
clockevents.c time: fix typo in comments 2008-02-08 09:22:29 -08:00
clocksource.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/tglx/linux-2.6-hrt 2008-04-18 08:37:41 -07:00
jiffies.c [PATCH] fix jiffies clocksource inittime 2007-04-04 21:12:47 -07:00
ntp.c time: remove obsolete CLOCK_TICK_ADJUST 2008-03-09 08:42:57 +01:00
tick-broadcast.c [S390] genirq/clockevents: move irq affinity prototypes/inlines to interrupt.h 2008-04-17 07:47:05 +02:00
tick-common.c [S390] genirq/clockevents: move irq affinity prototypes/inlines to interrupt.h 2008-04-17 07:47:05 +02:00
tick-internal.h timer: clean up tick-broadcast.c 2008-01-30 13:30:01 +01:00
tick-oneshot.c [S390] genirq/clockevents: move irq affinity prototypes/inlines to interrupt.h 2008-04-17 07:47:05 +02:00
tick-sched.c clockevents: optimise tick_nohz_stop_sched_tick() a bit 2008-04-17 12:22:31 +02:00
timekeeping.c x86: tsc prevent time going backwards 2008-04-19 19:19:55 +02:00
timer_list.c timer_list: print relative expiry time signed 2008-02-17 17:29:38 +01:00
timer_stats.c time: more timer related cleanups 2008-01-30 13:30:00 +01:00