Re: [PATCH v3] x86: tsc: make TSC calibration immune to interrupts

From: Thomas Gleixner
Date: Wed May 25 2011 - 06:51:18 EST


> It is safe to use the first value that passes SMI_TRESHOLD
> for the initial calibration: As long as tsc_khz is above
> 100MHz, SMI_TRESHOLD represents less than 1% of error.
>
> The 8 additional samples costs us 28 microseconds in startup
> time.

That's a good reason to avoid the whole conditional thing and just do
the best of 5 always.

> /*
> * Read TSC and the reference counters. Take care of SMI disturbance
> */
> -static u64 tsc_read_refs(u64 *p, int hpet)
> +static u64 tsc_read_refs(u64 *p, int hpet, int find_best)
> {
> - u64 t1, t2;
> + u64 t1, t2, tp, best_uncertainty, uncertainty, best_t2;
> int i;
> + unsigned long flags;
>
> - for (i = 0; i < MAX_RETRIES; i++) {
> + best_uncertainty = SMI_TRESHOLD;
> + best_t2 = 0;
> + for (i = 0; i < BESTOF_SAMPLES; i++) {
> + local_irq_save(flags);
> t1 = get_cycles();
> if (hpet)
> - *p = hpet_readl(HPET_COUNTER) & 0xFFFFFFFF;
> + tp = hpet_readl(HPET_COUNTER) & 0xFFFFFFFF;
> else
> - *p = acpi_pm_read_early();
> + tp = acpi_pm_read_early();
> t2 = get_cycles();
> - if ((t2 - t1) < SMI_TRESHOLD)
> - return t2;
> + local_irq_restore(flags);
> + uncertainty = t2 - t1;
> + if (uncertainty < best_uncertainty) {
> + best_uncertainty = uncertainty;
> + best_t2 = t2;
> + *p = tp;
> + if (!find_best)
> + break;
> + }
> }
> + if (best_uncertainty < SMI_TRESHOLD)
> + return best_t2;
> +
> + *p = tp;

The value is completely uninteresting when we return ULLONG_MAX.

Thanks,

tglx
--
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/