From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Oliver Neukum <oliver@neukum.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-pm <linux-pm@lists.linux-foundation.org>
Subject: Re: Towards eliminating the freezer
Date: Tue, 24 Jul 2007 17:24:49 +0200 [thread overview]
Message-ID: <200707241724.50330.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0707241027280.3568-100000@iolanthe.rowland.org>
On Tuesday, 24 July 2007 16:29, Alan Stern wrote:
> On Tue, 24 Jul 2007, Rafael J. Wysocki wrote:
>
> > > Now here's an idea which might work. Can we require every caller of
> > > device_add() to hold some existing device's semaphore? Normally it
> > > would be the semaphore of the new device's parent, but it could be a
> > > higher ancestor. There even could be a single "root" semaphore for
> > > drivers registering a top-level device with no parent.
> > >
> > > (Some testing shows that during startup things like ACPI and IDE don't
> > > fulfill this requirement, so maybe we should require it only after
> > > userspace has begun running. After all, the system can't suspend
> > > until then.)
> > >
> > > It seems like a reasonable sort of thing to do. Hotplugged devices
> > > tend to be registered as they are discovered by their parent's driver,
> > > so it shouldn't be too much to ask that the parent's semaphore be held
> > > when the new device is registered. Static devices generally aren't
> > > quite so nice; the serial and floppy drivers in particular would need a
> > > little work (and probably some other drivers too).
> > >
> > > If we do this, then once the PM core has acquired the semaphore for
> > > every device it will be guaranteed that no new devices can be added.
> > > It would be a simple solution to a rather nasty problem.
> >
> > Hmm, in device_pm_add() and device_pm_remove() we acquire dpm_list_mtx which
> > also is acquired by device_suspend() and device_resume(). Thus, every attempt
> > to register a new device or unregister an existing one will be blocked while
> > either device_suspend() or device_resume() is running.
> >
> > If we arrange things so that dpm_list_mtx is acquired, but not released, by
> > device_suspend() and released, but not acquired, by device_resume(), then it
> > won't be possible to register/unregister a device during a suspend-resume
> > cycle.
>
> As with Oliver's suggestion, this would create a locking order
> violation. Drivers registering children (and thus acquiring
> dpm_list_mtx) will often already hold the parent's sem. But
> device_suspend() needs to acquire device sems while holding
> dpm_list_mtx.
Hmm, but this is done already (ie. device_suspend() acquires device sems
while holding dpm_list_mtx in the current code).
What I'm suggesting is not to let device_suspend() release dpm_list_mtx
when it's finished. The appended patch illustrates that I mean.
Greetings,
Rafael
---
dpm_list_mtx is used by the PM core to prevent device objects from being
added/removed while device_suspend() and device_resume() are running. However,
it should also be impossible to add a device after device_suspend() has
finished, because at that time the dpm_active list is empty and adding new
devices to it would break the ordering of devices during the next suspend.
Thus, it seems reasonable to leave device_suspend() with dpm_list_mtx held
and release at the end of device_resume().
In that case device_suspend() and device_resume() cannot be run concurrently
and dpm_mtx is no longer needed. Also, it's a bug to run device_resume() after
a failing device_suspend(), so the APM code needs to be updated.
---
arch/i386/kernel/apm.c | 5 ++++-
drivers/base/power/main.c | 1 -
drivers/base/power/power.h | 5 -----
drivers/base/power/resume.c | 3 ---
drivers/base/power/suspend.c | 3 ---
5 files changed, 4 insertions(+), 13 deletions(-)
Index: linux-2.6.23-rc1/arch/i386/kernel/apm.c
===================================================================
--- linux-2.6.23-rc1.orig/arch/i386/kernel/apm.c 2007-07-23 22:28:35.000000000 +0200
+++ linux-2.6.23-rc1/arch/i386/kernel/apm.c 2007-07-24 11:04:45.000000000 +0200
@@ -1202,7 +1202,9 @@ static int suspend(int vetoable)
printk(KERN_CRIT "apm: suspend was vetoed, but suspending anyway.\n");
}
- device_suspend(PMSG_SUSPEND);
+ err = device_suspend(PMSG_SUSPEND);
+ if (err)
+ goto send_resume;
local_irq_disable();
device_power_down(PMSG_SUSPEND);
@@ -1224,6 +1226,7 @@ static int suspend(int vetoable)
device_power_up();
local_irq_enable();
device_resume();
+ send_resume:
pm_send_all(PM_RESUME, (void *)0);
queue_event(APM_NORMAL_RESUME, NULL);
out:
Index: linux-2.6.23-rc1/drivers/base/power/resume.c
===================================================================
--- linux-2.6.23-rc1.orig/drivers/base/power/resume.c 2007-07-23 22:06:42.000000000 +0200
+++ linux-2.6.23-rc1/drivers/base/power/resume.c 2007-07-24 11:18:04.000000000 +0200
@@ -72,7 +72,6 @@ static int resume_device_early(struct de
*/
void dpm_resume(void)
{
- mutex_lock(&dpm_list_mtx);
while(!list_empty(&dpm_off)) {
struct list_head * entry = dpm_off.next;
struct device * dev = to_device(entry);
@@ -99,9 +98,7 @@ void dpm_resume(void)
void device_resume(void)
{
might_sleep();
- mutex_lock(&dpm_mtx);
dpm_resume();
- mutex_unlock(&dpm_mtx);
}
EXPORT_SYMBOL_GPL(device_resume);
Index: linux-2.6.23-rc1/drivers/base/power/suspend.c
===================================================================
--- linux-2.6.23-rc1.orig/drivers/base/power/suspend.c 2007-07-23 22:06:42.000000000 +0200
+++ linux-2.6.23-rc1/drivers/base/power/suspend.c 2007-07-24 11:17:52.000000000 +0200
@@ -127,7 +127,6 @@ int device_suspend(pm_message_t state)
int error = 0;
might_sleep();
- mutex_lock(&dpm_mtx);
mutex_lock(&dpm_list_mtx);
while (!list_empty(&dpm_active) && error == 0) {
struct list_head * entry = dpm_active.prev;
@@ -153,11 +152,9 @@ int device_suspend(pm_message_t state)
error == -EAGAIN ? " (please convert to suspend_late)" : "");
put_device(dev);
}
- mutex_unlock(&dpm_list_mtx);
if (error)
dpm_resume();
- mutex_unlock(&dpm_mtx);
return error;
}
Index: linux-2.6.23-rc1/drivers/base/power/main.c
===================================================================
--- linux-2.6.23-rc1.orig/drivers/base/power/main.c 2007-07-23 22:06:42.000000000 +0200
+++ linux-2.6.23-rc1/drivers/base/power/main.c 2007-07-24 11:17:16.000000000 +0200
@@ -28,7 +28,6 @@ LIST_HEAD(dpm_active);
LIST_HEAD(dpm_off);
LIST_HEAD(dpm_off_irq);
-DEFINE_MUTEX(dpm_mtx);
DEFINE_MUTEX(dpm_list_mtx);
int (*platform_enable_wakeup)(struct device *dev, int is_on);
Index: linux-2.6.23-rc1/drivers/base/power/power.h
===================================================================
--- linux-2.6.23-rc1.orig/drivers/base/power/power.h 2007-07-23 22:06:42.000000000 +0200
+++ linux-2.6.23-rc1/drivers/base/power/power.h 2007-07-24 11:17:33.000000000 +0200
@@ -12,11 +12,6 @@ extern void device_shutdown(void);
*/
/*
- * Used to synchronize global power management operations.
- */
-extern struct mutex dpm_mtx;
-
-/*
* Used to serialize changes to the dpm_* lists.
*/
extern struct mutex dpm_list_mtx;
next prev parent reply other threads:[~2007-07-24 15:17 UTC|newest]
Thread overview: 220+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-15 12:33 Hibernation considerations Rafael J. Wysocki
2007-07-15 12:51 ` Nigel Cunningham
2007-07-15 12:58 ` Dr. David Alan Gilbert
2007-07-15 22:38 ` Rafael J. Wysocki
2007-07-15 22:27 ` david
2007-07-17 17:40 ` Dr. David Alan Gilbert
2007-07-17 17:49 ` david
2007-07-29 6:53 ` Vojtech Pavlik
2007-07-29 9:56 ` Rafael J. Wysocki
2007-08-05 19:56 ` encrypted hibernation (was Re: Hibernation considerations) Pavel Machek
2007-08-11 23:43 ` Dr. David Alan Gilbert
2007-08-12 22:12 ` Rafael J. Wysocki
2007-08-18 19:37 ` Dr. David Alan Gilbert
2007-08-21 7:29 ` Pavel Machek
2007-08-13 2:30 ` Michael Chang
2007-08-13 4:53 ` alon.barlev
2007-07-15 15:10 ` Hibernation considerations Al Boldi
2007-07-15 15:35 ` jimmy bahuleyan
2007-07-15 17:40 ` Al Boldi
2007-07-15 16:29 ` Alan Stern
2007-07-15 17:40 ` Al Boldi
2007-07-15 23:28 ` Alan Stern
2007-07-15 23:58 ` david
2007-07-16 5:02 ` Al Boldi
2007-07-16 6:49 ` david
2007-07-16 13:32 ` Al Boldi
2007-07-17 4:33 ` david
2007-07-17 12:08 ` Al Boldi
2007-07-17 14:18 ` Rafael J. Wysocki
2007-07-17 15:23 ` david
2007-07-16 14:53 ` Alan Stern
2007-07-16 16:51 ` Al Boldi
2007-07-17 4:37 ` david
2007-07-15 19:52 ` david
2007-07-15 20:13 ` david
2007-07-15 22:47 ` Rafael J. Wysocki
2007-07-15 22:42 ` david
2007-07-15 23:15 ` Alan Stern
2007-07-15 23:38 ` Nigel Cunningham
2007-07-16 14:15 ` Alan Stern
2007-07-16 15:25 ` Rafael J. Wysocki
2007-07-15 23:41 ` david
2007-07-16 14:21 ` Alan Stern
2007-07-17 4:45 ` david
2007-07-17 14:15 ` Alan Stern
2007-07-17 14:40 ` Rafael J. Wysocki
2007-07-17 15:29 ` david
2007-07-17 16:02 ` Rafael J. Wysocki
2007-07-17 17:06 ` david
2007-07-17 19:50 ` Rafael J. Wysocki
2007-07-17 20:18 ` david
2007-07-17 20:39 ` Jeremy Maitin-Shepard
2007-07-17 20:39 ` david
2007-07-17 20:58 ` Rafael J. Wysocki
2007-07-17 20:57 ` Rafael J. Wysocki
2007-07-17 20:53 ` david
2007-07-17 21:37 ` Rafael J. Wysocki
2007-07-17 21:42 ` david
2007-07-17 21:53 ` Jeremy Maitin-Shepard
2007-07-21 10:25 ` Pavel Machek
2007-07-21 15:35 ` Jeremy Maitin-Shepard
2007-07-21 17:56 ` Pavel Machek
2007-07-21 19:35 ` david
2007-07-21 19:49 ` Pavel Machek
2007-07-21 22:14 ` david
2007-08-01 16:58 ` Stefan Seyfried
2007-07-17 20:24 ` Jeremy Maitin-Shepard
2007-07-17 20:44 ` david
2007-07-17 21:00 ` Rafael J. Wysocki
2007-07-17 16:09 ` Jeremy Maitin-Shepard
2007-07-17 19:54 ` Rafael J. Wysocki
2007-07-17 18:32 ` Alan Stern
2007-07-17 20:17 ` Rafael J. Wysocki
2007-07-17 20:34 ` david
2007-07-17 20:54 ` Jeremy Maitin-Shepard
2007-07-17 21:04 ` david
2007-07-17 21:23 ` Rafael J. Wysocki
2007-07-17 21:17 ` david
2007-07-17 21:27 ` Jeremy Maitin-Shepard
2007-07-17 21:27 ` david
2007-07-17 21:54 ` Rafael J. Wysocki
2007-07-17 21:45 ` Rafael J. Wysocki
2007-07-17 21:43 ` Rafael J. Wysocki
2007-07-17 20:34 ` Jeremy Maitin-Shepard
2007-07-17 20:37 ` david
2007-07-17 20:56 ` Jeremy Maitin-Shepard
2007-07-17 21:06 ` david
2007-07-17 21:40 ` Rafael J. Wysocki
2007-07-17 21:24 ` Rafael J. Wysocki
2007-07-17 21:11 ` Rafael J. Wysocki
2007-07-17 20:27 ` david
2007-07-17 21:20 ` Rafael J. Wysocki
[not found] ` <ea7a437ca4038d408ac544bbc3c2434a@bga.com>
2007-07-19 17:31 ` [linux-pm] " david
2007-07-20 14:24 ` Milton Miller
2007-07-20 15:44 ` david
2007-07-19 20:28 ` Rafael J. Wysocki
2007-07-19 23:07 ` david
2007-07-20 11:17 ` Rafael J. Wysocki
2007-07-20 15:35 ` david
2007-07-20 16:15 ` Alan Stern
2007-07-20 21:46 ` Rafael J. Wysocki
2007-07-20 16:56 ` Milton Miller
2007-07-20 17:31 ` Jeremy Maitin-Shepard
2007-07-20 21:30 ` Rafael J. Wysocki
2007-07-20 19:26 ` david
2007-07-20 21:28 ` Rafael J. Wysocki
2007-07-20 21:33 ` Jeremy Maitin-Shepard
2007-07-20 22:19 ` Rafael J. Wysocki
[not found] ` <20070720152744.GH20529@grifter.jdc.home>
2007-07-20 15:36 ` david
2007-07-20 21:43 ` Rafael J. Wysocki
2007-07-20 21:39 ` david
2007-07-20 22:22 ` Rafael J. Wysocki
2007-07-20 22:39 ` david
2007-07-20 16:08 ` Milton Miller
2007-07-20 16:20 ` Alan Stern
2007-07-20 17:32 ` Milton Miller
2007-07-20 18:17 ` Alan Stern
2007-07-20 19:08 ` Milton Miller
2007-07-20 19:37 ` Alan Stern
2007-07-20 20:03 ` Oliver Neukum
2007-07-20 20:12 ` Alan Stern
2007-07-20 21:35 ` Oliver Neukum
2007-07-20 22:25 ` Alan Stern
2007-07-23 14:23 ` Oliver Neukum
2007-07-23 20:05 ` Towards eliminating the freezer Alan Stern
2007-07-24 8:21 ` Oliver Neukum
2007-07-24 14:27 ` Alan Stern
2007-07-24 9:33 ` Rafael J. Wysocki
2007-07-24 14:29 ` Alan Stern
2007-07-24 15:24 ` Rafael J. Wysocki [this message]
2007-07-24 16:06 ` Alan Stern
2007-07-24 19:20 ` Rafael J. Wysocki
2007-07-24 20:24 ` Alan Stern
2007-07-24 21:14 ` Rafael J. Wysocki
2007-07-24 22:14 ` Alan Stern
2007-07-25 12:23 ` Rafael J. Wysocki
2007-08-01 9:34 ` [linux-pm] Re: Hibernation considerations Pavel Machek
2007-08-03 3:50 ` david
2007-07-20 20:31 ` david
2007-07-20 21:24 ` Alan Stern
2007-07-20 21:34 ` david
2007-07-20 22:15 ` Rafael J. Wysocki
2007-07-20 21:37 ` Jeremy Maitin-Shepard
2007-07-20 22:35 ` Alan Stern
2007-07-20 22:43 ` david
2007-07-21 5:21 ` Nigel Cunningham
2007-07-21 14:10 ` Alan Stern
2007-07-22 3:43 ` david
2007-07-22 16:00 ` Alan Stern
2007-07-22 21:50 ` david
2007-07-23 15:19 ` Alan Stern
2007-07-23 19:01 ` david
2007-07-23 20:22 ` Alan Stern
2007-07-24 13:26 ` Huang, Ying
2007-07-24 14:50 ` Alan Stern
2007-07-20 22:48 ` Jeremy Maitin-Shepard
2007-07-20 21:02 ` Rafael J. Wysocki
2007-07-21 11:44 ` Miklos Szeredi
2007-07-21 12:43 ` Nigel Cunningham
2007-07-21 13:56 ` Alan Stern
2007-07-21 16:13 ` Jeremy Maitin-Shepard
2007-07-21 18:12 ` Miklos Szeredi
2007-07-21 19:20 ` Rafael J. Wysocki
2007-08-01 9:22 ` Pavel Machek
2007-08-02 17:02 ` Rafael J. Wysocki
2007-07-21 22:21 ` Nigel Cunningham
2007-07-21 22:16 ` Nigel Cunningham
2007-07-22 15:26 ` Alan Stern
2007-07-22 16:27 ` Miklos Szeredi
2007-07-22 20:09 ` Alan Stern
2007-07-22 21:54 ` david
2007-07-22 22:42 ` Nigel Cunningham
2007-07-22 23:09 ` Rafael J. Wysocki
2007-07-22 23:18 ` Nigel Cunningham
2007-07-23 0:04 ` Paul Mackerras
2007-07-23 3:11 ` Nigel Cunningham
2007-07-23 15:23 ` Alan Stern
2007-07-23 21:55 ` Nigel Cunningham
2007-07-23 22:10 ` Rafael J. Wysocki
2007-07-23 5:31 ` david
2007-07-23 10:24 ` Miklos Szeredi
2007-07-23 12:08 ` Rafael J. Wysocki
2007-07-23 12:14 ` Miklos Szeredi
2007-07-23 12:27 ` Rafael J. Wysocki
2007-07-23 12:31 ` Oliver Neukum
2007-07-23 13:08 ` Miklos Szeredi
2007-07-23 14:01 ` Rafael J. Wysocki
2007-07-23 14:01 ` Miklos Szeredi
2007-07-23 19:08 ` david
2007-08-01 9:19 ` Pavel Machek
[not found] ` <40fa2626aff7b6b590ad6aa4737fc873@bga.com>
2007-07-20 14:48 ` Huang, Ying
2007-07-20 15:48 ` david
2007-07-22 2:17 ` Huang, Ying
2007-07-22 2:32 ` david
2007-07-20 21:34 ` Rafael J. Wysocki
2007-07-17 22:38 ` Alan Stern
2007-07-17 22:37 ` david
2007-07-18 14:29 ` Alan Stern
2007-07-18 14:47 ` Rafael J. Wysocki
2007-07-20 4:40 ` Al Boldi
2007-07-20 10:59 ` Rafael J. Wysocki
2007-07-21 10:17 ` Pavel Machek
2007-07-15 23:22 ` Rafael J. Wysocki
2007-07-15 23:49 ` david
2007-07-16 12:06 ` Rafael J. Wysocki
[not found] ` <20070716123849.GC14212@grifter.jdc.home>
2007-07-16 15:29 ` Rafael J. Wysocki
2007-07-17 4:28 ` david
2007-07-17 10:42 ` Matthew Garrett
2007-07-17 15:19 ` david
2007-07-18 2:18 ` Matthew Garrett
2007-07-18 3:54 ` david
2007-07-18 11:10 ` Matthew Garrett
2007-07-18 12:56 ` david
2007-07-15 23:17 ` Alan Stern
2007-07-15 23:53 ` david
2007-07-16 5:18 ` Jeremy Maitin-Shepard
2007-07-15 20:35 ` Cornelius Riemenschneider
2007-07-15 19:46 ` david
2007-07-16 0:51 ` Matthew Garrett
2007-07-16 0:51 ` david
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=200707241724.50330.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=oliver@neukum.org \
--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 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®