The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Kasper Pedersen <kkp2010@kasperkp.dk>
Cc: linux-kernel@vger.kernel.org,
	Suresh Siddha <suresh.b.siddha@intel.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	John Stultz <johnstul@us.ibm.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Ingo Molnar <mingo@redhat.com>,
	Josh Triplett <josh@joshtriplett.org>
Subject: Re: [PATCH v3] x86: tsc: make TSC calibration immune to interrupts
Date: Wed, 25 May 2011 12:51:05 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.02.1105251243330.3078@ionos> (raw)
In-Reply-To: <4DDC0B4F.6060202@kasperkp.dk>

> 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

  reply	other threads:[~2011-05-25 10:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-24 19:47 [PATCH v3] x86: tsc: make TSC calibration immune to interrupts Kasper Pedersen
2011-05-25 10:51 ` Thomas Gleixner [this message]
2011-05-25 22:07   ` Kasper Pedersen
2011-05-25 22:23     ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.02.1105251243330.3078@ionos \
    --to=tglx@linutronix.de \
    --cc=a.p.zijlstra@chello.nl \
    --cc=hpa@zytor.com \
    --cc=johnstul@us.ibm.com \
    --cc=josh@joshtriplett.org \
    --cc=kkp2010@kasperkp.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=suresh.b.siddha@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox