mirror of https://lore.kernel.org/lkml/
 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>
Subject: [PATCH v1 06/10] PM: sleep: Adjust check before setting power.must_resume
Date: Tue, 11 Feb 2025 22:10:39 +0100	[thread overview]
Message-ID: <3548152.QJadu78ljV@rjwysocki.net> (raw)
In-Reply-To: <2314745.iZASKD2KPV@rjwysocki.net>

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

Use pm_runtime_need_not_resume() in the check deciding whether or not
the device's power.must_resume flag needs to be set, so it covers the
device's active children counter in addition to its runtime PM usage
counter, rearrange that check and adjust the comment next to it.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/base/power/main.c    |   12 +++++-------
 drivers/base/power/runtime.c |    2 +-
 include/linux/pm_runtime.h   |    2 ++
 3 files changed, 8 insertions(+), 8 deletions(-)

--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1268,14 +1268,12 @@
 	dev->power.is_noirq_suspended = true;
 
 	/*
-	 * Skipping the resume of devices that were in use right before the
-	 * system suspend (as indicated by their PM-runtime usage counters)
-	 * would be suboptimal.  Also resume them if doing that is not allowed
-	 * to be skipped.
+	 * If it is not allowed to skip the resume of the device or it was in
+	 * use before the system suspend has started (in which case it needs to
+	 * be resumed for consistency), set the "must resume" flag for it.
 	 */
-	if (atomic_read(&dev->power.usage_count) > 1 ||
-	    !(dev_pm_test_driver_flags(dev, DPM_FLAG_MAY_SKIP_RESUME) &&
-	      dev->power.may_skip_resume))
+	if (!(dev_pm_test_driver_flags(dev, DPM_FLAG_MAY_SKIP_RESUME) &&
+	      dev->power.may_skip_resume) || !pm_runtime_need_not_resume(dev))
 		dev->power.must_resume = true;
 
 	if (dev->power.must_resume) {
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1874,7 +1874,7 @@
 	pm_request_idle(link->supplier);
 }
 
-static bool pm_runtime_need_not_resume(struct device *dev)
+bool pm_runtime_need_not_resume(struct device *dev)
 {
 	return atomic_read(&dev->power.usage_count) <= 1 &&
 		(atomic_read(&dev->power.child_count) == 0 ||
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -66,6 +66,7 @@
 
 extern int pm_generic_runtime_suspend(struct device *dev);
 extern int pm_generic_runtime_resume(struct device *dev);
+extern bool pm_runtime_need_not_resume(struct device *dev);
 extern int pm_runtime_force_suspend(struct device *dev);
 extern int pm_runtime_force_resume(struct device *dev);
 
@@ -254,6 +255,7 @@
 
 static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
 static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
+static inline bool pm_runtime_need_not_resume(struct device *dev) {return true; }
 static inline int pm_runtime_force_suspend(struct device *dev) { return 0; }
 static inline int pm_runtime_force_resume(struct device *dev) { return 0; }
 




  parent reply	other threads:[~2025-02-11 21:25 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-11 21:01 [PATCH v1 00/10] PM: Make the core and pm_runtime_force_suspend/resume() agree more Rafael J. Wysocki
2025-02-11 21:02 ` [PATCH v1 01/10] PM: runtime: Introduce pm_runtime_no_support() Rafael J. Wysocki
2025-02-11 21:03 ` [PATCH v1 02/10] PM: sleep: core: Use pm_runtime_no_support() during set_active updates Rafael J. Wysocki
2025-02-11 21:05 ` [PATCH v1 03/10] PM: runtime: Use pm_runtime_no_support() in pm_runtime_force_suspend() Rafael J. Wysocki
2025-02-11 21:07 ` [PATCH v1 04/10] PM: runtime: Drop status check from pm_runtime_force_resume() Rafael J. Wysocki
2025-02-11 21:09 ` [PATCH v1 05/10] PM: runtime: Do not enable wakeup IRQs during system resume Rafael J. Wysocki
2025-02-11 21:10 ` Rafael J. Wysocki [this message]
2025-02-11 21:11 ` [PATCH v1 07/10] PM: sleep: Clear the power.set_active upfront Rafael J. Wysocki
2025-02-11 21:19 ` [PATCH v1 08/10] PM: sleep: Make pm_runtime_force_resume() look at power.set_active Rafael J. Wysocki
2025-02-11 21:21 ` [PATCH v1 09/10] PM: sleep: Propagate power.set_active in dependency chains Rafael J. Wysocki
2025-02-11 21:25 ` [PATCH v1 10/10] PM: runtime: Discover the lack of runtime PM support Rafael J. Wysocki
2025-02-12 11:14   ` Rafael J. Wysocki
2025-02-12  9:12 ` [PATCH v1 00/10] PM: Make the core and pm_runtime_force_suspend/resume() agree more Ulf Hansson
2025-02-12 10:59   ` Rafael J. Wysocki
2025-02-12 11:33     ` Rafael J. Wysocki
2025-02-12 11:36       ` Rafael J. Wysocki
2025-02-12 15:14       ` Ulf Hansson
2025-02-12 17:05         ` Rafael J. Wysocki
2025-02-12 19:04           ` Rafael J. Wysocki
2025-02-13 13:37             ` Ulf Hansson
2025-02-13 20:42               ` Rafael J. Wysocki
2025-02-13 13:10           ` Ulf Hansson
2025-02-13 20:17             ` Rafael J. Wysocki
2025-02-14  9:55               ` Ulf Hansson
2025-02-15 12:32                 ` 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=3548152.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=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®