PM / wakeup: Use wakeup_source_register() in wakelock.c
kernel/power/wakelock.c duplicates wakeup source creation and registration code from drivers/base/power/wakeup.c. Change struct wakelock's wakeup source to a pointer and use wakeup_source_register() function to create and register said wakeup source. Use wakeup_source_unregister() on cleanup path. Signed-off-by: Tri Vo <trong@android.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
0d105d0f25
commit
2434aea58e
|
@ -27,7 +27,7 @@ static DEFINE_MUTEX(wakelocks_lock);
|
||||||
struct wakelock {
|
struct wakelock {
|
||||||
char *name;
|
char *name;
|
||||||
struct rb_node node;
|
struct rb_node node;
|
||||||
struct wakeup_source ws;
|
struct wakeup_source *ws;
|
||||||
#ifdef CONFIG_PM_WAKELOCKS_GC
|
#ifdef CONFIG_PM_WAKELOCKS_GC
|
||||||
struct list_head lru;
|
struct list_head lru;
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,7 +46,7 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active)
|
||||||
|
|
||||||
for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) {
|
for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) {
|
||||||
wl = rb_entry(node, struct wakelock, node);
|
wl = rb_entry(node, struct wakelock, node);
|
||||||
if (wl->ws.active == show_active)
|
if (wl->ws->active == show_active)
|
||||||
str += scnprintf(str, end - str, "%s ", wl->name);
|
str += scnprintf(str, end - str, "%s ", wl->name);
|
||||||
}
|
}
|
||||||
if (str > buf)
|
if (str > buf)
|
||||||
|
@ -112,16 +112,16 @@ static void __wakelocks_gc(struct work_struct *work)
|
||||||
u64 idle_time_ns;
|
u64 idle_time_ns;
|
||||||
bool active;
|
bool active;
|
||||||
|
|
||||||
spin_lock_irq(&wl->ws.lock);
|
spin_lock_irq(&wl->ws->lock);
|
||||||
idle_time_ns = ktime_to_ns(ktime_sub(now, wl->ws.last_time));
|
idle_time_ns = ktime_to_ns(ktime_sub(now, wl->ws->last_time));
|
||||||
active = wl->ws.active;
|
active = wl->ws->active;
|
||||||
spin_unlock_irq(&wl->ws.lock);
|
spin_unlock_irq(&wl->ws->lock);
|
||||||
|
|
||||||
if (idle_time_ns < ((u64)WL_GC_TIME_SEC * NSEC_PER_SEC))
|
if (idle_time_ns < ((u64)WL_GC_TIME_SEC * NSEC_PER_SEC))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!active) {
|
if (!active) {
|
||||||
wakeup_source_remove(&wl->ws);
|
wakeup_source_unregister(wl->ws);
|
||||||
rb_erase(&wl->node, &wakelocks_tree);
|
rb_erase(&wl->node, &wakelocks_tree);
|
||||||
list_del(&wl->lru);
|
list_del(&wl->lru);
|
||||||
kfree(wl->name);
|
kfree(wl->name);
|
||||||
|
@ -187,9 +187,15 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
|
||||||
kfree(wl);
|
kfree(wl);
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
}
|
||||||
wl->ws.name = wl->name;
|
|
||||||
wl->ws.last_time = ktime_get();
|
wl->ws = wakeup_source_register(wl->name);
|
||||||
wakeup_source_add(&wl->ws);
|
if (!wl->ws) {
|
||||||
|
kfree(wl->name);
|
||||||
|
kfree(wl);
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
}
|
||||||
|
wl->ws->last_time = ktime_get();
|
||||||
|
|
||||||
rb_link_node(&wl->node, parent, node);
|
rb_link_node(&wl->node, parent, node);
|
||||||
rb_insert_color(&wl->node, &wakelocks_tree);
|
rb_insert_color(&wl->node, &wakelocks_tree);
|
||||||
wakelocks_lru_add(wl);
|
wakelocks_lru_add(wl);
|
||||||
|
@ -233,9 +239,9 @@ int pm_wake_lock(const char *buf)
|
||||||
u64 timeout_ms = timeout_ns + NSEC_PER_MSEC - 1;
|
u64 timeout_ms = timeout_ns + NSEC_PER_MSEC - 1;
|
||||||
|
|
||||||
do_div(timeout_ms, NSEC_PER_MSEC);
|
do_div(timeout_ms, NSEC_PER_MSEC);
|
||||||
__pm_wakeup_event(&wl->ws, timeout_ms);
|
__pm_wakeup_event(wl->ws, timeout_ms);
|
||||||
} else {
|
} else {
|
||||||
__pm_stay_awake(&wl->ws);
|
__pm_stay_awake(wl->ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
wakelocks_lru_most_recent(wl);
|
wakelocks_lru_most_recent(wl);
|
||||||
|
@ -271,7 +277,7 @@ int pm_wake_unlock(const char *buf)
|
||||||
ret = PTR_ERR(wl);
|
ret = PTR_ERR(wl);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
__pm_relax(&wl->ws);
|
__pm_relax(wl->ws);
|
||||||
|
|
||||||
wakelocks_lru_most_recent(wl);
|
wakelocks_lru_most_recent(wl);
|
||||||
wakelocks_gc();
|
wakelocks_gc();
|
||||||
|
|
Loading…
Reference in New Issue