From: Joshua Crofts <crofts@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Pavel Machek <pavel@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>, Samuel Wu <wusamuel@google.com>
Cc: linux-pm@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org, Joshua Crofts <crofts@kernel.org>
Subject: [PATCH v4 1/2] PM: runtime: add additional suspend/resume metrics
Date: Mon, 30 Nov 2026 11:57:37 +0100 [thread overview]
Message-ID: <20261130-pm-runtime-summary-v4-1-154a4c079ea7@kernel.org> (raw)
In-Reply-To: <20261130-pm-runtime-summary-v4-0-154a4c079ea7@kernel.org>
The current implementation only logs the total accumulated time a device
spends in suspended or active states.
Add tracking for the following metrics, which will be available through
debugfs:
- 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 | 65 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/pm.h | 18 +++++++++++-
2 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 4e9c23059a40..5b010abede5d 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -103,11 +103,74 @@ 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)
+{
+ if (dev->power.active_sleep)
+ return;
+
+ dev->power.suspend_time = dev->power.suspended_time;
+ dev->power.suspend_count++;
+ dev->power.active_sleep = true;
+}
+
+static void rpm_account_resume_complete(struct device *dev)
+{
+ u64 duration;
+
+ if (!dev->power.active_sleep)
+ return;
+
+ duration = dev->power.suspended_time - 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;
+
+ dev->power.resume_count++;
+ dev->power.active_sleep = false;
+}
+
+static void rpm_update_runtime_metrics(struct device *dev,
+ enum rpm_status old_status,
+ enum rpm_status status)
+{
+ if (old_status != RPM_SUSPENDED && status == RPM_SUSPENDED)
+ rpm_account_suspend(dev);
+ else if (old_status != RPM_ACTIVE && status == RPM_ACTIVE)
+ rpm_account_resume_complete(dev);
+}
+
+static void rpm_init_debugfs_metrics(struct device *dev)
+{
+ 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.active_sleep = false;
+}
+#else
+static inline void rpm_update_runtime_metrics(struct device *dev,
+ enum rpm_status old_status,
+ enum rpm_status status) {}
+static inline void rpm_init_debugfs_metrics(struct device *dev) {}
+#endif /* CONFIG_DEBUG_FS */
+
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;
+
+ rpm_update_runtime_metrics(dev, old_status, status);
}
static u64 rpm_get_accounted_time(struct device *dev, bool suspended)
@@ -1870,6 +1933,8 @@ void pm_runtime_init(struct device *dev)
pm_suspend_ignore_children(dev, false);
dev->power.runtime_auto = true;
+ rpm_init_debugfs_metrics(dev);
+
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..077153b26c19 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -747,6 +747,13 @@ 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: Snapshot when device entered RPM_SUSPENDED mode
+ * @last_suspended_time: Residency of the last sleep period (ns)
+ * @min_suspended_time: Shortest sleep duration
+ * @max_suspended_time: Longest sleep duration
+ * @active_sleep: Whether a runtime suspend cycle is currently being tracked
* @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 +823,16 @@ 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;
+ bool active_sleep;
+#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
next prev parent reply other threads:[~2026-11-30 10:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:57 [PATCH v4 0/2] PM: runtime: add new runtime metrics and summary Joshua Crofts
2026-11-30 10:57 ` Joshua Crofts [this message]
2026-11-30 10:57 ` [PATCH v4 2/2] PM: runtime: add debugfs entry for pm_runtime_summary Joshua Crofts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130-pm-runtime-summary-v4-1-154a4c079ea7@kernel.org \
--to=crofts@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=wusamuel@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox