From: "Jan H. Schönherr" <jan@schnhrr.de>
To: Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
x86@kernel.org
Cc: "Jan H. Schönherr" <jan@schnhrr.de>,
"Paul Menzel" <pmenzel@molgen.mpg.de>,
"Thomas Lendacky" <Thomas.Lendacky@amd.com>,
"H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] cpu/hotplug: Unfreeze sibling CPU first on resume from S3
Date: Tue, 29 Jan 2019 11:23:29 +0100 [thread overview]
Message-ID: <20190129102329.27610-3-jan@schnhrr.de> (raw)
In-Reply-To: <20190129102329.27610-1-jan@schnhrr.de>
At least one system declares the TSC unstable after resume from S3,
because the TSC is observed going backwards up to roughly 500 cycles
every now and then, when bringing secondary CPUs back online.
The system in question is an AMD Ryzen Threadripper 2950X, microcode
0x800820b, on an ASRock Fatal1ty X399 Professional Gaming, BIOS P3.30.
This unexplained behavior goes away as soon as the sibling CPU of the
boot CPU is brought back up. Hence, add a hack to restore the sibling
CPU before all others on unfreeze. This keeps the TSC stable.
Signed-off-by: Jan H. Schönherr <jan@schnhrr.de>
---
kernel/cpu.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 91d5c38eb7e5..7097ee8c1b17 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1193,6 +1193,7 @@ EXPORT_SYMBOL_GPL(cpu_up);
#ifdef CONFIG_PM_SLEEP_SMP
static cpumask_var_t frozen_cpus;
+static int frozen_primary_sibling;
int freeze_secondary_cpus(int primary)
{
@@ -1211,6 +1212,8 @@ int freeze_secondary_cpus(int primary)
for_each_online_cpu(cpu) {
if (cpu == primary)
continue;
+ if (cpumask_test_cpu(cpu, topology_sibling_cpumask(primary)))
+ frozen_primary_sibling = cpu;
trace_suspend_resume(TPS("CPU_OFF"), cpu, true);
error = _cpu_down(cpu, 1, CPUHP_OFFLINE);
trace_suspend_resume(TPS("CPU_OFF"), cpu, false);
@@ -1246,9 +1249,23 @@ void __weak arch_enable_nonboot_cpus_end(void)
{
}
+static void enable_nonboot_cpu(int cpu)
+{
+ int error;
+
+ trace_suspend_resume(TPS("CPU_ON"), cpu, true);
+ error = _cpu_up(cpu, 1, CPUHP_ONLINE);
+ trace_suspend_resume(TPS("CPU_ON"), cpu, false);
+ if (!error) {
+ pr_info("CPU%d is up\n", cpu);
+ return;
+ }
+ pr_warn("Error taking CPU%d up: %d\n", cpu, error);
+}
+
void enable_nonboot_cpus(void)
{
- int cpu, error;
+ int cpu;
/* Allow everyone to use the CPU hotplug again */
cpu_maps_update_begin();
@@ -1260,16 +1277,13 @@ void enable_nonboot_cpus(void)
arch_enable_nonboot_cpus_begin();
- for_each_cpu(cpu, frozen_cpus) {
- trace_suspend_resume(TPS("CPU_ON"), cpu, true);
- error = _cpu_up(cpu, 1, CPUHP_ONLINE);
- trace_suspend_resume(TPS("CPU_ON"), cpu, false);
- if (!error) {
- pr_info("CPU%d is up\n", cpu);
- continue;
- }
- pr_warn("Error taking CPU%d up: %d\n", cpu, error);
+ cpu = frozen_primary_sibling;
+ if (cpumask_test_cpu(cpu, frozen_cpus)) {
+ enable_nonboot_cpu(cpu);
+ cpumask_clear_cpu(cpu, frozen_cpus);
}
+ for_each_cpu(cpu, frozen_cpus)
+ enable_nonboot_cpu(cpu);
arch_enable_nonboot_cpus_end();
--
2.19.2
next prev parent reply other threads:[~2019-01-29 10:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-29 10:23 [PATCH 0/2] Fix TSC issues on (some) AMD Ryzen based systems Jan H. Schönherr
2019-01-29 10:23 ` [PATCH 1/2] x86/tsc: Allow quick PIT calibration despite interruptions Jan H. Schönherr
[not found] ` <5C50558B.8060405@schnhrr.de>
2019-01-29 22:28 ` Thomas Gleixner
2019-02-12 11:57 ` Thomas Gleixner
2019-02-14 21:48 ` Jan H. Schönherr
2019-01-29 10:23 ` Jan H. Schönherr [this message]
2019-01-29 23:02 ` [PATCH 2/2] cpu/hotplug: Unfreeze sibling CPU first on resume from S3 Thomas Gleixner
2019-01-29 19:33 ` [PATCH 0/2] Fix TSC issues on (some) AMD Ryzen based systems Paul Menzel
2019-01-29 19:37 ` Paul Menzel
2019-01-29 22:31 ` Thomas Gleixner
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=20190129102329.27610-3-jan@schnhrr.de \
--to=jan@schnhrr.de \
--cc=Thomas.Lendacky@amd.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pmenzel@molgen.mpg.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®