Skip to content

Commit 613f5d1

Browse files
colincrossrafaeljw
authored andcommitted
freezer: skip waking up tasks with PF_FREEZER_SKIP set
Android goes through suspend/resume very often (every few seconds when on a busy wifi network with the screen off), and a significant portion of the energy used to go in and out of suspend is spent in the freezer. If a task has called freezer_do_not_count(), don't bother waking it up. If it happens to wake up later it will call freezer_count() and immediately enter the refrigerator. Combined with patches to convert freezable helpers to use freezer_do_not_count() and convert common sites where idle userspace tasks are blocked to use the freezable helpers, this reduces the time and energy required to suspend and resume. Acked-by: Tejun Heo <tj@kernel.org> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Colin Cross <ccross@android.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 18ad0c6 commit 613f5d1

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎kernel/freezer.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ bool freeze_task(struct task_struct *p)
110110
{
111111
unsigned long flags;
112112

113+
/*
114+
* This check can race with freezer_do_not_count, but worst case that
115+
* will result in an extra wakeup being sent to the task. It does not
116+
* race with freezer_count(), the barriers in freezer_count() and
117+
* freezer_should_skip() ensure that either freezer_count() sees
118+
* freezing == true in try_to_freeze() and freezes, or
119+
* freezer_should_skip() sees !PF_FREEZE_SKIP and freezes the task
120+
* normally.
121+
*/
122+
if (freezer_should_skip(p))
123+
return false;
124+
113125
spin_lock_irqsave(&freezer_lock, flags);
114126
if (!freezing(p) || frozen(p)) {
115127
spin_unlock_irqrestore(&freezer_lock, flags);

0 commit comments

Comments
 (0)