[PATCH] x86: quick TSC calibration, improve

From: Ingo Molnar
Date: Thu Sep 04 2008 - 16:47:47 EST


- make sure the final TSC timestamp is reliable too

- make sure nobody increases QUICK_PIT_MS so that
QUICK_PIT_ITERATIONS can get larger than 0xff, breaking the iteration.
(It would take about 60 msecs to reach that limit.)

Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
---
arch/x86/kernel/tsc.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 839070b..4832a40 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -304,6 +304,11 @@ static unsigned long quick_pit_calibrate(void)
outb(0xff, 0x42);
outb(0xff, 0x42);

+ /*
+ * The iteration assumes that expect never goes below zero:
+ */
+ BUILD_BUG_ON(QUICK_PIT_ITERATIONS >= 0xff);
+
if (pit_expect_msb(0xff)) {
int i;
u64 t1, t2, delta;
@@ -317,6 +322,12 @@ static unsigned long quick_pit_calibrate(void)
t2 = get_cycles();

/*
+ * Make sure we can rely on the second TSC timestamp:
+ */
+ if (!pit_expect_msb(--expect))
+ goto failed;
+
+ /*
* Ok, if we get here, then we've seen the
* MSB of the PIT decrement QUICK_PIT_ITERATIONS
* times, and each MSB had many hits, so we never
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/