Linux Power Management development
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: Brian Norris <briannorris@chromium.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Ulf Hansson <ulf.hansson@oss.qualcomm.com>,
	Linux Driver Core Development <driver-core@lists.linux.dev>
Subject: [PATCH v2 2/2] PM: runtime: Call rpm_idle() in rpm_resume() for active devices
Date: Mon, 30 Nov 2026 16:07:41 +0100	[thread overview]
Message-ID: <3453261.aeNJFYEL58@rafael.j.wysocki> (raw)
In-Reply-To: <5129504.GXAFRqVoOG@rafael.j.wysocki>

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

If rpm_resume() actually resumes the device successfully (that is, the
device's runtime resume callback is invoked and does not fail), it calls
rpm_idle() to check whether or not the device really is in use and
possibly start an autosuspend timer for it or advance its last_busy
timestamp.  However, rpm_idle() is not called by rpm_resume() if the
runtime PM status of the device is RPM_ACTIVE to start with, which is
inconsistent and may be confusing.

Most importantly, if no runtime PM references to the given device are
held when rpm_resume() is about to return, skipping the rpm_idle()
invocation means missing an opportunity to suspend the device that is
not otherwise prevented from suspending.  If autosuspend is used by the
device, an autosuspend timer can be expected to be started for it when
rpm_resume() is about to return, but that will not happen if the
device's runtime PM status is RPM_ACTIVE to start with.  The next
opportunity to start an autosuspend timer for the device may not
appear at any time soon.

Address this by rearranging rpm_resume() to call rpm_idle() also if the
device was already active and drop the direct last_busy update carried
out in that case as it is not necessary any more because rpm_idle()
updates last_busy.  Also make the rpm_resume() kerneldoc comment match
the new code flow.

Note that if the device is prevented from suspending when rpm_idle() is
called, the overhead of calling rpm_idle() boils down to checking that
the device in fact cannot be suspended, so it should not be significant.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/base/power/runtime.c |   18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -833,7 +833,8 @@ static int rpm_suspend(struct device *de
  * suspending (deferred_resume) or wait for it to finish.  If the RPM_ASYNC
  * flag is set then queue a resume request; otherwise run the
  * ->runtime_resume() callback directly.  Queue an idle notification for the
- * device if the resume succeeded.
+ * device if the resume succeeded or the device's runtime PM status was
+ * RPM_ACTIVE to start with.
  *
  * This function must be called under dev->power.lock with interrupts disabled.
  */
@@ -872,14 +873,8 @@ static int rpm_resume(struct device *dev
 		pm_runtime_deactivate_timer(dev);
 
 	if (dev->power.runtime_status == RPM_ACTIVE) {
-		/*
-		 * The attempt to resume the device means that it is needed for
-		 * something, so update its last_busy timestamp as in the case
-		 * in which it actually resumes below.
-		 */
-		pm_runtime_mark_last_busy(dev);
 		retval = 1;
-		goto out;
+		goto success;
 	}
 
 	if (dev->power.runtime_status == RPM_RESUMING ||
@@ -1009,8 +1004,11 @@ static int rpm_resume(struct device *dev
 	}
 	wake_up_all(&dev->power.wait_queue);
 
-	if (retval >= 0)
-		rpm_idle(dev, RPM_ASYNC);
+	if (retval < 0)
+		goto out;
+
+ success:
+	rpm_idle(dev, RPM_ASYNC);
 
  out:
 	if (parent && !dev->power.irq_safe) {




      parent reply	other threads:[~2026-11-30 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 15:01 [PATCH v2 0/2] PM: runtime: Consolidation of last_busy updates and calling rpm_idle() in rpm_resume() Rafael J. Wysocki
2026-11-30 15:04 ` [PATCH v2 1/2] PM: runtime: Drop redundant last_busy update from rpm_resume() Rafael J. Wysocki
2026-11-30 15:07 ` Rafael J. Wysocki [this message]

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=3453261.aeNJFYEL58@rafael.j.wysocki \
    --to=rafael@kernel.org \
    --cc=briannorris@chromium.org \
    --cc=driver-core@lists.linux.dev \
    --cc=linux-pm@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=ulf.hansson@oss.qualcomm.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