platform/x86/intel/pmc: Don't truncate HW sleep time to 32 bits
Subsystems (2)
PATCH 1/1 platform/x86/intel/pmc: Don't truncate HW sleep time to 32 bits
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.
---
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(-)
drivers/platform/x86/intel/pmc/core.c +8 -3
@@ -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;
Signature · 1 line
2.43.0