From: Thomas Gleixner <tglx@linutronix.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alok Kataria <akataria@vmware.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
LKML <linux-kernel@vger.kernel.org>,
Arjan van de Veen <arjan@infradead.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Dan Hecht <dhecht@vmware.com>, Garrett Smith <garrett@vmware.com>
Subject: Re: [RFC patch 0/4] TSC calibration improvements
Date: Sat, 6 Sep 2008 22:03:04 +0200 (CEST) [thread overview]
Message-ID: <alpine.LFD.1.10.0809061803470.3243@apollo.tec.linutronix.de> (raw)
In-Reply-To: <alpine.LFD.1.10.0809051522410.3117@nehalem.linux-foundation.org>
On Fri, 5 Sep 2008, Linus Torvalds wrote:
> On Fri, 5 Sep 2008, Alok Kataria wrote:
> >
> > This can happen if, in the pit_expect_msb (the one just before the
> > second read_tsc), we hit an SMI/virtualization event *after* doing the
> > 50 iterations of PIT read loop, this allows the pit_expect_msb to
> > succeed when the SMI returns.
>
> So theoretically, on real hardware, the minimum of 50 reads will take
> 100us. The 256 PTI cycles will take 214us, so in the absolute worst case,
> you can have two consecutive successful cycles despite having a 228us SMI
> (or other event) if it happens just in the middle.
I just ran your patch in a loop on the SMI mephitic laptop with random
delays between the loops.
20 out of 10000 results are between 2200 and 8400Mhz while the CPU
still runs @2GHz.
And it also happened in an automated boot/reboot cycle (no extra loop)
once out of 50.
So the SMI hit exactly:
+ t1 = get_cycles();
+ for (expect = 0xfe, i = 0; i < QUICK_PIT_ITERATIONS; i++, expect--) {
+ if (!pit_expect_msb(expect))
+ goto failed;
+ }
-----> HERE
+ t2 = get_cycles();
The SMIs on that machine take between 500us and 100+ms according to my
instrumentation experiments: http://lkml.org/lkml/2008/9/2/202
Adding another check after the second get_cycles() makes it reliable:
+ t1 = get_cycles();
+ for (expect = 0xfe, i = 0; i < QUICK_PIT_ITERATIONS; i++) {
+ if (!pit_expect_msb(expect--))
+ goto failed;
+ }
+ t2 = get_cycles();
+
+ if (!pit_expect_msb(expect))
+ goto failed;
That solves the problem on that box and will detect any virtualization
delay as well. I just had to move out the "expect--" from the for() as
gcc is overly clever.
> Of course, then the actual _error_ on the TSC read will be just half that,
> but since there are two TSC reads - one at the beginning and one at the
> end - and if the errors of the two reads go in opposite directions, they
> can add up to 228us.
>
> So I agree - in theory you can have a fairly big error if you hit
> everything just right. In practice, of course, even that *maximal* error
> is actually perfectly fine for TSC calibration.
The above _maximal_ error of 400% is not perfectly fine at all.
> So I just don't care one whit. The fact is, fast bootup is more important
> than some crazy and totally unrealistic VM situation. The 50ms thing was
> already too long, the 250ms one is unbearable.
True. You applied a first draft of my patch right away from mail. It
was the accumulated findings of my detective work on various wreckaged
hardware.
The follow up patches I sent (http://lkml.org/lkml/2008/9/4/254),
bring it down to 10ms in the good and 30ms in the worst case with the
option for 50ms in the last round to make the virtualized/emulated
stuff happy. With that I have not seen any wrong result on any of my
jinxed boxen so far and it works very reliable on virtualized
environments as well.
Combining them with your fast calibration should be a solid and
reasonable fast solution in all corner cases.
Ingo put them into the -tip tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git x86/tsc
Thanks,
tglx
next prev parent reply other threads:[~2008-09-06 20:03 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-04 15:18 Thomas Gleixner
2008-09-04 15:18 ` [RFC patch 1/4] x86: TSC: define the PIT latch value separate Thomas Gleixner
2008-09-04 15:18 ` [RFC patch 2/4] x86: TSC: separate hpet/pmtimer calculation out Thomas Gleixner
2008-09-04 15:18 ` [RFC patch 3/4] x86: TSC: use one set of reference variables Thomas Gleixner
2008-09-04 15:18 ` [RFC patch 4/4] x86: TSC make the calibration loop smarter Thomas Gleixner
2008-09-04 15:36 ` [RFC patch 0/4] TSC calibration improvements Ingo Molnar
2008-09-04 15:45 ` Linus Torvalds
2008-09-04 16:00 ` Ingo Molnar
2008-09-04 16:21 ` Linus Torvalds
2008-09-04 16:36 ` Ingo Molnar
2008-09-04 17:41 ` Linus Torvalds
2008-09-04 18:07 ` Alan Cox
2008-09-04 18:26 ` Linus Torvalds
2008-09-04 18:30 ` H. Peter Anvin
2008-09-04 20:09 ` Linus Torvalds
2008-09-04 20:43 ` Ingo Molnar
2008-09-04 20:52 ` Ingo Molnar
2008-09-04 21:09 ` Linus Torvalds
2008-09-04 21:21 ` Ingo Molnar
2008-09-04 21:30 ` Linus Torvalds
2008-09-04 21:34 ` Linus Torvalds
2008-09-04 21:39 ` Ingo Molnar
2008-09-04 21:33 ` Ingo Molnar
2008-09-05 22:18 ` Alok Kataria
2008-09-05 22:34 ` Linus Torvalds
2008-09-06 20:03 ` Thomas Gleixner [this message]
2008-09-06 20:29 ` Linus Torvalds
2008-09-06 20:37 ` Thomas Gleixner
2008-09-06 20:50 ` Linus Torvalds
2008-09-06 20:55 ` Linus Torvalds
2008-09-06 21:15 ` Thomas Gleixner
2008-09-06 21:22 ` Linus Torvalds
2008-09-06 21:30 ` Thomas Gleixner
2008-09-06 22:40 ` Ingo Molnar
2008-09-06 20:58 ` Thomas Gleixner
2008-09-06 21:10 ` Linus Torvalds
2008-09-07 6:01 ` Willy Tarreau
2008-09-06 20:52 ` Thomas Gleixner
2008-09-06 20:59 ` Linus Torvalds
2008-09-06 21:07 ` Thomas Gleixner
2008-09-06 21:15 ` Linus Torvalds
2008-09-06 21:26 ` Thomas Gleixner
2008-09-06 21:32 ` Linus Torvalds
2008-09-04 20:53 ` Linus Torvalds
2008-09-04 21:38 ` Alok Kataria
2008-09-04 21:52 ` Linus Torvalds
2008-09-04 22:09 ` Alok Kataria
2008-09-04 17:39 ` Alok Kataria
2008-09-04 17:53 ` Linus Torvalds
2008-09-04 18:31 ` Alok Kataria
2008-09-04 18:34 ` H. Peter Anvin
2008-09-04 21:00 ` Valdis.Kletnieks
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.1.10.0809061803470.3243@apollo.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=a.p.zijlstra@chello.nl \
--cc=akataria@vmware.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjan@infradead.org \
--cc=dhecht@vmware.com \
--cc=garrett@vmware.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®