Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 305841
b: refs/heads/master
c: c73893e
h: refs/heads/master
i:
  305839: 6833659
v: v3
  • Loading branch information
Rafael J. Wysocki committed May 11, 2012
1 parent 421da3b commit f6c9024
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6237dd132d4eb408ffa80830fe395448e5657ab0
refs/heads/master: c73893e2ca731b4a81ae59246ab57979aa188777
6 changes: 6 additions & 0 deletions trunk/kernel/power/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 26 additions & 5 deletions trunk/kernel/power/wakelock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -58,6 +56,29 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active)
return (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)
{
Expand Down Expand Up @@ -85,7 +106,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
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. */
Expand All @@ -103,7 +124,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f6c9024

Please sign in to comment.