Skip to contentSkip to conversation

PM: Use suspend_console in swsusp and make it configureable

PATCH In review Rafael J. Wysocki 4 participants 8 messages Aug 16, 2006 – Aug 17, 2006

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

cover PM: Use suspend_console in swsusp and make it configureable

Hi,

The following patches add suspend_console() and resume_console() to the suspend-to-disk code paths, make it possible to disable the console suspending and remove the CONFIG_PM_TRACE option from kernel/power/Kconfig .

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#1 lore raw

PATCH 1/3 swsusp: Use suspend_console

Add suspend_console() and resume_console() to the suspend-to-disk code paths so that the users of netconsole can use swsusp with it.

---
 kernel/power/disk.c |    8 ++++++++
 kernel/power/user.c |    8 +++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
kernel/power/disk.c +8 -0
Index: linux-2.6.18-rc4-mm1/kernel/power/disk.c
===================================================================
@@ -18,6 +18,7 @@
 #include <linux/fs.h>
 #include <linux/mount.h>
 #include <linux/pm.h>
+#include <linux/console.h>
 #include <linux/cpu.h>
 
 #include "power.h"
@@ -119,8 +120,10 @@ int pm_suspend_disk(void)
 	if (error)
 		return error;
 
+	suspend_console();
 	error = device_suspend(PMSG_FREEZE);
 	if (error) {
+		resume_console();
 		printk("Some devices failed to suspend\n");
 		unprepare_processes();
 		return error;
@@ -133,6 +136,7 @@ int pm_suspend_disk(void)
 
 	if (in_suspend) {
 		device_resume();
+		resume_console();
 		pr_debug("PM: writing image.\n");
 		error = swsusp_write();
 		if (!error)
@@ -148,6 +152,7 @@ int pm_suspend_disk(void)
 	swsusp_free();
  Done:
 	device_resume();
+	resume_console();
 	unprepare_processes();
 	return error;
 }
@@ -212,7 +217,9 @@ static int software_resume(void)
 
 	pr_debug("PM: Preparing devices for restore.\n");
 
+	suspend_console();
 	if ((error = device_suspend(PMSG_PRETHAW))) {
+		resume_console();
 		printk("Some devices failed to suspend\n");
 		swsusp_free();
 		goto Thaw;
@@ -224,6 +231,7 @@ static int software_resume(void)
 	swsusp_resume();
 	pr_debug("PM: Restore failed, recovering.n");
 	device_resume();
+	resume_console();
  Thaw:
 	unprepare_processes();
  Done:
kernel/power/user.c +7 -1
Index: linux-2.6.18-rc4-mm1/kernel/power/user.c
===================================================================
@@ -19,6 +19,7 @@
 #include <linux/swapops.h>
 #include <linux/pm.h>
 #include <linux/fs.h>
+#include <linux/console.h>
 #include <linux/cpu.h>
 
 #include <asm/uaccess.h>
@@ -173,12 +174,14 @@ static int snapshot_ioctl(struct inode *
 		/* Free memory before shutting down devices. */
 		error = swsusp_shrink_memory();
 		if (!error) {
+			suspend_console();
 			error = device_suspend(PMSG_FREEZE);
 			if (!error) {
 				in_suspend = 1;
 				error = swsusp_suspend();
 				device_resume();
 			}
+			resume_console();
 		}
 		up(&pm_sem);
 		if (!error)
@@ -196,11 +199,13 @@ static int snapshot_ioctl(struct inode *
 		}
 		down(&pm_sem);
 		pm_prepare_console();
+		suspend_console();
 		error = device_suspend(PMSG_PRETHAW);
 		if (!error) {
 			error = swsusp_resume();
 			device_resume();
 		}
+		resume_console();
 		pm_restore_console();
 		up(&pm_sem);
 		break;
@@ -289,6 +294,7 @@ static int snapshot_ioctl(struct inode *
 		}
 
 		/* Put devices to sleep */
+		suspend_console();
 		error = device_suspend(PMSG_SUSPEND);
 		if (error) {
 			printk(KERN_ERR "Failed to suspend some devices.\n");
@@ -299,7 +305,7 @@ static int snapshot_ioctl(struct inode *
 			/* Wake up devices */
 			device_resume();
 		}
-
+		resume_console();
 		if (pm_ops->finish)
 			pm_ops->finish(PM_SUSPEND_MEM);
 
#2 lore raw

PATCH 2/3 PM: Make it possible to disable console suspending

In reply to Rafael J. Wysocki

Change suspend_console() so that it waits for all consoles to flush the remaining messages and make it possible to switch the console suspending off with the help of a Kconfig option.

---
 include/linux/console.h |    5 +++++
 kernel/power/Kconfig    |   11 +++++++++++
 kernel/printk.c         |    8 ++++++++
 3 files changed, 24 insertions(+)
include/linux/console.h +5 -0
Index: linux-2.6.18-rc4-mm1/include/linux/console.h
===================================================================
@@ -120,9 +120,14 @@ extern void console_stop(struct console 
 extern void console_start(struct console *);
 extern int is_console_locked(void);
 
+#ifndef CONFIG_DISABLE_CONSOLE_SUSPEND
 /* Suspend and resume console messages over PM events */
 extern void suspend_console(void);
 extern void resume_console(void);
+#else
+static inline void suspend_console(void) {}
+static inline void resume_console(void) {}
+#endif /* CONFIG_DISABLE_CONSOLE_SUSPEND */
 
 /* Some debug stub to catch some of the obvious races in the VT code */
 #if 1
kernel/power/Kconfig +11 -0
Index: linux-2.6.18-rc4-mm1/kernel/power/Kconfig
===================================================================
@@ -36,6 +36,17 @@ config PM_DEBUG
 	code. This is helpful when debugging and reporting various PM bugs, 
 	like suspend support.
 
+config PM_DISABLE_CONSOLE_SUSPEND
+	bool "Keep console(s) enabled during suspend/resume (DANGEROUS)"
+	depends on PM && PM_DEBUG
+	default n
+	---help---
+	This option turns off the console suspend mechanism that prevents
+	debug messages from reaching the console during the suspend/resume
+	operations.  This may be helpful when debugging device drivers'
+	suspend/resume routines, but may itself lead to problems, for example
+	if netconsole is used.
+
 config PM_TRACE
 	bool "Suspend/resume event tracing"
 	depends on PM && PM_DEBUG && X86_32 && EXPERIMENTAL
kernel/printk.c +8 -0
Index: linux-2.6.18-rc4-mm1/kernel/printk.c
===================================================================
@@ -702,6 +702,7 @@ int __init add_preferred_console(char *n
 	return 0;
 }
 
+#ifndef CONFIG_DISABLE_CONSOLE_SUSPEND
 /**
  * suspend_console - suspend the console subsystem
  *
@@ -709,8 +710,14 @@ int __init add_preferred_console(char *n
  */
 void suspend_console(void)
 {
+	printk("Suspending console(s)\n");
 	acquire_console_sem();
 	console_suspended = 1;
+	/* This is needed so that all of the messages that have already been
+	 * written to all consoles can be actually transmitted (eg. over a
+	 * network) before we try to suspend the consoles' devices.
+	 */
+	ssleep(2);
 }
 
 void resume_console(void)
@@ -718,6 +725,7 @@ void resume_console(void)
 	console_suspended = 0;
 	release_console_sem();
 }
+#endif /* CONFIG_DISABLE_CONSOLE_SUSPEND */
 
 /**
  * acquire_console_sem - lock the console system for exclusive use.
#3 lore raw

PATCH 3/3 PM: Remove PM_TRACE from Kconfig

In reply to Rafael J. Wysocki

Remove the CONFIG_PM_TRACE option, which is dangerous and should only be used by people who know exactly what they are doing, from kernel/power/Kconfig .

---
 kernel/power/Kconfig |   18 ------------------
 1 files changed, 18 deletions(-)
kernel/power/Kconfig +0 -18
Index: linux-2.6.18-rc4-mm1/kernel/power/Kconfig
===================================================================
@@ -47,24 +47,6 @@ config PM_DISABLE_CONSOLE_SUSPEND
 	suspend/resume routines, but may itself lead to problems, for example
 	if netconsole is used.
 
-config PM_TRACE
-	bool "Suspend/resume event tracing"
-	depends on PM && PM_DEBUG && X86_32 && EXPERIMENTAL
-	default n
-	---help---
-	This enables some cheesy code to save the last PM event point in the
-	RTC across reboots, so that you can debug a machine that just hangs
-	during suspend (or more commonly, during resume).
-
-	To use this debugging feature you should attempt to suspend the machine,
-	then reboot it, then run
-
-		dmesg -s 1000000 | grep 'hash matches'
-
-	CAUTION: this option will cause your machine's real-time clock to be
-	set to an invalid time after a resume.
-
-
 config SOFTWARE_SUSPEND
 	bool "Software Suspend"
 	depends on PM && SWAP && (X86 && (!SMP || SUSPEND_SMP)) || ((FRV || PPC32) && !SMP)
#4 lore raw

Re: [PATCH 3/3] PM: Remove PM_TRACE from Kconfig

Quoted 28 lines · On Wed, 16 Aug 2006 23:05:33 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

Remove the CONFIG_PM_TRACE option, which is dangerous and should only be used by people who know exactly what they are doing, from kernel/power/Kconfig .

---
 kernel/power/Kconfig |   18 ------------------
 1 files changed, 18 deletions(-)

Index: linux-2.6.18-rc4-mm1/kernel/power/Kconfig
===================================================================

kernel/power/Kconfig +0 -11
@@ -47,24 +47,6 @@ config PM_DISABLE_CONSOLE_SUSPEND
 	suspend/resume routines, but may itself lead to problems, for example
 	if netconsole is used.
 
-config PM_TRACE
-	bool "Suspend/resume event tracing"
-	depends on PM && PM_DEBUG && X86_32 && EXPERIMENTAL
-	default n
-	---help---
-	This enables some cheesy code to save the last PM event point in the
-	RTC across reboots, so that you can debug a machine that just hangs
-	during suspend (or more commonly, during resume).
-
-	To use this debugging feature you should attempt to suspend the machine,
-	then reboot it, then run

kernel/power/Kconfig config PM_DISABLE_CONSOLE_SUSPEND · line 52

Quoted 10 lines
kernel/power/Kconfig +0 -7
-
-		dmesg -s 1000000 | grep 'hash matches'
-
-	CAUTION: this option will cause your machine's real-time clock to be
-	set to an invalid time after a resume.
-
-
 config SOFTWARE_SUSPEND
 	bool "Software Suspend"
 	depends on PM && SWAP && (X86 && (!SMP || SUSPEND_SMP)) || ((FRV || PPC32) && !SMP)

So... how are people supposed to turn it on again? By patching the kernel? That's a bit painful if they're using (say) fedora-of-the-day.

How about we add a kernel boot parameter to enable it at runtime?

#5 lore raw

Re: [PATCH 3/3] PM: Remove PM_TRACE from Kconfig

Quoted 45 lines · Andrew Morton
Quoted 28 lines · On Wed, 16 Aug 2006 23:05:33 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

Remove the CONFIG_PM_TRACE option, which is dangerous and should only be used by people who know exactly what they are doing, from kernel/power/Kconfig .

---
 kernel/power/Kconfig |   18 ------------------
 1 files changed, 18 deletions(-)

Index: linux-2.6.18-rc4-mm1/kernel/power/Kconfig
===================================================================

kernel/power/Kconfig +0 -11
@@ -47,24 +47,6 @@ config PM_DISABLE_CONSOLE_SUSPEND
 	suspend/resume routines, but may itself lead to problems, for example
 	if netconsole is used.
 
-config PM_TRACE
-	bool "Suspend/resume event tracing"
-	depends on PM && PM_DEBUG && X86_32 && EXPERIMENTAL
-	default n
-	---help---
-	This enables some cheesy code to save the last PM event point in the
-	RTC across reboots, so that you can debug a machine that just hangs
-	during suspend (or more commonly, during resume).
-
-	To use this debugging feature you should attempt to suspend the machine,
-	then reboot it, then run

kernel/power/Kconfig config PM_DISABLE_CONSOLE_SUSPEND · line 52

Quoted 10 lines
kernel/power/Kconfig +0 -7
-
-		dmesg -s 1000000 | grep 'hash matches'
-
-	CAUTION: this option will cause your machine's real-time clock to be
-	set to an invalid time after a resume.
-
-
 config SOFTWARE_SUSPEND
 	bool "Software Suspend"
 	depends on PM && SWAP && (X86 && (!SMP || SUSPEND_SMP)) || ((FRV || PPC32) && !SMP)

So... how are people supposed to turn it on again? By patching the kernel? That's a bit painful if they're using (say) fedora-of-the-day.

Quoted 1 line

How about we add a kernel boot parameter to enable it at runtime?

You need to add hooks to the .c code to use this, anyway. Normal fedora user is not expected to use this.

Pavel

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

Re: [PATCH 3/3] PM: Remove PM_TRACE from Kconfig

In reply to Andrew Morton
Quoted 45 lines · Andrew Morton
Quoted 28 lines · On Wed, 16 Aug 2006 23:05:33 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

Remove the CONFIG_PM_TRACE option, which is dangerous and should only be used by people who know exactly what they are doing, from kernel/power/Kconfig .

---
 kernel/power/Kconfig |   18 ------------------
 1 files changed, 18 deletions(-)

Index: linux-2.6.18-rc4-mm1/kernel/power/Kconfig
===================================================================

kernel/power/Kconfig +0 -11
@@ -47,24 +47,6 @@ config PM_DISABLE_CONSOLE_SUSPEND
 	suspend/resume routines, but may itself lead to problems, for example
 	if netconsole is used.
 
-config PM_TRACE
-	bool "Suspend/resume event tracing"
-	depends on PM && PM_DEBUG && X86_32 && EXPERIMENTAL
-	default n
-	---help---
-	This enables some cheesy code to save the last PM event point in the
-	RTC across reboots, so that you can debug a machine that just hangs
-	during suspend (or more commonly, during resume).
-
-	To use this debugging feature you should attempt to suspend the machine,
-	then reboot it, then run

kernel/power/Kconfig config PM_DISABLE_CONSOLE_SUSPEND · line 52

Quoted 10 lines
kernel/power/Kconfig +0 -7
-
-		dmesg -s 1000000 | grep 'hash matches'
-
-	CAUTION: this option will cause your machine's real-time clock to be
-	set to an invalid time after a resume.
-
-
 config SOFTWARE_SUSPEND
 	bool "Software Suspend"
 	depends on PM && SWAP && (X86 && (!SMP || SUSPEND_SMP)) || ((FRV || PPC32) && !SMP)

So... how are people supposed to turn it on again? By patching the kernel? That's a bit painful if they're using (say) fedora-of-the-day.

Quoted 1 line

How about we add a kernel boot parameter to enable it at runtime?

I'm considering a sysfs attribute in /sys/power .

If PM_TRACE is compiled in, an attribute, say "pm_trace", shows up in sysfs which is initially set to 0 and the user has to explicitly set it to 1 to enable the feature? Pavel, what do you think?

Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#7 lore raw

Re: [PATCH 3/3] PM: Remove PM_TRACE from Kconfig

Quoted 46 lines · Rafael J. Wysocki
Quoted 45 lines · Andrew Morton
Quoted 28 lines · On Wed, 16 Aug 2006 23:05:33 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

Remove the CONFIG_PM_TRACE option, which is dangerous and should only be used by people who know exactly what they are doing, from kernel/power/Kconfig .

---
 kernel/power/Kconfig |   18 ------------------
 1 files changed, 18 deletions(-)

Index: linux-2.6.18-rc4-mm1/kernel/power/Kconfig
===================================================================

kernel/power/Kconfig +0 -11
@@ -47,24 +47,6 @@ config PM_DISABLE_CONSOLE_SUSPEND
 	suspend/resume routines, but may itself lead to problems, for example
 	if netconsole is used.
 
-config PM_TRACE
-	bool "Suspend/resume event tracing"
-	depends on PM && PM_DEBUG && X86_32 && EXPERIMENTAL
-	default n
-	---help---
-	This enables some cheesy code to save the last PM event point in the
-	RTC across reboots, so that you can debug a machine that just hangs
-	during suspend (or more commonly, during resume).
-
-	To use this debugging feature you should attempt to suspend the machine,
-	then reboot it, then run

kernel/power/Kconfig config PM_DISABLE_CONSOLE_SUSPEND · line 52

Quoted 10 lines
kernel/power/Kconfig +0 -7
-
-		dmesg -s 1000000 | grep 'hash matches'
-
-	CAUTION: this option will cause your machine's real-time clock to be
-	set to an invalid time after a resume.
-
-
 config SOFTWARE_SUSPEND
 	bool "Software Suspend"
 	depends on PM && SWAP && (X86 && (!SMP || SUSPEND_SMP)) || ((FRV || PPC32) && !SMP)

So... how are people supposed to turn it on again? By patching the kernel? That's a bit painful if they're using (say) fedora-of-the-day.

Quoted 3 lines
Quoted 1 line

How about we add a kernel boot parameter to enable it at runtime?

I'm considering a sysfs attribute in /sys/power .

Okay, that would work...

Quoted 3 lines

If PM_TRACE is compiled in, an attribute, say "pm_trace", shows up in sysfs which is initially set to 0 and the user has to explicitly set it to 1 to enable the feature? Pavel, what do you think?

...I'd call it pm_trace_trash_my_time :-), and am wondering if we are not overengineering this. I should have NAKed Linus' patch in the first place, unfortunately I did not realize it was enabled by default.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html