From: Kevin Hilman <khilman@ti.com>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Linux-pm mailing list <linux-pm@lists.linux-foundation.org>,
linux-omap@vger.kernel.org, Magnus Damm <magnus.damm@gmail.com>,
Paul Walmsley <paul@pwsan.com>
Subject: Re: [linux-pm] calling runtime PM from system PM methods
Date: Fri, 10 Jun 2011 16:14:36 -0700 [thread overview]
Message-ID: <8739jhs2hv.fsf@ti.com> (raw)
In-Reply-To: <201106072332.30464.rjw@sisk.pl> (Rafael J. Wysocki's message of "Tue, 7 Jun 2011 23:32:30 +0200")
"Rafael J. Wysocki" <rjw@sisk.pl> writes:
[...]
> Whether or not user space has disabled runtime PM _doesn't_ _matter_ for
> system suspend, because _you_ _can't_ call pm_runtime_suspend(), or
> pm_runtime_put_sunc(), from a driver's .suspend() callback _anyway_.
> The reason is that doing that would cause the subsystem's (or power
> domain's in this case) .runtime_suspend() callback to be invoked and
> that's incorrect. Namely, it would require the subsystem (power domain)
> to expect that its .runtime_suspend() would always be executed indirectly
> as a result of calling its .suspend() (through the driver's callback)
> and that expectation may or may not be met (depending on the driver's
> design).
So here's an interesting scenario which I think it triggers the same
problem as you highlight above.
Assume you have a driver that's using runtime PM on a per-xfer basis.
Before each xfer, it does a pm_runtime_get_sync(), after each xfer it
does a pm_runtime_put_sync() (for this example, it's important that it's
a _put_sync()). The _put_sync() might happen in an ISR, or possibly in
a thread waiting on a completion which is awoken by the ISR, etc. etc.
(the runtime PM callbacks are IRQ safe, and device is marked as such.)
The driver is in the middle of an xfer and a system suspend request
happens.
The driver's ->suspend() callback happens, and the driver
- enables/disables wakeups based on device_may_wakeup()
- prevents future xfers
- waits for current xfer to finish
As soon as the xfer finishes, the driver gets notified (completion,
callback, IRQ, whatever) and calls pm_runtime_put_sync(), which triggers
subsys->runtime_suspend --> driver->runtime_suspend.
While the driver's ->suspend() callback doesn't directly call
pm_runtime_put_sync(), the act of waiting for the xfer to finish
causes the subsystem/driver->runtime_suspend callbacks to be called
during the subsytem/driver->suspend callback, which is the same problem
as you highlight above.
Based on your commit that removed incrementing the usage count across
suspend[1], you mentioned "we can rely on subsystems and device drivers
to avoid doing that unnecessarily." The above example shows that this
type of thing might not be that obvious to detect and thus avoid.
I suspect the solution to the above will be to add back the usage count
increment across system suspend, but I'm hoping not. IMO, it would be
more flexible to allow the subsystems to decide. The subsystems could
provide locking (or manage dev->power.usage_count) themselves if
necessary. For example, leave it to the subsystem->prepare() to
pm_runtime_get_noresume() if it wants to avoid the "nesting" of
callbacks.
A related question: does the pm_wq need to be freezable? From
Documentation/power/runtime_pm.txt:
* The power management workqueue pm_wq in which bus types and device drivers can
put their PM-related work items. It is strongly recommended that pm_wq be
used for queuing all work items related to run-time PM, because this allows
them to be synchronized with system-wide power transitions (suspend to RAM,
hibernation and resume from system sleep states). pm_wq is declared in
include/linux/pm_runtime.h and defined in kernel/power/main.c.
Is "synchronized with system-wide power transistions" correct here?
Rather than synchronize, using a freezable workqueue actually _prevents_
runtime PM events (at least async ones.)
Again, proper locking (or management of dev->power.usage_count) at the
subsystem level would get you the same effect, but still leave
flexibility to the subsystem/pwr_domain layer.
Kevin
P.S. the commit below[1] removed the usage count increment/decrement
across system suspend/resume, but Documentation/power/runtime_pm.txt
still refers to it. Patch below[2] removes it, ssuming you're
not planning on adding it back. ;)
[1]
commit e8665002477f0278f84f898145b1f141ba26ee26
Author: Rafael J. Wysocki <rjw@sisk.pl>
Date: Sat Feb 12 01:42:41 2011 +0100
PM: Allow pm_runtime_suspend() to succeed during system suspend
The dpm_prepare() function increments the runtime PM reference
counters of all devices to prevent pm_runtime_suspend() from
executing subsystem-level callbacks. However, this was supposed to
guard against a specific race condition that cannot happen, because
the power management workqueue is freezable, so pm_runtime_suspend()
can only be called synchronously during system suspend and we can
rely on subsystems and device drivers to avoid doing that
unnecessarily.
Make dpm_prepare() drop the runtime PM reference to each device
after making sure that runtime resume is not pending for it.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Kevin Hilman <khilman@ti.com>
[2]
>From 8968e3e41d785e7e5ce7584d64f6a55b303e7060 Mon Sep 17 00:00:00 2001
From: Kevin Hilman <khilman@ti.com>
Date: Fri, 10 Jun 2011 16:05:51 -0700
Subject: [PATCH] PM / Runtime: update doc: usage count no longer incremented across system PM
commit e8665002477f0278f84f898145b1f141ba26ee26 (PM: Allow
pm_runtime_suspend() to succeed during system suspend) removed usage
count increment across system PM.
Update doc to reflect this.
Signed-off-by: Kevin Hilman <khilman@ti.com>
---
Applies on v3.0-rc2
Documentation/power/runtime_pm.txt | 5 -----
1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt
index 654097b..22accb3 100644
--- a/Documentation/power/runtime_pm.txt
+++ b/Documentation/power/runtime_pm.txt
@@ -566,11 +566,6 @@ to do this is:
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
-The PM core always increments the run-time usage counter before calling the
-->prepare() callback and decrements it after calling the ->complete() callback.
-Hence disabling run-time PM temporarily like this will not cause any run-time
-suspend callbacks to be lost.
-
7. Generic subsystem callbacks
Subsystems may wish to conserve code space by using the set of generic power
--
1.7.4
next prev parent reply other threads:[~2011-06-10 23:14 UTC|newest]
Thread overview: 117+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-02 0:05 calling runtime PM from system PM methods Kevin Hilman
2011-06-02 14:18 ` [linux-pm] " Alan Stern
2011-06-02 17:10 ` Kevin Hilman
2011-06-02 18:38 ` Alan Stern
2011-06-02 18:38 ` Alan Stern
2011-06-06 18:29 ` Rafael J. Wysocki
2011-06-06 18:29 ` [linux-pm] " Rafael J. Wysocki
2011-06-06 19:16 ` Alan Stern
2011-06-06 19:16 ` [linux-pm] " Alan Stern
2011-06-06 22:25 ` Kevin Hilman
2011-06-07 13:55 ` Alan Stern
2011-06-07 13:55 ` [linux-pm] " Alan Stern
2011-06-07 21:32 ` Rafael J. Wysocki
2011-06-07 22:34 ` Kevin Hilman
2011-06-07 22:34 ` Kevin Hilman
2011-06-08 22:50 ` [linux-pm] " Kevin Hilman
2011-06-09 5:29 ` Magnus Damm
2011-06-09 5:29 ` Magnus Damm
2011-06-09 13:56 ` [linux-pm] " Alan Stern
2011-06-10 14:36 ` Mark Brown
2011-06-10 14:51 ` Alan Stern
2011-06-10 14:51 ` [linux-pm] " Alan Stern
2011-06-10 15:21 ` Mark Brown
2011-06-10 15:21 ` [linux-pm] " Mark Brown
2011-06-10 15:45 ` Alan Stern
2011-06-10 15:57 ` Mark Brown
2011-06-10 15:57 ` [linux-pm] " Mark Brown
2011-06-10 17:17 ` Alan Stern
2011-06-10 17:17 ` [linux-pm] " Alan Stern
2011-06-10 17:31 ` Mark Brown
2011-06-10 17:31 ` [linux-pm] " Mark Brown
2011-06-10 18:38 ` Rafael J. Wysocki
2011-06-10 18:42 ` Mark Brown
2011-06-10 20:27 ` Rafael J. Wysocki
2011-06-10 20:27 ` [linux-pm] " Rafael J. Wysocki
2011-06-10 21:27 ` Alan Stern
2011-06-10 21:27 ` [linux-pm] " Alan Stern
2011-06-11 11:42 ` Mark Brown
2011-06-11 20:56 ` Rafael J. Wysocki
2011-06-13 12:22 ` [linux-pm] " Mark Brown
2011-06-13 12:22 ` Mark Brown
2011-06-11 11:42 ` Mark Brown
2011-06-10 18:42 ` Mark Brown
2011-06-10 18:38 ` Rafael J. Wysocki
2011-06-10 15:45 ` Alan Stern
2011-06-10 18:49 ` Rafael J. Wysocki
2011-06-10 18:49 ` [linux-pm] " Rafael J. Wysocki
2011-06-10 18:54 ` Mark Brown
2011-06-10 20:45 ` Rafael J. Wysocki
2011-06-10 20:45 ` Rafael J. Wysocki
2011-06-10 18:54 ` Mark Brown
2011-06-10 14:36 ` Mark Brown
2011-06-10 23:52 ` [linux-pm] " Kevin Hilman
2011-06-11 16:42 ` Alan Stern
2011-06-11 22:46 ` Rafael J. Wysocki
2011-06-12 15:59 ` Alan Stern
2011-06-12 15:59 ` [linux-pm] " Alan Stern
2011-06-12 18:27 ` Rafael J. Wysocki
2011-06-12 18:27 ` Rafael J. Wysocki
2011-06-15 21:54 ` Kevin Hilman
2011-06-15 21:54 ` [linux-pm] " Kevin Hilman
2011-06-16 0:01 ` Rafael J. Wysocki
2011-06-16 0:01 ` [linux-pm] " Rafael J. Wysocki
2011-06-16 1:17 ` Kevin Hilman
2011-06-16 14:27 ` Alan Stern
2011-06-16 14:27 ` [linux-pm] " Alan Stern
2011-06-16 22:48 ` Rafael J. Wysocki
2011-06-16 22:48 ` [linux-pm] " Rafael J. Wysocki
2011-06-17 19:47 ` Rafael J. Wysocki
2011-06-17 19:47 ` [linux-pm] " Rafael J. Wysocki
2011-06-17 20:04 ` Alan Stern
2011-06-17 21:29 ` Rafael J. Wysocki
2011-06-18 11:08 ` Rafael J. Wysocki
2011-06-18 15:31 ` Alan Stern
2011-06-18 21:01 ` Rafael J. Wysocki
2011-06-18 21:01 ` [linux-pm] " Rafael J. Wysocki
2011-06-18 23:57 ` Rafael J. Wysocki
2011-06-19 1:42 ` Alan Stern
2011-06-19 1:42 ` Alan Stern
2011-06-19 14:04 ` Rafael J. Wysocki
2011-06-19 14:04 ` [linux-pm] " Rafael J. Wysocki
2011-06-19 15:01 ` Alan Stern
2011-06-19 15:01 ` [linux-pm] " Alan Stern
2011-06-19 15:01 ` Alan Stern
2011-06-19 19:36 ` Rafael J. Wysocki
2011-06-19 19:36 ` [linux-pm] " Rafael J. Wysocki
2011-06-20 14:39 ` Alan Stern
2011-06-20 14:39 ` Alan Stern
2011-06-20 19:53 ` Rafael J. Wysocki
2011-06-20 19:53 ` [linux-pm] " Rafael J. Wysocki
2011-06-20 14:39 ` Alan Stern
2011-06-19 1:42 ` Alan Stern
2011-06-18 23:57 ` Rafael J. Wysocki
2011-06-18 15:31 ` Alan Stern
2011-06-18 11:08 ` Rafael J. Wysocki
2011-06-17 21:29 ` Rafael J. Wysocki
2011-06-17 20:04 ` Alan Stern
2011-06-16 22:30 ` Rafael J. Wysocki
2011-06-16 22:30 ` [linux-pm] " Rafael J. Wysocki
2011-06-16 1:17 ` Kevin Hilman
2011-06-11 22:46 ` Rafael J. Wysocki
2011-06-11 16:42 ` Alan Stern
2011-06-10 23:52 ` Kevin Hilman
2011-06-09 13:56 ` Alan Stern
2011-06-08 22:50 ` Kevin Hilman
2011-06-10 23:14 ` Kevin Hilman [this message]
2011-06-11 16:27 ` Alan Stern
2011-06-11 16:27 ` [linux-pm] " Alan Stern
2011-06-11 23:13 ` Rafael J. Wysocki
2011-06-11 23:13 ` [linux-pm] " Rafael J. Wysocki
2011-06-10 23:14 ` Kevin Hilman
2011-06-07 21:32 ` Rafael J. Wysocki
2011-06-06 22:25 ` Kevin Hilman
2011-06-02 17:10 ` Kevin Hilman
2011-06-02 14:18 ` Alan Stern
2011-06-06 18:01 ` Rafael J. Wysocki
2011-06-06 18:01 ` 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=8739jhs2hv.fsf@ti.com \
--to=khilman@ti.com \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=magnus.damm@gmail.com \
--cc=paul@pwsan.com \
--cc=rjw@sisk.pl \
--cc=stern@rowland.harvard.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.