From 7720e8dbc578da02b020d7e8f5441e74b3726004 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Wed, 23 Jan 2019 00:24:37 +0100 Subject: [PATCH] x86/kernel/tsc: Debug early TSC calibration Signed-off-by: Paul Menzel --- arch/x86/kernel/tsc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 3fae23834069..4696ef7326b6 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -478,9 +478,15 @@ static unsigned long pit_calibrate_tsc(u32 latch, unsigned long ms, int loopmin) */ static inline int pit_verify_msb(unsigned char val) { + unsigned char val1; + /* Ignore LSB */ inb(0x42); - return inb(0x42) == val; + val1 = inb(0x42); + + if (val1 != val) + pr_err("%s: inb(0x42) = %x != %x = val", __func__, val1, val); + return val1 == val; } static inline int pit_expect_msb(unsigned char val, u64 *tscp, unsigned long *deltap) @@ -497,6 +503,8 @@ static inline int pit_expect_msb(unsigned char val, u64 *tscp, unsigned long *de *deltap = get_cycles() - prev_tsc; *tscp = tsc; + pr_err("%s: val = 0x%x: count = %d\n", __func__, val, count); + /* * We require _some_ success, but the quality control * will be based on the error terms on the TSC values. @@ -550,8 +558,10 @@ static unsigned long quick_pit_calibrate(void) if (pit_expect_msb(0xff, &tsc, &d1)) { for (i = 1; i <= MAX_QUICK_PIT_ITERATIONS; i++) { - if (!pit_expect_msb(0xff-i, &delta, &d2)) + if (!pit_expect_msb(0xff-i, &delta, &d2)) { + pr_err("%s: break in if !pit_expect_msb, i = %d\n", __func__, i); break; + } delta -= tsc; @@ -576,12 +586,14 @@ static unsigned long quick_pit_calibrate(void) * This also guarantees serialization of the * last cycle read ('d2') in pit_expect_msb. */ - if (!pit_verify_msb(0xfe - i)) + if (!pit_verify_msb(0xfe - i)) { + pr_err("%s: break in if !pit_verify_msb\n", __func__); break; + } goto success; } } - pr_info("Fast TSC calibration failed\n"); + pr_err("Fast TSC calibration failed, i = %u from %u\n", i, MAX_QUICK_PIT_ITERATIONS); return 0; success: -- 2.17.1