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>,
Bjorn Helgaas <helgaas@kernel.org>,
Linux PCI <linux-pci@vger.kernel.org>,
Ulf Hansson <ulf.hansson@linaro.org>,
Johan Hovold <johan@kernel.org>,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
Jon Hunter <jonathanh@nvidia.com>,
Linux ACPI <linux-acpi@vger.kernel.org>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 4/4] PM: sleep: Avoid unnecessary checks in device_prepare_smart_suspend()
Date: Tue, 18 Feb 2025 21:20:46 +0100 [thread overview]
Message-ID: <2978873.e9J7NaK4W3@rjwysocki.net> (raw)
In-Reply-To: <12612706.O9o76ZdvQC@rjwysocki.net>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Add an optimization (on top of previous changes) to avoid calling
pm_runtime_blocked(), which involves acquiring the device's PM spinlock,
for devices with no PM callbacks and runtime PM "blocked".
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/base/power/main.c | 16 +++++++++-------
drivers/base/power/runtime.c | 9 +++++++--
include/linux/pm_runtime.h | 4 ++--
3 files changed, 18 insertions(+), 11 deletions(-)
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1796,16 +1796,14 @@
/*
* The "smart suspend" feature is enabled for devices whose drivers ask
- * for it and for devices without PM callbacks unless runtime PM is
- * disabled and enabling it is blocked for them.
+ * for it and for devices without PM callbacks.
*
* However, if "smart suspend" is not enabled for the device's parent
* or any of its suppliers that take runtime PM into account, it cannot
* be enabled for the device either.
*/
- dev->power.smart_suspend = (dev->power.no_pm_callbacks ||
- dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND)) &&
- !pm_runtime_blocked(dev);
+ dev->power.smart_suspend = dev->power.no_pm_callbacks ||
+ dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND);
if (!dev_pm_smart_suspend(dev))
return;
@@ -1843,6 +1841,7 @@
static int device_prepare(struct device *dev, pm_message_t state)
{
int (*callback)(struct device *) = NULL;
+ bool no_runtime_pm;
int ret = 0;
/*
@@ -1858,7 +1857,7 @@
* suspend-resume cycle is complete, so prepare to trigger a warning on
* subsequent attempts to enable it.
*/
- pm_runtime_block_if_disabled(dev);
+ no_runtime_pm = pm_runtime_block_if_disabled(dev);
if (dev->power.syscore)
return 0;
@@ -1893,7 +1892,10 @@
pm_runtime_put(dev);
return ret;
}
- device_prepare_smart_suspend(dev);
+ /* Do not enable "smart suspend" for devices without runtime PM. */
+ if (!no_runtime_pm)
+ device_prepare_smart_suspend(dev);
+
/*
* A positive return value from ->prepare() means "this device appears
* to be runtime-suspended and its state is fine, so if it really is
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1460,14 +1460,19 @@
}
EXPORT_SYMBOL_GPL(pm_runtime_barrier);
-void pm_runtime_block_if_disabled(struct device *dev)
+bool pm_runtime_block_if_disabled(struct device *dev)
{
+ bool ret;
+
spin_lock_irq(&dev->power.lock);
- if (dev->power.disable_depth && dev->power.last_status == RPM_INVALID)
+ ret = dev->power.disable_depth && dev->power.last_status == RPM_INVALID;
+ if (ret)
dev->power.last_status = RPM_BLOCKED;
spin_unlock_irq(&dev->power.lock);
+
+ return ret;
}
void pm_runtime_unblock(struct device *dev)
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -77,7 +77,7 @@
extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
extern int pm_runtime_barrier(struct device *dev);
-extern void pm_runtime_block_if_disabled(struct device *dev);
+extern bool pm_runtime_block_if_disabled(struct device *dev);
extern void pm_runtime_unblock(struct device *dev);
extern void pm_runtime_enable(struct device *dev);
extern void __pm_runtime_disable(struct device *dev, bool check_resume);
@@ -274,7 +274,7 @@
static inline int __pm_runtime_set_status(struct device *dev,
unsigned int status) { return 0; }
static inline int pm_runtime_barrier(struct device *dev) { return 0; }
-static inline void pm_runtime_block_if_disabled(struct device *dev) {}
+static inline bool pm_runtime_block_if_disabled(struct device *dev) { return true; }
static inline void pm_runtime_unblock(struct device *dev) {}
static inline void pm_runtime_enable(struct device *dev) {}
static inline void __pm_runtime_disable(struct device *dev, bool c) {}
next prev parent reply other threads:[~2025-02-18 20:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 20:09 [PATCH v2 0/4] PM: Use DPM_FLAG_SMART_SUSPEND conditionally Rafael J. Wysocki
2025-02-18 20:11 ` [PATCH v2 1/4] PM: Block enabling of runtime PM during system suspend Rafael J. Wysocki
2025-02-18 20:13 ` [PATCH v2 2/4] PM: runtime: Introduce pm_runtime_blocked() Rafael J. Wysocki
2025-02-18 20:16 ` [PATCH v2 3/4] PM: sleep: Use DPM_FLAG_SMART_SUSPEND conditionally Rafael J. Wysocki
2025-02-18 22:20 ` Bjorn Helgaas
2025-02-19 12:14 ` Rafael J. Wysocki
2025-02-18 20:20 ` Rafael J. Wysocki [this message]
2025-03-03 11:35 ` [PATCH v2 4/4] PM: sleep: Avoid unnecessary checks in device_prepare_smart_suspend() Ulf Hansson
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=2978873.e9J7NaK4W3@rjwysocki.net \
--to=rjw@rjwysocki.net \
--cc=andriy.shevchenko@linux.intel.com \
--cc=helgaas@kernel.org \
--cc=johan@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=mika.westerberg@linux.intel.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