mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] PM: runtime: add new runtime metrics and summary
@ 2026-11-23  9:06 Joshua Crofts
  2026-11-23  9:06 ` [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics Joshua Crofts
  2026-11-23  9:06 ` [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary Joshua Crofts
  0 siblings, 2 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-11-23  9:06 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Samuel Wu
  Cc: linux-pm, driver-core, linux-kernel, 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.

This overview would be useful for 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.

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_time: 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.

Signed-off-by: Joshua Crofts <crofts@kernel.org>
---
Changes in v3:
- Guard new metrics with #ifdef CONFIG_DEBUG_FS to reduce overhead on
  non-debugfs enabled systems (Rafael)
- Fix runtime status transition fixes flagged by Sashiko
- Link to v2: https://lore.kernel.org/r/20261116-pm-runtime-summary-v2-0-a3d8654baf8f@kernel.org

Changes in v2:
- Drop sysfs patch as it would have a non-negligible impact on boot times and
  the debugfs summary is enough (Samuel Wu)
- Expand cover letter
- Fix Sashiko findings - typo in commit message, race condition, duplicate
  function call
- Link to v1: https://lore.kernel.org/r/20261110-pm-runtime-summary-v1-0-12ebf283db78@kernel.org

To: "Rafael J. Wysocki" <rafael@kernel.org>
To: Pavel Machek <pavel@kernel.org>
To: Len Brown <lenb@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Danilo Krummrich <dakr@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: linux-pm@vger.kernel.org
Cc: driver-core@lists.linux.dev
Cc: linux-kernel@vger.kernel.org

---
Joshua Crofts (2):
      PM: runtime: add additional suspend/resume metrics
      PM: runtime: add debugfs entry for pm_runtime_summary

 drivers/base/power/runtime.c | 179 +++++++++++++++++++++++++++++++++++++++++--
 include/linux/pm.h           |  16 +++-
 2 files changed, 189 insertions(+), 6 deletions(-)
---
base-commit: d40cb8a12ed25789f39404c5f7968a65e98d89c3
change-id: 20261110-pm-runtime-summary-8dd29a1383bc

Best regards,
--  
Joshua Crofts <crofts@kernel.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics
  2026-11-23  9:06 [PATCH v3 0/2] PM: runtime: add new runtime metrics and summary Joshua Crofts
@ 2026-11-23  9:06 ` Joshua Crofts
  2026-11-25 12:54   ` Rafael J. Wysocki (Intel)
  2026-11-23  9:06 ` [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary Joshua Crofts
  1 sibling, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-11-23  9:06 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Samuel Wu
  Cc: linux-pm, driver-core, linux-kernel, Joshua Crofts

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_time: shortest and longest sleep
  cycle durations to help detect power thrashing (ns)

Signed-off-by: Joshua Crofts <crofts@kernel.org>
---
 drivers/base/power/runtime.c | 93 +++++++++++++++++++++++++++++++++++++++++---
 include/linux/pm.h           | 16 +++++++-
 2 files changed, 103 insertions(+), 6 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 4e9c23059a40..17aee68366cf 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -5,6 +5,8 @@
  * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
  * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu>
  */
+#include <linux/pm.h>
+#include <linux/timekeeping.h>
 #include <linux/sched/mm.h>
 #include <linux/ktime.h>
 #include <linux/hrtimer.h>
@@ -103,11 +105,70 @@ static void update_pm_runtime_accounting(struct device *dev)
 		dev->power.active_time += delta;
 }
 
+#ifdef CONFIG_DEBUG_FS
+static void rpm_account_suspend(struct device *dev)
+{
+	dev->power.suspend_time = dev->power.accounting_timestamp;
+	dev->power.suspend_count++;
+}
+
+static void rpm_account_sleep_end(struct device *dev)
+{
+	u64 duration;
+
+	if (!dev->power.suspend_time)
+		return;
+
+	if (dev->power.accounting_timestamp <= dev->power.suspend_time)
+		return;
+
+	duration = dev->power.accounting_timestamp - 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;
+}
+#endif /* CONFIG_DEBUG_FS */
+
 static void __update_runtime_status(struct device *dev, enum rpm_status status)
 {
+#ifdef CONFIG_DEBUG_FS
+	enum rpm_status old_status = dev->power.runtime_status;
+#endif /* CONFIG_DEBUG_FS */
+
 	update_pm_runtime_accounting(dev);
 	trace_rpm_status(dev, status);
 	dev->power.runtime_status = status;
+
+#ifdef CONFIG_DEBUG_FS
+	if (dev->power.disable_depth > 0) {
+		if (status == RPM_ACTIVE)
+			dev->power.suspend_time = 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 = dev->power.accounting_timestamp;
+	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);
+#endif /* CONFIG_DEBUG_FS */
 }
 
 static u64 rpm_get_accounted_time(struct device *dev, bool suspended)
@@ -1580,6 +1641,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_disable);
 void pm_runtime_enable(struct device *dev)
 {
 	unsigned long flags;
+	u64 now;
 
 	spin_lock_irqsave(&dev->power.lock, flags);
 
@@ -1596,12 +1658,24 @@ void pm_runtime_enable(struct device *dev)
 		dump_stack();
 	}
 	dev->power.last_status = RPM_INVALID;
-	dev->power.accounting_timestamp = ktime_get_mono_fast_ns();
+	now = 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) {
+#ifdef CONFIG_DEBUG_FS
+		if (dev->power.suspend_time) {
+			if (dev->power.accounting_timestamp
+			    && now > dev->power.accounting_timestamp)
+				dev->power.suspend_time += now - dev->power.accounting_timestamp;
+		} else {
+			dev->power.suspend_time = now;
+		}
+#endif /* CONFIG_DEBUG_FS */
+		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");
+	}
+
+	dev->power.accounting_timestamp = now;
 
 out:
 	spin_unlock_irqrestore(&dev->power.lock, flags);
@@ -1870,6 +1944,15 @@ void pm_runtime_init(struct device *dev)
 	pm_suspend_ignore_children(dev, false);
 	dev->power.runtime_auto = true;
 
+#ifdef CONFIG_DEBUG_FS
+	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;
+#endif /* CONFIG_DEBUG_FS */
+
 	dev->power.request_pending = false;
 	dev->power.request = RPM_REQ_NONE;
 	dev->power.deferred_resume = false;
diff --git a/include/linux/pm.h b/include/linux/pm.h
index ef3f1310e749..caa4ba4a65de 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -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,7 +822,15 @@ struct dev_pm_info {
 	u64			active_time;
 	u64			suspended_time;
 	u64			accounting_timestamp;
-#endif
+#ifdef CONFIG_DEBUG_FS
+	u64			resume_count;
+	u64			suspend_count;
+	u64			suspend_time;
+	u64			last_suspended_time;
+	u64			min_suspended_time;
+	u64			max_suspended_time;
+#endif /* CONFIG_DEBUG_FS */
+#endif /* CONFIG_PM */
 	struct pm_subsys_data	*subsys_data;  /* Owned by the subsystem. */
 	void (*set_latency_tolerance)(struct device *, s32);
 	struct dev_pm_qos	*qos;

-- 
2.47.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary
  2026-11-23  9:06 [PATCH v3 0/2] PM: runtime: add new runtime metrics and summary Joshua Crofts
  2026-11-23  9:06 ` [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics Joshua Crofts
@ 2026-11-23  9:06 ` Joshua Crofts
  2026-11-25 13:01   ` Rafael J. Wysocki (Intel)
  1 sibling, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-11-23  9:06 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Samuel Wu
  Cc: linux-pm, driver-core, linux-kernel, Joshua Crofts

Add a debugfs entry for showing the runtime statistics for devices with
PM runtime enabled.

Signed-off-by: Joshua Crofts <crofts@kernel.org>
---
 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)
+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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics
  2026-11-23  9:06 ` [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics Joshua Crofts
@ 2026-11-25 12:54   ` Rafael J. Wysocki (Intel)
  2026-11-25 12:58     ` Rafael J. Wysocki (Intel)
  2026-11-25 14:38     ` Joshua Crofts
  0 siblings, 2 replies; 8+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-25 12:54 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Samuel Wu, linux-pm, driver-core,
	linux-kernel

On Mon, Nov 23, 2026 at 10:07 AM Joshua Crofts <crofts@kernel.org> wrote:
>
> 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_time: shortest and longest sleep
>   cycle durations to help detect power thrashing (ns)

I would mention that they would be only reachable through a debugfs interface.

> Signed-off-by: Joshua Crofts <crofts@kernel.org>
> ---
>  drivers/base/power/runtime.c | 93 +++++++++++++++++++++++++++++++++++++++++---
>  include/linux/pm.h           | 16 +++++++-
>  2 files changed, 103 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 4e9c23059a40..17aee68366cf 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -5,6 +5,8 @@
>   * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
>   * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu>
>   */
> +#include <linux/pm.h>
> +#include <linux/timekeeping.h>
>  #include <linux/sched/mm.h>
>  #include <linux/ktime.h>
>  #include <linux/hrtimer.h>
> @@ -103,11 +105,70 @@ static void update_pm_runtime_accounting(struct device *dev)
>                 dev->power.active_time += delta;
>  }
>
> +#ifdef CONFIG_DEBUG_FS
> +static void rpm_account_suspend(struct device *dev)
> +{
> +       dev->power.suspend_time = dev->power.accounting_timestamp;
> +       dev->power.suspend_count++;
> +}
> +
> +static void rpm_account_sleep_end(struct device *dev)
> +{
> +       u64 duration;
> +
> +       if (!dev->power.suspend_time)
> +               return;
> +
> +       if (dev->power.accounting_timestamp <= dev->power.suspend_time)
> +               return;
> +
> +       duration = dev->power.accounting_timestamp - 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;
> +}
> +#endif /* CONFIG_DEBUG_FS */
> +
>  static void __update_runtime_status(struct device *dev, enum rpm_status status)
>  {
> +#ifdef CONFIG_DEBUG_FS
> +       enum rpm_status old_status = dev->power.runtime_status;
> +#endif /* CONFIG_DEBUG_FS */
> +
>         update_pm_runtime_accounting(dev);
>         trace_rpm_status(dev, status);
>         dev->power.runtime_status = status;
> +
> +#ifdef CONFIG_DEBUG_FS
> +       if (dev->power.disable_depth > 0) {
> +               if (status == RPM_ACTIVE)
> +                       dev->power.suspend_time = 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 = dev->power.accounting_timestamp;
> +       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);
> +#endif /* CONFIG_DEBUG_FS */

Please move the code under CONFIG_DEBUG_FS in this function to a
separate function called by it and defined as an empty stub if
CONFIG_DEBUG_FS is unset.

>  }
>
>  static u64 rpm_get_accounted_time(struct device *dev, bool suspended)
> @@ -1580,6 +1641,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_disable);
>  void pm_runtime_enable(struct device *dev)
>  {
>         unsigned long flags;
> +       u64 now;
>
>         spin_lock_irqsave(&dev->power.lock, flags);
>
> @@ -1596,12 +1658,24 @@ void pm_runtime_enable(struct device *dev)
>                 dump_stack();
>         }
>         dev->power.last_status = RPM_INVALID;
> -       dev->power.accounting_timestamp = ktime_get_mono_fast_ns();
> +       now = 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) {
> +#ifdef CONFIG_DEBUG_FS
> +               if (dev->power.suspend_time) {
> +                       if (dev->power.accounting_timestamp
> +                           && now > dev->power.accounting_timestamp)
> +                               dev->power.suspend_time += now - dev->power.accounting_timestamp;
> +               } else {
> +                       dev->power.suspend_time = now;
> +               }
> +#endif /* CONFIG_DEBUG_FS */

Same here.

Plus you can use dev->power.accounting_timestamp as "now" in the new
function after setting it above.

> +               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");
> +       }
> +
> +       dev->power.accounting_timestamp = now;
>
>  out:
>         spin_unlock_irqrestore(&dev->power.lock, flags);
> @@ -1870,6 +1944,15 @@ void pm_runtime_init(struct device *dev)
>         pm_suspend_ignore_children(dev, false);
>         dev->power.runtime_auto = true;
>
> +#ifdef CONFIG_DEBUG_FS
> +       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;
> +#endif /* CONFIG_DEBUG_FS */

And here too.

> +
>         dev->power.request_pending = false;
>         dev->power.request = RPM_REQ_NONE;
>         dev->power.deferred_resume = false;
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index ef3f1310e749..caa4ba4a65de 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -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,7 +822,15 @@ struct dev_pm_info {
>         u64                     active_time;
>         u64                     suspended_time;
>         u64                     accounting_timestamp;
> -#endif
> +#ifdef CONFIG_DEBUG_FS
> +       u64                     resume_count;
> +       u64                     suspend_count;
> +       u64                     suspend_time;
> +       u64                     last_suspended_time;
> +       u64                     min_suspended_time;
> +       u64                     max_suspended_time;
> +#endif /* CONFIG_DEBUG_FS */
> +#endif /* CONFIG_PM */
>         struct pm_subsys_data   *subsys_data;  /* Owned by the subsystem. */
>         void (*set_latency_tolerance)(struct device *, s32);
>         struct dev_pm_qos       *qos;
>
> --
> 2.47.3
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics
  2026-11-25 12:54   ` Rafael J. Wysocki (Intel)
@ 2026-11-25 12:58     ` Rafael J. Wysocki (Intel)
  2026-11-25 14:38     ` Joshua Crofts
  1 sibling, 0 replies; 8+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-25 12:58 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Pavel Machek, Greg Kroah-Hartman, Danilo Krummrich, Johan Hovold,
	Samuel Wu, linux-pm, driver-core, linux-kernel

On Wed, Nov 25, 2026 at 1:54 PM Rafael J. Wysocki (Intel)
<rafael@kernel.org> wrote:
>
> On Mon, Nov 23, 2026 at 10:07 AM Joshua Crofts <crofts@kernel.org> wrote:
> >
> > 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_time: shortest and longest sleep
> >   cycle durations to help detect power thrashing (ns)
>
> I would mention that they would be only reachable through a debugfs interface.
>
> > Signed-off-by: Joshua Crofts <crofts@kernel.org>
> > ---
> >  drivers/base/power/runtime.c | 93 +++++++++++++++++++++++++++++++++++++++++---
> >  include/linux/pm.h           | 16 +++++++-
> >  2 files changed, 103 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index 4e9c23059a40..17aee68366cf 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -5,6 +5,8 @@
> >   * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
> >   * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu>
> >   */
> > +#include <linux/pm.h>
> > +#include <linux/timekeeping.h>
> >  #include <linux/sched/mm.h>
> >  #include <linux/ktime.h>
> >  #include <linux/hrtimer.h>
> > @@ -103,11 +105,70 @@ static void update_pm_runtime_accounting(struct device *dev)
> >                 dev->power.active_time += delta;
> >  }
> >
> > +#ifdef CONFIG_DEBUG_FS
> > +static void rpm_account_suspend(struct device *dev)
> > +{
> > +       dev->power.suspend_time = dev->power.accounting_timestamp;
> > +       dev->power.suspend_count++;
> > +}
> > +
> > +static void rpm_account_sleep_end(struct device *dev)
> > +{
> > +       u64 duration;
> > +
> > +       if (!dev->power.suspend_time)
> > +               return;
> > +
> > +       if (dev->power.accounting_timestamp <= dev->power.suspend_time)
> > +               return;
> > +
> > +       duration = dev->power.accounting_timestamp - 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;
> > +}
> > +#endif /* CONFIG_DEBUG_FS */
> > +
> >  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> >  {
> > +#ifdef CONFIG_DEBUG_FS
> > +       enum rpm_status old_status = dev->power.runtime_status;
> > +#endif /* CONFIG_DEBUG_FS */
> > +
> >         update_pm_runtime_accounting(dev);
> >         trace_rpm_status(dev, status);
> >         dev->power.runtime_status = status;
> > +
> > +#ifdef CONFIG_DEBUG_FS
> > +       if (dev->power.disable_depth > 0) {
> > +               if (status == RPM_ACTIVE)
> > +                       dev->power.suspend_time = 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 = dev->power.accounting_timestamp;
> > +       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);
> > +#endif /* CONFIG_DEBUG_FS */
>
> Please move the code under CONFIG_DEBUG_FS in this function to a
> separate function called by it and defined as an empty stub if
> CONFIG_DEBUG_FS is unset.
>
> >  }
> >
> >  static u64 rpm_get_accounted_time(struct device *dev, bool suspended)
> > @@ -1580,6 +1641,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_disable);
> >  void pm_runtime_enable(struct device *dev)
> >  {
> >         unsigned long flags;
> > +       u64 now;
> >
> >         spin_lock_irqsave(&dev->power.lock, flags);
> >
> > @@ -1596,12 +1658,24 @@ void pm_runtime_enable(struct device *dev)
> >                 dump_stack();
> >         }
> >         dev->power.last_status = RPM_INVALID;
> > -       dev->power.accounting_timestamp = ktime_get_mono_fast_ns();
> > +       now = 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) {
> > +#ifdef CONFIG_DEBUG_FS
> > +               if (dev->power.suspend_time) {
> > +                       if (dev->power.accounting_timestamp
> > +                           && now > dev->power.accounting_timestamp)
> > +                               dev->power.suspend_time += now - dev->power.accounting_timestamp;
> > +               } else {
> > +                       dev->power.suspend_time = now;
> > +               }
> > +#endif /* CONFIG_DEBUG_FS */
>
> Same here.
>
> Plus you can use dev->power.accounting_timestamp as "now" in the new
> function after setting it above.
>
> > +               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");
> > +       }
> > +
> > +       dev->power.accounting_timestamp = now;
> >
> >  out:
> >         spin_unlock_irqrestore(&dev->power.lock, flags);
> > @@ -1870,6 +1944,15 @@ void pm_runtime_init(struct device *dev)
> >         pm_suspend_ignore_children(dev, false);
> >         dev->power.runtime_auto = true;
> >
> > +#ifdef CONFIG_DEBUG_FS
> > +       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;
> > +#endif /* CONFIG_DEBUG_FS */
>
> And here too.
>
> > +
> >         dev->power.request_pending = false;
> >         dev->power.request = RPM_REQ_NONE;
> >         dev->power.deferred_resume = false;
> > diff --git a/include/linux/pm.h b/include/linux/pm.h
> > index ef3f1310e749..caa4ba4a65de 100644
> > --- a/include/linux/pm.h
> > +++ b/include/linux/pm.h
> > @@ -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)

It is better to say "suspension" instead of "sleep" in this comment
and the two comments below to avoid confusion.

> > + * @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,7 +822,15 @@ struct dev_pm_info {
> >         u64                     active_time;
> >         u64                     suspended_time;
> >         u64                     accounting_timestamp;
> > -#endif
> > +#ifdef CONFIG_DEBUG_FS
> > +       u64                     resume_count;
> > +       u64                     suspend_count;
> > +       u64                     suspend_time;
> > +       u64                     last_suspended_time;
> > +       u64                     min_suspended_time;
> > +       u64                     max_suspended_time;
> > +#endif /* CONFIG_DEBUG_FS */
> > +#endif /* CONFIG_PM */
> >         struct pm_subsys_data   *subsys_data;  /* Owned by the subsystem. */
> >         void (*set_latency_tolerance)(struct device *, s32);
> >         struct dev_pm_qos       *qos;
> >
> > --
> > 2.47.3
> >

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary
  2026-11-23  9:06 ` [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary Joshua Crofts
@ 2026-11-25 13:01   ` Rafael J. Wysocki (Intel)
  2026-11-25 14:29     ` Joshua Crofts
  0 siblings, 1 reply; 8+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-25 13:01 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Samuel Wu, linux-pm, driver-core,
	linux-kernel

On Mon, Nov 23, 2026 at 10:07 AM Joshua Crofts <crofts@kernel.org> wrote:
>
> Add a debugfs entry for showing the runtime statistics for devices with
> PM runtime enabled.
>
> Signed-off-by: Joshua Crofts <crofts@kernel.org>
> ---
>  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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary
  2026-11-25 13:01   ` Rafael J. Wysocki (Intel)
@ 2026-11-25 14:29     ` Joshua Crofts
  0 siblings, 0 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-11-25 14:29 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel)
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, Danilo Krummrich,
	Johan Hovold, Samuel Wu, linux-pm, driver-core, linux-kernel

On 25-Nov-26 14:01, Rafael J. Wysocki (Intel) wrote:
> On Mon, Nov 23, 2026 at 10:07 AM Joshua Crofts <crofts@kernel.org> wrote:
>>
>> Add a debugfs entry for showing the runtime statistics for devices with
>> PM runtime enabled.
>>
>> Signed-off-by: Joshua Crofts <crofts@kernel.org>
>> ---
>>  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.

dpm_for_each_dev() is guarded by #ifdef CONFIG_PM_SLEEP.

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics
  2026-11-25 12:54   ` Rafael J. Wysocki (Intel)
  2026-11-25 12:58     ` Rafael J. Wysocki (Intel)
@ 2026-11-25 14:38     ` Joshua Crofts
  1 sibling, 0 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-11-25 14:38 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel)
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, Danilo Krummrich,
	Johan Hovold, Samuel Wu, linux-pm, driver-core, linux-kernel

On 25-Nov-26 13:54, Rafael J. Wysocki (Intel) wrote:
> On Mon, Nov 23, 2026 at 10:07 AM Joshua Crofts <crofts@kernel.org> wrote:
>>
>> 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_time: shortest and longest sleep
>>   cycle durations to help detect power thrashing (ns)
> 
> I would mention that they would be only reachable through a debugfs interface.
> 
>> Signed-off-by: Joshua Crofts <crofts@kernel.org>
>> ---
>>  drivers/base/power/runtime.c | 93 +++++++++++++++++++++++++++++++++++++++++---
>>  include/linux/pm.h           | 16 +++++++-
>>  2 files changed, 103 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
>> index 4e9c23059a40..17aee68366cf 100644
>> --- a/drivers/base/power/runtime.c
>> +++ b/drivers/base/power/runtime.c
>> @@ -5,6 +5,8 @@
>>   * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
>>   * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu>
>>   */
>> +#include <linux/pm.h>
>> +#include <linux/timekeeping.h>
>>  #include <linux/sched/mm.h>
>>  #include <linux/ktime.h>
>>  #include <linux/hrtimer.h>
>> @@ -103,11 +105,70 @@ static void update_pm_runtime_accounting(struct device *dev)
>>                 dev->power.active_time += delta;
>>  }
>>
>> +#ifdef CONFIG_DEBUG_FS
>> +static void rpm_account_suspend(struct device *dev)
>> +{
>> +       dev->power.suspend_time = dev->power.accounting_timestamp;
>> +       dev->power.suspend_count++;
>> +}
>> +
>> +static void rpm_account_sleep_end(struct device *dev)
>> +{
>> +       u64 duration;
>> +
>> +       if (!dev->power.suspend_time)
>> +               return;
>> +
>> +       if (dev->power.accounting_timestamp <= dev->power.suspend_time)
>> +               return;
>> +
>> +       duration = dev->power.accounting_timestamp - 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;
>> +}
>> +#endif /* CONFIG_DEBUG_FS */
>> +
>>  static void __update_runtime_status(struct device *dev, enum rpm_status status)
>>  {
>> +#ifdef CONFIG_DEBUG_FS
>> +       enum rpm_status old_status = dev->power.runtime_status;
>> +#endif /* CONFIG_DEBUG_FS */
>> +
>>         update_pm_runtime_accounting(dev);
>>         trace_rpm_status(dev, status);
>>         dev->power.runtime_status = status;
>> +
>> +#ifdef CONFIG_DEBUG_FS
>> +       if (dev->power.disable_depth > 0) {
>> +               if (status == RPM_ACTIVE)
>> +                       dev->power.suspend_time = 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 = dev->power.accounting_timestamp;
>> +       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);
>> +#endif /* CONFIG_DEBUG_FS */
> 
> Please move the code under CONFIG_DEBUG_FS in this function to a
> separate function called by it and defined as an empty stub if
> CONFIG_DEBUG_FS is unset.

Ack, this patch is messy...

Also Sashiko still isn't happy with the way I calculate these metrics.

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-25 14:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23  9:06 [PATCH v3 0/2] PM: runtime: add new runtime metrics and summary Joshua Crofts
2026-11-23  9:06 ` [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics Joshua Crofts
2026-11-25 12:54   ` Rafael J. Wysocki (Intel)
2026-11-25 12:58     ` Rafael J. Wysocki (Intel)
2026-11-25 14:38     ` Joshua Crofts
2026-11-23  9:06 ` [PATCH v3 2/2] PM: runtime: add debugfs entry for pm_runtime_summary Joshua Crofts
2026-11-25 13:01   ` Rafael J. Wysocki (Intel)
2026-11-25 14:29     ` Joshua Crofts

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®