Skip to contentSkip to conversation

PM: invoke suspend notifications after console switch

PATCH In review Johannes Berg 4 participants 10 messages Dec 17, 2007 – Jan 25, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: invoke suspend notifications after console switch

A subsequent patch will enable apm-emulation notification for suspends triggered in any way by using the suspend notifications. This causes the system to lock up between X being needed to switch away from the VT and X already waiting for resume in the apm ioctl.

This patch moves the console switch (if enabled) before the suspend notification (and after the resume notification) to avoid this issue.

---
 kernel/power/main.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/power/main.c +4 -4
@@ -73,12 +73,12 @@ static int suspend_prepare(void)
 	if (!suspend_ops || !suspend_ops->enter)
 		return -EPERM;
 
+	pm_prepare_console();
+
 	error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
 	if (error)
 		goto Finish;
 
-	pm_prepare_console();
-
 	if (suspend_freeze_processes()) {
 		error = -EAGAIN;
 		goto Thaw;
@@ -98,9 +98,9 @@ static int suspend_prepare(void)
 
  Thaw:
 	suspend_thaw_processes();
-	pm_restore_console();
  Finish:
 	pm_notifier_call_chain(PM_POST_SUSPEND);
+	pm_restore_console();
 	return error;
 }
 
@@ -192,8 +192,8 @@ int suspend_devices_and_enter(suspend_st
 static void suspend_finish(void)
 {
 	suspend_thaw_processes();
-	pm_restore_console();
 	pm_notifier_call_chain(PM_POST_SUSPEND);
+	pm_restore_console();
 }
 
 
#1 lore raw
Quoted 7 lines · Johannes Berg

A subsequent patch will enable apm-emulation notification for suspends triggered in any way by using the suspend notifications. This causes the system to lock up between X being needed to switch away from the VT and X already waiting for resume in the apm ioctl.

This patch moves the console switch (if enabled) before the suspend notification (and after the resume notification) to avoid this issue.

I don't see this in the suspend git tree yet, anything wrong with it?

Quoted 50 lines
---
 kernel/power/main.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/power/main.c +4 -4
@@ -73,12 +73,12 @@ static int suspend_prepare(void)
 	if (!suspend_ops || !suspend_ops->enter)
 		return -EPERM;
 
+	pm_prepare_console();
+
 	error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
 	if (error)
 		goto Finish;
 
-	pm_prepare_console();
-
 	if (suspend_freeze_processes()) {
 		error = -EAGAIN;
 		goto Thaw;
@@ -98,9 +98,9 @@ static int suspend_prepare(void)
 
  Thaw:
 	suspend_thaw_processes();
-	pm_restore_console();
  Finish:
 	pm_notifier_call_chain(PM_POST_SUSPEND);
+	pm_restore_console();
 	return error;
 }
 
@@ -192,8 +192,8 @@ int suspend_devices_and_enter(suspend_st
 static void suspend_finish(void)
 {
 	suspend_thaw_processes();
-	pm_restore_console();
 	pm_notifier_call_chain(PM_POST_SUSPEND);
+	pm_restore_console();
 }
 
 

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#2 lore raw
Quoted 11 lines · Johannes Berg
Quoted 7 lines · Johannes Berg

A subsequent patch will enable apm-emulation notification for suspends triggered in any way by using the suspend notifications. This causes the system to lock up between X being needed to switch away from the VT and X already waiting for resume in the apm ioctl.

This patch moves the console switch (if enabled) before the suspend notification (and after the resume notification) to avoid this issue.

I don't see this in the suspend git tree yet, anything wrong with it?

No, it's fine.

I was distracted by the recent ACPI ordering issue, will push it to Len shortly.

Thanks,
Rafael

#3 lore raw
In reply to Johannes Berg
Quoted 11 lines · Johannes Berg
Quoted 7 lines · Johannes Berg

A subsequent patch will enable apm-emulation notification for suspends triggered in any way by using the suspend notifications. This causes the system to lock up between X being needed to switch away from the VT and X already waiting for resume in the apm ioctl.

This patch moves the console switch (if enabled) before the suspend notification (and after the resume notification) to avoid this issue.

I don't see this in the suspend git tree yet, anything wrong with it?

Its pretty intrusive I'd say. And it is wrong; we'd prefer userspace to know what we are doing; if they are told we are suspending, userspace may be able to do something more clever than long console switch.

I'd prefer this not to go into mainline.
Pavel

Quoted 57 lines
Quoted 45 lines
---
 kernel/power/main.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/power/main.c +4 -4
@@ -73,12 +73,12 @@ static int suspend_prepare(void)
 	if (!suspend_ops || !suspend_ops->enter)
 		return -EPERM;
 
+	pm_prepare_console();
+
 	error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
 	if (error)
 		goto Finish;
 
-	pm_prepare_console();
-
 	if (suspend_freeze_processes()) {
 		error = -EAGAIN;
 		goto Thaw;
@@ -98,9 +98,9 @@ static int suspend_prepare(void)
 
  Thaw:
 	suspend_thaw_processes();
-	pm_restore_console();
  Finish:
 	pm_notifier_call_chain(PM_POST_SUSPEND);
+	pm_restore_console();
 	return error;
 }
 
@@ -192,8 +192,8 @@ int suspend_devices_and_enter(suspend_st
 static void suspend_finish(void)
 {
 	suspend_thaw_processes();
-	pm_restore_console();
 	pm_notifier_call_chain(PM_POST_SUSPEND);
+	pm_restore_console();
 }
 
 
Quoted 5 lines

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#4 lore raw
Quoted 11 lines · Pavel Machek
Quoted 10 lines · Johannes Berg
Quoted 7 lines · Johannes Berg

A subsequent patch will enable apm-emulation notification for suspends triggered in any way by using the suspend notifications. This causes the system to lock up between X being needed to switch away from the VT and X already waiting for resume in the apm ioctl.

This patch moves the console switch (if enabled) before the suspend notification (and after the resume notification) to avoid this issue.

Quoted 8 lines
Quoted 1 line

I don't see this in the suspend git tree yet, anything wrong with it?

Its pretty intrusive I'd say. And it is wrong; we'd prefer userspace to know what we are doing; if they are told we are suspending, userspace may be able to do something more clever than long console switch.

I'd prefer this not to go into mainline.

Well, in uswsusp we do the console switch before the suspend notifiers (although from the user land).

Rafael

#5 lore raw
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Johannes Berg
Quoted 5 lines · Johannes Berg

A subsequent patch will enable apm-emulation notification for suspends triggered in any way by using the suspend notifications. This causes the system to lock up between X being needed to switch away from the VT and X already waiting for resume in the apm ioctl.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This patch moves the console switch (if enabled) before the suspend notification (and after the resume notification) to avoid this issue.

I don't see this in the suspend git tree yet, anything wrong with it?

Its pretty intrusive I'd say.

How so? There's only one user of the suspend notifiers right now, AFAICS.

Quoted 4 lines
Quoted 4 lines

And it is wrong; we'd prefer userspace
to know what we are doing; if they are told we are suspending, userspace may be able to do something more clever than long console switch.

Well, we're not telling the userspace that we're suspending right now.

Also, the patch only reorders the console switch vs the suspend notifiers. The console switch still happens before the freezer is run.

Thanks,
Rafael

#6 lore raw
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

triggered in any way by using the suspend notifications. This causes the system to lock up between X being needed to switch away from the VT and X already waiting for resume in the apm ioctl.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This patch moves the console switch (if enabled) before the suspend notification (and after the resume notification) to avoid this issue.

I don't see this in the suspend git tree yet, anything wrong with it?

Its pretty intrusive I'd say.

How so? There's only one user of the suspend notifiers right now, AFAICS.

Ok... that and consistence with uswsusp makes it acceptable I guess. Feel free to add my acked-by and sorry for noise.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#7 lore raw
In reply to Pavel Machek
Quoted 7 lines

Its pretty intrusive I'd say. And it is wrong; we'd prefer userspace to know what we are doing; if they are told we are suspending, userspace may be able to do something more clever than long console switch.

I'd prefer this not to go into mainline.

So you'd prefer mainline to be broken and X to lock up ? nice !

The console switch happens -anyway- with the current code right ? So we aren't changing that.

However, (even today I believe), users of /dev/apm_bios, such as X, will deadlock the VT subsystem if they get notified of the suspend before the kernel initiated console switch happen (which can happen today if the suspend is triggered by an APM application I -think- (to be verified) and will happen more once Johannes next patch gets in which fixes a regression of current APM emulation which doesn't notify user space when the suspend isn't APM originated.

So this patch will fix it by console switching before notifying them, which is by far the right way to go for now. In the future, we may have smarter ways to handle that graphic subsystem (and smarter gfx drivers) and may want to provide ways to totally disable the console switching, but that's a separate issue. In fact, some distro already disable the console switch in their kernels for various reasons.

But if we keep the console switch we have today, we need this patch to make it work properly and not potentially deadlock with X.

Ben.

#8 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines

Its pretty intrusive I'd say. And it is wrong; we'd prefer userspace to know what we are doing; if they are told we are suspending, userspace may be able to do something more clever than long console switch.

I'd prefer this not to go into mainline.

So you'd prefer mainline to be broken and X to lock up ? nice !

The console switch happens -anyway- with the current code right ? So we aren't changing that.

Mind you, that's the (only!) other alternative: removing the in-kernel console switch completely which is the only way to allow userspace to do something "more clever than long console switch".

Quoted 4 lines

However, (even today I believe), users of /dev/apm_bios, such as X, will deadlock the VT subsystem if they get notified of the suspend before the kernel initiated console switch happen (which can happen today if the suspend is triggered by an APM application I -think- (to be verified)

Yeah I'm pretty sure that can happen, but in fact, that will happen regardless of this patch until my other patch is applied.

johannes

#9 lore raw
In reply to Pavel Machek
Quoted 2 lines

Its pretty intrusive I'd say.

I can sort of subscribe to that, but the whole suspend stuff is pretty intrusive overall.

Quoted 1 line

And it is wrong;

Obviously, I disagree.

Quoted 4 lines

we'd prefer userspace
to know what we are doing; if they are told we are suspending, userspace may be able to do something more clever than long console switch.

Are you even talking about this patch? We don't currently give anyone a
choice: We *always* do a "long console switch" anyway! If userspace were to decide that it can do much better and X can support suspend, then now we take the decision off it and switch to a suspend console while userspace is thinking there's no need.

What this patch enables is basically allowing us to remove the suspend console switch. How? Currently, suspend notifications with a whole bunch of ramifications all over the place are invoked before the console switch. By moving the console switch up, we essentially make the sequence identical to (a) removing the in-kernel console switch and (b) replacing it with userspace doing a console switch right before asking us to suspend.

johannes