Skip to content

RFC Make it easier to measure % in HW sleep state

Mario Limonciello linux-pm lkml llvm oe-kbuild-all platform-driver-x86 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 RFC Latest4 patches 3 repliesIn review
  2. v2 RFC3 patches 15 repliesSuperseded
  3. v1 RFC3 patches 3 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4PM: Add a sysfs file to represent the total sleep durationDocumentation/ABI/testing/sysfs-power include/linux/suspend.h kernel/power/main.c +2 more+29 -02 replies
2/4platform/x86/intel/pmc: core: Drop check_countersdrivers/platform/x86/intel/pmc/core.c drivers/platform/x86/intel/pmc/core.h+2 -60 replies
3/4platform/x86/amd: pmc: Report duration of time in deepest hw stateDocumentation/ABI/testing/sysfs-amd-pmc drivers/platform/x86/amd/pmc.c+25 -30 replies
4/4platform/x86/amd: pmc: Populate cpuidle sysfs file with hw sleep datadrivers/platform/x86/amd/pmc.c+5 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [RFC v3 0/4] Make it easier to measure % in HW sleep state

Sven van Ashbrook brought a patch to the kernel mailing list that attempted to change the reporting level of a s0ix entry issue to a different debugging level so that infastructure used by Google could better scan logs to catch problems.

This approach was rejected, but during the conversation another suggestion was made by David E. Box to introduce some infrastructure into the kernel to report this information.

As it's information that is reported by both AMD and Intel platforms over s2idle, this seems to make sense.

RFC v1 and v2 introduced two new sysfs files to report the information, but Rafael pointed out that there was already a file that could be used on Intel platforms: low_power_idle_system_residency_us.

RFC v3 creates this file for AMD platforms and also introduces another file that can be used to determine total sleep time:
/sys/power/suspend_stats/last_total.

With these two files a simple shell script can be run after suspend to calculate the percentage.

```
 #!/bin/sh
total=$(cat /sys/power/suspend_stats/last_total)
hw=$(cat /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us)
percent=$(awk -v hw=$hw -v total=$total 'BEGIN { printf "%.2f%%", (hw/total*100) }')
echo "Last ${total}us suspend cycle spent $percent of the time in a hardware sleep state."
```

A sample run on an AMD platform that was just sleeping with this series on top of 6.1-rc5 shows the following:

 # ./compare.sh
Last 15699838us suspend cycle spent 98.63% of the time in a hardware sleep state.

Further discussion to be expected on this series:

* What last_total will represent from the suspend cycle

* Whether the semantics of all platforms will be the same for low_power_idle_system_residency_us
- AMD platforms reset this counter before s2idle entry. Do Intel? Others?

* Maybe the *kernel* should be responsible to do the calculation and export a last_hw_sleep_percent file instead. Platform differences can be abstracted then within individual drivers.

Mario Limonciello (4):
PM: Add a sysfs file to represent the total sleep duration platform/x86/intel/pmc: core: Drop check_counters platform/x86/amd: pmc: Report duration of time in deepest hw state platform/x86/amd: pmc: Populate cpuidle sysfs file with hw sleep data

 Documentation/ABI/testing/sysfs-amd-pmc |  6 ++++++
 Documentation/ABI/testing/sysfs-power   |  8 ++++++++
 drivers/platform/x86/amd/pmc.c          | 27 ++++++++++++++++++++++---
 drivers/platform/x86/intel/pmc/core.c   |  7 ++-----
 drivers/platform/x86/intel/pmc/core.h   |  1 -
 include/linux/suspend.h                 |  2 ++
 kernel/power/main.c                     | 15 ++++++++++++++
 kernel/power/suspend.c                  |  2 ++
 kernel/time/timekeeping.c               |  2 ++
 9 files changed, 61 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1