Skip to contentSkip to conversation

PM: Separate hibernation code from suspend code

PATCH In review Rafael J. Wysocki 6 participants 16 messages May 4, 2007 – May 8, 2007

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

PATCH 1/1 PM: Separate hibernation code from suspend code

From: Rafael J. Wysocki <[email protected]>, Johannes Berg <[email protected]>

Separate the hibernation (aka suspend to disk code) from the other suspend code. In particular:
* Remove the definitions related to hibernation from include/linux/pm.h
* Introduce struct hibernation_ops and a new hibernate() function to hibernate the system, defined in include/linux/suspend.h
* Separate suspend code in kernel/power/main.c from hibernation-related code in kernel/power/disk.c and kernel/power/user.c (with the help of hibernation_ops)
* Switch ACPI (the only user of pm_ops.pm_disk_mode) to hibernation_ops

---
 Documentation/power/userland-swsusp.txt |   26 ++--
 drivers/acpi/sleep/main.c               |   67 +++++++++--
 drivers/acpi/sleep/proc.c               |    2 
 drivers/i2c/chips/tps65010.c            |    2 
 include/linux/pm.h                      |   31 -----
 include/linux/suspend.h                 |   32 +++++
 kernel/power/disk.c                     |  185 ++++++++++++++++----------------
 kernel/power/main.c                     |   42 ++-----
 kernel/power/power.h                    |    7 -
 kernel/power/user.c                     |   13 +-
 kernel/sys.c                            |    2 
 11 files changed, 224 insertions(+), 185 deletions(-)
include/linux/pm.h +1 -30
Index: linux-2.6.21/include/linux/pm.h
===================================================================
@@ -107,26 +107,11 @@ typedef int __bitwise suspend_state_t;
 #define PM_SUSPEND_ON		((__force suspend_state_t) 0)
 #define PM_SUSPEND_STANDBY	((__force suspend_state_t) 1)
 #define PM_SUSPEND_MEM		((__force suspend_state_t) 3)
-#define PM_SUSPEND_DISK		((__force suspend_state_t) 4)
-#define PM_SUSPEND_MAX		((__force suspend_state_t) 5)
-
-typedef int __bitwise suspend_disk_method_t;
-
-/* invalid must be 0 so struct pm_ops initialisers can leave it out */
-#define PM_DISK_INVALID		((__force suspend_disk_method_t) 0)
-#define	PM_DISK_PLATFORM	((__force suspend_disk_method_t) 1)
-#define	PM_DISK_SHUTDOWN	((__force suspend_disk_method_t) 2)
-#define	PM_DISK_REBOOT		((__force suspend_disk_method_t) 3)
-#define	PM_DISK_TEST		((__force suspend_disk_method_t) 4)
-#define	PM_DISK_TESTPROC	((__force suspend_disk_method_t) 5)
-#define	PM_DISK_MAX		((__force suspend_disk_method_t) 6)
+#define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
 
 /**
  * struct pm_ops - Callbacks for managing platform dependent suspend states.
  * @valid: Callback to determine whether the given state can be entered.
- * 	If %CONFIG_SOFTWARE_SUSPEND is set then %PM_SUSPEND_DISK is
- *	always valid and never passed to this call. If not assigned,
- *	no suspend states are valid.
  *	Valid states are advertised in /sys/power/state but can still
  *	be rejected by prepare or enter if the conditions aren't right.
  *	There is a %pm_valid_only_mem function available that can be assigned
@@ -140,24 +125,12 @@ typedef int __bitwise suspend_disk_metho
  *
  * @finish: Called when the system has left the given state and all devices
  *	are resumed. The return value is ignored.
- *
- * @pm_disk_mode: The generic code always allows one of the shutdown methods
- *	%PM_DISK_SHUTDOWN, %PM_DISK_REBOOT, %PM_DISK_TEST and
- *	%PM_DISK_TESTPROC. If this variable is set, the mode it is set
- *	to is allowed in addition to those modes and is also made default.
- *	When this mode is sent selected, the @prepare call will be called
- *	before suspending to disk (if present), the @enter call should be
- *	present and will be called after all state has been saved and the
- *	machine is ready to be powered off; the @finish callback is called
- *	after state has been restored. All these calls are called with
- *	%PM_SUSPEND_DISK as the state.
  */
 struct pm_ops {
 	int (*valid)(suspend_state_t state);
 	int (*prepare)(suspend_state_t state);
 	int (*enter)(suspend_state_t state);
 	int (*finish)(suspend_state_t state);
-	suspend_disk_method_t pm_disk_mode;
 };
 
 /**
@@ -276,8 +249,6 @@ extern void device_power_up(void);
 extern void device_resume(void);
 
 #ifdef CONFIG_PM
-extern suspend_disk_method_t pm_disk_mode;
-
 extern int device_suspend(pm_message_t state);
 extern int device_prepare_suspend(pm_message_t state);
 
kernel/power/main.c +16 -26

88 lines not on this page · raw message

kernel/power/disk.c +98 -87

307 lines not on this page · raw message

Documentation/power/userland-swsusp.txt +14 -12
Index: linux-2.6.21/Documentation/power/userland-swsusp.txt
===================================================================
@@ -93,21 +93,23 @@ SNAPSHOT_S2RAM - suspend to RAM; using t
 	to resume the system from RAM if there's enough battery power or restore
 	its state on the basis of the saved suspend image otherwise)
 
-SNAPSHOT_PMOPS - enable the usage of the pmops->prepare, pmops->enter and
-	pmops->finish methods (the in-kernel swsusp knows these as the "platform
-	method") which are needed on many machines to (among others) speed up
-	the resume by letting the BIOS skip some steps or to let the system
-	recognise the correct state of the hardware after the resume (in
-	particular on many machines this ensures that unplugged AC
-	adapters get correctly detected and that kacpid does not run wild after
-	the resume).  The last ioctl() argument can take one of the three
-	values, defined in kernel/power/power.h:
+SNAPSHOT_PMOPS - enable the usage of the hibernation_ops->prepare,
+	hibernate_ops->enter and hibernation_ops->finish methods (the in-kernel
+	swsusp knows these as the "platform method") which are needed on many
+	machines to (among others) speed up the resume by letting the BIOS skip
+	some steps or to let the system recognise the correct state of the
+	hardware after the resume (in particular on many machines this ensures
+	that unplugged AC adapters get correctly detected and that kacpid does
+	not run wild after the resume).  The last ioctl() argument can take one
+	of the three values, defined in kernel/power/power.h:
 	PMOPS_PREPARE - make the kernel carry out the
-		pm_ops->prepare(PM_SUSPEND_DISK) operation
+		hibernation_ops->prepare() operation
 	PMOPS_ENTER - make the kernel power off the system by calling
-		pm_ops->enter(PM_SUSPEND_DISK)
+		hibernation_ops->enter()
 	PMOPS_FINISH - make the kernel carry out the
-		pm_ops->finish(PM_SUSPEND_DISK) operation
+		hibernation_ops->finish() operation
+	Note that the actual constants are misnamed because they surface
+	internal kernel implementation details that have changed.
 
 The device's read() operation can be used to transfer the snapshot image from
 the kernel.  It has the following limitations:
drivers/i2c/chips/tps65010.c +1 -1
Index: linux-2.6.21/drivers/i2c/chips/tps65010.c
===================================================================
@@ -354,7 +354,7 @@ static void tps65010_interrupt(struct tp
 			 * also needs to get error handling and probably
 			 * an #ifdef CONFIG_SOFTWARE_SUSPEND
 			 */
-			pm_suspend(PM_SUSPEND_DISK);
+			hibernate();
 #endif
 			poll = 1;
 		}
kernel/sys.c +1 -1
Index: linux-2.6.21/kernel/sys.c
===================================================================
@@ -881,7 +881,7 @@ asmlinkage long sys_reboot(int magic1, i
 #ifdef CONFIG_SOFTWARE_SUSPEND
 	case LINUX_REBOOT_CMD_SW_SUSPEND:
 		{
-			int ret = pm_suspend(PM_SUSPEND_DISK);
+			int ret = hibernate();
 			unlock_kernel();
 			return ret;
 		}
drivers/acpi/sleep/main.c +53 -14

106 lines not on this page · raw message

kernel/power/power.h +1 -6
Index: linux-2.6.21/kernel/power/power.h
===================================================================
@@ -25,12 +25,7 @@ struct swsusp_info {
  */
 #define SPARE_PAGES	((1024 * 1024) >> PAGE_SHIFT)
 
-extern int pm_suspend_disk(void);
-#else
-static inline int pm_suspend_disk(void)
-{
-	return -EPERM;
-}
+extern struct hibernation_ops *hibernation_ops;
 #endif
 
 extern struct mutex pm_mutex;
drivers/acpi/sleep/proc.c +1 -1
Index: linux-2.6.21/drivers/acpi/sleep/proc.c
===================================================================
@@ -60,7 +60,7 @@ acpi_system_write_sleep(struct file *fil
 	state = simple_strtoul(str, NULL, 0);
 #ifdef CONFIG_SOFTWARE_SUSPEND
 	if (state == 4) {
-		error = pm_suspend(PM_SUSPEND_DISK);
+		error = hibernate();
 		goto Done;
 	}
 #endif
kernel/power/user.c +6 -7
Index: linux-2.6.21/kernel/power/user.c
===================================================================
@@ -130,16 +130,16 @@ static inline int platform_prepare(void)
 {
 	int error = 0;
 
-	if (pm_ops && pm_ops->prepare)
-		error = pm_ops->prepare(PM_SUSPEND_DISK);
+	if (hibernation_ops)
+		error = hibernation_ops->prepare();
 
 	return error;
 }
 
 static inline void platform_finish(void)
 {
-	if (pm_ops && pm_ops->finish)
-		pm_ops->finish(PM_SUSPEND_DISK);
+	if (hibernation_ops)
+		hibernation_ops->finish();
 }
 
 static inline int snapshot_suspend(int platform_suspend)
@@ -384,7 +384,7 @@ static int snapshot_ioctl(struct inode *
 		switch (arg) {
 
 		case PMOPS_PREPARE:
-			if (pm_ops && pm_ops->enter) {
+			if (hibernation_ops) {
 				data->platform_suspend = 1;
 				error = 0;
 			} else {
@@ -395,8 +395,7 @@ static int snapshot_ioctl(struct inode *
 		case PMOPS_ENTER:
 			if (data->platform_suspend) {
 				kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK);
-				error = pm_ops->enter(PM_SUSPEND_DISK);
-				error = 0;
+				error = hibernation_ops->enter();
 			}
 			break;
 
include/linux/suspend.h +32 -0
Index: linux-2.6.21/include/linux/suspend.h
===================================================================
@@ -32,6 +32,24 @@ static inline int pm_prepare_console(voi
 static inline void pm_restore_console(void) {}
 #endif
 
+/**
+ * struct hibernation_ops - hibernation platform support
+ *
+ * The methods in this structure allow a platform to override the default
+ * mechanism of shutting down the machine during a hibernation transition.
+ *
+ * All three methods must be assigned.
+ *
+ * @prepare: prepare system for hibernation
+ * @enter: shut down system after state has been saved to disk
+ * @finish: finish/clean up after state has been reloaded
+ */
+struct hibernation_ops {
+	int (*prepare)(void);
+	int (*enter)(void);
+	void (*finish)(void);
+};
+
 #if defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND)
 /* kernel/power/snapshot.c */
 extern void __init register_nosave_region(unsigned long, unsigned long);
@@ -39,11 +57,25 @@ extern int swsusp_page_is_forbidden(stru
 extern void swsusp_set_page_free(struct page *);
 extern void swsusp_unset_page_free(struct page *);
 extern unsigned long get_safe_page(gfp_t gfp_mask);
+
+/**
+ * hibernation_set_ops - set the global hibernate operations
+ * @ops: the hibernation operations to use in subsequent hibernation transitions
+ */
+extern void hibernation_set_ops(struct hibernation_ops *ops);
+
+/**
+ * hibernate - hibernate the system
+ */
+extern int hibernate(void);
 #else
 static inline void register_nosave_region(unsigned long b, unsigned long e) {}
 static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
 static inline void swsusp_set_page_free(struct page *p) {}
 static inline void swsusp_unset_page_free(struct page *p) {}
+
+static inline void hibernation_set_ops(struct hibernation_ops *ops) {}
+static inline int hibernate(void) { return -ENOSYS; }
 #endif /* defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND) */
 
 void save_processor_state(void);
#1 lore raw

Trivial suggestions:

include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200

Quoted 8 lines · Rafael J. Wysocki
include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200 renamed from include/linux/suspend.h 2007-05-02 22:08:58.000000000 +0200 +5 -0
[...]
+/**
+ * hibernation_set_ops - set the global hibernate operations
+ * @ops: the hibernation operations to use in subsequent hibernation transitions
+ */
+extern void hibernation_set_ops(struct hibernation_ops *ops);

Comment must go near code, not with prototype in header.

include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200

Quoted 4 lines
include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200 renamed from include/linux/suspend.h 2007-05-02 22:08:58.000000000 +0200 +4 -0
+/**
+ * hibernate - hibernate the system
+ */
+extern int hibernate(void);

Pointless comment. You've already written a doc-book comment in the code for this function anyway, so could just as well remove this.

#2 lore raw
Quoted 14 lines · Satyam Sharma

Trivial suggestions:

include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200

Quoted 8 lines · Rafael J. Wysocki
include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200 renamed from include/linux/suspend.h 2007-05-02 22:08:58.000000000 +0200 +5 -0
[...]
+/**
+ * hibernation_set_ops - set the global hibernate operations
+ * @ops: the hibernation operations to use in subsequent hibernation transitions
+ */
+extern void hibernation_set_ops(struct hibernation_ops *ops);

Comment must go near code, not with prototype in header.

Quoted 7 lines

include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200

Quoted 4 lines
include/linux/suspend.h 2007-05-03 15:22:24.000000000 +0200 renamed from include/linux/suspend.h 2007-05-02 22:08:58.000000000 +0200 +4 -0
+/**
+ * hibernate - hibernate the system
+ */
+extern int hibernate(void);

Pointless comment. You've already written a doc-book comment in the code for this function anyway, so could just as well remove this.

The appended patch fixes these problems.

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Remove unnecessary comments in include/linux/suspend.h and add a comment describing hibernation_set_ops() in kernel/power/disk.c .

---
 include/linux/suspend.h |    8 --------
 kernel/power/disk.c     |    5 +++++
 2 files changed, 5 insertions(+), 8 deletions(-)
include/linux/suspend.h +0 -8
Index: linux-2.6.21/include/linux/suspend.h
===================================================================
@@ -58,15 +58,7 @@ extern void swsusp_set_page_free(struct 
 extern void swsusp_unset_page_free(struct page *);
 extern unsigned long get_safe_page(gfp_t gfp_mask);
 
-/**
- * hibernation_set_ops - set the global hibernate operations
- * @ops: the hibernation operations to use in subsequent hibernation transitions
- */
 extern void hibernation_set_ops(struct hibernation_ops *ops);
-
-/**
- * hibernate - hibernate the system
- */
 extern int hibernate(void);
 #else
 static inline void register_nosave_region(unsigned long b, unsigned long e) {}
kernel/power/disk.c +5 -0
Index: linux-2.6.21/kernel/power/disk.c
===================================================================
@@ -47,6 +47,11 @@ enum {
 
 struct hibernation_ops *hibernation_ops;
 
+/**
+ * hibernation_set_ops - set the global hibernate operations
+ * @ops: the hibernation operations to use in subsequent hibernation transitions
+ */
+
 void hibernation_set_ops(struct hibernation_ops *ops)
 {
 	if (ops && !(ops->prepare && ops->enter && ops->finish)) {
#3 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · On Fri, 4 May 2007 11:32:31 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

Separate the hibernation (aka suspend to disk code) from the other suspend code. In particular:
* Remove the definitions related to hibernation from include/linux/pm.h
* Introduce struct hibernation_ops and a new hibernate() function to hibernate the system, defined in include/linux/suspend.h
* Separate suspend code in kernel/power/main.c from hibernation-related code in kernel/power/disk.c and kernel/power/user.c (with the help of hibernation_ops)
* Switch ACPI (the only user of pm_ops.pm_disk_mode) to hibernation_ops

This causes the long-suffering Vaio to fail to power off during suspend to disk. It says "Please power me down manually".

<debugs a bit>

machine_ops.halt(); points at native_machine_halt(), which is a no-op.

However `halt -p' still works OK. How come it is not similarly affected?

#4 lore raw
Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Fri, 4 May 2007 11:32:31 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

Separate the hibernation (aka suspend to disk code) from the other suspend code. In particular:
* Remove the definitions related to hibernation from include/linux/pm.h
* Introduce struct hibernation_ops and a new hibernate() function to hibernate the system, defined in include/linux/suspend.h
* Separate suspend code in kernel/power/main.c from hibernation-related code in kernel/power/disk.c and kernel/power/user.c (with the help of hibernation_ops)
* Switch ACPI (the only user of pm_ops.pm_disk_mode) to hibernation_ops

Quoted 2 lines

This causes the long-suffering Vaio to fail to power off during suspend to disk. It says "Please power me down manually".

Hmm, looks like a failure of acpi_hibernation_enter(). Can you please put a printk() in there, after local_irq_restore()?

Quoted 5 lines

<debugs a bit>

machine_ops.halt(); points at native_machine_halt(), which is a no-op.

However `halt -p' still works OK. How come it is not similarly affected?

'halt -p' probably uses acpi_power_off() (which calls acpi_enter_sleep_state(ACPI_STATE_S5))

#5 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Fri, 4 May 2007 11:32:31 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

Separate the hibernation (aka suspend to disk code) from the other suspend code. In particular:
* Remove the definitions related to hibernation from include/linux/pm.h
* Introduce struct hibernation_ops and a new hibernate() function to hibernate the system, defined in include/linux/suspend.h
* Separate suspend code in kernel/power/main.c from hibernation-related code in kernel/power/disk.c and kernel/power/user.c (with the help of hibernation_ops)
* Switch ACPI (the only user of pm_ops.pm_disk_mode) to hibernation_ops

Quoted 5 lines
Quoted 2 lines

This causes the long-suffering Vaio to fail to power off during suspend to disk. It says "Please power me down manually".

Hmm, looks like a failure of acpi_hibernation_enter(). Can you please put a printk() in there, after local_irq_restore()?

Anyway, we should power off the system rather than halt it if hibernation_ops is not set.

---
From: Rafael J. Wysocki <[email protected]>

Power off the system instead of halting it if the 'platform' mode of hibernation has been requested, but hibernation_ops is not set.

---
 kernel/power/disk.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/power/disk.c +3 -3
Index: linux-2.6.21/kernel/power/disk.c
===================================================================
@@ -99,9 +99,6 @@ static void power_down(void)
 	case HIBERNATION_TEST:
 	case HIBERNATION_TESTPROC:
 		break;
-	case HIBERNATION_SHUTDOWN:
-		kernel_power_off();
-		break;
 	case HIBERNATION_REBOOT:
 		kernel_restart(NULL);
 		break;
@@ -111,6 +108,9 @@ static void power_down(void)
 			hibernation_ops->enter();
 			break;
 		}
+	case HIBERNATION_SHUTDOWN:
+		kernel_power_off();
+		break;
 	}
 	kernel_halt();
 	/*
#6 lore raw
Quoted 4 lines · Rafael J. Wysocki

Power off the system instead of halting it if the 'platform' mode of hibernation
has been requested, but hibernation_ops is not set.

Ehm, unless you made a mistake in the patch then that shouldn't be possible.

johannes

#7 lore raw
Quoted 8 lines · Johannes Berg
Quoted 4 lines · Rafael J. Wysocki

Power off the system instead of halting it if the 'platform' mode of hibernation
has been requested, but hibernation_ops is not set.

Ehm, unless you made a mistake in the patch then that shouldn't be possible.

Hmm, right, but the patch is correct nevertheless. :-)

I see where the problem is. hibernation_mode is 0 by default (HIBERNATION_INVALID) and it's not changed to anything else later if defaults are used.

Something like this is necessary, I think:

---
From: Rafael J. Wysocki <[email protected]>

Make sure that hibernation_mode is set to a reasonable value by default.

---
 kernel/power/disk.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/power/disk.c +5 -2
Index: linux-2.6.21/kernel/power/disk.c
===================================================================
@@ -30,8 +30,6 @@ char resume_file[256] = CONFIG_PM_STD_PA
 dev_t swsusp_resume_device;
 sector_t swsusp_resume_block;
 
-static int hibernation_mode;
-
 enum {
 	HIBERNATION_INVALID,
 	HIBERNATION_PLATFORM,
@@ -45,6 +43,8 @@ enum {
 #define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
 #define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
 
+static int hibernation_mode = HIBERNATION_SHUTDOWN;
+
 struct hibernation_ops *hibernation_ops;
 
 /**
@@ -60,6 +60,9 @@ void hibernation_set_ops(struct hibernat
 	}
 	mutex_lock(&pm_mutex);
 	hibernation_ops = ops;
+	if (ops)
+		hibernation_mode = HIBERNATION_PLATFORM;
+
 	mutex_unlock(&pm_mutex);
 }
 
#8 lore raw

Hi!

Quoted 13 lines
Quoted 6 lines
Quoted 3 lines

Power off the system instead of halting it if the 'platform' mode of hibernation
has been requested, but hibernation_ops is not set.

Ehm, unless you made a mistake in the patch then that shouldn't be possible.

Hmm, right, but the patch is correct nevertheless. :-)

I see where the problem is. hibernation_mode is 0 by default (HIBERNATION_INVALID) and it's not changed to anything else later if defaults are used.

Quoted 8 lines

Something like this is necessary, I think:

---
From: Rafael J. Wysocki <[email protected]>

Make sure that hibernation_mode is set to a reasonable value by default.

ACK.

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

kernel/power/disk.c void hibernation_set_ops(struct hibernat · line 64

Quoted 6 lines · Rafael J. Wysocki
kernel/power/disk.c +2 -0
@@ -60,6 +60,9 @@ void hibernation_set_ops(struct hibernat
 	}
 	mutex_lock(&pm_mutex);
 	hibernation_ops = ops;
+	if (ops)
+		hibernation_mode = HIBERNATION_PLATFORM;
	else if (hibernation_mode == HIBERNATION_PLATFORM)
		hibernation_mode = HIBERNATION_SHUTDOWN;

kernel/power/disk.c void hibernation_set_ops(struct hibernat · line 66

Quoted 2 lines
kernel/power/disk.c +1 -0
+
 	mutex_unlock(&pm_mutex);

johannes

#10 lore raw
Quoted 11 lines · Johannes Berg

kernel/power/disk.c void hibernation_set_ops(struct hibernat · line 64

Quoted 6 lines · Rafael J. Wysocki
kernel/power/disk.c +2 -0
@@ -60,6 +60,9 @@ void hibernation_set_ops(struct hibernat
 	}
 	mutex_lock(&pm_mutex);
 	hibernation_ops = ops;
+	if (ops)
+		hibernation_mode = HIBERNATION_PLATFORM;
	else if (hibernation_mode == HIBERNATION_PLATFORM)
		hibernation_mode = HIBERNATION_SHUTDOWN;

Also, you could then simplify all the instances of
(hibernation_mode == HIBERNATION_PLATFORM && hibernation_ops)
to just
(hibernation_mode == HIBERNATION_PLATFORM)
in various if statements and other places.

johannes

#11 lore raw
Quoted 13 lines · Johannes Berg
Quoted 11 lines · Johannes Berg

kernel/power/disk.c void hibernation_set_ops(struct hibernat · line 64

Quoted 6 lines · Rafael J. Wysocki
kernel/power/disk.c +2 -0
@@ -60,6 +60,9 @@ void hibernation_set_ops(struct hibernat
 	}
 	mutex_lock(&pm_mutex);
 	hibernation_ops = ops;
+	if (ops)
+		hibernation_mode = HIBERNATION_PLATFORM;
	else if (hibernation_mode == HIBERNATION_PLATFORM)
		hibernation_mode = HIBERNATION_SHUTDOWN;
Quoted 5 lines

Also, you could then simplify all the instances of
(hibernation_mode == HIBERNATION_PLATFORM && hibernation_ops)
to just
(hibernation_mode == HIBERNATION_PLATFORM)
in various if statements and other places.

No, that's not a good idea, because of the "reduce code duplication patch" that I'd like to go on top of this. I'd rather use 'if (hibernation_ops)' here. :-)

Greetings,
Rafael

#12 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines

Also, you could then simplify all the instances of
(hibernation_mode == HIBERNATION_PLATFORM && hibernation_ops)
to just
(hibernation_mode == HIBERNATION_PLATFORM)
in various if statements and other places.

No, that's not a good idea, because of the "reduce code duplication patch" that I'd like to go on top of this. I'd rather use 'if (hibernation_ops)' here. :-)

But if you want the user to be able to change away from 'platform' mode you still have to have
if (hibernation_ops && hibernation_mode == HIBERNATION_PLATFORM)
in most places, no?

johannes

#13 lore raw
Quoted 8 lines · Johannes Berg
Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines

Also, you could then simplify all the instances of
(hibernation_mode == HIBERNATION_PLATFORM && hibernation_ops)
to just
(hibernation_mode == HIBERNATION_PLATFORM)
in various if statements and other places.

Quoted 7 lines
Quoted 2 lines

No, that's not a good idea, because of the "reduce code duplication patch" that I'd like to go on top of this. I'd rather use 'if (hibernation_ops)' here. :-)

But if you want the user to be able to change away from 'platform' mode you still have to have
if (hibernation_ops && hibernation_mode == HIBERNATION_PLATFORM)
in most places, no?

Yes, and that's why I'm not going to change that. The code from user.c is also going to call these functions in the future, so the full test is necessary.

For now, I'll only add the 'else if' check to hibernation_set_ops().

Greetings,
Rafael

#14 lore raw

PATCH 1/1 swsusp: Use reasonable default for hibernation_mode

In reply to Johannes Berg

From: Rafael J. Wysocki <[email protected]>

Make sure that hibernation_mode is set to a reasonable value by default.

---
 kernel/power/disk.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/power/disk.c +7 -2
Index: linux-2.6.21/kernel/power/disk.c
===================================================================
@@ -30,8 +30,6 @@ char resume_file[256] = CONFIG_PM_STD_PA
 dev_t swsusp_resume_device;
 sector_t swsusp_resume_block;
 
-static int hibernation_mode;
-
 enum {
 	HIBERNATION_INVALID,
 	HIBERNATION_PLATFORM,
@@ -45,6 +43,8 @@ enum {
 #define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
 #define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
 
+static int hibernation_mode = HIBERNATION_SHUTDOWN;
+
 struct hibernation_ops *hibernation_ops;
 
 /**
@@ -60,6 +60,11 @@ void hibernation_set_ops(struct hibernat
 	}
 	mutex_lock(&pm_mutex);
 	hibernation_ops = ops;
+	if (ops)
+		hibernation_mode = HIBERNATION_PLATFORM;
+	else if (hibernation_mode == HIBERNATION_PLATFORM)
+		hibernation_mode = HIBERNATION_SHUTDOWN;
+
 	mutex_unlock(&pm_mutex);
 }
 
#15 lore raw
In reply to Andrew Morton
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"AM" == Andrew Morton <[email protected]> writes:

AM> This causes the long-suffering Vaio to fail to power off during AM> suspend to disk. It says "Please power me down manually".

Interesting; I'm seeing exactly the same thing on a Vaio TXN17P, which popped up somewhere between Fedora's 2.6.21-1.2116 and 2.6.21-1.2125 kernels, but the changelog there shows little more than wireless fixes and the 2.6.21.1 patch.

AM> However `halt -p' still works OK.

The same for me. It's odd to think that identical symptoms are caused by something completely different, but I guess this is the kernel.

- J<