linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Jesper Krogh <jesper@krogh.cc>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	john stultz <johnstul@us.ibm.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Len Brown <len.brown@intel.com>, Ingo Molnar <mingo@elte.hu>
Subject: Re: Linux 2.6.29-rc6
Date: Tue, 10 Mar 2009 23:22:06 +0100 (CET)	[thread overview]
Message-ID: <alpine.LFD.2.00.0903102107580.29264@localhost.localdomain> (raw)
In-Reply-To: <49B6C2B8.7000407@krogh.cc>

Jesper,

On Tue, 10 Mar 2009, Jesper Krogh wrote:
> First boot:
> [    0.000000] Fast TSC calibration using PIT
> [    0.000000] tsc 34202223 tscmin 474069 tscmax 500664
> Second boot:
> Here I didnt get above messages.. http://krogh.cc/~jesper/dmesg-boot2.txt
> Third boot:
> [    0.000000] Fast TSC calibration using PIT
> [    0.000000] tsc 34199856 tscmin 470321 tscmax 502182
> Forth boot:
> [    0.000000] Fast TSC calibration using PIT
> [    0.000000] tsc 34202008 tscmin 475510 tscmax 501501
> 
> The second one is really strange.. is'nt it?

No, there simply the fast PIT calibration failed and it dropped into
the slow path:
[    0.000000] TSC: PIT calibration matches PMTIMER. 1 loops
[    0.000000] Detected 2311.878 MHz processor.

But the variance of the third run is interesting:

    avg = tsc / loops = 495650
    avg - tscmin      =  25329 (~ 10.9 us)
    tscmax - avg      =   6532 (~  2.8 us)

While this is in the range which the PIT calibration code accepts the
resulting CPU frequency of this run is 2310.159 MHz which is way off
the result of the slow path in the 2nd run. The 1st and the 4th run
have significant high variance as well.

I run the same patch on a couple of test machines and all have
deviations from avg in the range of +/- 2 us and the calibration
result is stable and correct.

I have no idea what might cause the problem with your machine. PIT via
SMM emulation comes to mind :)

But we can use the tscmin/max method to figure out whether the fast
PIT result is reliable. See patch below. It should drop out into the
slow calibration path on every boot on your machine.

    (tscmax - tscmin) / avg = 0.064 (result from third run)

On my test machines I get values below 0.02

While it's statistically not really correct we still can use that info
to catch cases like we see on your machines.

> While booting up I saw this one on the serial console..
> root@quad12:~# hwclock --systohc
> Cannot access the Hardware Clock via any known method.
> Use the --debug option to see the details of our search for an access method.
> root@quad12:~# hwclock --systohc --debug
> hwclock from util-linux-ng 2.13.1
> hwclock: Open of /dev/rtc failed, errno=2: No such file or directory.
> No usable clock interface found.
> Cannot access the Hardware Clock via any known method.

Can you provide your .config file please ?

Thanks,

	tglx

--------->

Subject: x86: make TSC fast calibration more robust
From: Thomas Gleixner <tglx@linutronix.de>
Date: Tue, 10 Mar 2009 11:12:03 +0100

Check the min/max duration of each PIT loop against the resulting
average value and dismiss the fast calibration if it's larger than
2.5%. 2.5% is in the range of +/- 2us, which is a reasonable range
when we assume that a PIT read can easily take 1 us.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/tsc.c |   30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

Index: linux-2.6/arch/x86/kernel/tsc.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/tsc.c
+++ linux-2.6/arch/x86/kernel/tsc.c
@@ -317,15 +317,22 @@ static unsigned long quick_pit_calibrate
 
 	if (pit_expect_msb(0xff)) {
 		int i;
-		u64 t1, t2, delta;
+		u64 t1, t2, t3, delta;
 		unsigned char expect = 0xfe;
+		unsigned long tscmin = ULONG_MAX, tscmax = 0;
 
-		t1 = get_cycles();
+		t1 = t2 = get_cycles();
 		for (i = 0; i < QUICK_PIT_ITERATIONS; i++, expect--) {
 			if (!pit_expect_msb(expect))
 				goto failed;
+			t3 = get_cycles();
+			delta = t3 - t2;
+			t2 = t3;
+			if ((unsigned long) delta < tscmin)
+				tscmin = (unsigned long) delta;
+			if ((unsigned long) delta > tscmax)
+				tscmax = (unsigned long) delta;
 		}
-		t2 = get_cycles();
 
 		/*
 		 * Make sure we can rely on the second TSC timestamp:
@@ -334,6 +341,23 @@ static unsigned long quick_pit_calibrate
 			goto failed;
 
 		/*
+		 * Sanity check the min max values:
+		 *
+		 * We calculate the average tsc increment per loop
+		 * step. Now we take the tscmin and tscmax value and
+		 * check whether the deviation is inside an acceptable
+		 * range.
+		 */
+		delta = (t2 - t1);
+		do_div(delta, QUICK_PIT_ITERATIONS);
+		t3 = (unsigned long) delta;
+		delta = tscmax - tscmin;
+		delta *= 10000;
+		do_div(delta, t3);
+		/* Fail if the deviation is > 2.5 % */
+		if (delta > 250)
+			goto failed;
+		/*
 		 * Ok, if we get here, then we've seen the
 		 * MSB of the PIT decrement QUICK_PIT_ITERATIONS
 		 * times, and each MSB had many hits, so we never

  reply	other threads:[~2009-03-10 22:23 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-23  4:31 Linux 2.6.29-rc6 Linus Torvalds
2009-02-23 14:07 ` Linux 2.6.29-rc6 - Fix oops in i915_gem_retire_requests Karsten Wiese
2009-02-26 11:15 ` Linux 2.6.29-rc6 Jesper Krogh
2009-02-26 17:17   ` MTD_CK804XROM warning (Was: Linux 2.6.29-rc6) Marcin Slusarz
2009-02-26 17:53   ` Linux 2.6.29-rc6 Linus Torvalds
2009-02-26 19:22     ` David Woodhouse
2009-02-26 19:31     ` Jesper Krogh
2009-02-26 19:36       ` David Woodhouse
2009-02-26 19:46         ` Jesper Krogh
2009-02-26 19:49           ` David Woodhouse
2009-02-26 20:53         ` Carl-Daniel Hailfinger
2009-02-26 20:32       ` Linus Torvalds
2009-02-26 19:55 ` Jesper Krogh
2009-02-26 20:33   ` Linus Torvalds
2009-02-26 20:43     ` Jesper Krogh
2009-02-26 21:19       ` john stultz
2009-02-26 21:35         ` Jesper Krogh
2009-02-26 21:46           ` john stultz
2009-02-26 21:54             ` Thomas Gleixner
2009-02-26 22:04               ` Jesper Krogh
2009-02-27  6:30             ` Jesper Krogh
2009-03-01 13:51             ` Jesper Krogh
2009-02-26 21:49           ` Linus Torvalds
2009-03-01 15:04             ` Jesper Krogh
2009-02-26 21:54           ` john stultz
2009-02-26 22:06             ` Thomas Gleixner
2009-02-26 22:24               ` Linus Torvalds
2009-02-26 22:31                 ` Linus Torvalds
2009-02-26 22:31               ` john stultz
2009-02-26 22:40                 ` Linus Torvalds
2009-02-26 22:59                   ` john stultz
2009-02-27  7:33                     ` Ingo Molnar
2009-02-27 20:50                       ` john stultz
2009-02-27  6:47                 ` Jesper Krogh
2009-02-27 20:35                   ` john stultz
2009-03-01 20:13                     ` Jesper Krogh
2009-03-02  9:53                     ` Jesper Krogh
2009-03-02 21:27                       ` john stultz
2009-03-03  6:04                         ` Jesper Krogh
2009-03-03 19:53                           ` john stultz
2009-03-03 20:19                             ` Jesper Krogh
2009-03-03 22:22                               ` john stultz
2009-03-04 15:30                                 ` Jesper Krogh
2009-03-04 18:36                                   ` Jesper Krogh
2009-03-04 18:57                                     ` John Stultz
2009-03-05  2:39                                       ` john stultz
2009-03-05  2:52                                         ` john stultz
2009-03-05  8:43                                           ` Ingo Molnar
2009-03-06  3:13                                             ` john stultz
2009-03-06  3:54                                               ` john stultz
2009-03-06 11:34                                                 ` Ingo Molnar
2009-03-09 20:42                                           ` Jesper Krogh
2009-03-10  4:26                                             ` Linus Torvalds
2009-03-10 11:29                                               ` Thomas Gleixner
2009-03-10 19:42                                                 ` Jesper Krogh
2009-03-10 22:22                                                   ` Thomas Gleixner [this message]
2009-03-15 19:53                                                     ` Jesper Krogh
2009-03-16 18:40                                                       ` Jesper Krogh
2009-03-15  1:19                                             ` Linus Torvalds
2009-03-15 15:44                                               ` Jesper Krogh
2009-03-15 18:09                                                 ` Linus Torvalds
2009-03-15 18:38                                                   ` Jesper Krogh
2009-03-15 19:02                                                     ` Linus Torvalds
2009-03-15 19:52                                                       ` Jesper Krogh
2009-03-16 18:59                                                         ` Jesper Krogh
2009-03-16 19:32                                                           ` Linus Torvalds
2009-03-17  1:43                                                             ` john stultz
2009-03-17  8:14                                                             ` Ingo Molnar
2009-03-17 15:48                                                               ` Linus Torvalds
2009-03-17 16:13                                                                 ` Ingo Molnar
2009-03-17 16:28                                                                   ` Linus Torvalds
2009-03-17 16:40                                                                     ` Ingo Molnar
2009-03-17 17:28                                                                   ` Olivier Galibert
2009-03-21  9:11                                                             ` Jesper Krogh
2009-03-21 10:06                                                               ` Ingo Molnar
2009-03-15 20:32                                                     ` Linus Torvalds
2009-03-03 20:39                             ` Jesper Krogh
2009-03-03 22:16                               ` john stultz
2009-03-04  5:36                                 ` Jesper Krogh
2009-03-01 15:09   ` Jesper Krogh
2009-03-01 15:44     ` Linux 2.6.29-rc6 (clocksource) Sitsofe Wheeler

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.00.0903102107580.29264@localhost.localdomain \
    --to=tglx@linutronix.de \
    --cc=jesper@krogh.cc \
    --cc=johnstul@us.ibm.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).