12 #include <linux/capability.h>
13 #include <linux/ctype.h>
14 #include <linux/device.h>
16 #include <linux/hrtimer.h>
17 #include <linux/list.h>
18 #include <linux/rbtree.h>
19 #include <linux/slab.h>
27 #ifdef CONFIG_PM_WAKELOCKS_GC
45 if (wl->
ws.active == show_active)
57 #if CONFIG_PM_WAKELOCKS_LIMIT > 0
58 static unsigned int number_of_wakelocks;
60 static inline bool wakelocks_limit_exceeded(
void)
62 return number_of_wakelocks > CONFIG_PM_WAKELOCKS_LIMIT;
65 static inline void increment_wakelocks_number(
void)
67 number_of_wakelocks++;
70 static inline void decrement_wakelocks_number(
void)
72 number_of_wakelocks--;
75 static inline bool wakelocks_limit_exceeded(
void) {
return false; }
76 static inline void increment_wakelocks_number(
void) {}
77 static inline void decrement_wakelocks_number(
void) {}
80 #ifdef CONFIG_PM_WAKELOCKS_GC
81 #define WL_GC_COUNT_MAX 100
82 #define WL_GC_TIME_SEC 300
85 static unsigned int wakelocks_gc_count;
87 static inline void wakelocks_lru_add(
struct wakelock *wl)
89 list_add(&wl->lru, &wakelocks_lru_list);
92 static inline void wakelocks_lru_most_recent(
struct wakelock *wl)
94 list_move(&wl->lru, &wakelocks_lru_list);
97 static void wakelocks_gc(
void)
102 if (++wakelocks_gc_count <= WL_GC_COUNT_MAX)
110 spin_lock_irq(&wl->
ws.lock);
111 idle_time_ns = ktime_to_ns(ktime_sub(now, wl->
ws.last_time));
112 active = wl->
ws.active;
113 spin_unlock_irq(&wl->
ws.lock);
124 decrement_wakelocks_number();
127 wakelocks_gc_count = 0;
130 static inline void wakelocks_lru_add(
struct wakelock *wl) {}
131 static inline void wakelocks_lru_most_recent(
struct wakelock *wl) {}
132 static inline void wakelocks_gc(
void) {}
135 static struct wakelock *wakelock_lookup_add(
const char *
name,
size_t len,
136 bool add_if_not_found)
159 if (!add_if_not_found)
162 if (wakelocks_limit_exceeded())
177 rb_link_node(&wl->
node, parent, node);
179 wakelocks_lru_add(wl);
180 increment_wakelocks_number();
202 if (*str && *str !=
'\n') {
204 ret = kstrtou64(
skip_spaces(str), 10, &timeout_ns);
211 wl = wakelock_lookup_add(buf, len,
true);
219 do_div(timeout_ms, NSEC_PER_MSEC);
225 wakelocks_lru_most_recent(wl);
245 if (buf[len-1] ==
'\n')
253 wl = wakelock_lookup_add(buf, len,
false);
260 wakelocks_lru_most_recent(wl);