From: Joshua Crofts <crofts@kernel.org>
To: "Rafael J. Wysocki (Intel)" <rafael@kernel.org>
Cc: 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>,
linux-pm@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] PM: runtime: add additional suspend/resume metrics
Date: Wed, 25 Nov 2026 15:38:30 +0100 [thread overview]
Message-ID: <5387130c-df43-41d7-9ff8-8ee549e6e97f@kernel.org> (raw)
In-Reply-To: <CAJZ5v0hpnoGw89WHyofLr3SxnrJNs99LnhndeOv245y_LgGWXQ@mail.gmail.com>
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
next prev parent reply other threads:[~2026-11-25 14:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=5387130c-df43-41d7-9ff8-8ee549e6e97f@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.