public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alok Kataria <akataria@vmware.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Thomas Gleixner <tglx@linutronix.de>,
	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: Fri, 05 Sep 2008 15:18:15 -0700	[thread overview]
Message-ID: <1220653095.14401.72.camel@alok-dev1> (raw)
In-Reply-To: <20080904213350.GA15678@elte.hu>

On Thu, 2008-09-04 at 14:33 -0700, Ingo Molnar wrote:
> * Linus Torvalds <torvalds@linux-foundation.org> wrote:
> 
> > On Thu, 4 Sep 2008, Ingo Molnar wrote:
> > >
> > > hm, unless i'm missing something i think here we still have a small
> > > window for an SMI or some virtualization delay to slip in and cause
> > > massive inaccuracy: if the delay happens _after_ the last
> > > pit_expect_msb() and _before_ the external get_cycles() call. Right?
> >
> > Yes. I had the extra pit_expect_msb() originally, but decided that
> > basically a single-instruction race for somethign that ran without any
> > MSI for 15ms was a bit pointless.
> 
> the race is wider than that i think: all it takes an SMI at the last PIO
> access, so the window should be 1 usec, against a 15000 usecs period.
> That's 1 out of 15,000 boxes coming up with totally incorrect
> calibration.
> 
> we also might have a very theoretical race of an SMI taking exactly 65
> msecs so that the whole PIT wraps around and fools the fastpath - the
> chance for that would be around 1:300 - assuming we only have to hit the
> right MSB with a ~200 usecs precision). That assumes equal distribution
> of SMI costs which they certainly dont have - most of them are much less
> than 60 msecs. So i dont think it's an issue in practice - on real hw.
> 
> But it's still a possibility unless i'm missing something. We could
> protect against that case by reading the IRQ0-pending bit and making
> sure it's not pending after we have done the closing TSC readout.
> 
> > But adding another pit_expect_msb() is certainly not wrong.
> 

Hi, 
I ran the current tree with these patches on my VM setup for both 32 &
64bit around 200 reboots each. 
The system entered the FAST calibration mode more often this time,
around 25% of time.
And i had an interesting case where in the frequency that was calibrated
was 1875Mhz compared to actual ~1866Mhz, leaving an error of 0.5%.

Now, looking at the code.
Even with this last pit_expect_msb check, i think there can be a case
when a error spanning 114usec can slip in the TSC calculation. 

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.

If this SMI/Virtualization event spans across the next PIT MSB increment
interval leaving sufficient time (100us) for the last pit_expect_msb to
succeed.
We can have a error of 1MSB tick increment - time taken for the last
pit_expect_msb to succeed, in the read TSC value.

i.e. a error of (214us - 100us) in the 15msec period, i.e. error of
7600PPM ??

And, in order for the TSC clocksource to keep correct time (on systems
where the TSC clocksource is usable), the TSC frequency estimate must be
within 500 ppm of its true frequency, otherwise NTP will not be able to
correct it.

So, IMHO we should not use this algorithm. 

I don't know if increasing the count threshold will help too, since that
threshold value may fail for some system which perform better than our
assumption of "we take 2us to do the 2 PIT reads". Atleast in
virtualized environment I can make no such guarantees. 

Thanks,
Alok

> ok, i kept that bit.
> 
>         Ingo


  reply	other threads:[~2008-09-05 22:18 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-04 15:18 [RFC patch 0/4] TSC calibration improvements 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 [this message]
2008-09-05 22:34                           ` Linus Torvalds
2008-09-06 20:03                             ` Thomas Gleixner
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=1220653095.14401.72.camel@alok-dev1 \
    --to=akataria@vmware.com \
    --cc=a.p.zijlstra@chello.nl \
    --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=tglx@linutronix.de \
    --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