Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] powercap: intel_rapl: Restore power limits after hibernation
@ 2026-11-20 15:30 Sebastien WALD
  2026-11-20 15:36 ` Srinivas Pandruvada
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastien WALD @ 2026-11-20 15:30 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Srinivas Pandruvada, linux-pm

rapl_pm_callback() saves the package power limits on PM_SUSPEND_PREPARE
and restores them on PM_POST_SUSPEND, but does nothing for hibernation.

When the system resumes from hibernation, the boot that loads the image
goes through the firmware again, which reprograms its default power
limits. The values set from user space before hibernating are lost.

On an MSI GS76 Stealth 11UH (Core i9-11900H), thermald sets PL1/PL2 to
45 W/64 W. After resume from hibernation, PL2 reads 120 W, the firmware
default, and stays there; thermald does not re-apply an unchanged
target. Suspend-to-RAM is not affected, because of the existing
save/restore.

Handle PM_HIBERNATION_PREPARE and PM_POST_HIBERNATION in the same way as
their suspend counterparts. The saved values live in kernel memory, so
they are part of the hibernation image and available when
PM_POST_HIBERNATION is delivered after the image has been restored.

The problem was analysed, and this change written, with the help of an
AI coding assistant (Claude); the analysis was checked against the
driver source and against the behaviour of the machine above.

Fixes: 52b3672c1354 ("powercap: add suspend and resume mechanism for SOC power limit")
Signed-off-by: Sebastien WALD <contact@sebastien-wald.fr>
---
Notes (not for the changelog):

Reported first to thermald, where Srinivas asked to take it to the kernel:
https://github.com/intel/thermal_daemon/issues/621

Testing, on 7.3.5 (CachyOS build, clang/ThinLTO):

- Without the patch, PL2 of intel-rapl:0 reads 120 W after resume from
  hibernation instead of 64 W (observed with thermald running; it does
  not re-apply an unchanged target).
- With the patch applied to the 7.3.5 driver, built out of tree (no
  warnings with W=1) and loaded in place of the stock module, thermald
  stopped and the limits written by hand:
    before hibernation: intel-rapl:0 PL1=45 W PL2=64 W
    after resume:       intel-rapl:0 PL1=45 W PL2=64 W
  The intel-rapl-mmio:0 limits were also unchanged across the cycle.
- I have not run a control with the stock module and thermald stopped;
  the "without" case above comes from the original thermald report.
- checkpatch.pl reports no problem (apart from an unknown commit id,
  since it was run outside a kernel tree).

The machine runs an ACPI SSDT override for an unrelated firmware bug
(\_SB.IETM._OSC references an undefined \_TZ.ETMD) and the out-of-tree
nvidia and msi-ec modules, so the kernel is tainted (A, O, E). None of
these touches the RAPL MSRs as far as I can tell.

 drivers/powercap/intel_rapl_common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index f58649f..eb8c02a 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -1878,9 +1878,11 @@ static int rapl_pm_callback(struct notifier_block *nb,
 {
 	switch (mode) {
 	case PM_SUSPEND_PREPARE:
+	case PM_HIBERNATION_PREPARE:
 		power_limit_state_save();
 		break;
 	case PM_POST_SUSPEND:
+	case PM_POST_HIBERNATION:
 		power_limit_state_restore();
 		break;
 	}
-- 
2.56.1


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

end of thread, other threads:[~2026-11-20 15:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 15:30 [PATCH] powercap: intel_rapl: Restore power limits after hibernation Sebastien WALD
2026-11-20 15:36 ` Srinivas Pandruvada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox