public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] softlockup: ensure the task has been switched out once
@ 2009-02-10 15:52 Frederic Weisbecker
  2009-02-10 18:15 ` Mandeep Singh Baines
  0 siblings, 1 reply; 3+ messages in thread
From: Frederic Weisbecker @ 2009-02-10 15:52 UTC (permalink / raw)
  To: Ingo Molnar, Mandeep Singh Baines; +Cc: linux-kernel, rientjes, mbligh, thockin

When we check if a task has been switched out since the last scan, we might
have a race condition on the following scenario:

_ the task is freshly created and scheduled
_ it puts its state to TASK_UNINTERRUPTIBLE and is not yet switched out
_ check_hung_task() scans this task and will report a false positive because
  t->nvcsw + t->nivcsw == t->last_switch_count == 0

Add a check for such cases.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/hung_task.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index 0c924de..022a492 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -72,7 +72,13 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
 {
 	unsigned long switch_count = t->nvcsw + t->nivcsw;
 
-	if (t->flags & PF_FROZEN)
+	/*
+	 * Ensure the task is not frozen.
+	 * Also, when a freshly created task is scheduled once, changes
+	 * its state to TASK_UNINTERRUPTIBLE without having ever been
+	 * switched out once, it musn't be checked.
+	 */
+	if (unlikely(t->flags & PF_FROZEN || !switch_count))
 		return;
 
 	if (switch_count != t->last_switch_count) {
-- 
1.6.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-02-11 10:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-10 15:52 [PATCH] softlockup: ensure the task has been switched out once Frederic Weisbecker
2009-02-10 18:15 ` Mandeep Singh Baines
2009-02-11 10:04   ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox