Skip to contentSkip to conversation

x86, suspend: Save/restore THERM_CONTROL register for suspend

PATCH Superseded Chen Yu 3 participants 8 messages Aug 17, 2015 – Aug 18, 2015

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chen Yu

author
#0 lore raw

PATCH 1/1 x86, suspend: Save/restore THERM_CONTROL register for suspend

A bug is reported(https://bugzilla.redhat.com/show_bug.cgi?id=1227208) that, after resuming from S3, CPU is working at a low speed. After investigation, it is found that, BIOS has modified the value of THERM_CONTROL register during S3, changes it from 0 to 0x10, while the latter means CPU can only get 25% of the Duty Cycle, and this caused the problem.

Simple scenario to reproduce:
1.Boot up system
2.Get MSR with address 0x19a, it should output 0
3.Put system into sleep, then wake up
4.Get MSR with address 0x19a, it should output 0(actual it outputs 0x10)

Although this is a BIOS issue, it would be more robust for linux to deal with this situation. This patch fixes this issue by saving/restoring THERM_CONTROL(now called CLOCK_MODULATION) register on suspend/resume.

---
 arch/x86/include/asm/suspend_64.h | 1 +
 arch/x86/power/cpu.c              | 2 ++
 2 files changed, 3 insertions(+)
arch/x86/include/asm/suspend_64.h +1 -0
index 7ebf0eb..b9f5591 100644
@@ -25,6 +25,7 @@ struct saved_context {
 	u64 misc_enable;
 	bool misc_enable_saved;
 	unsigned long efer;
+	unsigned long clock_modulation;
 	u16 gdt_pad; /* Unused */
 	struct desc_ptr gdt_desc;
 	u16 idt_pad;
arch/x86/power/cpu.c +2 -0
index 9ab5279..f82577b 100644
@@ -97,6 +97,7 @@ static void __save_processor_state(struct saved_context *ctxt)
 	mtrr_save_fixed_ranges(NULL);
 
 	rdmsrl(MSR_EFER, ctxt->efer);
+	rdmsrl(MSR_IA32_THERM_CONTROL, ctxt->clock_modulation);
 #endif
 
 	/*
@@ -178,6 +179,7 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
 #else
 /* CONFIG X86_64 */
 	wrmsrl(MSR_EFER, ctxt->efer);
+	wrmsrl(MSR_IA32_THERM_CONTROL, ctxt->clock_modulation);
 	write_cr8(ctxt->cr8);
 	__write_cr4(ctxt->cr4);
 #endif
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 41 lines · Chen Yu

A bug is reported(https://bugzilla.redhat.com/show_bug.cgi?id=1227208) that, after resuming from S3, CPU is working at a low speed. After investigation, it is found that, BIOS has modified the value of THERM_CONTROL register during S3, changes it from 0 to 0x10, while the latter means CPU can only get 25% of the Duty Cycle, and this caused the problem.

Simple scenario to reproduce:
1.Boot up system
2.Get MSR with address 0x19a, it should output 0
3.Put system into sleep, then wake up
4.Get MSR with address 0x19a, it should output 0(actual it outputs 0x10)

Although this is a BIOS issue, it would be more robust for linux to deal with this situation. This patch fixes this issue by saving/restoring THERM_CONTROL(now called CLOCK_MODULATION) register on suspend/resume.

---
 arch/x86/include/asm/suspend_64.h | 1 +
 arch/x86/power/cpu.c              | 2 ++
 2 files changed, 3 insertions(+)
arch/x86/include/asm/suspend_64.h +1 -0
index 7ebf0eb..b9f5591 100644
@@ -25,6 +25,7 @@ struct saved_context {
 	u64 misc_enable;
 	bool misc_enable_saved;
 	unsigned long efer;
+	unsigned long clock_modulation;
 	u16 gdt_pad; /* Unused */
 	struct desc_ptr gdt_desc;
 	u16 idt_pad;
arch/x86/power/cpu.c +0 -0
index 9ab5279..f82577b 100644

arch/x86/power/cpu.c static void __save_processor_state(struct saved_context *ctxt) · line 100

Quoted 4 lines
arch/x86/power/cpu.c +1 -0
@@ -97,6 +97,7 @@ static void __save_processor_state(struct saved_context *ctxt)
 	mtrr_save_fixed_ranges(NULL);
 
 	rdmsrl(MSR_EFER, ctxt->efer);
+	rdmsrl(MSR_IA32_THERM_CONTROL, ctxt->clock_modulation);

So what your changelog fails to mention:

- You only add this code to the 64-bit kernel. Are 32-bit kernels not affected?

- the MSR read is done unconditionally. Is MSR_IA32_THERM_CONTROL available architecturally and readable (and has sensible values) on all 64-bit capable x86 CPUs that run this code path?

Thanks,

Ingo

author
#2 lore raw

Hi, Ingo, thanks for your review,

Quoted 3 lines · Ingo Molnar

So what your changelog fails to mention:

- You only add this code to the 64-bit kernel. Are 32-bit kernels not affected?

Yes, 32-bit kernel should also do the save/restore operation. I'll adjust them to 64/32-bit common path.

Quoted 4 lines

- the MSR read is done unconditionally. Is MSR_IA32_THERM_CONTROL available architecturally and readable (and has sensible values) on all 64-bit capable x86 CPUs that run this code path?

MSR_IA32_THERM_CONTROL is available on Intel Pentium 4, Xeon, Pentium M and later processors, so I think not all the 64/32-bit capable x86 CPUs have this register. Maybe codes like the following would be more reasonable?

save:
ctxt->clock_modulation_saved = !rdmsrl_safe(MSR_IA32_THERM_CONTROL,

	&ctxt->clock_modulation);

restore:
if (ctxt->clock_modulation_saved)

	wrmsrl(MSR_IA32_THERM_CONTROL, ctxt->clock_modulation);

Thanks a lot.

Best Regards,
Yu

#3 lore raw
In reply to Ingo Molnar
Quoted 4 lines · Ingo Molnar
Quoted 1 line · Chen Yu

A bug is reported(https://bugzilla.redhat.com/show_bug.cgi?id=1227208)

Access denied :-(

Quoted 5 lines
Quoted 5 lines

that, after resuming from S3, CPU is working at a low speed. After investigation, it is found that, BIOS has modified the value of THERM_CONTROL register during S3, changes it from 0 to 0x10, while the latter means CPU can only get 25% of the Duty Cycle, and this caused the problem.

What HW is this on?

Quoted 10 lines

arch/x86/power/cpu.c static void __save_processor_state(struct saved_context *ctxt) · line 100

Quoted 7 lines
arch/x86/power/cpu.c +1 -0
@@ -97,6 +97,7 @@ static void __save_processor_state(struct saved_context *ctxt)
 	mtrr_save_fixed_ranges(NULL);
 
 	rdmsrl(MSR_EFER, ctxt->efer);
+	rdmsrl(MSR_IA32_THERM_CONTROL, ctxt->clock_modulation);

So what your changelog fails to mention:

Quoted 5 lines

- You only add this code to the 64-bit kernel. Are 32-bit kernels not affected?

- the MSR read is done unconditionally. Is MSR_IA32_THERM_CONTROL available architecturally and readable (and has sensible values) on all 64-bit capable x86 CPUs that run this code path?

- So BIOS expects to control MSR_IA32_THERM_CONTROL . Now you suspend in hot enironment but resume in cool one. BIOS sets up MSR_IA32_THERM_CONTROL the right way, but you override it.

As BIOS expects to control MSR_IA32_THERM_CONTROL and machine is kept cool, BIOS will not write new value to it, and machine will keep running slowly.

Doing this unconditionally is asking for trouble. Blacklist entry with affected BIOS info might be acceptable, but...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#4 lore raw

Hi Pavel, thanks for your review,

Quoted 8 lines · Pavel Machek
Quoted 4 lines · Ingo Molnar
Quoted 1 line · Chen Yu

A bug is reported(https://bugzilla.redhat.com/show_bug.cgi?id=1227208)

Access denied :-(

Might need to register for accessing.

Quoted 3 lines

What HW is this on?

Intel Braswell and Broadwell, detail for Broadwell:
Platform: MayanCity
Processor: 2x BROADWELL BDX_EP A0 QHPR
Chipset: Wellsburg B1 QR7E

Quoted 9 lines

- So BIOS expects to control MSR_IA32_THERM_CONTROL . Now you suspend in hot enironment but resume in cool one. BIOS sets up MSR_IA32_THERM_CONTROL the right way, but you override it.

As BIOS expects to control MSR_IA32_THERM_CONTROL and machine is kept cool, BIOS will not write new value to it, and machine will keep running slowly.

Sorry, I can not quite catch up, do you mean we should let
BIOS modifying MSR_IA32_THERM_CONTROL and leverage linux
to adjust this value at runtime(after S3)?

Quoted 4 lines

Doing this unconditionally is asking for trouble. Blacklist entry with affected BIOS info might be acceptable, but...
Pavel

you mean a quirk here(accroding to dmi info ,etc)?

Best Regards,
Yu

#5 lore raw

Hi!

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

A bug is reported(https://bugzilla.redhat.com/show_bug.cgi?id=1227208)

Access denied :-(

Quoted 8 lines

Might need to register for accessing.

Quoted 3 lines

What HW is this on?

Intel Braswell and Broadwell, detail for Broadwell:
Platform: MayanCity
Processor: 2x BROADWELL BDX_EP A0 QHPR
Chipset: Wellsburg B1 QR7E

So it is desktop board?

Quoted 4 lines
Quoted 3 lines

Doing this unconditionally is asking for trouble. Blacklist entry with affected BIOS info might be acceptable, but...

you mean a quirk here(accroding to dmi info ,etc)?

Yes, please.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#6 lore raw

Hi!

Quoted 8 lines · Pavel Machek

Hi!

Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

A bug is reported(https://bugzilla.redhat.com/show_bug.cgi?id=1227208)

Access denied :-(

Might need to register for accessing.

Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

What HW is this on?

Intel Braswell and Broadwell, detail for Broadwell:
Platform: MayanCity
Processor: 2x BROADWELL BDX_EP A0 QHPR
Chipset: Wellsburg B1 QR7E

So it is desktop board?

It is a server of Xeon family.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Doing this unconditionally is asking for trouble. Blacklist entry with affected BIOS info might be acceptable, but...

you mean a quirk here(accroding to dmi info ,etc)?

Yes, please.

Will do. thanks

Quoted 2 lines

Pavel

Best Regards,
Yu

author
#7 lore raw
In reply to Ingo Molnar

(not sure if previous reply has been sent out)
Hi, Ingo, thanks for your review,

Quoted 8 lines · Ingo Molnar

* Chen Yu <[email protected]> wrote:

So what your changelog fails to mention:

- You only add this code to the 64-bit kernel. Are 32-bit kernels not affected?

I missed the 32-bit case, I'll adjust them to 32/64-bit common path.

Quoted 4 lines

- the MSR read is done unconditionally. Is MSR_IA32_THERM_CONTROL available architecturally and readable (and has sensible values) on all 64-bit capable x86 CPUs that run this code path?

MSR_IA32_THERM_CONTROL is avaliable on Intel Pentium 4, Xeon, Pentium M and later processors, so I think not all of the 32/64-bit x86 CPUs have this regiser. Maybe codes like this would be more reasonable? save:
ctx->clock_modulation_saved = !rdmsrl_safe(MSR_IA32_THERM_CONTROL,

	&ctxt->clock_modulation);
retore:
if (ctxt->clock_modulation_saved)
	wrmsrl(MSR_IA32_THERM_CONTROL, ctxt->clock_modulation);

Best Regards,
Yu

Quoted 8 lines

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html