From: "Mårten Lindahl" <marten.lindahl@axis.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Pavel Machek <pavel@ucw.cz>, Jonathan Cameron <jic23@kernel.org>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
linux-pm@vger.kernel.org, linux-iio@vger.kernel.org,
kernel@axis.com, "Mårten Lindahl" <marten.lindahl@axis.com>
Subject: [PATCH 1/2] PM: runtime: Synchronize PM runtime enable state with parent
Date: Thu, 29 Sep 2022 16:46:17 +0200 [thread overview]
Message-ID: <20220929144618.1086985-2-marten.lindahl@axis.com> (raw)
In-Reply-To: <20220929144618.1086985-1-marten.lindahl@axis.com>
A device that creates a child character device with cdev_device_add by
default create a PM sysfs group with power attributes for userspace
control. This means that the power attributes monitors the child device
only and thus does not reflect the parent device PM runtime behavior.
But as the PM runtime framework (rpm_suspend/rpm_resume) operates not
only on a single device that has been enabled for runtime PM, but also
on its parent, it should be possible to synchronize the child and the
parent so that the power attribute monitoring reflects the child and the
parent as one.
As an example, if an i2c_client device registers an iio_device, the
iio_device will create sysfs power/attribute nodes for userspace
control. But if the dev_pm_ops with resume/suspend callbacks is attached
to the struct i2c_driver.driver.pm, the PM runtime needs to be enabled
for the i2c_client device and not for the child iio_device.
In this case PM runtime can be enabled for the i2c_client device and
suspend/resume callbacks will be triggered, but the child sysfs power
attributes will be visible but marked as 'unsupported' and can not be
used for control or monitoring. This can be confusing as the sysfs
device node presents the i2c_client and the iio_device as one device.
Add a function to synchronize the runtime PM enable state of a device
with its parent. As there already exists a link from the child to its
parent and both are enabled, all sysfs control/monitoring can reflect
both devices, which from a userspace perspective makes more sense.
Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
---
drivers/base/power/runtime.c | 18 ++++++++++++++++++
include/linux/pm_runtime.h | 2 ++
2 files changed, 20 insertions(+)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 997be3ac20a7..b202d513684a 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1499,6 +1499,24 @@ void pm_runtime_enable(struct device *dev)
}
EXPORT_SYMBOL_GPL(pm_runtime_enable);
+/**
+ * pm_runtime_sync_parent_enable - Synchronize enable state.
+ * @dev: Device to handle.
+ *
+ * Synchronize the device enable state with its parent.
+ * NOTE: This function should only be used if the parent will never disable
+ * PM runtime (i.e. calling __pm_runtime_disable()) without telling its child.
+ */
+void pm_runtime_sync_parent_enable(struct device *dev)
+{
+ struct device *parent = dev->parent;
+
+ if (parent && !parent->power.ignore_children
+ && pm_runtime_enabled(parent))
+ pm_runtime_enable(dev);
+}
+EXPORT_SYMBOL_GPL(pm_runtime_sync_parent_enable);
+
static void pm_runtime_disable_action(void *data)
{
pm_runtime_dont_use_autosuspend(data);
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 0a41b2dcccad..5054427adbd1 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -89,6 +89,7 @@ extern void pm_runtime_put_suppliers(struct device *dev);
extern void pm_runtime_new_link(struct device *dev);
extern void pm_runtime_drop_link(struct device_link *link);
extern void pm_runtime_release_supplier(struct device_link *link);
+extern void pm_runtime_sync_parent_enable(struct device *dev);
extern int devm_pm_runtime_enable(struct device *dev);
@@ -315,6 +316,7 @@ static inline void pm_runtime_put_suppliers(struct device *dev) {}
static inline void pm_runtime_new_link(struct device *dev) {}
static inline void pm_runtime_drop_link(struct device_link *link) {}
static inline void pm_runtime_release_supplier(struct device_link *link) {}
+static inline void pm_runtime_sync_parent_enable(struct device *dev) {}
#endif /* !CONFIG_PM */
--
2.30.2
next prev parent reply other threads:[~2022-09-29 14:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 14:46 [PATCH 0/2] Synchronize PM runtime enable state with parent Mårten Lindahl
2022-09-29 14:46 ` Mårten Lindahl [this message]
2022-10-25 16:20 ` [PATCH 1/2] PM: runtime: " Rafael J. Wysocki
2022-10-31 16:48 ` Marten Lindahl
2022-11-06 15:33 ` Jonathan Cameron
2022-11-06 17:16 ` Rafael J. Wysocki
2022-11-12 15:33 ` Jonathan Cameron
2022-11-28 22:50 ` Marten Lindahl
2022-09-29 14:46 ` [PATCH 2/2] iio: light: vcnl4000: Incorporate iio_device with PM runtime Mårten Lindahl
2022-10-16 16:41 ` [PATCH 0/2] Synchronize PM runtime enable state with parent Jonathan Cameron
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=20220929144618.1086985-2-marten.lindahl@axis.com \
--to=marten.lindahl@axis.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=kernel@axis.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.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