PM: runtime: add new runtime metrics and summary
Subsystems (4)
cover PM: runtime: add new runtime metrics and summary
Add a new set additional PM runtime metrics to improve power management debugging and reporting (these metrics may be useful to userspace utilities such as Powertop).
MOTIVATION:
The current implementation only measures the duration a device spends in suspended or active mode, which is very limiting. We can't find out how many times a device changed state or what its shortest suspend cycle was (to detect a sort of power "thrashing" behaviour).
NEW FEATURES:
This series introduces the following new metrics:
- resume_count : number of successful transitions to active
- suspend_count: number of successful transitions to suspended
- last_suspended_time: duration of the most recent sleep cycle (ns)
- min_suspended_time / max_suspended_sleep: shortest and longest sleep cycle durations to help detect power thrashing (ns)
By reading the debugfs file /sys/kernel/debug/pm_runtime_summary, you get the following table describing the power stats of each device with runtime PM enabled:
Device Status Resumes Suspends Active(ms) Suspend(ms) Last(ms) Min(ms) Max(ms)
--------------------------------------------------------------------------------------------------------------------------
0000:00:02.0 active 1 0 45688 0 0 0 0 0000:00:1f.0 active 1 0 45687 0 0 0 0 0000:00:1f.2 active 1 0 45686 0 0 0 0 0000:00:1f.3 suspended 1 1 1658 44028 0 0 0 00:03:0 active 15 14 19627 25899 42 5 14811 00:03:0.0 active 14 13 19626 25900 42 5 14811
TESTING:
Tested with an x86_64 defconfig kernel and QEMU.
AI ASSISTANCE:
Gemini was used to prepare this series.
---
Joshua Crofts (3):
PM: runtime: add additional suspend/resume metrics
PM: add sysfs attributes for additional suspend/resume metrics
PM: runtime: add debugfs entry for pm_runtime_summary
Documentation/ABI/testing/sysfs-devices-power | 36 ++++++ drivers/base/power/runtime.c | 156 +++++++++++++++++++++++++- drivers/base/power/sysfs.c | 81 +++++++++++++ include/linux/pm.h | 12 ++ 4 files changed, 281 insertions(+), 4 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261110-pm-runtime-summary-8dd29a1383bc
Best regards,
Signature · 1 line
Joshua Crofts <[email protected]>
PATCH 1/3 PM: runtime: add additional suspend/resume metrics
The current implementation only logs the total accumulated time a device spends in suspended or active states.
Add tracking for:
- resume_count : number of successful transitions to active
- suspend_count: number of successful transitions to suspended
- last_suspended_time: duration of the most recent sleep cycle (ns)
- min_suspended_time / max_suspended_sleep: shortest and longest sleep cycle durations to help detect power thrashing (ns)
--- drivers/base/power/runtime.c | 70 +++++++++++++++++++++++++++++++++++++++++--- include/linux/pm.h | 12 ++++++++ 2 files changed, 78 insertions(+), 4 deletions(-)
drivers/base/power/runtime.c +66 -4
@@ -5,6 +5,8 @@* Copyright (c) 2009 Rafael J. Wysocki <[email protected]>, Novell Inc. * Copyright (C) 2010 Alan Stern <[email protected]> */ +#include <linux/pm.h> +#include <linux/timekeeping.h> #include <linux/sched/mm.h> #include <linux/ktime.h> #include <linux/hrtimer.h>
@@ -103,11 +105,62 @@ static void update_pm_runtime_accounting(struct device *dev) dev->power.active_time += delta; } +static void rpm_account_suspend (struct device *dev) +{ + dev->power.suspend_time =ktime_get_mono_fast_ns (); + dev->power.suspend_count++; +} + +static void rpm_account_sleep_end (struct device *dev) +{ +u64 now, duration; + +if (!dev->power.suspend_time) +return ; + + now =ktime_get_mono_fast_ns (); +if (now <= dev->power.suspend_time) +return ; + + duration = now - dev->power.suspend_time; + dev->power.last_suspended_time = duration; + +/* Update min/max extrema at the exact same moment as last_suspended_time */ +if (!dev->power.min_suspended_time || duration < dev->power.min_suspended_time) + dev->power.min_suspended_time = duration; + +if (duration > dev->power.max_suspended_time) + dev->power.max_suspended_time = duration; +} + +static void rpm_account_resume_complete (struct device *dev) +{ + dev->power.resume_count++; + dev->power.suspend_time =0 ; +} +static void __update_runtime_status (struct device *dev,enum rpm_status status) { +enum rpm_status old_status = dev->power.runtime_status; +update_pm_runtime_accounting (dev);trace_rpm_status (dev, status); dev->power.runtime_status = status; + +if (dev->power.disable_depth >0 ) +return ; + +if ((old_status ==RPM_SUSPENDING || old_status ==RPM_ACTIVE ) && + status ==RPM_SUSPENDED ) +rpm_account_suspend (dev); +else if (old_status ==RPM_RESUMING && status ==RPM_SUSPENDED ) + dev->power.suspend_time =ktime_get_mono_fast_ns (); +else if (old_status ==RPM_SUSPENDED && status !=RPM_SUSPENDED ) +rpm_account_sleep_end (dev); + +if ((old_status ==RPM_RESUMING || old_status ==RPM_SUSPENDED ) && + status ==RPM_ACTIVE ) +rpm_account_resume_complete (dev); }static u64 rpm_get_accounted_time (struct device *dev,bool suspended)
@@ -1589,10 +1642,12 @@ void pm_runtime_enable(struct device *dev) dev->power.last_status =RPM_INVALID ; dev->power.accounting_timestamp =ktime_get_mono_fast_ns (); -if (dev->power.runtime_status ==RPM_SUSPENDED && - !dev->power.ignore_children && -atomic_read (&dev->power.child_count) >0 ) -dev_warn (dev,"Enabling runtime PM for inactive device with active children\n" ); +if (dev->power.runtime_status ==RPM_SUSPENDED ) { + dev->power.suspend_time = dev->power.accounting_timestamp; +if (!dev->power.ignore_children && +atomic_read (&dev->power.child_count) >0 ) +dev_warn (dev,"Enabling runtime PM for inactive device with active children\n" ); + } out:spin_unlock_irqrestore (&dev->power.lock, flags);
@@ -1861,6 +1916,13 @@ void pm_runtime_init(struct device *dev)pm_suspend_ignore_children (dev, false); dev->power.runtime_auto = true; + dev->power.resume_count =0 ; + dev->power.suspend_count =0 ; + dev->power.suspend_time =0 ; + dev->power.last_suspended_time =0 ; + dev->power.min_suspended_time =0 ; + dev->power.max_suspended_time =0 ; + dev->power.request_pending = false; dev->power.request =RPM_REQ_NONE ; dev->power.deferred_resume = false;
include/linux/pm.h +12 -0
@@ -747,6 +747,12 @@ struct pm_subsys_data {* state. * @accounting_timestamp: Timestamp in nanoseconds of the last runtime PM state * accounting update. +* @resume_count: Number of transitions from suspended -> active +* @suspend_count: Number of transitions from active -> suspended +* @suspend_time: Timestamp when device entered RPM_SUSPENDED +* @last_suspended_time: Residency of the last sleep period (ns) +* @min_suspended_time: Shortest sleep duration +* @max_suspended_time: Longest sleep duration * @subsys_data: Subsystem-specific power management data. * @set_latency_tolerance: Callback for setting latency tolerance. * @qos: Per-device PM Quality of Service (QoS) constraints.
@@ -816,6 +822,12 @@ struct dev_pm_info {u64 active_time;u64 suspended_time;u64 accounting_timestamp; +u64 resume_count; +u64 suspend_count; +u64 suspend_time; +u64 last_suspended_time; +u64 min_suspended_time; +u64 max_suspended_time;#endif struct pm_subsys_data *subsys_data;/* Owned by the subsystem. */ void (*set_latency_tolerance)(struct device *,s32 );
Signature · 1 line
2.47.3
PATCH 2/3 PM: add sysfs attributes for additional suspend/resume metrics
In reply to Joshua CroftsAdd sysfs entries for additional suspend/resume statistics. These are useful for investigating the behaviour of devices with PM runtime enabled.
--- Documentation/ABI/testing/sysfs-devices-power | 36 ++++++++++++ drivers/base/power/sysfs.c | 81 +++++++++++++++++++++++++++ 2 files changed, 117 insertions(+)
Documentation/ABI/testing/sysfs-devices-power +36 -0
@@ -284,6 +284,42 @@ Description: Reports total time that the device has been suspended, in milliseconds. Used for runtime PM statistics. +What: /sys/devices/.../power/runtime_resume_count +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the total number of times the device entered a resume + state. + +What: /sys/devices/.../power/runtime_suspend_count +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the total number of times the device entered a suspended + state. + +What: /sys/devices/.../power/runtime_last_suspended_time +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the residency duration of the most recent suspended + state, in milliseconds. + +What: /sys/devices/.../power/runtime_min_suspended_time +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the shortest measured duration the device spent in + suspended mode, in milliseconds. + +What: /sys/devices/.../power/runtime_max_suspended_time +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the longest measured duration the device spent in + suspended mode, in milliseconds. + + What: /sys/devices/.../power/runtime_usage Date: Apr 2010 Contact: Dominik Brodowski <[email protected]>
drivers/base/power/sysfs.c +81 -0
93 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 3/3 PM: runtime: add debugfs entry for pm_runtime_summary
In reply to Joshua CroftsAdd a debugfs entry for showing the runtime statistics for devices with PM runtime enabled.
--- drivers/base/power/runtime.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)
drivers/base/power/runtime.c +86 -0
@@ -14,6 +14,8 @@#include <linux/pm_runtime.h> #include <linux/pm_wakeirq.h> #include <linux/rculist.h> +#include <linux/debugfs.h> +#include <linux/seq_file.h> #include <trace/events/rpm.h> #include "../base.h"
@@ -2193,3 +2195,87 @@ bool pm_runtime_need_not_resume(struct device *dev) }#endif /* CONFIG_PM_SLEEP */ + +#if defined(CONFIG_DEBUG_FS ) && defined(CONFIG_PM_SLEEP ) +static void rpm_summary_show_dev (struct device *dev,void *data) +{ +struct seq_file *s = data; +unsigned long flags; +u64 active_time, suspended_time; +u64 last_sleep, min_sleep, max_sleep; +u64 resumes, suspends; +const char *status_str; +bool enabled; + +spin_lock_irqsave (&dev->power.lock, flags); + + enabled =pm_runtime_enabled (dev); +if (!enabled && !dev->power.resume_count && !dev->power.suspend_count) { +spin_unlock_irqrestore (&dev->power.lock, flags); +return ; + } + +update_pm_runtime_accounting (dev); + +switch (dev->power.runtime_status) { +case RPM_ACTIVE : + status_str ="active" ; +break ; +case RPM_SUSPENDED : + status_str ="suspended" ; +break ; +case RPM_SUSPENDING : + status_str ="suspending" ; +break ; +case RPM_RESUMING : + status_str ="resuming" ; +break ; +default : + status_str ="unknown" ; +break ; + } + + active_time = dev->power.active_time; + suspended_time = dev->power.suspended_time; + resumes = dev->power.resume_count; + suspends = dev->power.suspend_count; + last_sleep = dev->power.last_suspended_time; + min_sleep = dev->power.min_suspended_time; + max_sleep = dev->power.max_suspended_time; + +spin_unlock_irqrestore (&dev->power.lock, flags); + +do_div (active_time,NSEC_PER_MSEC ); +do_div (suspended_time,NSEC_PER_MSEC ); +do_div (last_sleep,NSEC_PER_MSEC ); +do_div (min_sleep,NSEC_PER_MSEC ); +do_div (max_sleep,NSEC_PER_MSEC ); + +seq_printf (s,"%-32s %-12s %8llu %8llu %12llu %12llu %10llu %10llu %10llu\n" , +dev_name (dev), enabled ? status_str :"disabled" , + resumes, suspends, active_time, suspended_time, + last_sleep, min_sleep, max_sleep); +} + +static int pm_runtime_summary_show (struct seq_file *s,void *unused) +{ +seq_printf (s,"%-32s %-12s %8s %8s %12s %12s %10s %10s %10s\n" , +"Device" ,"Status" ,"Resumes" ,"Suspends" , +"Active(ms)" ,"Suspend(ms)" ,"Last(ms)" ,"Min(ms)" ,"Max(ms)" ); +seq_puts (s,"--------------------------------------------------------------------------------------------------------------------------\n" ); + +dpm_for_each_dev (s, rpm_summary_show_dev); + +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (pm_runtime_summary); + +static int __init pm_runtime_debugfs_init (void ) +{ +debugfs_create_file ("pm_runtime_summary" ,0444 ,NULL ,NULL , + &pm_runtime_summary_fops); + +return 0 ; +} +late_initcall (pm_runtime_debugfs_init); +#endif /* defined(CONFIG_DEBUG_FS) && defined(CONFIG_PM_SLEEP) */
Signature · 1 line
2.47.3
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] PM: add sysfs attributes for additional suspend/resume metrics
In reply to Joshua CroftsQuoted 64 lines · Joshua Crofts
Add sysfs entries for additional suspend/resume statistics. These are useful for investigating the behaviour of devices with PM runtime enabled.
Signed-off-by Joshua Crofts <[email protected]>--- Documentation/ABI/testing/sysfs-devices-power | 36 ++++++++++++ drivers/base/power/sysfs.c | 81 +++++++++++++++++++++++++++ 2 files changed, 117 insertions(+)Documentation/ABI/testing/sysfs-devices-power +36
-0@@ -284,6 +284,42 @@ Description: Reports total time that the device has been suspended, in milliseconds. Used for runtime PM statistics. +What: /sys/devices/.../power/runtime_resume_count +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the total number of times the device entered a resume + state. + +What: /sys/devices/.../power/runtime_suspend_count +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the total number of times the device entered a suspended + state. + +What: /sys/devices/.../power/runtime_last_suspended_time +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the residency duration of the most recent suspended + state, in milliseconds. + +What: /sys/devices/.../power/runtime_min_suspended_time +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the shortest measured duration the device spent in + suspended mode, in milliseconds. + +What: /sys/devices/.../power/runtime_max_suspended_time +Date: Nov 2026 +Contact: Joshua Crofts <[email protected]> +Description: + Reports the longest measured duration the device spent in + suspended mode, in milliseconds. + + What: /sys/devices/.../power/runtime_usage Date: Apr 2010 Contact: Dominik Brodowski <[email protected]>drivers/base/power/sysfs.c +0
-0@@ -178,6 +178,82 @@ static ssize_t runtime_status_show(struct device *dev,static DEVICE_ATTR_RO (runtime_status);
drivers/base/power/sysfs.c static ssize_t runtime_status_show(struct device *dev, · line 189
Quoted 10 lines
drivers/base/power/sysfs.c +9
-0+static ssize_t runtime_resume_count_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +u64 count; + +spin_lock_irq (&dev->power.lock); + count = dev->power.resume_count; +spin_unlock_irq (&dev->power.lock);
Why is a lock needed at all? The value isn't going to "smear", it will change right after the lock anyway.
Quoted 4 lines
drivers/base/power/sysfs.c +4
-0+ +return sysfs_emit (buf,"%llu\n" , count); +} +static DEVICE_ATTR_RO (runtime_resume_count);
drivers/base/power/sysfs.c static ssize_t runtime_status_show(struct device *dev, · line 203
Quoted 10 lines
drivers/base/power/sysfs.c +10
-0+ +static ssize_t runtime_suspend_count_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +u64 count; + +spin_lock_irq (&dev->power.lock); + count = dev->power.suspend_count; +spin_unlock_irq (&dev->power.lock);
Same here, why a lock?
And if you need one, why not a guard()?
Same for rest of this patch.
thanks,
greg k-h
Re: [PATCH 2/3] PM: add sysfs attributes for additional suspend/resume metrics
On Tue, 10 Nov 2026 12:29:11 -0500
Greg Kroah-Hartman <[email protected]> wrote:
...
Quoted 4 lines
Quoted 4 lines
drivers/base/power/sysfs.c +4
-0+static ssize_t runtime_resume_count_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{
Quoted 8 lines
drivers/base/power/sysfs.c static ssize_t runtime_status_show(struct device *dev, · line 189
Quoted 5 lines
drivers/base/power/sysfs.c +5
-0+u64 count; + +spin_lock_irq (&dev->power.lock); + count = dev->power.resume_count; +spin_unlock_irq (&dev->power.lock);Why is a lock needed at all? The value isn't going to "smear", it will change right after the lock anyway.
On 64-bit systems an aligned u64 read is atomic, but on 32-bit systems it gets split into two 32-bit loads. Without locking, the read can tear between the upper and lower halves.
Quoted 1 line
And if you need one, why not a
guard()?
Yeah, I realized this after sending the series out, nevertheless Sashiko flagged some other stuff so I thought I'd fixup in v2.
Thanks!
Signature · 2 lines
Kind regards, Joshua Crofts
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] PM: add sysfs attributes for additional suspend/resume metrics
Quoted 18 lines · Joshua Crofts
On Tue, 10 Nov 2026 12:29:11 -0500
Greg Kroah-Hartman <[email protected]> wrote:...
Quoted 4 lines
Quoted 4 lines
drivers/base/power/sysfs.c +4
-0+static ssize_t runtime_resume_count_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{Quoted 8 lines
drivers/base/power/sysfs.c static ssize_t runtime_status_show(struct device *dev, · line 189
Quoted 5 lines
drivers/base/power/sysfs.c +5
-0+u64 count; + +spin_lock_irq (&dev->power.lock); + count = dev->power.resume_count; +spin_unlock_irq (&dev->power.lock);Why is a lock needed at all? The value isn't going to "smear", it will change right after the lock anyway.
Quoted 3 lines
On 64-bit systems an aligned u64 read is atomic, but on 32-bit systems it gets split into two 32-bit loads. Without locking, the read can tear between the upper and lower halves.
Are you sure? ANd if so, is that so bad? The value is "best effort" as it can, and will, change right after reading it.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] PM: add sysfs attributes for additional suspend/resume metrics
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Joshua Crofts
On Tue, 10 Nov 2026 12:29:11 -0500
Greg Kroah-Hartman <[email protected]> wrote:...
Quoted 12 lines
drivers/base/power/sysfs.c static ssize_t runtime_status_show(struct device *dev, · line 189
Quoted 9 lines
drivers/base/power/sysfs.c +9
-0+static ssize_t runtime_resume_count_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +u64 count; + +spin_lock_irq (&dev->power.lock); + count = dev->power.resume_count; +spin_unlock_irq (&dev->power.lock);Why is a lock needed at all? The value isn't going to "smear", it will change right after the lock anyway.
Quoted 6 lines
Quoted 3 lines
On 64-bit systems an aligned u64 read is atomic, but on 32-bit systems it gets split into two 32-bit loads. Without locking, the read can tear between the upper and lower halves.
Are you sure? ANd if so, is that so bad? The value is "best effort" as it can, and will, change right after reading it.
And even more relevant, what specific 32bit system are you using that this new api is going to be relying on?
thanks,
greg k-h
Re: [PATCH 2/3] PM: add sysfs attributes for additional suspend/resume metrics
Quoted 20 lines · On Tue, 10 Nov 2026 13:58:34 -0500 Greg Kroah-Hartman…
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Joshua Crofts
On Tue, 10 Nov 2026 12:29:11 -0500
Greg Kroah-Hartman <[email protected]> wrote:...
Quoted 12 lines
drivers/base/power/sysfs.c static ssize_t runtime_status_show(struct device *dev, · line 189
Quoted 9 lines
drivers/base/power/sysfs.c +9
-0+static ssize_t runtime_resume_count_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +u64 count; + +spin_lock_irq (&dev->power.lock); + count = dev->power.resume_count; +spin_unlock_irq (&dev->power.lock);Why is a lock needed at all? The value isn't going to "smear", it will change right after the lock anyway.
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
On 64-bit systems an aligned u64 read is atomic, but on 32-bit systems it gets split into two 32-bit loads. Without locking, the read can tear between the upper and lower halves.
Are you sure? ANd if so, is that so bad? The value is "best effort" as it can, and will, change right after reading it.
Fair enough, I agree this is "best effort", so no problem on my end with dropping the locks.
Quoted 2 lines
And even more relevant, what specific 32bit system are you using that this new api is going to be relying on?
I'm not using any 32-bit system, this issue was flagged by a local Sashiko run and at the time it made sense to me.
Signature · 2 lines
Kind regards, Joshua Crofts
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] PM: add sysfs attributes for additional suspend/resume metrics
Quoted 30 lines · Joshua Crofts
Quoted 20 lines · On Tue, 10 Nov 2026 13:58:34 -0500 Greg Kroah-Hartman…
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Joshua Crofts
On Tue, 10 Nov 2026 12:29:11 -0500
Greg Kroah-Hartman <[email protected]> wrote:...
Quoted 12 lines
drivers/base/power/sysfs.c static ssize_t runtime_status_show(struct device *dev, · line 189
Quoted 9 lines
drivers/base/power/sysfs.c +9
-0+static ssize_t runtime_resume_count_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +u64 count; + +spin_lock_irq (&dev->power.lock); + count = dev->power.resume_count; +spin_unlock_irq (&dev->power.lock);Why is a lock needed at all? The value isn't going to "smear", it will change right after the lock anyway.
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
On 64-bit systems an aligned u64 read is atomic, but on 32-bit systems it gets split into two 32-bit loads. Without locking, the read can tear between the upper and lower halves.
Are you sure? ANd if so, is that so bad? The value is "best effort" as it can, and will, change right after reading it.
Quoted 8 lines
Fair enough, I agree this is "best effort", so no problem on my end with dropping the locks.
Quoted 2 lines
And even more relevant, what specific 32bit system are you using that this new api is going to be relying on?
I'm not using any 32-bit system, this issue was flagged by a local Sashiko run and at the time it made sense to me.
Don't let a random number generator replace your thinking :)
Quoted 50 lines · Joshua Crofts
Add a new set additional PM runtime metrics to improve power management debugging and reporting (these metrics may be useful to userspace utilities such as Powertop).
MOTIVATION:
The current implementation only measures the duration a device spends in suspended or active mode, which is very limiting. We can't find out how many times a device changed state or what its shortest suspend cycle was (to detect a sort of power "thrashing" behaviour).NEW FEATURES:
This series introduces the following new metrics:
-resume_count: number of successful transitions to active
-suspend_count: number of successful transitions to suspended
-last_suspended_time: duration of the most recent sleep cycle (ns)
-min_suspended_time/max_suspended_sleep: shortest and longest sleep cycle durations to help detect power thrashing (ns)By reading the debugfs file
/sys/kernel/debug/pm_runtime_summary, you get the following table describing the power stats of each device with runtime PM enabled:Device Status Resumes Suspends Active(ms) Suspend(ms) Last(ms) Min(ms) Max(ms)
--------------------------------------------------------------------------------------------------------------------------0000:00:02.0 active 1 0 45688 0 0 0 0 0000:00:1f.0 active 1 0 45687 0 0 0 0 0000:00:1f.2 active 1 0 45686 0 0 0 0 0000:00:1f.3 suspended 1 1 1658 44028 0 0 0 00:03:0 active 15 14 19627 25899 42 5 14811 00:03:0.0 active 14 13 19626 25900 42 5 14811TESTING:
Tested with anx86_64defconfig kernel and QEMU.AI ASSISTANCE:
Gemini was used to prepare this series.Signed-off-by Joshua Crofts <[email protected]>---
Joshua Crofts (3):
PM: runtime: add additional suspend/resume metrics
PM: add sysfs attributes for additional suspend/resume metrics
PM: runtime: add debugfs entry forpm_runtime_summaryDocumentation/ABI/testing/sysfs-devices-power | 36 ++++++ drivers/base/power/runtime.c | 156 +++++++++++++++++++++++++- drivers/base/power/sysfs.c | 81 +++++++++++++ include/linux/pm.h | 12 ++ 4 files changed, 281 insertions(+), 4 deletions(-)
Quoted 7 lines
---
base-commit:6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261110-pm-runtime-summary-8dd29a1383bcBest regards,
--
Joshua Crofts <[email protected]>
What is the vision for using these runtime PM stats once surfaced to userspace? Runtime PM and suspend have disjoint portions, but I'm curious if you see any non-obvious areas where these stats would be insightful.
And is there a reason the stats need to be surfaced in both sysfs and debugfs?
Thanks!
Sam
On Tue, 10 Nov 2026 19:38:39 -0800
Samuel Wu <[email protected]> wrote:
...
Quoted 5 lines
What is the vision for using these runtime PM stats once surfaced to userspace? Runtime PM and suspend have disjoint portions, but I'm curious if you see any non-obvious areas where these stats would be insightful.
The main things this is useful for are detecting power "thrashing" and tuning autosuspend delays. Currently, sysfs only shows the total time a device spent in active and suspended mode; from an energy standpoint, a continuous 50 second suspension is different from a device cycling 1000 times for 50ms each (these transitions can be pretty power-hungry). This could help userspace utilities like PowerTOP to more effectively determine what is causing an increased power consumption.
From the kernel dev standpoint - this is genuinely useful when testing runtime PM functions in new drivers (for example in the IIO subsystem we deal with a lot of runtime PM stuff).
Quoted 1 line
And is there a reason the stats need to be surfaced in both sysfs and debugfs?
sysfs definitely, as you should definitely be able to access this info per-device (and this is the way userspace tools would get this info).
The debugfs summary is however pretty elegant IMO and useful. I'm sure a lot of people investigating odd device behaviour would like this (plus there are overviews like this in the kernel already - clk_summary for example).
I'll add these points to the cover letter in v2.
Thanks.
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 20 lines · Joshua Crofts
On Tue, 10 Nov 2026 19:38:39 -0800
Samuel Wu <[email protected]> wrote:...
Quoted 5 lines
What is the vision for using these runtime PM stats once surfaced to userspace? Runtime PM and suspend have disjoint portions, but I'm curious if you see any non-obvious areas where these stats would be insightful.
The main things this is useful for are detecting power "thrashing" and tuning autosuspend delays. Currently, sysfs only shows the total time a device spent in active and suspended mode; from an energy standpoint, a continuous 50 second suspension is different from a device cycling 1000 times for 50ms each (these transitions can be pretty power-hungry). This could help userspace utilities like PowerTOP to more effectively determine what is causing an increased power consumption.
Quoted 3 lines
From the kernel dev standpoint - this is genuinely useful when testing runtime PM functions in new drivers (for example in the IIO subsystem we deal with a lot of runtime PM stuff).
Makes sense, there is value in this info.
Quoted 4 lines
Quoted 1 line
And is there a reason the stats need to be surfaced in both sysfs and debugfs?
sysfs definitely, as you should definitely be able to access this info per-device (and this is the way userspace tools would get this info).
Is there already a userspace user of these sysfs nodes?
Adding these five sysfs nodes would easily create 10k+ new sysfs nodes (a typical Android device can easily have 2k+ devices). Most userspace apps would iterate through every possible node, meaning this would be an inconsistent snapshot across the 10k+ syscalls, in addition to being inefficient.
These sysfs nodes would have a boot time impact, a non-negligible memory impact, and constitute a permanent ABI.
Quoted 3 lines
The debugfs summary is however pretty elegant IMO and useful. I'm sure a lot of people investigating odd device behaviour would like this (plus there are overviews like this in the kernel already -
clk_summaryfor example).
The debugfs addition makes more sense IMO. It filters with pm_runtime_enabled() instead of presenting every device, and the spinlock at least keeps the view of each device consistent. It's also more flexible without the ABI guarantee.
On Wed, 11 Nov 2026 08:56:30 -0800
Samuel Wu <[email protected]> wrote:
...
Quoted 12 lines
Quoted 11 lines
The main things this is useful for are detecting power "thrashing" and tuning autosuspend delays. Currently, sysfs only shows the total time a device spent in active and suspended mode; from an energy standpoint, a continuous 50 second suspension is different from a device cycling 1000 times for 50ms each (these transitions can be pretty power-hungry). This could help userspace utilities like PowerTOP to more effectively determine what is causing an increased power consumption.
From the kernel dev standpoint - this is genuinely useful when testing runtime PM functions in new drivers (for example in the IIO subsystem we deal with a lot of runtime PM stuff).
Quoted 8 lines
Makes sense, there is value in this info.
Quoted 4 lines
Quoted 1 line
And is there a reason the stats need to be surfaced in both sysfs and debugfs?
sysfs definitely, as you should definitely be able to access this info per-device (and this is the way userspace tools would get this info).
Is there already a userspace user of these sysfs nodes?
No, there isn't.
Quoted 8 lines
Adding these five sysfs nodes would easily create 10k+ new sysfs nodes (a typical Android device can easily have 2k+ devices). Most userspace apps would iterate through every possible node, meaning this would be an inconsistent snapshot across the 10k+ syscalls, in addition to being inefficient.
These sysfs nodes would have a boot time impact, a non-negligible memory impact, and constitute a permanent ABI.
Fair enough, I didn't account for this. 2k+ devices is a lot!
Quoted 8 lines
Quoted 3 lines
The debugfs summary is however pretty elegant IMO and useful. I'm sure a lot of people investigating odd device behaviour would like this (plus there are overviews like this in the kernel already -
clk_summaryfor example).The debugfs addition makes more sense IMO. It filters with
pm_runtime_enabled()instead of presenting every device, and the spinlock at least keeps the view of each device consistent. It's also more flexible without the ABI guarantee.
Okay, I've no problem with dropping the sysfs patch. The debugfs summary is machine-readable for any userspace tools to parse.
Signature · 2 lines
Kind regards, Joshua Crofts