mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86/intel/pmc: Don't truncate HW sleep time to 32 bits
@ 2026-11-17  1:29 HyeongJun An
  0 siblings, 0 replies; only message in thread
From: HyeongJun An @ 2026-11-17  1:29 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Hans de Goede, Rajneesh Bhardwaj, David E . Box, Xi Pardee,
	Mario Limonciello, platform-driver-x86, linux-kernel,
	HyeongJun An

The pmc_core_is_s0ix_failed() casts the S0ix residency delta to u32
before it calls pm_report_hw_sleep_time(). The delta is already in
microseconds, so any suspend longer than 71.6 minutes is reported
modulo 2^32 us. But the limit set by pm_report_max_hw_sleep() is 2^32
counter ticks, which is 145.6 hours with the 122 us step.

On a Tiger Lake laptop, one suspend raised the LPIT S0ix residency by
22559 s, but last_hw_sleep reads 1085 s. The LPIT value modulo 2^32 us
is 1084 s.

The cast also hid a wrap of the 32-bit counter during a suspend.
Without it, the u64 difference of the scaled values becomes huge.

To fix this, drop the cast and add one counter period when the
counter wrapped.

Fixes: ddd66d634735 ("platform/x86/intel/pmc: core: Report duration of time in HW sleep state")
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
Prepared with Claude Code (Claude Opus 5.5). Tested on x86_64 (Dell
Latitude 9420, Tiger Lake). After a 13.1 h suspend, last_hw_sleep reads
47063.5 s and the LPIT S0ix residency 47061.9 s. The counter wrap path
was only checked in a simulation.

 drivers/platform/x86/intel/pmc/core.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c
index 71be313bdf0e..0190160a4c0b 100644
--- a/drivers/platform/x86/intel/pmc/core.c
+++ b/drivers/platform/x86/intel/pmc/core.c
@@ -2052,12 +2052,17 @@ static inline bool pmc_core_is_deepest_pkgc_failed(struct pmc_dev *pmcdev)
 
 static inline bool pmc_core_is_s0ix_failed(struct pmc_dev *pmcdev)
 {
-	u64 s0ix_counter;
+	struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
+	u64 s0ix_counter, hw_sleep;
 
-	if (pmc_core_dev_state_get(pmcdev->pmcs[PMC_IDX_MAIN], &s0ix_counter))
+	if (pmc_core_dev_state_get(pmc, &s0ix_counter))
 		return false;
 
-	pm_report_hw_sleep_time((u32)(s0ix_counter - pmcdev->s0ix_counter));
+	/* The 32-bit residency counter can wrap during a long suspend */
+	hw_sleep = s0ix_counter - pmcdev->s0ix_counter;
+	if (s0ix_counter < pmcdev->s0ix_counter)
+		hw_sleep += pmc_core_adjust_slp_s0_step(pmc, 1) << 32;
+	pm_report_hw_sleep_time(hw_sleep);
 
 	if (s0ix_counter == pmcdev->s0ix_counter)
 		return true;
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-17  1:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  1:29 [PATCH] platform/x86/intel/pmc: Don't truncate HW sleep time to 32 bits HyeongJun An

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®