lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 25 May 2011 12:51:05 +0200 (CEST)
From:	Thomas Gleixner <tglx@...utronix.de>
To:	Kasper Pedersen <kkp2010@...perkp.dk>
cc:	linux-kernel@...r.kernel.org,
	Suresh Siddha <suresh.b.siddha@...el.com>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	John Stultz <johnstul@...ibm.com>, x86@...nel.org,
	"H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
	Josh Triplett <josh@...htriplett.org>
Subject: Re: [PATCH v3] x86: tsc: make TSC calibration immune to interrupts

> 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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ