PM: Implement autosleep and "wake locks"
Subsystems (8)
Re: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
In reply to Rafael J. WysockiQuoted 23 lines · Rafael J. Wysocki
From: Rafael J. Wysocki<[email protected]>
Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITwakeup sources created with the help ofwake_lockpresent at a time.
Quoted 5 lines
The data type used to track wakeup sources created by user space is called "struct wakelock" to indicate the origins of this feature.
Signed-off-by Rafael J. Wysocki<[email protected]>---
One small bug. In wakelock_lookup_add, you're assigning parent after you assign node, so at loop exit the parent might be null. This resulted in some strange cases where I'd add two wakelocks and everything would be fine, but then adding the third would cause the first two to get lost.
The following patch seems to fix it.
thanks
-john
kernel/power/wakelock.c +1 -2
@@ -70,6 +70,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,while (*node) {int diff; + parent = *node; wl = rb_entry(*node, struct wakelock, node); diff =strncmp (name, wl->name, len);if (diff ==0 ) {
@@ -82,8 +83,6 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len, node =&(*node)->rb_left; else node =&(*node)->rb_right; - - parent = *node; }if (!add_if_not_found)return ERR_PTR (-EINVAL );
Rafael J. Wysocki
Acked-by Greg Kroah-HartmanRe: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
Quoted 29 lines · John Stultz
Quoted 23 lines · Rafael J. Wysocki
From: Rafael J. Wysocki<[email protected]>
Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITwakeup sources created with the help ofwake_lockpresent at a time.Quoted 5 lines
The data type used to track wakeup sources created by user space is called "struct wakelock" to indicate the origins of this feature.
Signed-off-by Rafael J. Wysocki<[email protected]>---
Quoted 7 lines
One small bug. In
wakelock_lookup_add, you're assigning parent after you assign node, so at loop exit the parent might be null. This resulted in some strange cases where I'd add two wakelocks and everything would be fine, but then adding the third would cause the first two to get lost.The following patch seems to fix it.
Thanks a lot for the fix!
I have folded it into the $subject patch and the new version is appended.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v2
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.
--- Documentation/ABI/testing/sysfs-power | 42 ++++++ drivers/base/power/wakeup.c | 1 kernel/power/Kconfig | 8 + kernel/power/Makefile | 1 kernel/power/main.c | 41 ++++++ kernel/power/power.h | 9 + kernel/power/wakelock.c | 217 ++++++++++++++++++++++++++++++++++ 7 files changed, 319 insertions(+)
kernel/power/main.c +41 -0
@@ -431,6 +431,43 @@ static ssize_t autosleep_store(struct kopower_attr (autosleep);#endif /* CONFIG_PM_AUTOSLEEP */ + +#ifdef CONFIG_PM_WAKELOCKS +static ssize_t wake_lock_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf) +{ +return pm_show_wakelocks (buf, true); +} + +static ssize_t wake_lock_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +int error =pm_wake_lock (buf); +return error ? error : n; +} + +power_attr (wake_lock); + +static ssize_t wake_unlock_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf) +{ +return pm_show_wakelocks (buf, false); +} + +static ssize_t wake_unlock_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +int error =pm_wake_unlock (buf); +return error ? error : n; +} + +power_attr (wake_unlock); + +#endif /* CONFIG_PM_WAKELOCKS */ #endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_PM_TRACE
@@ -487,6 +524,10 @@ static struct attribute * g[] = {#ifdef CONFIG_PM_AUTOSLEEP &autosleep_attr.attr,#endif +#ifdef CONFIG_PM_WAKELOCKS + &wake_lock_attr.attr, + &wake_unlock_attr.attr, +#endif #ifdef CONFIG_PM_DEBUG &pm_test_attr.attr, #endif
kernel/power/power.h +9 -0
@@ -282,3 +282,12 @@ static inline void pm_autosleep_unlock(vstatic inline suspend_state_t pm_autosleep_state (void ) {return PM_SUSPEND_ON ; }#endif /* !CONFIG_PM_AUTOSLEEP */ + +#ifdef CONFIG_PM_WAKELOCKS + +/* kernel/power/wakelock.c */ +extern ssize_t pm_show_wakelocks (char *buf,bool show_active); +extern int pm_wake_lock (const char *buf); +extern int pm_wake_unlock (const char *buf); + +#endif /* !CONFIG_PM_WAKELOCKS */
kernel/power/Kconfig +8 -0
@@ -111,6 +111,14 @@ config PM_AUTOSLEEP Allow the kernel to trigger a system transition into a global sleep state automatically whenever there are no active wakeup sources. +config PM_WAKELOCKS + bool "User space wakeup sources interface" + depends on PM_SLEEP + default n + ---help--- + Allow user space to create, activate and deactivate wakeup source + objects with the help of a sysfs-based interface. + config PM_RUNTIME bool "Run-time PM core functionality" depends on !IA64_HP_SIM
kernel/power/wakelock.c new file +217 -0
217 lines not on this page · raw message
kernel/power/Makefile +1 -0
@@ -10,5 +10,6 @@ obj-$(CONFIG_PM_TEST_SUSPEND) += suspend obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o \ block_io.o obj-$(CONFIG_PM_AUTOSLEEP) += autosleep.o +obj-$(CONFIG_PM_WAKELOCKS) += wakelock.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
drivers/base/power/wakeup.c +1 -0
@@ -133,6 +133,7 @@ void wakeup_source_add(struct wakeup_souspin_lock_init (&ws->lock);setup_timer (&ws->timer, pm_wakeup_timer_fn, (unsigned long )ws); ws->active = false; + ws->last_time =ktime_get ();spin_lock_irq (&events_lock);list_add_rcu (&ws->entry, &wakeup_sources);
Documentation/ABI/testing/sysfs-power +42 -0
45 lines not on this page · raw message
Re: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
Quoted 24 lines · On Tue, 24 Apr 2012 23:27:17 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v2Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITwakeup sources created with the help ofwake_lockpresent at a time.
Quoted 4 lines
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.
Looks good. Just a couple of minor suggestions.
Quoted 6 lines
kernel/power/wakelock.c new file +6
-0+ssize_t pm_show_wakelocks (char *buf,bool show_active) +{ +struct rb_node *node; +struct wakelock *wl; +char *str = buf; +char *end = buf +PAGE_SIZE ;
kernel/power/wakelock.c line 53
Quoted 10 lines
kernel/power/wakelock.c new file +10
-0+ +mutex_lock (&wakelocks_lock); + +for (node =rb_first (&wakelocks_tree); node; node =rb_next (node)) { +bool active; + + wl = rb_entry(node, struct wakelock, node); +spin_lock_irq (&wl->ws.lock); + active = wl->ws.active; +spin_unlock_irq (&wl->ws.lock);
I don't think the spin_lock is needed. We are just reading one value and it is either 0 or not. So there is no possibility for any inconsistency.
if (wl->ws.active == show_active)
?
kernel/power/wakelock.c line 55
Quoted 2 lines
kernel/power/wakelock.c new file +2
-0+if (active == show_active) + str +=scnprintf (str, end - str,"%s " , wl->name);
Arg. Extra space on the end of the line!! :-)
I would suggest the entries be terminated by '\n' rather than separate by space.
one-item-per-line is much more common in Unix in general. 'grep' allows you to find things more easily etc.
while read a
do echo $a > wake_unlock
done < wake_lock
kernel/power/wakelock.c line 62
Quoted 7 lines
kernel/power/wakelock.c new file +7
-0+ } + str +=scnprintf (str, end - str,"\n" ); + +mutex_unlock (&wakelocks_lock); +return (str - buf); +} +
Thanks,
NeilBrown
Rafael J. Wysocki
Acked-by Greg Kroah-HartmanRe: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
Quoted 53 lines · NeilBrown
Quoted 24 lines · On Tue, 24 Apr 2012 23:27:17 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v2Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITwakeup sources created with the help ofwake_lockpresent at a time.Quoted 4 lines
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.
Looks good. Just a couple of minor suggestions.
Quoted 6 lines
(quoted diff) +6
-0+ssize_t pm_show_wakelocks(char *buf, bool show_active) +{ + struct rb_node *node; + struct wakelock *wl; + char *str = buf; + char *end = buf + PAGE_SIZE;Review
Quoted 10 lines
(quoted diff) +10
-0+ + mutex_lock(&wakelocks_lock); + + for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) { + bool active; + + wl = rb_entry(node, struct wakelock, node); + spin_lock_irq(&wl->ws.lock); + active = wl->ws.active; + spin_unlock_irq(&wl->ws.lock);I don't think the
spin_lockis needed. We are just reading one value and it is either 0 or not. So there is no possibility for any inconsistency.
Quoted 2 lines
if (wl->ws.active == show_active)?
Good point.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (active == show_active) + str += scnprintf(str, end - str, "%s ", wl->name);Arg. Extra space on the end of the line!! :-)
Well, it's not too difficult to get rid of it (as in the patch below).
Quoted 7 lines
I would suggest the entries be terminated by '\n' rather than separate by space.
one-item-per-line is much more common in Unix in general. 'grep' allows you to find things more easily etc.
while read a
do echo $a >wake_unlock
done <wake_lock
I know, but this follows the general convention of the files under /sys/power/.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: 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.
--- Documentation/ABI/testing/sysfs-power | 42 ++++++ drivers/base/power/wakeup.c | 1 kernel/power/Kconfig | 8 + kernel/power/Makefile | 1 kernel/power/main.c | 41 ++++++ kernel/power/power.h | 9 + kernel/power/wakelock.c | 215 ++++++++++++++++++++++++++++++++++ 7 files changed, 317 insertions(+)
kernel/power/main.c +41 -0
@@ -431,6 +431,43 @@ static ssize_t autosleep_store(struct kopower_attr (autosleep);#endif /* CONFIG_PM_AUTOSLEEP */ + +#ifdef CONFIG_PM_WAKELOCKS +static ssize_t wake_lock_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf) +{ +return pm_show_wakelocks (buf, true); +} + +static ssize_t wake_lock_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +int error =pm_wake_lock (buf); +return error ? error : n; +} + +power_attr (wake_lock); + +static ssize_t wake_unlock_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf) +{ +return pm_show_wakelocks (buf, false); +} + +static ssize_t wake_unlock_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +int error =pm_wake_unlock (buf); +return error ? error : n; +} + +power_attr (wake_unlock); + +#endif /* CONFIG_PM_WAKELOCKS */ #endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_PM_TRACE
@@ -487,6 +524,10 @@ static struct attribute * g[] = {#ifdef CONFIG_PM_AUTOSLEEP &autosleep_attr.attr,#endif +#ifdef CONFIG_PM_WAKELOCKS + &wake_lock_attr.attr, + &wake_unlock_attr.attr, +#endif #ifdef CONFIG_PM_DEBUG &pm_test_attr.attr, #endif
kernel/power/power.h +9 -0
@@ -282,3 +282,12 @@ static inline void pm_autosleep_unlock(vstatic inline suspend_state_t pm_autosleep_state (void ) {return PM_SUSPEND_ON ; }#endif /* !CONFIG_PM_AUTOSLEEP */ + +#ifdef CONFIG_PM_WAKELOCKS + +/* kernel/power/wakelock.c */ +extern ssize_t pm_show_wakelocks (char *buf,bool show_active); +extern int pm_wake_lock (const char *buf); +extern int pm_wake_unlock (const char *buf); + +#endif /* !CONFIG_PM_WAKELOCKS */
kernel/power/Kconfig +8 -0
@@ -111,6 +111,14 @@ config PM_AUTOSLEEP Allow the kernel to trigger a system transition into a global sleep state automatically whenever there are no active wakeup sources. +config PM_WAKELOCKS + bool "User space wakeup sources interface" + depends on PM_SLEEP + default n + ---help--- + Allow user space to create, activate and deactivate wakeup source + objects with the help of a sysfs-based interface. + config PM_RUNTIME bool "Run-time PM core functionality" depends on !IA64_HP_SIM
kernel/power/wakelock.c new file +215 -0
215 lines not on this page · raw message
kernel/power/Makefile +1 -0
@@ -10,5 +10,6 @@ obj-$(CONFIG_PM_TEST_SUSPEND) += suspend obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o \ block_io.o obj-$(CONFIG_PM_AUTOSLEEP) += autosleep.o +obj-$(CONFIG_PM_WAKELOCKS) += wakelock.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
drivers/base/power/wakeup.c +1 -0
@@ -133,6 +133,7 @@ void wakeup_source_add(struct wakeup_souspin_lock_init (&ws->lock);setup_timer (&ws->timer, pm_wakeup_timer_fn, (unsigned long )ws); ws->active = false; + ws->last_time =ktime_get ();spin_lock_irq (&events_lock);list_add_rcu (&ws->entry, &wakeup_sources);
Documentation/ABI/testing/sysfs-power +42 -0
45 lines not on this page · raw message
NeilBrown
Reviewed-byRe: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
Quoted 3 lines · On Fri, 27 Apr 2012 00:04:27 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Thanks.
NeilBrown
Re: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
Quoted 7 lines · NeilBrown
Quoted 3 lines · On Fri, 27 Apr 2012 00:04:27 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Reviewed-by NeilBrown <[email protected]>
Thanks!
Re: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
In reply to Rafael J. Wysocki2012/4/26 Rafael J. Wysocki <[email protected]>:
...
Quoted 12 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.
Quoted 11 lines
Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMIT
I think it would be better if the garbage collection and limit was configurable and optional. I would probably turn both features off since I do not want to chase down bugs because a wakelock was ignored, and I think the garbage collection will erase stats that we care about.
Signature · 1 line
Arve Hjønnevåg
Re: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
Quoted 26 lines · Arve Hjønnevåg
2012/4/26 Rafael J. Wysocki <[email protected]>:
...Quoted 12 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Quoted 11 lines
Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMIT
Quoted 5 lines
I think it would be better if the garbage collection and limit was configurable and optional. I would probably turn both features off since I do not want to chase down bugs because a wakelock was ignored, and I think the garbage collection will erase stats that we care about.
OK, but would you mind if I added the configurability as a separate incremental patch?
Rafael
Re: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
2012/4/27 Rafael J. Wysocki <[email protected]>:
Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines
2012/4/26 Rafael J. Wysocki <[email protected]>:
...Quoted 23 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMIT
Quoted 9 lines
Quoted 5 lines
I think it would be better if the garbage collection and limit was configurable and optional. I would probably turn both features off since I do not want to chase down bugs because a wakelock was ignored, and I think the garbage collection will erase stats that we care about.
OK, but would you mind if I added the configurability as a separate incremental patch?
That is fine with me.
Signature · 1 line
Arve Hjønnevåg
Re: [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources
Quoted 34 lines · Arve Hjønnevåg
2012/4/27 Rafael J. Wysocki <[email protected]>:
Quoted 33 lines · Arve Hjønnevåg
Quoted 31 lines
2012/4/26 Rafael J. Wysocki <[email protected]>:
...Quoted 12 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Quoted 11 lines
Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITI think it would be better if the garbage collection and limit was configurable and optional. I would probably turn both features off since I do not want to chase down bugs because a wakelock was ignored, and I think the garbage collection will erase stats that we care about.
Quoted 5 lines
Quoted 3 lines
OK, but would you mind if I added the configurability as a separate incremental patch?
That is fine with me.
Cool, thanks!
cover : Kconfig options for wakelocks limit and gc (was: Re: [RFC][PATCH 8/8] PM / Sleep: Add user space ...)
Quoted 35 lines · Rafael J. Wysocki
Quoted 34 lines · Arve Hjønnevåg
2012/4/27 Rafael J. Wysocki <[email protected]>:
Quoted 33 lines · Arve Hjønnevåg
Quoted 31 lines
2012/4/26 Rafael J. Wysocki <[email protected]>:
...Quoted 12 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Quoted 11 lines
Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITI think it would be better if the garbage collection and limit was configurable and optional. I would probably turn both features off since I do not want to chase down bugs because a wakelock was ignored, and I think the garbage collection will erase stats that we care about.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
OK, but would you mind if I added the configurability as a separate incremental patch?
That is fine with me.
Cool, thanks!
The following two patches add the configuration options for the limit and garbage collector. Please let me know if they are OK with you.
Thanks,
Rafael
PATCH 1/2 PM / Sleep: Make the limit of user space wakeup sources configurable
From: Rafael J. Wysocki <[email protected]>
Make it possible to configure out the check against the limit of user space wakeup sources for debugging and default Android builds.
--- kernel/power/Kconfig | 6 ++++++ kernel/power/wakelock.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-)
kernel/power/Kconfig +6 -0
@@ -119,6 +119,12 @@ config PM_WAKELOCKS Allow user space to create, activate and deactivate wakeup source objects with the help of a sysfs-based interface. +config PM_WAKELOCKS_LIMIT + int "Maximum number of user space wakeup sources (0 = no limit)" + range 0 100000 + default 100 + depends on PM_WAKELOCKS + config PM_RUNTIME bool "Run-time PM core functionality" depends on !IA64_HP_SIM
kernel/power/wakelock.c +26 -5
@@ -17,7 +17,6 @@#include <linux/rbtree.h> #include <linux/slab.h> -#define WL_NUMBER_LIMIT 100#define WL_GC_COUNT_MAX 100#define WL_GC_TIME_SEC 300
@@ -32,7 +31,6 @@ struct wakelock {static struct rb_root wakelocks_tree =RB_ROOT ;static LIST_HEAD (wakelocks_lru_list); -static unsigned int number_of_wakelocks;static unsigned int wakelocks_gc_count;ssize_t pm_show_wakelocks (char *buf,bool show_active)
@@ -58,6 +56,29 @@ ssize_t pm_show_wakelocks(char *buf, booreturn (str - buf); } +#if CONFIG_PM_WAKELOCKS_LIMIT >0 +static unsigned int number_of_wakelocks; + +static inline bool wakelocks_limit_exceeded (void ) +{ +return number_of_wakelocks >CONFIG_PM_WAKELOCKS_LIMIT ; +} + +static inline void increment_wakelocks_number (void ) +{ + number_of_wakelocks++; +} + +static inline void decrement_wakelocks_number (void ) +{ + number_of_wakelocks--; +} +#else /* CONFIG_PM_WAKELOCKS_LIMIT = 0 */ +static inline bool wakelocks_limit_exceeded (void ) {return false; } +static inline void increment_wakelocks_number (void ) {} +static inline void decrement_wakelocks_number (void ) {} +#endif /* CONFIG_PM_WAKELOCKS_LIMIT */ +static struct wakelock *wakelock_lookup_add (const char *name,size_t len,bool add_if_not_found) {
@@ -85,7 +106,7 @@ static struct wakelock *wakelock_lookup_if (!add_if_not_found)return ERR_PTR (-EINVAL ); -if (number_of_wakelocks >WL_NUMBER_LIMIT ) +if (wakelocks_limit_exceeded ())return ERR_PTR (-ENOSPC );/* Not found, we have to add a new one. */
@@ -103,7 +124,7 @@ static struct wakelock *wakelock_lookup_rb_link_node (&wl->node, parent, node);rb_insert_color (&wl->node, &wakelocks_tree);list_add (&wl->lru, &wakelocks_lru_list); - number_of_wakelocks++; +increment_wakelocks_number ();return wl; }
@@ -175,7 +196,7 @@ static void wakelocks_gc(void)list_del (&wl->lru);kfree (wl->name);kfree (wl); - number_of_wakelocks--; +decrement_wakelocks_number (); } } wakelocks_gc_count =0 ;
PATCH 2/2 PM / Sleep: User space wakeup sources garbage collector Kconfig option
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Make it possible to configure out the user space wakeup sources garbage collector for debugging and default Android builds.
--- kernel/power/Kconfig | 5 ++ kernel/power/wakelock.c | 101 +++++++++++++++++++++++++++++------------------- 2 files changed, 67 insertions(+), 39 deletions(-)
kernel/power/Kconfig +5 -0
@@ -125,6 +125,11 @@ config PM_WAKELOCKS_LIMIT default 100 depends on PM_WAKELOCKS +config PM_WAKELOCKS_GC + bool "Garbage collector for user space wakeup sources" + depends on PM_WAKELOCKS + default y + config PM_RUNTIME bool "Run-time PM core functionality" depends on !IA64_HP_SIM
kernel/power/wakelock.c +62 -39
147 lines not on this page · raw message
Re: [PATCH 0/2]: Kconfig options for wakelocks limit and gc (was: Re: [RFC][PATCH 8/8] PM / Sleep: Add user space ...)
In reply to Rafael J. WysockiQuoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Rafael J. Wysocki
Quoted 38 lines · Arve Hjønnevåg
2012/4/27 Rafael J. Wysocki <[email protected]>:
Quoted 36 lines · Arve Hjønnevåg
Quoted 26 lines
2012/4/26 Rafael J. Wysocki <[email protected]>:
...Quoted 12 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Quoted 11 lines
Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITQuoted 5 lines
I think it would be better if the garbage collection and limit was configurable and optional. I would probably turn both features off since I do not want to chase down bugs because a wakelock was ignored, and I think the garbage collection will erase stats that we care about.
OK, but would you mind if I added the configurability as a separate incremental patch?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
That is fine with me.
Cool, thanks!
The following two patches add the configuration options for the limit and garbage collector. Please let me know if they are OK with you.
Yes.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 0/2]: Kconfig options for wakelocks limit and gc (was: Re: [RFC][PATCH 8/8] PM / Sleep: Add user space ...)
Quoted 43 lines · Arve Hjønnevåg
Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · Rafael J. Wysocki
Quoted 39 lines · Arve Hjønnevåg
2012/4/27 Rafael J. Wysocki <[email protected]>:
Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines
2012/4/26 Rafael J. Wysocki <[email protected]>:
...Quoted 23 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Add user space interface for manipulating wakeup sources, v3Android allows user space to manipulate wakelocks using two sysfs file located in
/sys/power/,wake_lockandwake_unlock. Writing a wakelock name and optionally a timeout to thewake_lockfile 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 towake_unlockcauses that wakelock to be released.Implement an analogous interface for user space using wakeup sources. Add the
/sys/power/wake_lockand/sys/power/wake_unlockfiles allowing user space to create, activate and deactivate wakeup sources, such that writing a name and optionally a timeout towake_lockcauses 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 towake_unlockcauses the wakeup source of that name, if there is one, to be deactivated. Wakeup sources created with the help ofwake_lockthat haven't been used for more than 5 minutes are garbage collected and destroyed. Moreover, there can be onlyWL_NUMBER_LIMITQuoted 9 lines
Quoted 5 lines
I think it would be better if the garbage collection and limit was configurable and optional. I would probably turn both features off since I do not want to chase down bugs because a wakelock was ignored, and I think the garbage collection will erase stats that we care about.
OK, but would you mind if I added the configurability as a separate incremental patch?
That is fine with me.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Cool, thanks!
The following two patches add the configuration options for the limit and garbage collector. Please let me know if they are OK with you.
Yes.
Good, thanks!
Re: [RFC][PATCH 0/8] PM: Implement autosleep and "wake locks", take 3
In reply to Rafael J. WysockiQuoted 7 lines · Rafael J. Wysocki
Hi all,
Following is the third update of the autosleep patchset.
Patches [1-4/8] are regarded as v3.5 material, the rest - depending on the feedback I get (lack of feedback will be understood as no objections, though).
This all looks great to me, thanks for continuing to push this:
Re: [RFC][PATCH 0/8] PM: Implement autosleep and "wake locks", take 3
Quoted 11 lines · Greg KH
Quoted 7 lines · Rafael J. Wysocki
Hi all,
Following is the third update of the autosleep patchset.
Patches [1-4/8] are regarded as v3.5 material, the rest - depending on the feedback I get (lack of feedback will be understood as no objections, though).
This all looks great to me, thanks for continuing to push this:
Thanks a lot!
Rafael