Skip to contentSkip to conversation

PM: fast power off - core

PATCH In review akuster 3 participants 5 messages Jan 27, 2007 – Jan 29, 2007

Subsystems (3)
lore
Share & tools
lore

akuster

author
#0 lore raw

PATCH 1/2 PM: fast power off - core

Fastpoweroff allows a user to power down the system without using rc kill scripts. This is used in the advent of a battery operated device about to lose power. The user interface is vis sysfs /sys/power/fastpoweroff. A simple cat of the fastpoweroff will list any registered profiles. To invoke
the profile sequence, echo {profile name} > /sys/power/fastpoweroff.

This is the core code for fastpoweroff profile support, it includes a register/unregister and default profile callbacks.

---
 fs/super.c                    |    6 +
 kernel/power/Kconfig          |    2 
 kernel/power/Makefile         |    2 
 kernel/power/fastoff/Kconfig  |   13 +++
 kernel/power/fastoff/Makefile |    8 ++
 kernel/power/fastoff/fpo.c    |  155 ++++++++++++++++++++++++++++++++++++++++++
 kernel/power/fastoff/fpo.h    |   27 +++++++
 7 files changed, 213 insertions(+)
kernel/power/Kconfig +2 -0
Index: linux-2.6_dev/kernel/power/Kconfig
===================================================================
@@ -131,3 +131,5 @@ config SUSPEND_SMP
 	bool
 	depends on HOTPLUG_CPU && X86 && PM
 	default y
+
+source "kernel/power/fastoff/Kconfig"
kernel/power/Makefile +2 -0
Index: linux-2.6_dev/kernel/power/Makefile
===================================================================
@@ -8,3 +8,5 @@ obj-$(CONFIG_PM_LEGACY)		+= pm.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= swsusp.o disk.o snapshot.o swap.o user.o
 
 obj-$(CONFIG_MAGIC_SYSRQ)	+= poweroff.o
+
+obj-$(CONFIG_FAST_POWER_OFF)	+= fastoff/
kernel/power/fastoff/Kconfig new file +13 -0
Index: linux-2.6_dev/kernel/power/fastoff/Kconfig
===================================================================
@@ -0,0 +1,13 @@
+#
+# Fast power off configuration
+#
+menu "Fast Power off"
+
+config FAST_POWER_OFF
+	bool "Fast power off support"
+	default y
+	depends on PM && SYSFS
+	---help---
+	  Say yes if you want core support for sysfs/power/fastoff
+
+endmenu
kernel/power/fastoff/Makefile new file +8 -0
Index: linux-2.6_dev/kernel/power/fastoff/Makefile
===================================================================
@@ -0,0 +1,8 @@
+#
+# Makefile for Fast Power off
+#
+# 15 Jan. 2007 Armin Kuster <[email protected]>
+#
+
+obj-$(CONFIG_FAST_POWER_OFF)	:= fpo.o
+
kernel/power/fastoff/fpo.h new file +27 -0
Index: linux-2.6_dev/kernel/power/fastoff/fpo.h
===================================================================
@@ -0,0 +1,27 @@
+#ifndef __FASTOFF_H__
+#define __FASTOFF_H__
+/*
+ * kernel/power/fastoff/fpo.h
+ *
+ * Author: Armin Kuster <[email protected], or [email protected]>
+ *
+ * 2006, 2007  (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#define FPO_NAME_LEN 16
+
+struct fpo_driver {
+	char name[FPO_NAME_LEN];
+	int (*policy) (void);
+	struct list_head fpo_list;
+};
+
+extern int fastpoweroff_register(struct fpo_driver *fpo);
+extern void fastpoweroff_unregister(struct fpo_driver *fpo);
+extern void fastpoweroff_prepare(void);
+extern void fastpoweroff(void);
+extern void fastpoweroff_standby(void);
+#endif	/* __FASTOFF_H__ */
kernel/power/fastoff/fpo.c new file +155 -0

155 lines not on this page · raw message

fs/super.c +6 -0
Index: linux-2.6_dev/fs/super.c
===================================================================
@@ -649,6 +649,12 @@ void emergency_remount(void)
 	pdflush_operation(do_emergency_remount, 0);
 }
 
+#ifdef CONFIG_FAST_POWER_OFF
+void suspend_emergency_remount(void)
+{
+	do_emergency_remount(0);
+}
+#endif
 /*
  * Unnamed block devices are dummy devices used by virtual
  * filesystems which don't use real block-devices.  -- jrs
#1 lore raw
Quoted 2 lines · On Sat, 27 Jan 2007 09:36:53 -1000 akuster <[email protected]> wrote:

Fastpoweroff allows a user to power down the system without using rc kill scripts.

Confused. I just type `halt -pfn'. Why is this patch better?

author
#2 lore raw

Andrew,

Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Sat, 27 Jan 2007 09:36:53 -1000 akuster <[email protected]> wrote:

Fastpoweroff allows a user to power down the system without using rc kill scripts.

Confused.

I have a knack of doing that.

I just type `halt -pfn'.

Thats fine but from what I can tell, it does not try to remount the file system before powering off.

Why is this patch better?

It allows the user to configure how a power off sequence is defined beyond the "Halt" via inserting a new profile module. In the default, processes are frozen and the file system is remounted as read only.

- Armin

#3 lore raw
In reply to akuster

Hi!

Quoted 5 lines

Fastpoweroff allows a user to power down the system without using rc kill scripts. This is used in the advent of a battery operated device about to lose power. The user interface is vis sysfs /sys/power/fastpoweroff. A simple cat of the fastpoweroff will list any registered profiles. To invoke
the profile sequence, echo {profile name} > /sys/power/fastpoweroff.

No, we do not want "poweroff profiles" in kernel. Sorry.

rc kill scripts should be fast enough, if not, fix them. If it is impossible (time is spent in kernel waiting for network card to shut off), fix that.

What you want is pretty much "echo b > ..../sysrq; halt --now".

Pavel

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

Hi!

Quoted 5 lines

Fastpoweroff allows a user to power down the system without using rc kill scripts. This is used in the advent of a battery operated device about to lose power. The user interface is vis sysfs /sys/power/fastpoweroff. A simple cat of the fastpoweroff will list any registered profiles. To invoke
the profile sequence, echo {profile name} > /sys/power/fastpoweroff.

No, we do not want "poweroff profiles" in kernel. Sorry.

No need to be.

Quoted 6 lines

rc kill scripts should be fast enough, if not, fix them. If it is impossible (time is spent in kernel waiting for network card to shut off), fix that.

What you want is pretty much "echo b > ..../sysrq; halt --now".

The one draw back is that Magic sysrq needs to be enabled and it might not be desired in a deployed system. "echo u " is more of what I was looking for.

Thanks for you time.

Armin