From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Alan Stern <stern@rowland.harvard.edu>,
Ulf Hansson <ulf.hansson@linaro.org>,
Johan Hovold <johan@kernel.org>,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
Jon Hunter <jonathanh@nvidia.com>,
Saravana Kannan <saravanak@google.com>
Subject: [PATCH v3 2/5] PM: sleep: Suspend async parents after suspending children
Date: Fri, 14 Mar 2025 14:13:53 +0100 [thread overview]
Message-ID: <3541233.QJadu78ljV@rjwysocki.net> (raw)
In-Reply-To: <10629535.nUPlyArG6x@rjwysocki.net>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
In analogy with the previous change affecting the resume path,
make device_suspend() start the async suspend of the device's parent
after the device itself has been processed and make dpm_suspend() start
processing "async" leaf devices (that is, devices without children)
upfront so they don't need to wait for the "sync" devices they don't
depend on.
On the Dell XPS13 9360 in my office, this change reduces the total
duration of device suspend by approximately 100 ms (over 20%).
Suggested-by: Saravana Kannan <saravanak@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v2 -> v3:
* When starting async processing early, only take parents and children
into account.
* Refine parent check in dpm_async_suspend_parent().
* Use list_splice() for merging lists on errors.
* Adjust subject and changelog.
* Adjust comments.
v1 -> v2:
* Adjust for the changes in patch [1/3].
* Fix walking suppliers in dpm_async_suspend_superior().
* Use device links read locking in dpm_async_suspend_superior() (Saravana).
* Move all devices to the target list even if there are errors in
dpm_suspend() so they are properly resumed during rollback (Saravana).
---
drivers/base/power/main.c | 67 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 63 insertions(+), 4 deletions(-)
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1236,6 +1236,41 @@
/*------------------------- Suspend routines -------------------------*/
+static bool dpm_leaf_device(struct device *dev)
+{
+ struct device *child;
+
+ lockdep_assert_held(&dpm_list_mtx);
+
+ child = device_find_any_child(dev);
+ if (child) {
+ put_device(child);
+
+ return false;
+ }
+
+ return true;
+}
+
+static void dpm_async_suspend_parent(struct device *dev, async_func_t func)
+{
+ guard(mutex)(&dpm_list_mtx);
+
+ /*
+ * If the device is suspended asynchronously and the parent's callback
+ * deletes both the device and the parent itself, the parent object may
+ * be freed while this function is running, so avoid that by checking
+ * if the device has been deleted already as the parent cannot be
+ * deleted before it.
+ */
+ if (!device_pm_initialized(dev))
+ return;
+
+ /* Start processing the device's parent if it is "async". */
+ if (dev->parent)
+ dpm_async_with_cleanup(dev->parent, func);
+}
+
/**
* resume_event - Return a "resume" message for given "suspend" sleep state.
* @sleep_state: PM message representing a sleep state.
@@ -1661,6 +1696,8 @@
device_links_read_unlock(idx);
}
+static void async_suspend(void *data, async_cookie_t cookie);
+
/**
* device_suspend - Execute "suspend" callbacks for given device.
* @dev: Device to handle.
@@ -1790,7 +1827,13 @@
complete_all(&dev->power.completion);
TRACE_SUSPEND(error);
- return error;
+
+ if (error || async_error)
+ return error;
+
+ dpm_async_suspend_parent(dev, async_suspend);
+
+ return 0;
}
static void async_suspend(void *data, async_cookie_t cookie)
@@ -1808,6 +1851,7 @@
int dpm_suspend(pm_message_t state)
{
ktime_t starttime = ktime_get();
+ struct device *dev;
int error = 0;
trace_suspend_resume(TPS("dpm_suspend"), state.event, true);
@@ -1821,12 +1865,21 @@
mutex_lock(&dpm_list_mtx);
+ /*
+ * Start processing "async" leaf devices upfront so they don't need to
+ * wait for the "sync" devices they don't depend on.
+ */
+ list_for_each_entry_reverse(dev, &dpm_prepared_list, power.entry) {
+ dpm_clear_async_state(dev);
+ if (dpm_leaf_device(dev))
+ dpm_async_with_cleanup(dev, async_suspend);
+ }
+
while (!list_empty(&dpm_prepared_list)) {
- struct device *dev = to_device(dpm_prepared_list.prev);
+ dev = to_device(dpm_prepared_list.prev);
list_move(&dev->power.entry, &dpm_suspended_list);
- dpm_clear_async_state(dev);
if (dpm_async_fn(dev, async_suspend))
continue;
@@ -1840,8 +1893,14 @@
mutex_lock(&dpm_list_mtx);
- if (error || async_error)
+ if (error || async_error) {
+ /*
+ * Move all devices to the target list to resume them
+ * properly.
+ */
+ list_splice(&dpm_prepared_list, &dpm_suspended_list);
break;
+ }
}
mutex_unlock(&dpm_list_mtx);
next prev parent reply other threads:[~2025-03-14 13:23 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 12:46 [PATCH v3 0/5] PM: sleep: Improvements of async suspend and resume of devices Rafael J. Wysocki
2025-03-14 12:50 ` [PATCH v3 1/5] PM: sleep: Resume children after resuming the parent Rafael J. Wysocki
2025-05-01 9:51 ` Jon Hunter
2025-05-02 20:33 ` Rafael J. Wysocki
2025-05-07 13:21 ` Jon Hunter
2025-05-07 13:39 ` Rafael J. Wysocki
2025-05-07 14:25 ` Rafael J. Wysocki
2025-05-07 14:39 ` Jon Hunter
2025-05-07 14:56 ` Rafael J. Wysocki
2025-05-07 15:39 ` Jon Hunter
2025-05-07 16:43 ` Rafael J. Wysocki
2025-05-08 13:38 ` Jon Hunter
2025-05-08 18:06 ` Rafael J. Wysocki
2025-05-10 11:39 ` Rafael J. Wysocki
2025-05-10 11:50 ` Jon Hunter
2025-07-11 13:08 ` Tudor Ambarus
2025-07-11 13:38 ` Rafael J. Wysocki
2025-07-11 13:54 ` Rafael J. Wysocki
2025-07-11 18:30 ` Saravana Kannan
2025-07-12 7:57 ` Rafael J. Wysocki
2025-07-12 7:54 ` Rafael J. Wysocki
2025-07-14 7:09 ` Tudor Ambarus
2025-07-14 7:29 ` Rafael J. Wysocki
2025-07-14 10:35 ` Tudor Ambarus
2025-07-14 12:14 ` Tudor Ambarus
2025-03-14 13:13 ` Rafael J. Wysocki [this message]
2025-06-02 12:11 ` [PATCH v3 2/5] PM: sleep: Suspend async parents after suspending children Chris Bainbridge
2025-06-02 14:29 ` Rafael J. Wysocki
2025-06-02 15:21 ` Mario Limonciello
2025-06-02 19:58 ` Rafael J. Wysocki
2025-06-03 9:38 ` Rafael J. Wysocki
2025-06-03 10:17 ` Chris Bainbridge
2025-06-03 10:29 ` Rafael J. Wysocki
2025-06-03 10:30 ` Rafael J. Wysocki
2025-06-03 11:37 ` Rafael J. Wysocki
2025-06-03 11:39 ` Rafael J. Wysocki
2025-06-03 12:14 ` Chris Bainbridge
2025-06-03 12:23 ` Rafael J. Wysocki
2025-06-03 12:26 ` Chris Bainbridge
2025-06-03 13:04 ` Rafael J. Wysocki
2025-06-03 13:36 ` Chris Bainbridge
2025-06-03 13:59 ` Rafael J. Wysocki
2025-03-14 13:14 ` [PATCH v3 3/5] PM: sleep: Make suspend of devices more asynchronous Rafael J. Wysocki
2025-03-14 13:16 ` [PATCH v3 4/5] PM: sleep: Make async suspend handle suppliers like parents Rafael J. Wysocki
2025-03-14 13:17 ` [PATCH v3 5/5] PM: sleep: Make async resume handle consumers like children Rafael J. Wysocki
2025-03-14 21:06 ` [PATCH v3 0/5] PM: sleep: Improvements of async suspend and resume of devices Saravana Kannan
2025-03-15 14:57 ` Rafael J. Wysocki
2025-04-08 13:39 ` Rafael J. Wysocki
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=3541233.QJadu78ljV@rjwysocki.net \
--to=rjw@rjwysocki.net \
--cc=johan@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=saravanak@google.com \
--cc=stern@rowland.harvard.edu \
--cc=ulf.hansson@linaro.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
all inboxes | Powered by JetHome®