public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* Power event notification patch
@ 2007-07-05 12:01 V, Sankara Narayanan
  2007-07-05 12:08 ` Oliver Neukum
  2007-07-06 18:41 ` Greg KH
  0 siblings, 2 replies; 23+ messages in thread
From: V, Sankara Narayanan @ 2007-07-05 12:01 UTC (permalink / raw)
  To: linux-pm


[-- Attachment #1.1: Type: text/plain, Size: 873 bytes --]

Hi Folks,

 

Here is a simple patch for power event notification to user-space
applications. Basically, what it does is notify the user-space
applications that the system is going to a low power state
(Suspend-to-RAM and Suspend-to-Disk) and resume from that state. This is
useful for the user-space applications to do some significant action
when the system goes to the low power state (like saving an unsaved
file). The user-space objects can form a netlink socket and listen to
these events. It is done through a kobject-netlink socket. For this I
have used the kobject_uevent system call, posting the notification to
user space with standby, hibernate and resume in the action parameter of
the kobject_uevent call (mapped to KOBJ_S3, KOBJ_S4 and KOBJ_RESUME
enums). Appreciate your comments on the patch.

 

Thanks,

Sankara Narayanan V.

 


[-- Attachment #1.2: Type: text/html, Size: 3573 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 23+ messages in thread
* Power event notification patch
@ 2007-07-05 12:02 V, Sankara Narayanan
  0 siblings, 0 replies; 23+ messages in thread
From: V, Sankara Narayanan @ 2007-07-05 12:02 UTC (permalink / raw)
  To: linux-pm


[-- Attachment #1.1: Type: text/plain, Size: 873 bytes --]

Hi Folks,

 

Here is a simple patch for power event notification to user-space
applications. Basically, what it does is notify the user-space
applications that the system is going to a low power state
(Suspend-to-RAM and Suspend-to-Disk) and resume from that state. This is
useful for the user-space applications to do some significant action
when the system goes to the low power state (like saving an unsaved
file). The user-space objects can form a netlink socket and listen to
these events. It is done through a kobject-netlink socket. For this I
have used the kobject_uevent system call, posting the notification to
user space with standby, hibernate and resume in the action parameter of
the kobject_uevent call (mapped to KOBJ_S3, KOBJ_S4 and KOBJ_RESUME
enums). Appreciate your comments on the patch.

 

Thanks,

Sankara Narayanan V.

 


[-- Attachment #1.2: Type: text/html, Size: 3733 bytes --]

[-- Attachment #2: pwr-evnt-notfn.patch --]
[-- Type: application/octet-stream, Size: 3444 bytes --]

diff -aruN kernel-mid/.gitignore linux-pwr-evnt-notfn/.gitignore
--- kernel-mid/.gitignore	1970-01-01 05:30:00.000000000 +0530
+++ linux-pwr-evnt-notfn/.gitignore	2007-07-05 15:17:02.000000000 +0530
@@ -0,0 +1,47 @@
+#
+# NOTE! Don't add files that are generated in specific
+# subdirectories here. Add them in the ".gitignore" file
+# in that subdirectory instead.
+#
+# Normal rules
+#
+.*
+*.o
+*.a
+*.s
+*.ko
+*.so
+*.mod.c
+*.i
+*.lst
+*.symtypes
+
+#
+# Top-level generic files
+#
+tags
+TAGS
+vmlinux*
+System.map
+Module.symvers
+
+#
+# Generated include files
+#
+include/asm
+include/asm-*/asm-offsets.h
+include/config
+include/linux/autoconf.h
+include/linux/compile.h
+include/linux/version.h
+include/linux/utsrelease.h
+
+# stgit generated dirs
+patches-*
+
+# quilt's files
+patches
+series
+
+# cscope files
+cscope.*
diff -aruN kernel-mid/include/linux/kobject.h linux-pwr-evnt-notfn/include/linux/kobject.h
--- kernel-mid/include/linux/kobject.h	2007-04-16 05:20:57.000000000 +0530
+++ linux-pwr-evnt-notfn/include/linux/kobject.h	2007-07-05 15:17:11.000000000 +0530
@@ -48,6 +48,9 @@
 	KOBJ_OFFLINE	= (__force kobject_action_t) 0x06,	/* device offline */
 	KOBJ_ONLINE	= (__force kobject_action_t) 0x07,	/* device online */
 	KOBJ_MOVE	= (__force kobject_action_t) 0x08,	/* device move */
+	KOBJ_S3		= (__force kobject_action_t) 0x09,	/* system suspend to RAM */
+	KOBJ_S4		= (__force kobject_action_t) 0x0A,	/* system suspend to disk */
+	KOBJ_RESUME	= (__force kobject_action_t) 0x0B,	/* system resume */
 };
 
 struct kobject {
diff -aruN kernel-mid/kernel/power/disk.c linux-pwr-evnt-notfn/kernel/power/disk.c
--- kernel-mid/kernel/power/disk.c	2007-04-16 05:20:57.000000000 +0530
+++ linux-pwr-evnt-notfn/kernel/power/disk.c	2007-07-05 15:17:04.000000000 +0530
@@ -184,6 +184,7 @@
 	resume_console();
  Thaw:
 	unprepare_processes();
+	kobject_uevent(&power_subsys.kset.kobj, KOBJ_RESUME);
 	return error;
 }
 
diff -aruN kernel-mid/kernel/power/main.c linux-pwr-evnt-notfn/kernel/power/main.c
--- kernel-mid/kernel/power/main.c	2007-04-16 05:20:57.000000000 +0530
+++ linux-pwr-evnt-notfn/kernel/power/main.c	2007-07-05 15:17:04.000000000 +0530
@@ -141,6 +141,7 @@
 
 static void suspend_finish(suspend_state_t state)
 {
+	kobject_uevent(&power_subsys.kset.kobj, KOBJ_RESUME);
 	enable_nonboot_cpus();
 	pm_finish(state);
 	device_resume();
@@ -191,6 +192,11 @@
 {
 	int error;
 
+	if (state == PM_SUSPEND_MEM) /* if suspend to RAM */
+		kobject_uevent(&power_subsys.kset.kobj, KOBJ_S3);
+	if (state == PM_SUSPEND_DISK) /* if suspend to disk */
+		kobject_uevent(&power_subsys.kset.kobj, KOBJ_S4);
+
 	if (!valid_state(state))
 		return -ENODEV;
 	if (!mutex_trylock(&pm_mutex))
@@ -335,8 +341,10 @@
 static int __init pm_init(void)
 {
 	int error = subsystem_register(&power_subsys);
-	if (!error)
+	if (!error) {
+		kset_set_kset_s(&power_subsys, power_subsys);
 		error = sysfs_create_group(&power_subsys.kset.kobj,&attr_group);
+	}
 	return error;
 }
 
diff -aruN kernel-mid/lib/kobject_uevent.c linux-pwr-evnt-notfn/lib/kobject_uevent.c
--- kernel-mid/lib/kobject_uevent.c	2007-04-16 05:20:57.000000000 +0530
+++ linux-pwr-evnt-notfn/lib/kobject_uevent.c	2007-07-05 15:15:14.000000000 +0530
@@ -52,6 +52,12 @@
 		return "online";
 	case KOBJ_MOVE:
 		return "move";
+	case KOBJ_S3:
+		return "standby";
+	case KOBJ_S4:
+		return "hibernate";
+	case KOBJ_RESUME:
+		return "resume";
 	default:
 		return NULL;
 	}

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2007-07-09 16:34 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-05 12:01 Power event notification patch V, Sankara Narayanan
2007-07-05 12:08 ` Oliver Neukum
2007-07-05 12:17   ` V, Sankara Narayanan
2007-07-05 12:34     ` Oliver Neukum
2007-07-05 12:44       ` V, Sankara Narayanan
2007-07-05 12:51         ` Oliver Neukum
2007-07-05 12:54         ` Igor Stoppa
2007-07-05 13:09           ` V, Sankara Narayanan
2007-07-05 13:12             ` Johannes Berg
2007-07-05 13:17               ` V, Sankara Narayanan
2007-07-05 13:28                 ` Johannes Berg
2007-07-05 13:33                   ` V, Sankara Narayanan
2007-07-06 10:46                     ` Johannes Berg
2007-07-05 13:56                   ` Scott Preece
2007-07-05 13:22               ` Johannes Berg
2007-07-05 13:20             ` Igor Stoppa
2007-07-05 13:39               ` V, Sankara Narayanan
2007-07-05 13:46                 ` Igor Stoppa
2007-07-05 12:48       ` Johannes Berg
2007-07-06 18:41 ` Greg KH
2007-07-09  4:34   ` V, Sankara Narayanan
2007-07-09 16:34     ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2007-07-05 12:02 V, Sankara Narayanan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox