public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Hotplug events for system suspend/resume
@ 2004-05-11  1:00 Todd Poynor
  2004-05-11 23:00 ` Greg KH
  0 siblings, 1 reply; 13+ messages in thread
From: Todd Poynor @ 2004-05-11  1:00 UTC (permalink / raw)
  To: mochel, linux-hotplug-devel, linux-kernel

Generate synchronous hotplug events for system suspend and resume
events, via the power subsystem.  Recent discussions have indicated
various methods for notification of these events are in use today; this
is an attempt to move these into the generic power subsystem.  The patch
relies on the "synchronous hotplug events via kobject" patch sent
previously.

I fumbled around with the best to way to hook this into kobject.
Subsystems apparently aren't setup to generate hotplug events directly,
only kobjects below a subsystem may issue hotplug events.  A notifier
kobject has been created within the power subsystem for this purpose.
Any advice welcome.

Thanks -- Todd

--- linux-2.6.6-orig/kernel/power/main.c	2004-05-10 11:26:35.000000000 -0700
+++ linux-2.6.6-pm/kernel/power/main.c	2004-05-10 17:25:30.000000000 -0700
@@ -25,6 +25,9 @@
 
 struct pm_ops * pm_ops = NULL;
 u32 pm_disk_mode = PM_DISK_SHUTDOWN;
+int pm_state = PM_SUSPEND_ON;
+
+static void power_notify(void);
 
 /**
  *	pm_set_ops - Set the global power method table. 
@@ -150,20 +153,26 @@
 		goto Unlock;
 	}
 
+	pm_state = state;
+	power_notify();
+
 	if (state == PM_SUSPEND_DISK) {
 		error = pm_suspend_disk();
-		goto Unlock;
+		goto NotifyUnlock;
 	}
 
 	pr_debug("PM: Preparing system for suspend\n");
 	if ((error = suspend_prepare(state)))
-		goto Unlock;
+		goto NotifyUnlock;
 
 	pr_debug("PM: Entering state.\n");
 	error = suspend_enter(state);
 
 	pr_debug("PM: Finishing up.\n");
 	suspend_finish(state);
+ NotifyUnlock:
+	pm_state = PM_SUSPEND_ON;
+	power_notify();
  Unlock:
 	up(&pm_sem);
 	return error;
@@ -186,8 +195,28 @@
 }
 
 
+static int power_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
+			 int num_envp, char *buffer, int buffer_size)
+{
+	int i = 0;
+	int length = 0;
 
-decl_subsys(power,NULL,NULL);
+	envp[i++] = buffer;
+	length += scnprintf (buffer, buffer_size - length, "STATE=%s",
+			     pm_states[pm_state] ? pm_states[pm_state] : "on");
+	if ((buffer_size - length <= 0) || (i >= num_envp))
+		return -ENOMEM;
+	++length;
+
+	envp[i] = 0;
+	return 0;
+}
+
+static struct kset_hotplug_ops power_hotplug_ops = {
+	.hotplug =	power_hotplug,
+};
+
+decl_subsys(power,NULL,&power_hotplug_ops);
 
 
 /**
@@ -247,12 +276,28 @@
 	.attrs = g,
 };
 
+struct power_notifier {
+	struct kobject kobj;
+};
+
+static struct power_notifier power_notifier;
+
+static void power_notify()
+{
+	kobject_hotplug_wait("state-change", &power_notifier.kobj);
+}
 
 static int __init pm_init(void)
 {
 	int error = subsystem_register(&power_subsys);
 	if (!error)
 		error = sysfs_create_group(&power_subsys.kset.kobj,&attr_group);
+	if (!error) {
+		kobj_set_kset_s(&power_notifier, power_subsys);
+		error = kobject_set_name(&power_notifier.kobj, "notifier");
+		if (! error)
+			kobject_register(&power_notifier.kobj);
+	}
 	return error;
 }


^ permalink raw reply	[flat|nested] 13+ messages in thread
* RE: Hotplug events for system suspend/resume
@ 2004-05-12 18:52 Grover, Andrew
  0 siblings, 0 replies; 13+ messages in thread
From: Grover, Andrew @ 2004-05-12 18:52 UTC (permalink / raw)
  To: ncunningham, Todd Poynor
  Cc: Greg KH, mochel, linux-hotplug-devel, linux-kernel


> > > In my mind, this approach is simpler and makes more 
> sense: userspace
> > > should worry about userspace actions related to 
> suspending before calling
> > > kernelspace. Kernel space should then only worry about saving and
> > > restoring driver states and should be transparent to user 
> space. ...
> >
> > Agreed, with the minor reservations listed in a previous 
> email (suspend
> > initiated by drivers must coordinate ad-hoc with userspace, etc.).
> 
> You're thinking ACPI drivers initiating a suspend? They would 
> do it through 
> acpid, wouldn't they? At least that's the glue I use to get 
> my sleep button 
> to initiate a suspend. I would assume thermal events 
> would/should work the 
> same.

Yeah. There definitely is a need for userspace apps to be power-aware,
and have the ability to prevent suspend, but I think this should all be
done via the daemon (talking to apps via D-BUS?) and then the daemon
pulls the trigger if all power-aware apps in userspace agree it's OK. I
don't think ACPI kernel code should do anything without being told to.

The kernel sleep interface should only ever be used by the daemon. If
the user decides to use it from the cmdline then things aren't going to
work right.

My 2c,

-- Andy

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

end of thread, other threads:[~2004-05-17 13:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-11  1:00 Hotplug events for system suspend/resume Todd Poynor
2004-05-11 23:00 ` Greg KH
2004-05-12  0:39   ` Todd Poynor
2004-05-12  2:16     ` Nigel Cunningham
2004-05-12  2:44       ` Todd Poynor
2004-05-12  3:59         ` Nigel Cunningham
2004-05-12 19:36           ` Todd Poynor
2004-05-15  3:03             ` Pavel Machek
2004-05-12 15:08     ` Greg KH
2004-05-13 22:46       ` Tim Bird
2004-05-13 23:28         ` Greg KH
2004-05-15  2:59     ` Pavel Machek
  -- strict thread matches above, loose matches on Subject: below --
2004-05-12 18:52 Grover, Andrew

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