From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Brian Norris <briannorris@chromium.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Pavel Machek <pavel@kernel.org>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
kunit-dev@googlegroups.com, Len Brown <lenb@kernel.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] PM: runtime: Update kerneldoc return codes
Date: Tue, 2 Sep 2025 10:18:05 +0300 [thread overview]
Message-ID: <aLaaLc0TPhtm-H5j@kekkonen.localdomain> (raw)
In-Reply-To: <20250829003319.2785282-3-briannorris@chromium.org>
Hi Brian,
Thanks for posting this. A few comments below.
On Thu, Aug 28, 2025 at 05:28:28PM -0700, Brian Norris wrote:
> APIs based on __pm_runtime_idle() (pm_runtime_idle(), pm_request_idle())
> do not return 1 when already suspended. They return -EAGAIN. This is
> already covered in the docs, so the entry for "1" is redundant and
> conflicting.
>
> (pm_runtime_put() and pm_runtime_put_sync() were previously incorrect,
> but that's fixed in "PM: runtime: pm_runtime_put{,_sync}() returns 1
> when already suspended", to ensure consistency with APIs like
> pm_runtime_put_autosuspend().)
>
> RPM_GET_PUT APIs based on __pm_runtime_suspend() do return 1 when
> already suspended, but the language is a little unclear -- it's not
> really an "error", so it seems better to list as a clarification before
> the 0/success case. Additionally, they only actually return 1 when the
> refcount makes it to 0; if the usage_count is still non-zero, we return
> 0.
>
> pm_runtime_put(), etc., also don't appear at first like they can ever
> see "-EAGAIN: Runtime PM usage_count non-zero", because in non-racy
> conditions, pm_runtime_put() would drop its reference count, see it's
> non-zero, and return early (in __pm_runtime_idle()). However, it's
> possible to race with another actor that increments the usage_count
> afterward, since rpm_idle() is protected by a separate lock; in such a
> case, we may see -EAGAIN.
>
> Because this case is only seen in the presence of concurrent actors, it
> makes sense to clarify that this is when "usage_count **became**
> non-zero", by way of some racing actor.
>
> Lastly, pm_runtime_put_sync_suspend() duplicated some -EAGAIN language.
> Fix that.
>
> Fixes: 271ff96d6066 ("PM: runtime: Document return values of suspend-related API functions")
> Link: https://lore.kernel.org/linux-pm/aJ5pkEJuixTaybV4@google.com/
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
>
> include/linux/pm_runtime.h | 33 ++++++++++++++++++---------------
> 1 file changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> index d88d6b6ccf5b..fd17ffe1bc79 100644
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -356,7 +356,6 @@ static inline int pm_runtime_force_resume(struct device *dev) { return -ENXIO; }
> * * -EPERM: Device PM QoS resume latency 0.
> * * -EINPROGRESS: Suspend already in progress.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> * Other values and conditions for the above values are possible as returned by
> * Runtime PM idle and suspend callbacks.
> */
> @@ -439,7 +438,6 @@ static inline int pm_runtime_resume(struct device *dev)
> * * -EPERM: Device PM QoS resume latency 0.
> * * -EINPROGRESS: Suspend already in progress.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> */
> static inline int pm_request_idle(struct device *dev)
> {
> @@ -540,15 +538,16 @@ static inline int pm_runtime_resume_and_get(struct device *dev)
> * equal to 0, queue up a work item for @dev like in pm_request_idle().
> *
> * Return:
> + * * 1: Usage counts dropped to zero, but device was already suspended.
Does this actually happen? pm_runtime_put() calls __pm_runtime_idle() that
doesn't appear to return 1 in any case.
> * * 0: Success.
> * * -EINVAL: Runtime PM error.
> * * -EACCES: Runtime PM disabled.
> - * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
> + * * -EAGAIN: Runtime PM usage_count became non-zero or Runtime PM status
> + * change ongoing.
> * * -EBUSY: Runtime PM child_count non-zero.
> * * -EPERM: Device PM QoS resume latency 0.
> * * -EINPROGRESS: Suspend already in progress.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> */
> static inline int pm_runtime_put(struct device *dev)
> {
> @@ -565,15 +564,16 @@ DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T))
> * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
> *
> * Return:
> + * * 1: Usage counts dropped to zero, but device was already suspended.
> * * 0: Success.
"usage_count" and "usage counter" is being used in kernel-doc already, I'd
use either of the two. "usage_count" refers directly to the field in struct
dev_pm_info (and is used a few lines below). Same elsewhere.
> * * -EINVAL: Runtime PM error.
> * * -EACCES: Runtime PM disabled.
> - * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
> + * * -EAGAIN: Runtime PM usage_count became non-zero or Runtime PM status
> + * change ongoing.
> * * -EBUSY: Runtime PM child_count non-zero.
> * * -EPERM: Device PM QoS resume latency 0.
> * * -EINPROGRESS: Suspend already in progress.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> */
> static inline int __pm_runtime_put_autosuspend(struct device *dev)
> {
> @@ -590,15 +590,16 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
> * in pm_request_autosuspend().
> *
> * Return:
> + * * 1: Usage counts dropped to zero, but device was already suspended.
> * * 0: Success.
> * * -EINVAL: Runtime PM error.
> * * -EACCES: Runtime PM disabled.
> - * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
> + * * -EAGAIN: Runtime PM usage_count became non-zero or Runtime PM status
> + * change ongoing.
> * * -EBUSY: Runtime PM child_count non-zero.
> * * -EPERM: Device PM QoS resume latency 0.
> * * -EINPROGRESS: Suspend already in progress.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> */
> static inline int pm_runtime_put_autosuspend(struct device *dev)
> {
> @@ -619,14 +620,15 @@ static inline int pm_runtime_put_autosuspend(struct device *dev)
> * if it returns an error code.
> *
> * Return:
> + * * 1: Usage counts dropped to zero, but device was already suspended.
> * * 0: Success.
Does this happen (pm_runtime_put_sync() calls __pm_runtime_idle())?
> * * -EINVAL: Runtime PM error.
> * * -EACCES: Runtime PM disabled.
> - * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
> + * * -EAGAIN: Runtime PM usage_count became non-zero or Runtime PM status
> + * change ongoing.
> * * -EBUSY: Runtime PM child_count non-zero.
> * * -EPERM: Device PM QoS resume latency 0.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> * Other values and conditions for the above values are possible as returned by
> * Runtime PM suspend callbacks.
> */
> @@ -646,15 +648,15 @@ static inline int pm_runtime_put_sync(struct device *dev)
> * if it returns an error code.
> *
> * Return:
> + * * 1: Usage counts dropped to zero, but device was already suspended.
> * * 0: Success.
> * * -EINVAL: Runtime PM error.
> * * -EACCES: Runtime PM disabled.
> - * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
> - * * -EAGAIN: usage_count non-zero or Runtime PM status change ongoing.
> + * * -EAGAIN: Runtime PM usage_count became non-zero or Runtime PM status
> + * change ongoing.
> * * -EBUSY: Runtime PM child_count non-zero.
> * * -EPERM: Device PM QoS resume latency 0.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> * Other values and conditions for the above values are possible as returned by
> * Runtime PM suspend callbacks.
> */
> @@ -677,15 +679,16 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev)
> * if it returns an error code.
> *
> * Return:
> + * * 1: Usage counts dropped to zero, but device was already suspended.
> * * 0: Success.
> * * -EINVAL: Runtime PM error.
> * * -EACCES: Runtime PM disabled.
> - * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
> + * * -EAGAIN: Runtime PM usage_count became non-zero or Runtime PM status
> + * change ongoing.
> * * -EBUSY: Runtime PM child_count non-zero.
> * * -EPERM: Device PM QoS resume latency 0.
> * * -EINPROGRESS: Suspend already in progress.
> * * -ENOSYS: CONFIG_PM not enabled.
> - * * 1: Device already suspended.
> * Other values and conditions for the above values are possible as returned by
> * Runtime PM suspend callbacks.
> */
--
Kind regards,
Sakari Ailus
next prev parent reply other threads:[~2025-09-02 7:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 0:28 [PATCH 1/3] PM: runtime: Add basic kunit tests for API contracts Brian Norris
2025-08-29 0:28 ` [PATCH 2/3] PM: runtime: Make put{,_sync}() return 1 when already suspended Brian Norris
2025-09-02 7:25 ` Sakari Ailus
2025-09-05 17:42 ` Rafael J. Wysocki
2025-09-24 9:48 ` Dhruva Gole
2025-08-29 0:28 ` [PATCH 3/3] PM: runtime: Update kerneldoc return codes Brian Norris
2025-09-02 7:18 ` Sakari Ailus [this message]
2025-09-05 17:54 ` Rafael J. Wysocki
2025-09-05 17:37 ` [PATCH 1/3] PM: runtime: Add basic kunit tests for API contracts Rafael J. Wysocki
2025-09-10 20:44 ` Brian Norris
2025-09-19 16:58 ` Rafael J. Wysocki
2025-09-23 21:51 ` Brian Norris
2025-09-24 17:32 ` Rafael J. Wysocki
2025-09-24 17:34 ` Rafael J. Wysocki
2025-09-25 18:36 ` Brian Norris
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=aLaaLc0TPhtm-H5j@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=briannorris@chromium.org \
--cc=kunit-dev@googlegroups.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=rafael@kernel.org \
/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