Skip to contentSkip to conversation

x86, CPU: Restore MSR_IA32_ENERGY_PERF_BIAS after resume

PATCH New Laura Abbott 2 participants 2 messages Jul 20, 2015 – Jul 21, 2015 x86

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 x86, CPU: Restore MSR_IA32_ENERGY_PERF_BIAS after resume

MSR_IA32_ENERGY_PERF_BIAS is lost after suspend/resume:

x86_energy_perf_policy -r before

cpu0: 0x0000000000000006
cpu1: 0x0000000000000006
cpu2: 0x0000000000000006
cpu3: 0x0000000000000006
cpu4: 0x0000000000000006
cpu5: 0x0000000000000006
cpu6: 0x0000000000000006
cpu7: 0x0000000000000006

after

cpu0: 0x0000000000000000
cpu1: 0x0000000000000006
cpu2: 0x0000000000000006
cpu3: 0x0000000000000006
cpu4: 0x0000000000000006
cpu5: 0x0000000000000006
cpu6: 0x0000000000000006
cpu7: 0x0000000000000006

This register is set via init_intel at bootup. During resume, the secondary CPUs are brought online again and init_intel is callled which re-initializes the register. The boot cpu however never reinitializes the register. Add a syscore callback to reinitialize the register for the boot CPU.

---
v3: Minor code cleanup in init_intel_energy_perf, added intel_bsp_resume to make it more obvious what's happening.

v2: Tweaked a few names to be more descriptive

---
 arch/x86/kernel/cpu/common.c | 18 +++++++++++++++++
 arch/x86/kernel/cpu/cpu.h    |  1 +
 arch/x86/kernel/cpu/intel.c  | 47 ++++++++++++++++++++++++++++++--------------
 3 files changed, 51 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/common.c +18 -0
index 922c5e0..fa95bb8 100644
@@ -13,6 +13,7 @@
 #include <linux/kgdb.h>
 #include <linux/smp.h>
 #include <linux/io.h>
+#include <linux/syscore_ops.h>
 
 #include <asm/stackprotector.h>
 #include <asm/perf_event.h>
@@ -1488,3 +1489,20 @@ inline bool __static_cpu_has_safe(u16 bit)
 	return boot_cpu_has(bit);
 }
 EXPORT_SYMBOL_GPL(__static_cpu_has_safe);
+
+static void bsp_resume(void)
+{
+	if (this_cpu->c_bsp_resume)
+		this_cpu->c_bsp_resume(&boot_cpu_data);
+}
+
+static struct syscore_ops cpu_syscore_ops = {
+	.resume		= bsp_resume,
+};
+
+static int __init init_cpu_syscore(void)
+{
+	register_syscore_ops(&cpu_syscore_ops);
+	return 0;
+}
+core_initcall(init_cpu_syscore);
arch/x86/kernel/cpu/cpu.h +1 -0
index c37dc37..2584265 100644
@@ -13,6 +13,7 @@ struct cpu_dev {
 	void		(*c_init)(struct cpuinfo_x86 *);
 	void		(*c_identify)(struct cpuinfo_x86 *);
 	void		(*c_detect_tlb)(struct cpuinfo_x86 *);
+	void		(*c_bsp_resume)(struct cpuinfo_x86 *);
 	int		c_x86_vendor;
 #ifdef CONFIG_X86_32
 	/* Optional vendor specific routine to obtain the cache size. */
arch/x86/kernel/cpu/intel.c +32 -15

65 lines not on this page · raw message

Signature · 1 line
2.4.3
#1 lore raw

[tip:x86/cpu] x86/cpu: Restore MSR_IA32_ENERGY_PERF_BIAS after resume

x86/cpu: Restore MSR_IA32_ENERGY_PERF_BIAS after resume
Commit-ID:  b51ef52df71cb28e9d90cd1d48b79bf19f0bab06
Gitweb:     http://git.kernel.org/tip/b51ef52df71cb28e9d90cd1d48b79bf19f0bab06
Author:     Laura Abbott <[email protected]>
AuthorDate: Mon, 20 Jul 2015 14:47:58 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 21 Jul 2015 07:51:38 +0200

x86/cpu: Restore MSR_IA32_ENERGY_PERF_BIAS after resume

MSR_IA32_ENERGY_PERF_BIAS is lost after suspend/resume:

	x86_energy_perf_policy -r before

	cpu0: 0x0000000000000006
	cpu1: 0x0000000000000006
	cpu2: 0x0000000000000006
	cpu3: 0x0000000000000006
	cpu4: 0x0000000000000006
	cpu5: 0x0000000000000006
	cpu6: 0x0000000000000006
	cpu7: 0x0000000000000006

	after

	cpu0: 0x0000000000000000
	cpu1: 0x0000000000000006
	cpu2: 0x0000000000000006
	cpu3: 0x0000000000000006
	cpu4: 0x0000000000000006
	cpu5: 0x0000000000000006
	cpu6: 0x0000000000000006
	cpu7: 0x0000000000000006

Resulting in inconsistent energy policy settings across CPUs.

This register is set via init_intel() at bootup. During resume, the secondary CPUs are brought online again and init_intel() is callled which re-initializes the register. The boot CPU however never reinitializes the register.

Add a syscore callback to reinitialize the register for the boot CPU.

---
 arch/x86/kernel/cpu/common.c | 18 +++++++++++++++++
 arch/x86/kernel/cpu/cpu.h    |  1 +
 arch/x86/kernel/cpu/intel.c  | 47 ++++++++++++++++++++++++++++++--------------
 3 files changed, 51 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/common.c +18 -0
index 922c5e0..fa95bb8 100644
@@ -13,6 +13,7 @@
 #include <linux/kgdb.h>
 #include <linux/smp.h>
 #include <linux/io.h>
+#include <linux/syscore_ops.h>
 
 #include <asm/stackprotector.h>
 #include <asm/perf_event.h>
@@ -1488,3 +1489,20 @@ inline bool __static_cpu_has_safe(u16 bit)
 	return boot_cpu_has(bit);
 }
 EXPORT_SYMBOL_GPL(__static_cpu_has_safe);
+
+static void bsp_resume(void)
+{
+	if (this_cpu->c_bsp_resume)
+		this_cpu->c_bsp_resume(&boot_cpu_data);
+}
+
+static struct syscore_ops cpu_syscore_ops = {
+	.resume		= bsp_resume,
+};
+
+static int __init init_cpu_syscore(void)
+{
+	register_syscore_ops(&cpu_syscore_ops);
+	return 0;
+}
+core_initcall(init_cpu_syscore);
arch/x86/kernel/cpu/cpu.h +1 -0
index c37dc37..2584265 100644
@@ -13,6 +13,7 @@ struct cpu_dev {
 	void		(*c_init)(struct cpuinfo_x86 *);
 	void		(*c_identify)(struct cpuinfo_x86 *);
 	void		(*c_detect_tlb)(struct cpuinfo_x86 *);
+	void		(*c_bsp_resume)(struct cpuinfo_x86 *);
 	int		c_x86_vendor;
 #ifdef CONFIG_X86_32
 	/* Optional vendor specific routine to obtain the cache size. */
arch/x86/kernel/cpu/intel.c +32 -15

65 lines not on this page · raw message