From: Borislav Petkov <bp@amd64.org>
To: john stultz <johnstul@us.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
Alok Kataria <akataria@vmware.com>,
the arch/x86 maintainers <x86@kernel.org>,
Greg KH <gregkh@suse.de>, "greg@kroah.com" <greg@kroah.com>,
"ksrinivasan@novell.com" <ksrinivasan@novell.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86, tsc: Limit CPU frequency calibration on AMD
Date: Thu, 19 Aug 2010 22:29:15 +0200 [thread overview]
Message-ID: <20100819202915.GA20551@aftab> (raw)
In-Reply-To: <AANLkTimYjqHJDuBg+koGETdFkJkKS7kQ-kK+fF75L0T4@mail.gmail.com>
From: john stultz <johnstul@us.ibm.com>
Date: Thu, Aug 19, 2010 at 02:47:35PM -0400
Hi John,
> On Wed, Aug 18, 2010 at 9:16 AM, Borislav Petkov <bp@amd64.org> wrote:
> > 6b37f5a20c0e5c334c010a587058354215433e92 introduced the CPU frequency
> > calibration code for AMD CPUs whose TSCs didn't increment with the
> > core's P0 frequency. From F10h, revB onward, the TSC increment rate is
> > denoted by MSRC001_0015[24] and when this bit is set (which is normally
> > done by the BIOS,) the TSC increments with the P0 frequency so the
> > calibration is not needed and booting can be a couple of mcecs faster on
> > those machines.
>
> Very cool. This was brought up on an earlier thread and is really nice
> because it also avoids the 50+ppm variability easily seen in the
> calibrate results boot to boot. That variance causes difficulty
> keeping close NTP sync across reboots, as the persistent drift value
> is invalid after a reboot.
>
> I recently proposed a timer based solution that doesn't block bootup,
> and allows for very accurate calibration. This might help fill the
> gaps on legacy systems that do not provide TSC freq information. I'd
> be interested if you had any comments.
>
> https://kerneltrap.org/mailarchive/linux-kernel/2010/7/28/4598868
>
> Notes on the code below.
>
> > Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
> > ---
> > arch/x86/kernel/tsc.c | 14 ++++++++++++--
> > 1 files changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> > index ce8e502..41b2b8b 100644
> > --- a/arch/x86/kernel/tsc.c
> > +++ b/arch/x86/kernel/tsc.c
> > @@ -927,8 +927,18 @@ void __init tsc_init(void)
> > }
> >
> > if (cpu_has(&boot_cpu_data, X86_FEATURE_CONSTANT_TSC) &&
> > - (boot_cpu_data.x86_vendor == X86_VENDOR_AMD))
> > - cpu_khz = calibrate_cpu();
> > + (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)) {
> > +
> > + if (boot_cpu_data.x86 > 0x10 ||
> > + (boot_cpu_data.x86 == 0x10 &&
> > + boot_cpu_data.x86_model >= 0x2)) {
> > + u64 val;
> > +
> > + rdmsrl(MSR_K7_HWCR, val);
> > + if (!(val & BIT(24)))
> > + cpu_khz = calibrate_cpu();
> > + }
> > + }
>
> Am I just missing the point in the code where you actually use the msr
> value to assign cpu_khz? Or is the idea that the default tsc
> calibration already is correct, and we don't need to further refine
> it?
Yes.
Actually Alok brought the code to my attention originally, and what
puzzled me was the fact that we do calibrate_cpu() on all F10h and later
AMD machines needlessly (well, almost all, maybe 99%). This is because,
on F10h, revB machines and later we support "TSC increments with P0
frequency" so what native_calibrate_tsc() comes up with in terms of
tsc_khz should be the same as cpu_khz.
So the MSR bit check above is to see whether the TSC increments with P0
frequency and call calibrate_cpu only if _not_.
As a result, this patch basically drops the additional cpu_khz
calibration when it isn't needed. And as such it doesn't have a whole
lot to do with the actual TSC calibration - this is up to you guys :).
The original reason for the calibrate_cpu() is that there's the
possibility for the TSC to count with the northbridge clockrate and
there we need to recalibrate obviously.
Hope that makes it more clear.
> And yea, the calibrate_cpu function needs to be renamed.
Done, the whole code is moved to cpu/amd.c anyway. I'm currently testing
the new version and will be sending out maybe tomorrow or so.
Thanks.
--
Regards/Gruss,
Boris.
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
next prev parent reply other threads:[~2010-08-19 20:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-16 19:25 [Patch] Skip cpu_calibrate for kernel running under hypervisors Alok Kataria
2010-08-16 23:56 ` H. Peter Anvin
2010-08-17 5:51 ` Alok Kataria
2010-08-17 6:30 ` H. Peter Anvin
2010-08-17 7:05 ` Borislav Petkov
2010-08-17 16:45 ` Alok Kataria
2010-08-17 18:56 ` Borislav Petkov
2010-08-18 16:16 ` [PATCH] x86, tsc: Limit CPU frequency calibration on AMD Borislav Petkov
2010-08-18 16:23 ` H. Peter Anvin
2010-08-18 17:34 ` Borislav Petkov
2010-08-18 17:44 ` H. Peter Anvin
2010-08-18 17:51 ` Alok Kataria
2010-08-18 18:45 ` Borislav Petkov
2010-08-24 15:53 ` [PATCH -v2] " Borislav Petkov
2010-08-24 17:51 ` Alok Kataria
2010-08-24 22:33 ` H. Peter Anvin
2010-08-25 7:06 ` Borislav Petkov
2010-08-25 13:04 ` Andreas Herrmann
2010-08-25 13:39 ` Andreas Herrmann
2010-08-25 16:28 ` [PATCH -v3] x86, tsc: Remove " Borislav Petkov
2010-08-25 21:36 ` [tip:x86/cpu] " tip-bot for Borislav Petkov
2010-08-25 22:33 ` [PATCH -v3] " Alok Kataria
2010-08-26 7:19 ` Borislav Petkov
2010-08-19 18:47 ` [PATCH] x86, tsc: Limit " john stultz
2010-08-19 20:29 ` Borislav Petkov [this message]
2010-08-19 20:52 ` john stultz
2010-08-17 16:48 ` [Patch] Skip cpu_calibrate for kernel running under hypervisors Alok Kataria
2010-08-17 16:49 ` H. Peter Anvin
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=20100819202915.GA20551@aftab \
--to=bp@amd64.org \
--cc=akataria@vmware.com \
--cc=bp@alien8.de \
--cc=greg@kroah.com \
--cc=gregkh@suse.de \
--cc=hpa@zytor.com \
--cc=johnstul@us.ibm.com \
--cc=ksrinivasan@novell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.