freezer: Check frozen() before freezing() in freeze_task()
PATCH 1/1 freezer: Check frozen() before freezing() in freeze_task()
During the freeze stage of suspend, there are multiple passes over the same list of tasks. Each pass tries to freeze non-frozen tasks, meaning that the number of frozen tasks increase monotonically, and that each subsequent pass will mostly be iterating over frozen tasks. Therefore, it is faster to *first* check that a task is frozen before other checks, especially since the frozen check is computationally trivial.
Check frozen(p) before !freezing(p) to short circuit the more expensive freezing_slow_path() calls, while retaining identical return semantics.
On a v7.3 Pixel 9 device, this consistently reduces freeze_processes latency by ~10% (~4.5 ms).
--- kernel/freezer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/freezer.c +1 -1
@@ -166,7 +166,7 @@ bool freeze_task(struct task_struct *p)unsigned long flags;spin_lock_irqsave (&freezer_lock, flags); -if (!freezing (p) ||frozen (p) ||__freeze_task (p)) { +if (frozen (p) || !freezing (p) ||__freeze_task (p)) {spin_unlock_irqrestore (&freezer_lock, flags);return false; }
Signature · 1 line
2.56.0.679.gc527c65306-goog
Quoted 7 lines · Samuel Wu
During the freeze stage of suspend, there are multiple passes over the same list of tasks. Each pass tries to freeze non-frozen tasks, meaning that the number of frozen tasks increase monotonically, and that each subsequent pass will mostly be iterating over frozen tasks. Therefore, it is faster to *first* check that a task is frozen before other checks, especially since the frozen check is computationally trivial.
Quoted 5 lines
Check frozen(p) before !freezing(p) to short circuit the more expensive
freezing_slow_path()calls, while retaining identical return semantics.On a v7.3 Pixel 9 device, this consistently reduces
freeze_processeslatency by ~10% (~4.5 ms).
7.3 PIXEL 9??? WHAT HOW? THE BASE ON STOCK IS 6.12!!!! WOW! (Please do for pixel 7, I want flair :c)
Quoted 11 lines
Signed-off-by Samuel Wu <[email protected]>---
kernel/freezer.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)kernel/freezer.c +0
-0
kernel/freezer.c bool freeze_task(struct task_struct *p) · line 172
Quoted 8 lines
kernel/freezer.c +1
-1@@ -166,7 +166,7 @@ bool freeze_task(struct task_struct *p)unsigned long flags;spin_lock_irqsave (&freezer_lock, flags); -if (!freezing (p) ||frozen (p) ||__freeze_task (p)) { +if (frozen (p) || !freezing (p) ||__freeze_task (p)) {spin_unlock_irqrestore (&freezer_lock, flags);return false; }
Good good.
Quoted 1 line
--- Thanks!
Quoted 40 lines · Bradley Morgan
Quoted 7 lines · Samuel Wu
During the freeze stage of suspend, there are multiple passes over the same list of tasks. Each pass tries to freeze non-frozen tasks, meaning that the number of frozen tasks increase monotonically, and that each subsequent pass will mostly be iterating over frozen tasks. Therefore, it is faster to *first* check that a task is frozen before other checks, especially since the frozen check is computationally trivial.
Quoted 5 lines
Check frozen(p) before !freezing(p) to short circuit the more expensive
freezing_slow_path()calls, while retaining identical return semantics.On a v7.3 Pixel 9 device, this consistently reduces
freeze_processeslatency by ~10% (~4.5 ms).7.3 PIXEL 9??? WHAT HOW? THE BASE ON STOCK IS 6.12!!!! WOW! (Please do for pixel 7, I want flair :c)
Quoted 11 lines
Signed-off-by Samuel Wu <[email protected]>---
kernel/freezer.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)kernel/freezer.c +0
-0kernel/freezer.c bool freeze_task(struct task_struct *p) · line 172
Quoted 8 lines
kernel/freezer.c +1
-1@@ -166,7 +166,7 @@ bool freeze_task(struct task_struct *p)unsigned long flags;spin_lock_irqsave (&freezer_lock, flags); -if (!freezing (p) ||frozen (p) ||__freeze_task (p)) { +if (frozen (p) || !freezing (p) ||__freeze_task (p)) {spin_unlock_irqrestore (&freezer_lock, flags);return false; }Good good.
Quoted 1 line
Reviewed-by Bradley Morgan <[email protected]>
Applied as 7.5 material, thanks!