linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Piecuch <piecuch@protonmail.com>
To: "linux-kernel\\@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo\\@redhat.com" <mingo@redhat.com>,
	"bp\\@alien8.de" <bp@alien8.de>,
	"hpa\\@zytor.com" <hpa@zytor.com>,
	"x86\\@kernel.org" <x86@kernel.org>,
	"rafael.j.wysocki\\@intel.com" <rafael.j.wysocki@intel.com>,
	"drake\\@endlessm.com" <drake@endlessm.com>,
	"viresh.kumar\\@linaro.org" <viresh.kumar@linaro.org>,
	"juri.lelli\\@redhat.com" <juri.lelli@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	"mzhivich\\@akamai.com" <mzhivich@akamai.com>,
	"malat\\@debian.org" <malat@debian.org>,
	"piecuch@protonmail.com" <piecuch@protonmail.com>
Subject: [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration
Date: Thu, 23 Jan 2020 16:09:26 +0000	[thread overview]
Message-ID: <O2CpIOrqLZHgNRkfjRpz_LGqnc1ix_seNIiOCvHY4RHoulOVRo6kMXKuLOfBVTi0SMMevg6Go1uZ_cL9fLYtYdTRNH78ChaFaZyG3VAyYz8=@protonmail.com> (raw)

Changing base clock frequency directly impacts TSC Hz but not CPUID.16h
value. An overclocked CPU supporting CPUID.16h and with partial CPUID.15h
support will set TSC Hz according to "best guess" given by CPUID.16h
relying on tsc_refine_calibration_work to give better numbers later.
tsc_refine_calibration_work will refuse to do its work when the outcome is
off the early TSC Hz value by more than 1% which is certain to happen
on an overclocked system.

Fix this by adding a tsc_early_khz command line parameter that makes the
kernel skip early TSC calibration and use the given value instead.
This allows the user to provide the expected TSC frequency that is closer
to reality than the one reported by the hardware, enabling
tsc_refine_calibration_work to do meaningful error checking.

Signed-off-by: Krzysztof Piecuch <piecuch@protonmail.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  6 ++++++
 arch/x86/kernel/tsc.c                           | 16 +++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index ade4e6ec23e0..28646ea99549 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4905,6 +4905,12 @@
 			interruptions from clocksource watchdog are not
 			acceptable).

+	tsc_early_khz=  [X86] Skip early TSC calibration and use the given
+			value instead. Useful when the early TSC frequency discovery
+			procedure is not reliable, such as on overclocked systems
+			with CPUID.16h support and partial CPUID.15h support.
+			Format: <unsigned int>
+
 	tsx=		[X86] Control Transactional Synchronization
 			Extensions (TSX) feature in Intel processors that
 			support TSX control.
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 7e322e2daaf5..9566a50f9fdb 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -41,6 +41,7 @@ EXPORT_SYMBOL(tsc_khz);
  * TSC can be unstable due to cpufreq or due to unsynced TSCs
  */
 static int __read_mostly tsc_unstable;
+static unsigned int __read_mostly tsc_early_khz;

 static DEFINE_STATIC_KEY_FALSE(__use_tsc);

@@ -59,6 +60,16 @@ struct cyc2ns {

 static DEFINE_PER_CPU_ALIGNED(struct cyc2ns, cyc2ns);

+static int __init tsc_early_khz_setup(char *buf)
+{
+	int err = kstrtouint(buf, 0, &tsc_early_khz);
+
+	if (err)
+		tsc_early_khz = 0;
+	return err;
+}
+early_param("tsc_early_khz", tsc_early_khz_setup);
+
 __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data)
 {
 	int seq, idx;
@@ -1404,7 +1415,10 @@ static bool __init determine_cpu_tsc_frequencies(bool early)

 	if (early) {
 		cpu_khz = x86_platform.calibrate_cpu();
-		tsc_khz = x86_platform.calibrate_tsc();
+		if (tsc_early_khz)
+			tsc_khz = tsc_early_khz;
+		else
+			tsc_khz = x86_platform.calibrate_tsc();
 	} else {
 		/* We should not be here with non-native cpu calibration */
 		WARN_ON(x86_platform.calibrate_cpu != native_calibrate_cpu);
--
2.17.1


             reply	other threads:[~2020-01-23 16:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23 16:09 Krzysztof Piecuch [this message]
2020-01-30 19:10 ` Krzysztof Piecuch
2020-02-01 20:52   ` Thomas Gleixner
2020-05-21 14:42     ` Krzysztof Piecuch

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='O2CpIOrqLZHgNRkfjRpz_LGqnc1ix_seNIiOCvHY4RHoulOVRo6kMXKuLOfBVTi0SMMevg6Go1uZ_cL9fLYtYdTRNH78ChaFaZyG3VAyYz8=@protonmail.com' \
    --to=piecuch@protonmail.com \
    --cc=bp@alien8.de \
    --cc=drake@endlessm.com \
    --cc=hpa@zytor.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=malat@debian.org \
    --cc=mingo@redhat.com \
    --cc=mzhivich@akamai.com \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.org \
    --cc=x86@kernel.org \
    --subject='Re: [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration' \
    /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

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).