Skip to content

Commit 2ef7c01

Browse files
Doug Bergerrafaeljw
authored andcommitted
PM / wakeup: Only update last time for active wakeup sources
When wakelock support was added, the wakeup_source_add() function was updated to set the last_time value of the wakeup source. This has the unintended side effect of producing confusing output from pm_print_active_wakeup_sources() when a wakeup source is added prior to a sleep that is blocked by a different wakeup source. The function pm_print_active_wakeup_sources() will search for the most recently active wakeup source when no active source is found. If a wakeup source is added after a different wakeup source blocks the system from going to sleep it may have a later last_time value than the blocking source and be output as the last active wakeup source even if it has never actually been active. It looks to me like the change to wakeup_source_add() was made to prevent the wakelock garbage collection from accidentally dropping a wakelock during the narrow window between adding the wakelock to the wakelock list in wakelock_lookup_add() and the activation of the wakeup source in pm_wake_lock(). This commit changes the behavior so that only the last_time of the wakeup source used by a wakelock is initialized prior to adding it to the wakeup source list. This preserves the meaning of the last_time value as the last time the wakeup source was active and allows a wakeup source that has never been active to have a last_time value of 0. Fixes: b86ff98 (PM / Sleep: Add user space interface for manipulating wakeup sources, v3) Signed-off-by: Doug Berger <opendmb@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 00ee22c commit 2ef7c01

2 files changed

Lines changed: 1 addition & 1 deletion

File tree

‎drivers/base/power/wakeup.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ void wakeup_source_add(struct wakeup_source *ws)
183183
spin_lock_init(&ws->lock);
184184
timer_setup(&ws->timer, pm_wakeup_timer_fn, 0);
185185
ws->active = false;
186-
ws->last_time = ktime_get();
187186

188187
spin_lock_irqsave(&events_lock, flags);
189188
list_add_rcu(&ws->entry, &wakeup_sources);

‎kernel/power/wakelock.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
188188
return ERR_PTR(-ENOMEM);
189189
}
190190
wl->ws.name = wl->name;
191+
wl->ws.last_time = ktime_get();
191192
wakeup_source_add(&wl->ws);
192193
rb_link_node(&wl->node, parent, node);
193194
rb_insert_color(&wl->node, &wakelocks_tree);

0 commit comments

Comments
 (0)