[Pm-utils] [patch] userspace-suspend, revisited

Stefan Seyfried seife at suse.de
Mon Mar 26 11:16:41 PDT 2007


Hi,

just to make sure that we don't forget about it... :-)

This is my current minimal userspace suspend patch. It should in theory
be easy to also patch suspend2 support into it, and it already provides
a do_suspend_hybrid (untested, i have to admit). It also introduces error
reporting up the stack, which we also want to have (see also the small
echo replacement i posted some days ago to further improve this).

Index: pm/functions
===================================================================
RCS file: /cvs/pm-utils/pm-utils/pm/functions,v
retrieving revision 1.44
diff -u -r1.44 functions
--- pm/functions	26 Mar 2007 14:18:07 -0000	1.44
+++ pm/functions	26 Mar 2007 18:15:44 -0000
@@ -12,6 +12,8 @@
 INHIBIT=/var/run/pm-utils.inhibit
 PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
 SUSPEND_MODULES=""
+HIBERNATE_METHOD=""
+S2DISK_CONF="/etc/suspend.conf"
 TEMPORARY_CPUFREQ_GOVERNOR="userspace"
 
 set -a
@@ -120,22 +122,72 @@
 
 do_suspend()
 {
-	pm-pmu --suspend || echo -n "mem" > /sys/power/state
+	local RET
+	if [ -x /usr/sbin/s2ram ]; then
+		set -x
+		/usr/sbin/s2ram $S2RAM_OPTS
+		RET=$?
+		set +x
+	else
+		pm-pmu --suspend || echo -n "mem" > /sys/power/state
+		RET=$?
+	fi
+	return $RET
 }
 
 do_hibernate()
 {
-	echo -n "platform" > /sys/power/disk
-	echo -n "disk" > /sys/power/state
+	local RET=1
+	if [ -z "$HIBERNATE_METHOD" ]; then
+		if [ -x /usr/sbin/s2disk -a -c /dev/snapshot ]; then
+			HIBERNATE_METHOD="userspace"
+		else
+			HIBERNATE_METHOD="kernel"
+		fi
+	fi
+	case $HIBERNATE_METHOD in
+		userspace)
+			set -x
+			/usr/sbin/s2disk -f $S2DISK_CONF
+			RET=$?
+			set +x
+			;;
+		kernel)
+			echo -n "platform" > /sys/power/disk
+			echo -n "disk" > /sys/power/state
+			RET=$?
+			;;
+	esac
+	return $RET
 }
 
 do_suspend_hybrid()
 {
-	return 1
+	local RET=1
+	if [ -z "$HIBERNATE_METHOD" ]; then
+		if [ -x /usr/sbin/s2both -a -c /dev/snapshot ]; then
+			HIBERNATE_METHOD="userspace"
+		else
+			HIBERNATE_METHOD="kernel"
+		fi
+	fi
+	case $HIBERNATE_METHOD in
+		userspace)
+			set -x
+			/usr/sbin/s2both -f $S2DISK_CONF
+			RET=$?
+			set +x
+			;;
+		*)
+			RET=1
+			;;
+	esac
+	return $RET
 }
 
 pm_main()
 {
+	local RET=1
 	if [ -n "$PM_LOGFILE" ]; then
 		[ -f "$PM_LOGFILE" ] && rm -f "$PM_LOGFILE"
 		exec > "$PM_LOGFILE" 2>&1
@@ -149,13 +201,14 @@
 	if [ ! -e "$INHIBIT" -a "$(type -t "do_$1")" == "function" ]; then
 		sync ; sync ; sync
 		"do_$1"
+		RET=$?
 	fi
 
 	run_hooks "$2" reverse
 
 	remove_suspend_lock 200
 
-	return 0
+	return $RET
 }
 
 _rmmod() {
-- 
Stefan Seyfried

"Any ideas, John?"
"Well, surrounding them's out." 


More information about the Pm-utils mailing list