From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM list <linux-pm@vger.kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Alan Stern <stern@rowland.harvard.edu>,
Grant Likely <grant.likely@linaro.org>,
Mark Brown <broonie@kernel.og>, Rob Herring <robh@kernel.org>,
Tomeu Vizoso <tomeu.vizoso@collabora.com>,
Thierry Reding <treding@nvidia.com>,
Dmitry Torokhov <dtor@google.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Michael Turquette <mturquette@baylibre.com>
Subject: [RFC][PATCH 3/5] PM core: Make async suspend/resume of devices use device links
Date: Thu, 14 Jan 2016 02:55:25 +0100 [thread overview]
Message-ID: <2464004.VfRsJaNrp3@vostro.rjw.lan> (raw)
In-Reply-To: <2576341.476ZsjkPgF@vostro.rjw.lan>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Make the device suspend/resume part of the core system
suspend/resume code use device links to ensure that supplier
and consumer devices will be suspended and resumed in the right
order in case of async suspend/resume.
The idea, roughly, is to use dpm_wait() to wait for all consumers
before a supplier device suspend and to wait for all suppliers
before a consumer device resume.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/base/base.h | 2 +
drivers/base/core.c | 4 +-
drivers/base/power/main.c | 68 +++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 66 insertions(+), 8 deletions(-)
Index: linux-pm/drivers/base/base.h
===================================================================
--- linux-pm.orig/drivers/base/base.h
+++ linux-pm/drivers/base/base.h
@@ -163,3 +163,5 @@ extern void device_links_driver_gone(str
extern void device_links_no_driver(struct device *dev);
extern bool device_links_busy(struct device *dev);
extern void device_links_unbind_consumers(struct device *dev);
+extern int device_links_read_lock(void);
+extern void device_links_read_unlock(int idx);
Index: linux-pm/drivers/base/core.c
===================================================================
--- linux-pm.orig/drivers/base/core.c
+++ linux-pm/drivers/base/core.c
@@ -163,12 +163,12 @@ void device_link_del(struct devlink *lin
}
EXPORT_SYMBOL_GPL(device_link_del);
-static int device_links_read_lock(void)
+int device_links_read_lock(void)
{
return srcu_read_lock(&device_links_srcu);
}
-static void device_links_read_unlock(int idx)
+void device_links_read_unlock(int idx)
{
return srcu_read_unlock(&device_links_srcu, idx);
}
Index: linux-pm/drivers/base/power/main.c
===================================================================
--- linux-pm.orig/drivers/base/power/main.c
+++ linux-pm/drivers/base/power/main.c
@@ -244,6 +244,62 @@ static void dpm_wait_for_children(struct
device_for_each_child(dev, &async, dpm_wait_fn);
}
+static void dpm_wait_for_suppliers(struct device *dev, bool async)
+{
+ struct devlink *link;
+ int idx;
+
+ idx = device_links_read_lock();
+
+ /*
+ * If the supplier goes away right after we've checked the link to it,
+ * we'll wait for its completion to change the state, but that's fine,
+ * because the only things that will block as a result are the SRCU
+ * callbacks freeing the link objects for the links in the list we're
+ * walking.
+ */
+ list_for_each_entry_rcu(link, &dev->consumer_links, c_node)
+ if (link->status != DEVICE_LINK_DORMANT)
+ dpm_wait(link->supplier, async);
+
+ device_links_read_unlock(idx);
+}
+
+static void dpm_wait_for_superior(struct device *dev, bool async)
+{
+ dpm_wait(dev->parent, async);
+ dpm_wait_for_suppliers(dev, async);
+}
+
+static void dpm_wait_for_consumers(struct device *dev, bool async)
+{
+ struct devlink *link;
+ int idx;
+
+ idx = device_links_read_lock();
+
+ /*
+ * The status of a device link can only be changed from "dormant" by a
+ * probe, but that cannot happen during system suspend/resume. In
+ * theory it can change to "dormant" at that time, but then it is
+ * reasonable to wait for the target device anyway (eg. if it goes
+ * away, it's better to wait for it to go away completely and then
+ * continue instead of trying to continue in parallel with its
+ * unregistration).
+ */
+ list_for_each_entry_rcu(link, &dev->supplier_links, s_node)
+ if (link->status != DEVICE_LINK_DORMANT)
+ dpm_wait(link->consumer, async);
+
+ device_links_read_unlock(idx);
+}
+
+static void dpm_wait_for_subordinate(struct device *dev, bool async)
+{
+ dpm_wait_for_children(dev, async);
+ dpm_wait_for_consumers(dev, async);
+}
+
/**
* pm_op - Return the PM operation appropriate for given PM event.
* @ops: PM operations to choose from.
@@ -488,7 +544,7 @@ static int device_resume_noirq(struct de
if (!dev->power.is_noirq_suspended)
goto Out;
- dpm_wait(dev->parent, async);
+ dpm_wait_for_superior(dev, async);
if (dev->pm_domain) {
info = "noirq power domain ";
@@ -618,7 +674,7 @@ static int device_resume_early(struct de
if (!dev->power.is_late_suspended)
goto Out;
- dpm_wait(dev->parent, async);
+ dpm_wait_for_superior(dev, async);
if (dev->pm_domain) {
info = "early power domain ";
@@ -750,7 +806,7 @@ static int device_resume(struct device *
goto Complete;
}
- dpm_wait(dev->parent, async);
+ dpm_wait_for_superior(dev, async);
dpm_watchdog_set(&wd, dev);
device_lock(dev);
@@ -1038,7 +1094,7 @@ static int __device_suspend_noirq(struct
if (dev->power.syscore || dev->power.direct_complete)
goto Complete;
- dpm_wait_for_children(dev, async);
+ dpm_wait_for_subordinate(dev, async);
if (dev->pm_domain) {
info = "noirq power domain ";
@@ -1185,7 +1241,7 @@ static int __device_suspend_late(struct
if (dev->power.syscore || dev->power.direct_complete)
goto Complete;
- dpm_wait_for_children(dev, async);
+ dpm_wait_for_subordinate(dev, async);
if (dev->pm_domain) {
info = "late power domain ";
@@ -1357,7 +1413,7 @@ static int __device_suspend(struct devic
TRACE_DEVICE(dev);
TRACE_SUSPEND(0);
- dpm_wait_for_children(dev, async);
+ dpm_wait_for_subordinate(dev, async);
if (async_error)
goto Complete;
next prev parent reply other threads:[~2016-01-14 1:58 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 15:24 [RFD] Functional dependencies between devices Rafael J. Wysocki
2015-10-27 15:20 ` Tomeu Vizoso
2015-10-28 2:15 ` Rafael J. Wysocki
2015-10-28 14:26 ` Tomeu Vizoso
2015-10-28 15:54 ` Rafael J. Wysocki
2015-10-29 0:18 ` Mark Brown
2015-10-29 14:03 ` Tomeu Vizoso
2015-10-29 14:31 ` Alan Stern
2015-10-31 2:23 ` Rafael J. Wysocki
2015-10-31 15:22 ` Alan Stern
2015-10-29 0:15 ` Mark Brown
2015-10-31 2:13 ` Rafael J. Wysocki
2015-10-31 2:40 ` Mark Brown
2015-10-30 9:50 ` Linus Walleij
2015-10-30 22:52 ` Greg Kroah-Hartman
2016-01-07 14:55 ` Tomeu Vizoso
2016-01-07 21:29 ` Greg Kroah-Hartman
2016-01-08 7:28 ` Tomeu Vizoso
2016-01-08 15:15 ` Greg Kroah-Hartman
2015-11-09 12:32 ` Thierry Reding
2015-11-09 21:42 ` Rafael J. Wysocki
2015-11-17 12:44 ` Andrzej Hajda
2015-11-18 2:17 ` Rafael J. Wysocki
2015-11-19 9:08 ` Andrzej Hajda
2015-11-19 22:04 ` Rafael J. Wysocki
2015-11-20 1:11 ` Rafael J. Wysocki
2015-11-24 14:57 ` Andrzej Hajda
2015-11-24 16:28 ` Rafael J. Wysocki
2015-11-30 7:16 ` Andrzej Hajda
2015-11-17 12:49 ` Andrzej Hajda
2015-11-17 13:55 ` Mark Brown
2015-11-19 6:50 ` Andrzej Hajda
2015-11-21 14:04 ` Mark Brown
2015-11-24 13:56 ` Andrzej Hajda
2015-11-19 13:18 ` Thierry Reding
2015-11-21 13:26 ` Mark Brown
2015-11-17 20:31 ` Alan Stern
2015-11-17 22:47 ` Mark Brown
2016-01-14 1:52 ` [RFC][PATCH 0/5] " Rafael J. Wysocki
2016-01-14 1:53 ` [RFC][PATCH 1/5] driver core: Add a wrapper around __device_release_driver() Rafael J. Wysocki
2016-01-14 1:54 ` [RFC][PATCH 2/5] driver core: Functional dependencies tracking support Rafael J. Wysocki
2016-06-08 12:48 ` Mark Brown
2016-06-08 18:12 ` Rafael J. Wysocki
2016-06-08 18:35 ` Mark Brown
2016-06-08 20:48 ` Rafael J. Wysocki
2016-06-08 22:24 ` Mark Brown
2016-01-14 1:55 ` Rafael J. Wysocki [this message]
2016-06-08 12:59 ` [RFC][PATCH 3/5] PM core: Make async suspend/resume of devices use device links Mark Brown
2016-01-14 1:56 ` [RFC][PATCH 4/5] PM core: Make runtime PM " Rafael J. Wysocki
2016-01-14 1:56 ` [RFC][PATCH 5/5] PM core: Optimize the use of device links for runtime PM Rafael J. Wysocki
2016-01-14 14:19 ` [RFC][PATCH 0/5] Functional dependencies between devices Tomeu Vizoso
2016-01-15 0:44 ` Rafael J. Wysocki
2016-06-08 12:15 ` Mark Brown
2016-06-08 17:24 ` Rafael J. Wysocki
2016-06-08 17:33 ` Mark Brown
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=2464004.VfRsJaNrp3@vostro.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=broonie@kernel.og \
--cc=dtor@google.com \
--cc=geert@linux-m68k.org \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=robh@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tomeu.vizoso@collabora.com \
--cc=treding@nvidia.com \
/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).