Re: [RFC patch 0/4] TSC calibration improvements

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



> +static unsigned long quick_pit_calibrate(void)
> +{
[...]
> + if (pit_expect_msb(0xff)) {
> + int i;
> + u64 t1, t2, delta;
> + unsigned char expect = 0xfe;
> +
> + t1 = get_cycles();
> + for (i = 0; i < QUICK_PIT_ITERATIONS; i++, expect--) {
> + if (!pit_expect_msb(expect))
> + goto failed;
> + }
> + t2 = get_cycles();

hm, unless i'm missing something i think here we still have a small
window for an SMI or some virtualization delay to slip in and cause
massive inaccuracy: if the delay happens _after_ the last
pit_expect_msb() and _before_ the external get_cycles() call. Right?

i fixed that by adding one more pit_expect_msb() call.

plus i think QUICK_PIT_ITERATIONS is quite close to overflowing 255
which is built into the u32 'expect' variable (the MSB will only
overflow to 10 bits or so) - so i've added a BUILD_BUG_ON() to make sure
anyone tuning QUICK_PIT_MS above 60msec or so would get a build error
instead of some hard(er) to track down calibration error.

but it's getting late here so please double-check me ... The commit is
below.

Ingo

------------>