linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration
@ 2020-01-23 16:09 Krzysztof Piecuch
  2020-01-30 19:10 ` Krzysztof Piecuch
  0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Piecuch @ 2020-01-23 16:09 UTC (permalink / raw)
  To: linux-kernel\@vger.kernel.org
  Cc: tglx, mingo\@redhat.com, bp\@alien8.de, hpa\@zytor.com,
	x86\@kernel.org, rafael.j.wysocki\@intel.com,
	drake\@endlessm.com, viresh.kumar\@linaro.org,
	juri.lelli\@redhat.com, Peter Zijlstra, mzhivich\@akamai.com,
	malat\@debian.org, piecuch

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration
  2020-01-23 16:09 [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration Krzysztof Piecuch
@ 2020-01-30 19:10 ` Krzysztof Piecuch
  2020-02-01 20:52   ` Thomas Gleixner
  0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Piecuch @ 2020-01-30 19:10 UTC (permalink / raw)
  To: linux-kernel\@vger.kernel.org
  Cc: tglx, mingo\@redhat.com, bp\@alien8.de, hpa\@zytor.com,
	x86\@kernel.org, rafael.j.wysocki\@intel.com,
	drake\@endlessm.com, viresh.kumar\@linaro.org,
	juri.lelli\@redhat.com, Peter Zijlstra, mzhivich\@akamai.com,
	malat\@debian.org, piecuch

Can I please have some feedback on this patch?


Kind regards,
Krzysztof Piecuch


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration
  2020-01-30 19:10 ` Krzysztof Piecuch
@ 2020-02-01 20:52   ` Thomas Gleixner
  2020-05-21 14:42     ` Krzysztof Piecuch
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2020-02-01 20:52 UTC (permalink / raw)
  To: Krzysztof Piecuch, linux-kernel\@vger.kernel.org
  Cc: mingo\@redhat.com, bp\@alien8.de, hpa\@zytor.com,
	x86\@kernel.org, rafael.j.wysocki\@intel.com,
	drake\@endlessm.com, viresh.kumar\@linaro.org,
	juri.lelli\@redhat.com, Peter Zijlstra, mzhivich\@akamai.com,
	malat\@debian.org, piecuch

Krzysztof Piecuch <piecuch@protonmail.com> writes:

> Can I please have some feedback on this patch?

It's in my backlog and todo list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration
  2020-02-01 20:52   ` Thomas Gleixner
@ 2020-05-21 14:42     ` Krzysztof Piecuch
  0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Piecuch @ 2020-05-21 14:42 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel\\\@vger.kernel.org, mingo\\\@redhat.com,
	bp\\\@alien8.de, hpa\\\@zytor.com, x86\\\@kernel.org,
	rafael.j.wysocki\\\@intel.com, drake\\\@endlessm.com,
	viresh.kumar\\\@linaro.org, juri.lelli\\\@redhat.com,
	Peter Zijlstra, mzhivich\\\@akamai.com, malat\\\@debian.org

On Saturday, February 1, 2020 8:52 PM, Thomas Gleixner <tglx@linutronix.de> wrote:
> It's in my backlog and todo list

Hi, I just wanted to check if there's an ETA on this?

Thanks,
Krzysztof Piecuch

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-21 14:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-23 16:09 [PATCH] x86/tsc: Add tsc_early_khz command line parameter overriding early TSC calibration Krzysztof Piecuch
2020-01-30 19:10 ` Krzysztof Piecuch
2020-02-01 20:52   ` Thomas Gleixner
2020-05-21 14:42     ` Krzysztof Piecuch

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