[PATCH 3/9] PM: suspend_block: Abort task freezing if a suspend_blocker is active.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=
Date: Thursday, April 22, 2010 - 6:08 pm

If a suspend_blocker is active, suspend will fail anyway. Since
try_to_freeze_tasks can take up to 20 seconds to complete or fail, aborting
as soon as someone blocks suspend (e.g. from an interrupt handler) improves
the worst case wakeup latency.

On an older kernel where task freezing could fail for processes attached
to a debugger, this fixed a problem where the device sometimes hung for
20 seconds before the screen turned on.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
---
 kernel/power/process.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/kernel/power/process.c b/kernel/power/process.c
index 71ae290..d8ebd50 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -15,6 +15,7 @@
 #include <linux/syscalls.h>
 #include <linux/freezer.h>
 #include <linux/delay.h>
+#include <linux/suspend_blocker.h>
 
 /* 
  * Timeout for stopping processes
@@ -38,6 +39,7 @@ static int try_to_freeze_tasks(bool sig_only)
 	struct timeval start, end;
 	u64 elapsed_csecs64;
 	unsigned int elapsed_csecs;
+	bool wakeup = false;
 
 	do_gettimeofday(&start);
 
@@ -63,6 +65,10 @@ static int try_to_freeze_tasks(bool sig_only)
 				todo++;
 		} while_each_thread(g, p);
 		read_unlock(&tasklist_lock);
+		if (todo && suspend_is_blocked()) {
+			wakeup = true;
+			break;
+		}
 		if (!todo || time_after(jiffies, end_time))
 			break;
 
@@ -85,13 +91,15 @@ static int try_to_freeze_tasks(bool sig_only)
 		 * but it cleans up leftover PF_FREEZE requests.
 		 */
 		printk("\n");
-		printk(KERN_ERR "Freezing of tasks failed after %d.%02d seconds "
+		printk(KERN_ERR "Freezing of tasks %s after %d.%02d seconds "
 				"(%d tasks refusing to freeze):\n",
+				wakeup ? "aborted" : "failed",
 				elapsed_csecs / 100, elapsed_csecs % 100, todo);
 		read_lock(&tasklist_lock);
 		do_each_thread(g, p) {
 			task_lock(p);
-			if (freezing(p) && !freezer_should_skip(p))
+			if (freezing(p) && !freezer_should_skip(p)
+					&& elapsed_csecs > 100)
 				sched_show_task(p);
 			cancel_freezing(p);
 			task_unlock(p);
-- 
1.6.5.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/9] Suspend block api (version 4), =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 1/9] PM: Add suspend block api., =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 2/9] PM: suspend_block: Add driver to access suspen ..., =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 3/9] PM: suspend_block: Abort task freezing if a su ..., =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 4/9] PM: suspend_block: Switch to list of active an ..., =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 5/9] PM: suspend_block: Add debugfs file, =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 6/9] PM: suspend_block: Add suspend_blocker stats, =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 7/9] PM: Add suspend blocking work., =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 8/9] Input: Block suspend while event queue is not ..., =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
[PATCH 9/9] power_supply: Block suspend while power supply ..., =?UTF-8?q?Arve=20Hj= ..., (Thu Apr 22, 6:08 pm)
Re: [PATCH 7/9] PM: Add suspend blocking work., Tejun Heo, (Fri Apr 23, 1:16 am)
Re: [PATCH 7/9] PM: Add suspend blocking work., Oleg Nesterov, (Fri Apr 23, 5:20 am)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Randy Dunlap, (Fri Apr 23, 1:58 pm)
Re: [PATCH 7/9] PM: Add suspend blocking work., Arve Hjønnevåg, (Fri Apr 23, 3:49 pm)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Arve Hjønnevåg, (Fri Apr 23, 8:23 pm)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Randy Dunlap, (Fri Apr 23, 9:24 pm)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Arve Hjønnevåg, (Fri Apr 23, 9:54 pm)
Re: [PATCH 8/9] Input: Block suspend while event queue is ..., Arve Hjønnevåg, (Fri Apr 23, 9:58 pm)
Re: [PATCH 8/9] Input: Block suspend while event queue is ..., Arve Hjønnevåg, (Fri Apr 23, 10:02 pm)
Re: [PATCH 7/9] PM: Add suspend blocking work., Arve Hjønnevåg, (Fri Apr 23, 10:21 pm)
Re: [PATCH 7/9] PM: Add suspend blocking work., Tejun Heo, (Fri Apr 23, 11:33 pm)
Re: [PATCH 7/9] PM: Add suspend blocking work., Arve Hjønnevåg, (Sat Apr 24, 12:21 am)
Re: [PATCH 7/9] PM: Add suspend blocking work., Tejun Heo, (Sat Apr 24, 12:43 am)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Randy Dunlap, (Sun Apr 25, 12:53 pm)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Randy Dunlap, (Sun Apr 25, 5:23 pm)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Randy Dunlap, (Sun Apr 25, 5:50 pm)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Brian Swetland, (Sun Apr 25, 11:24 pm)
Re: [PATCH 5/9] PM: suspend_block: Add debugfs file, Randy Dunlap, (Mon Apr 26, 6:28 am)
Re: [PATCH 7/9] PM: Add suspend blocking work., Oleg Nesterov, (Mon Apr 26, 7:06 am)