linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Norris <briannorris@chromium.org>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-pm@vger.kernel.org, "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@kernel.org>,
	Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Subject: Re: [PATCH v2 1/6] pm: runtime: Document return values of suspend related API functions
Date: Thu, 28 Aug 2025 17:46:07 -0700	[thread overview]
Message-ID: <aLD4TwJftEAeCJyf@google.com> (raw)
In-Reply-To: <aJ5pkEJuixTaybV4@google.com>

After reading and rereading ... and then writing unit tests, because I
can't trust my reading ... I think I can answer my own questions:

On Thu, Aug 14, 2025 at 03:56:24PM -0700, Brian Norris wrote:
> Hi,
> 
> On Mon, Jun 16, 2025 at 09:12:07AM +0300, Sakari Ailus wrote:
> > Document return values for device suspend and idle related API functions.
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> I appreciate the documentation attempt here. I've often found it a maze
> trying to weave through the indirection and figure out the actual API
> contract for some of these.
> 
> But I have a few questions below:
> 
> > ---
> >  include/linux/pm_runtime.h | 147 ++++++++++++++++++++++++++++++++++---
> >  1 file changed, 138 insertions(+), 9 deletions(-)
> > 
> > diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> > index e7cb70fcc0af..9dd2e4031a27 100644
> > --- a/include/linux/pm_runtime.h
> > +++ b/include/linux/pm_runtime.h
> 
> 
> > @@ -464,6 +525,17 @@ static inline int pm_runtime_resume_and_get(struct device *dev)
> >   *
> >   * Decrement the runtime PM usage counter of @dev and if it turns out to be
> >   * equal to 0, queue up a work item for @dev like in pm_request_idle().
> > + *
> > + * Return:
> > + * * 0: Success.
> > + * * -EINVAL: Runtime PM error.
> > + * * -EACCES: Runtime PM disabled.
> > + * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
> 
> ^^ Is the "usage_count non-zero" true? For RPM_GET_PUT, we drop the
> refcount, and if it's still nonzero, we simply return 0.

It *is* possible, but it would only occur with the following:

(1) we've acquired our usage_count by way of pm_runtime_get_noresume();
    and
(2) some other actor is racing with us, acquiring a usage_count between
    when we decremented usage_count to 0, and when we check again in
    rpm_idle()

IMO, as-is, the language is a bit misleading though. But then, the
behavior is pretty subtle and hard to describe succinctly...

> > + * * -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.
> 
> This part isn't very clear to me: can we even hit this case? If the
> usage count was already 0, we'd hit EINVAL, since this is a PUT
> operation. If the usage count was non-zero, we can't already be
> suspended. At a minimum, we'd be RESUMING (e.g., an async resume), no?

This is sort of possible in the same scenario as above. But it doesn't
actually return 1; it still returns -EAGAIN.

Confusingly, pm_runtime_put_autosuspend() behaves differently, because
it's based on rpm_suspend() instead of rpm_idle().

I plan to fix this, because I don't see why pm_runtime_put() and
pm_runtime_put_autosuspend() should differ here.

> >   */
> >  static inline int pm_runtime_put(struct device *dev)
> >  {
> 
> If these are indeed errors, I expect they're repeated on some of the
> other related APIs too (like pm_runtime_put_sync(), pm_runtime_idle(),
> and probably more).
> 
> I ask mostly for my own understanding, but I might consider patching the
> docs if I'm not hallucinating these errors.

I've sent a patch series to fix some of the inconsistencies in the API
and to fix the API docs:

Subject: [PATCH 3/3] PM: runtime: Update kerneldoc return codes
https://lore.kernel.org/all/20250829003319.2785282-3-briannorris@chromium.org/

Brian

  reply	other threads:[~2025-08-29  0:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16  6:12 [PATCH v2 0/6] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
2025-06-16  6:12 ` [PATCH v2 1/6] pm: runtime: Document return values of suspend related API functions Sakari Ailus
2025-08-14 22:56   ` Brian Norris
2025-08-29  0:46     ` Brian Norris [this message]
2025-08-29 10:23       ` Sakari Ailus
2025-06-16  6:12 ` [PATCH v2 2/6] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend() Sakari Ailus
2025-06-16  6:12 ` [PATCH v2 3/6] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend() Sakari Ailus
2025-06-16  6:12 ` [PATCH v2 4/6] pm: runtime: Mark last busy stamp in pm_runtime_autosuspend() Sakari Ailus
2025-06-16  6:12 ` [PATCH v2 5/6] pm: runtime: Mark last busy stamp in pm_request_autosuspend() Sakari Ailus
2025-06-16  6:12 ` [PATCH v2 6/6] Documentation: PM: *_autosuspend() functions update last busy time Sakari Ailus
2025-06-16 11:21 ` [PATCH v2 0/6] Update last busy timestamp in Runtime PM autosuspend callbacks Rafael J. Wysocki
2025-06-16 19:20   ` Sakari Ailus
2025-06-16 20:10     ` Laurent Pinchart
2025-06-18 19:43     ` Rafael J. Wysocki
2025-06-25  9:15       ` Sakari Ailus
2025-06-23 13:28 ` Oliver Neukum
2025-06-25  6:59   ` Sakari Ailus

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=aLD4TwJftEAeCJyf@google.com \
    --to=briannorris@chromium.org \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=len.brown@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    --cc=sakari.ailus@linux.intel.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;
as well as URLs for NNTP newsgroup(s).