linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 3/5] PM: sleep: Make suspend of devices more asynchronous
Date: Fri, 14 Mar 2025 14:14:30 +0100	[thread overview]
Message-ID: <1924195.CQOukoFCf9@rjwysocki.net> (raw)
In-Reply-To: <10629535.nUPlyArG6x@rjwysocki.net>

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

In analogy with previous changes, make device_suspend_late() and
device_suspend_noirq() start the async suspend of the device's parent
after the device itself has been processed and make dpm_suspend_late()
and dpm_noirq_suspend_devices() start processing "async" leaf devices
(that is, devices without children) upfront so they don't need to wait
for the other devices they don't depend on.

This change reduces the total duration of device suspend on some systems
measurably, but not significantly.

Suggested-by: Saravana Kannan <saravanak@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v2 -> v3:
   * Adjust for the changes made in patch [2/5].
   * Use list_splice() for merging lists on errors.
   * Adjust changelog.

v1 -> v2:
   * Adjust for the changes in patches [1-2/3].
   * Move all devices to the target lists even if there are errors in
     dpm_suspend_late() and dpm_noirq_suspend_devices() so they are
     properly resumed during rollback (Saravana).

---
 drivers/base/power/main.c |   64 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 56 insertions(+), 8 deletions(-)

--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1308,6 +1308,8 @@
 	device_links_read_unlock(idx);
 }
 
+static void async_suspend_noirq(void *data, async_cookie_t cookie);
+
 /**
  * device_suspend_noirq - Execute a "noirq suspend" callback for given device.
  * @dev: Device to handle.
@@ -1386,7 +1388,13 @@
 Complete:
 	complete_all(&dev->power.completion);
 	TRACE_SUSPEND(error);
-	return error;
+
+	if (error || async_error)
+		return error;
+
+	dpm_async_suspend_parent(dev, async_suspend_noirq);
+
+	return 0;
 }
 
 static void async_suspend_noirq(void *data, async_cookie_t cookie)
@@ -1400,6 +1408,7 @@
 static int dpm_noirq_suspend_devices(pm_message_t state)
 {
 	ktime_t starttime = ktime_get();
+	struct device *dev;
 	int error = 0;
 
 	trace_suspend_resume(TPS("dpm_suspend_noirq"), state.event, true);
@@ -1409,12 +1418,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_late_early_list, power.entry) {
+		dpm_clear_async_state(dev);
+		if (dpm_leaf_device(dev))
+			dpm_async_with_cleanup(dev, async_suspend_noirq);
+	}
+
 	while (!list_empty(&dpm_late_early_list)) {
-		struct device *dev = to_device(dpm_late_early_list.prev);
+		dev = to_device(dpm_late_early_list.prev);
 
 		list_move(&dev->power.entry, &dpm_noirq_list);
 
-		dpm_clear_async_state(dev);
 		if (dpm_async_fn(dev, async_suspend_noirq))
 			continue;
 
@@ -1428,8 +1446,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_late_early_list, &dpm_noirq_list);
 			break;
+		}
 	}
 
 	mutex_unlock(&dpm_list_mtx);
@@ -1482,6 +1506,8 @@
 	spin_unlock_irq(&parent->power.lock);
 }
 
+static void async_suspend_late(void *data, async_cookie_t cookie);
+
 /**
  * device_suspend_late - Execute a "late suspend" callback for given device.
  * @dev: Device to handle.
@@ -1558,7 +1584,13 @@
 Complete:
 	TRACE_SUSPEND(error);
 	complete_all(&dev->power.completion);
-	return error;
+
+	if (error || async_error)
+		return error;
+
+	dpm_async_suspend_parent(dev, async_suspend_late);
+
+	return 0;
 }
 
 static void async_suspend_late(void *data, async_cookie_t cookie)
@@ -1576,6 +1608,7 @@
 int dpm_suspend_late(pm_message_t state)
 {
 	ktime_t starttime = ktime_get();
+	struct device *dev;
 	int error = 0;
 
 	trace_suspend_resume(TPS("dpm_suspend_late"), state.event, true);
@@ -1587,12 +1620,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_suspended_list, power.entry) {
+		dpm_clear_async_state(dev);
+		if (dpm_leaf_device(dev))
+			dpm_async_with_cleanup(dev, async_suspend_late);
+	}
+
 	while (!list_empty(&dpm_suspended_list)) {
-		struct device *dev = to_device(dpm_suspended_list.prev);
+		dev = to_device(dpm_suspended_list.prev);
 
 		list_move(&dev->power.entry, &dpm_late_early_list);
 
-		dpm_clear_async_state(dev);
 		if (dpm_async_fn(dev, async_suspend_late))
 			continue;
 
@@ -1606,8 +1648,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_suspended_list, &dpm_late_early_list);
 			break;
+		}
 	}
 
 	mutex_unlock(&dpm_list_mtx);




  parent reply	other threads:[~2025-03-14 13:19 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 ` [PATCH v3 2/5] PM: sleep: Suspend async parents after suspending children Rafael J. Wysocki
2025-06-02 12:11   ` 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 ` Rafael J. Wysocki [this message]
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=1924195.CQOukoFCf9@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;
as well as URLs for NNTP newsgroup(s).