linux/arch
Dave Johnson edaf420fdc x86: fix TSC clock source calibration error
I ran into this problem on a system that was unable to obtain NTP sync
because the clock was running very slow (over 10000ppm slow). ntpd had
declared all of its peers 'reject' with 'peer_dist' reason.

On investigation, the tsc_khz variable was significantly incorrect
causing xtime to run slow.  After a reboot tsc_khz was correct so I
did a reboot test to see how often the problem occurred:

Test was done on a 2000 Mhz Xeon system.  Of 689 reboots, 8 of them
had unacceptable tsc_khz values (>500ppm):

 range of tsc_khz  # of boots  % of boots
 ----------------  ----------  ----------
        < 1999750           0      0.000%
1999750 - 1999800          21      3.048%
1999800 - 1999850         166     24.128%
1999850 - 1999900         241     35.029%
1999900 - 1999950         211     30.669%
1999950 - 2000000          42      6.105%
2000000 - 2000000           0      0.000%
2000050 - 2000100           0      0.000%
                   [...]
2000100 - 2015000           1      0.145%  << BAD
2015000 - 2030000           6      0.872%  << BAD
2030000 - 2045000           1      0.145%  << BAD
2045000 <                   0      0.000%

The worst boot was 2032.577 Mhz, over 1.5% off!

It appears that on rare occasions, mach_countup() is taking longer to
complete than necessary.

I suspect that this is caused by the CPU taking a periodic SMI
interrupt right at the end of the 30ms calibration loop.  This would
cause the loop to delay while the SMI BIOS hander runs. The resulting
TSC value is beyond what it actually should be resulting in a higher
tsc_khz.

The below patch makes native_calculate_cpu_khz() take the best
(shortest duration, lowest khz) run of it's 3 calibration loops.  If a
SMI goes off causing a bad result (long duration, higher khz) it will
be discarded.

With the patch applied, 300 boots of the same system produce good
results:

 range of tsc_khz  # of boots  % of boots
 ----------------  ----------  ----------
        < 1999750           0      0.000%
1999750 - 1999800          30     10.000%
1999800 - 1999850         166     55.333%
1999850 - 1999900          89     29.667%
1999900 - 1999950          15      5.000%
1999950 <                   0      0.000%

Problem was found and tested against 2.6.18.  Patch is against 2.6.22.

Signed-off-by: Dave Johnson <djohnson@sw.starentnetworks.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2007-10-23 22:37:22 +02:00
..
alpha alpha: sg_virt() fallout 2007-10-23 12:31:05 +02:00
arm arm: build fix 2007-10-23 09:11:41 +02:00
avr32 [AVR32] ARRAY_SIZE() cleanup 2007-10-23 11:20:26 +02:00
blackfin Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/cooloney/blackfin-2.6 2007-10-22 19:29:05 -07:00
cris typo fixes 2007-10-20 01:34:40 +02:00
frv spelling fixes: arch/frv/ 2007-10-20 01:09:42 +02:00
h8300 spelling fixes: arch/h8300/ 2007-10-20 01:10:46 +02:00
i386 x86: add instrumentation menu 2007-10-23 22:37:22 +02:00
ia64 Merge branch 'sg' of git://git.kernel.dk/linux-2.6-block 2007-10-22 19:11:06 -07:00
m32r spelling fixes: arch/m32r/ 2007-10-20 01:14:39 +02:00
m68k Update arch/ to use sg helpers 2007-10-22 21:19:59 +02:00
m68knommu m68knommu: cleanup m68knommu timer code 2007-10-23 08:32:35 -07:00
mips mips: sg_page() fallout 2007-10-23 12:32:34 +02:00
parisc parisc: fix sg_page() fallout 2007-10-23 09:49:31 +02:00
powerpc Merge branch 'for-2.6.24' of master.kernel.org:/pub/scm/linux/kernel/git/jwboyer/powerpc-4xx into merge 2007-10-23 22:20:51 +10:00
ppc kbuild: restore arch/{ppc/xtensa}/boot cflags 2007-10-20 20:35:23 +02:00
s390 [S390] 4level-fixup cleanup 2007-10-22 12:52:49 +02:00
sh Combine instrumentation menus in kernel/Kconfig.instrumentation 2007-10-19 11:53:54 -07:00
sh64 Fix misspellings of "system", "controller", "interrupt" and "necessary". 2007-10-19 23:10:43 +02:00
sparc Update arch/ to use sg helpers 2007-10-22 21:19:59 +02:00
sparc64 sparc64: zero out dma_length 2007-10-23 12:58:39 +02:00
um [SG] Update drivers to use sg helpers 2007-10-22 21:19:53 +02:00
v850 spelling fixes: arch/v850/ 2007-10-20 01:24:05 +02:00
x86 x86: fix TSC clock source calibration error 2007-10-23 22:37:22 +02:00
x86_64 x86: add instrumentation menu 2007-10-23 22:37:22 +02:00
xtensa kbuild: restore arch/{ppc/xtensa}/boot cflags 2007-10-20 20:35:23 +02:00