Re: [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary
From: Rafael J. Wysocki (Intel)
Date: Wed Nov 25 2026 - 08:01:24 EST
On Mon, Nov 23, 2026 at 10:07 AM Joshua Crofts <crofts@xxxxxxxxxx> wrote:
>
> Add a debugfs entry for showing the runtime statistics for devices with
> PM runtime enabled.
>
> Signed-off-by: Joshua Crofts <crofts@xxxxxxxxxx>
> ---
> drivers/base/power/runtime.c | 86 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 86 insertions(+)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 17aee68366cf..cf657251633e 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -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"
> @@ -2223,3 +2225,87 @@ bool pm_runtime_need_not_resume(struct device *dev)
> }
>
> #endif /* CONFIG_PM_SLEEP */
> +
> +#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_PM_SLEEP)
Why do you want to make it depend on CONFIG_PM_SLEEP?
There's nothing related to system sleep in it AFAICS.
> +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) */
>
> --
> 2.47.3
>