From: Ingo Molnar <mingo@elte.hu>
To: john stultz <johnstul@us.ibm.com>
Cc: Jesper Krogh <jesper@krogh.cc>,
Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Len Brown <len.brown@intel.com>
Subject: Re: Linux 2.6.29-rc6
Date: Fri, 6 Mar 2009 12:34:51 +0100 [thread overview]
Message-ID: <20090306113451.GA18798@elte.hu> (raw)
In-Reply-To: <1236311641.7766.260.camel@localhost.localdomain>
* john stultz <johnstul@us.ibm.com> wrote:
> On Thu, 2009-03-05 at 19:13 -0800, john stultz wrote:
> > On Thu, 2009-03-05 at 09:43 +0100, Ingo Molnar wrote:
> > > * john stultz <johnstul@us.ibm.com> wrote:
> > >
> > > > > Ingo, Thomas: On the hardware I'm testing the fast-pit
> > > > > calibration only triggers probably 80-90% of the time. About
> > > > > 10-20% of the time, the initial check to
> > > > > pit_expect_msb(0xff) fails (count=0), so we may need to look
> > > > > more at this approach.
> > >
> > > We definitely need to improve calibration quality.
> > >
> > > The question is - why does fast-calibration fail 10-20% of the
> > > time on your test-system? Also, why exactly do we miscalibrate?
> > > Could you please have a look at that?
> >
> > Working on it, I just wanted to let you know I was seeing some different
> > odd behavior then Jesper.
> >
> > > One theory would be that the PIT readout is unreliable. Windows
> > > does not make use of it, so it's not the most tested aspect of
> > > the PIT. Is that what happens on your box?
> >
> > Still looking into it, but from my initial debugging it seems that by
> > reading the PIT very quickly after setting it, we may be getting junk
> > values. If I re-read the PIT again, I see the expected 0xff value.
> >
> > Its been somewhat of a heisenbug, as if I add any printk's or even just
> > a mb() after the outb it seems to make the problem go away (or just rare
> > enough I don't have the patience to reproduce it :)
> >
> > So I don't know if a small delay is appropriate here (seems counter
> > productive to the whole fast-pit calibration ;) or if we should just try
> > to catch these bad reads and try again before failing?
>
> Maybe something like the following? (Not tested heavily yet!)
>
> Again, just for clarity, as we've mixed a few issues here, this patch is
> for a side issue and not related to the original regression reported by
> Jesper. I'm still waiting on debug output from Jesper to further
> diagnose whats going wrong with his TSC calibration.
>
> thanks
> -john
>
>
> Apparently some hardware may occasionally return junk values if you try
> to read the pit immediately after setting it. This causes the
> pit_expect_msb() to occasionally fail (~10% of the time).
>
> This patch tries to work around this issue by not failing if the first
> read right after setting the PIT is not what we expect.
>
> NOT FOR INCLUSION (yet!)
>
> Signed-off-by: John Stultz <johnstul@us.ibm.com>
>
> diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> index 599e581..2ca5ba4 100644
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -280,8 +280,17 @@ static inline int pit_expect_msb(unsigned char val)
> for (count = 0; count < 50000; count++) {
> /* Ignore LSB */
> inb(0x42);
> - if (inb(0x42) != val)
> + if (inb(0x42) != val) {
> + /*
> + * If we're too fast, we may read
> + * junk values right after we set
> + * the PIT. So if this is the first
> + * read, try again
> + */
> + if (val == 0xff && count == 0)
> + continue;
> break;
We could do something like that if it helps the end result. But
this special thing inside the loop should just be an
unconditional inb(0x42) outside the loop. It does not hurt
performance there, and we'll get simpler code that way.
But ... i really dont like how we rely on PIT readouts and how
we work around PIT readout artifacts. Only Linux does PIT
readouts while Windows does not - so we rely on a under-tested
aspect of PC hardware.
I think we should think about a fundamentally different, IRQ
driven way of calibration. For example we could program a 27
milliseconds PIT periodic interrupt with the maximum count and
measure its arrival timestamp in two subsequent interrupts.
We could do that with about 1-2 usecs precision realistically
(this early during bootup we are really quiescent) - and over a
27,000 usecs period that gives us an accuracy of 1:13500, or
about 75 ppm. That's still only about 50 milliseconds spent
calibrating, so very fast.
We can re-write the IRQ#0 vector with a special temporary
calibration interrupt handler to make this really single-purpose
and precise.
Hm?
Ingo
next prev parent reply other threads:[~2009-03-06 11:35 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 [this message]
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
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=20090306113451.GA18798@elte.hu \
--to=mingo@elte.hu \
--cc=jesper@krogh.cc \
--cc=johnstul@us.ibm.com \
--cc=len.brown@intel.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