public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: john stultz <johnstul@us.ibm.com>
To: George Spelvin <linux@horizon.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, tglx@linutronix.de,
	ulrich.windl@rz.uni-regensburg.de, williams@redhat.com,
	zippel@linux-m68k.org
Subject: Re: [RFC][PATCH] tsc_khz= boot option to avoid TSC calibration  variance
Date: Fri, 08 May 2009 12:02:52 -0700	[thread overview]
Message-ID: <1241809372.7297.3.camel@localhost.localdomain> (raw)
In-Reply-To: <20090508121913.9039.qmail@science.horizon.com>

On Fri, 2009-05-08 at 08:19 -0400, George Spelvin wrote:
> > To mitigate this, I wanted to provide a tsc_khz= boot option. This would
> > allow users to set the tsc_khz value at boot-up, assuming they are
> > within 1Mhz of the calibrated value (to protect against bad values).
> > Once the tsc_khz value is set in grub, the box will always boot with the
> > same value, so the NTP drift value prior to reboot will still be correct
> > after rebooting.
> 
> A run-time adjustable would be more convenient, but this is simple and works.
> 
> The 1 MHz tolerance, however, isn't implemented right.  I can't quote
> figure out what you were trying to do; was that (x + (x/2))/1000 trying
> to round the /1000 properly?  That should be (x + 1000/2)/1000 in that
> case, which I normally write as (x/500 + 1)/2;
> 
> But in any case, no equality comparison can possibly work; there's
> always a case where the measured value rounds to k and the correct
> value rounds to k+1.  Also, 1 MHz is a pretty wide tolerance on
> sub-GHz processors.  I'd suggest the following:

Ah. Indeed you're right. Thanks for catching this.
Your version is much better.

-john

> diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> index d57de05..d7ab640 100644
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -825,15 +825,42 @@ static void __init init_tsc_clocksource(void)
>  	clocksource_register(&clocksource_tsc);
>  }
> 
> +unsigned long tsc_khz_specified;
> +static int __init tsc_khz_specified_setup(char *str)
> +{
> +	tsc_khz_specified = simple_strtoul(str, NULL, 0);
> +	return 1;
> +}
> +
> +__setup("tsc_khz=", tsc_khz_specified_setup);
> +
> +
>  void __init tsc_init(void)
>  {
>  	u64 lpj;
>  	int cpu;
> +	long difference;
> 
>  	if (!cpu_has_tsc)
>  		return;
> 
>  	tsc_khz = calibrate_tsc();
> +
> +	/*
> *	 * If the calibrated TSC freq and user specified TSC freq
> *	 * are close enough, pick the what the user told us.  Reject
> *	 * obviously bogus values to make the option safe to use.
> +	 */
> +	difference = tsc_khz - tsc_khz_specified;
> +	if (difference < 0)
> +		difference = -difference;
> +	if (difference <= tsc_khz >> 10) {	/* 1/1024 = 976 ppm */
> +		printk(KERN_INFO "Using user defined TSC freq: %lu.%03lu MHz\n",
> +			tsc_khz_specified/1000,
> +			tsc_khz_specified%1000);
> +		tsc_khz = tsc_khz_specified;
> +	}
> +
>  	cpu_khz = tsc_khz;
> 
>  	if (!tsc_khz) {


  parent reply	other threads:[~2009-05-08 19:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-08  0:30 [RFC][PATCH] tsc_khz= boot option to avoid TSC calibration variance john stultz
2009-05-08 12:15 ` Ingo Molnar
2009-05-08 15:12   ` George Spelvin
2009-05-08 19:06   ` [RFC][PATCH] tsc_khz= boot option to avoid TSC calibrationvariance john stultz
2009-05-08 12:19 ` [RFC][PATCH] tsc_khz= boot option to avoid TSC calibration variance George Spelvin
2009-05-08 15:27   ` George Spelvin
2009-05-08 19:02   ` john stultz [this message]
2009-05-11  6:54     ` George Spelvin

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=1241809372.7297.3.camel@localhost.localdomain \
    --to=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@horizon.com \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=ulrich.windl@rz.uni-regensburg.de \
    --cc=williams@redhat.com \
    --cc=zippel@linux-m68k.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