aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power/main.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2012-04-29 16:53:42 -0400
committerRafael J. Wysocki <rjw@sisk.pl>2012-05-01 15:26:05 -0400
commitb86ff9820fd5df69295273b9aa68e58786ffc23f (patch)
treee8af5745652c926b9a82b3b7531dc455564efdfb /kernel/power/main.c
parent55850945e872531644f31fefd217d61dd15dcab8 (diff)
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two sysfs file located in /sys/power/, wake_lock and wake_unlock. Writing a wakelock name and optionally a timeout to the wake_lock file causes the wakelock whose name was written to be acquired (it is created before is necessary), optionally with the given timeout. Writing the name of a wakelock to wake_unlock causes that wakelock to be released. Implement an analogous interface for user space using wakeup sources. Add the /sys/power/wake_lock and /sys/power/wake_unlock files allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout to wake_lock causes the wakeup source of that name to be activated, optionally with the given timeout. If that wakeup source doesn't exist, it will be created and then activated. Writing a name to wake_unlock causes the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help of wake_lock that haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT wakeup sources created with the help of wake_lock present at a time. The data type used to track wakeup sources created by user space is called "struct wakelock" to indicate the origins of this feature. This version of the patch includes an rbtree manipulation fix from John Stultz. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'kernel/power/main.c')
-rw-r--r--kernel/power/main.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/kernel/power/main.c b/kernel/power/main.c
index ba6a5645952d..54ec071de337 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -431,6 +431,43 @@ static ssize_t autosleep_store(struct kobject *kobj,
431 431
432power_attr(autosleep); 432power_attr(autosleep);
433#endif /* CONFIG_PM_AUTOSLEEP */ 433#endif /* CONFIG_PM_AUTOSLEEP */
434
435#ifdef CONFIG_PM_WAKELOCKS
436static ssize_t wake_lock_show(struct kobject *kobj,
437 struct kobj_attribute *attr,
438 char *buf)
439{
440 return pm_show_wakelocks(buf, true);
441}
442
443static ssize_t wake_lock_store(struct kobject *kobj,
444 struct kobj_attribute *attr,
445 const char *buf, size_t n)
446{
447 int error = pm_wake_lock(buf);
448 return error ? error : n;
449}
450
451power_attr(wake_lock);
452
453static ssize_t wake_unlock_show(struct kobject *kobj,
454 struct kobj_attribute *attr,
455 char *buf)
456{
457 return pm_show_wakelocks(buf, false);
458}
459
460static ssize_t wake_unlock_store(struct kobject *kobj,
461 struct kobj_attribute *attr,
462 const char *buf, size_t n)
463{
464 int error = pm_wake_unlock(buf);
465 return error ? error : n;
466}
467
468power_attr(wake_unlock);
469
470#endif /* CONFIG_PM_WAKELOCKS */
434#endif /* CONFIG_PM_SLEEP */ 471#endif /* CONFIG_PM_SLEEP */
435 472
436#ifdef CONFIG_PM_TRACE 473#ifdef CONFIG_PM_TRACE
@@ -487,6 +524,10 @@ static struct attribute * g[] = {
487#ifdef CONFIG_PM_AUTOSLEEP 524#ifdef CONFIG_PM_AUTOSLEEP
488 &autosleep_attr.attr, 525 &autosleep_attr.attr,
489#endif 526#endif
527#ifdef CONFIG_PM_WAKELOCKS
528 &wake_lock_attr.attr,
529 &wake_unlock_attr.attr,
530#endif
490#ifdef CONFIG_PM_DEBUG 531#ifdef CONFIG_PM_DEBUG
491 &pm_test_attr.attr, 532 &pm_test_attr.attr,
492#endif 533#endif