Re: wait_for_completion_timeout() spurious failure under heavy load?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Ingo Molnar
Date: Friday, June 20, 2008 - 8:21 am

* Oleg Nesterov <oleg@tv-sign.ru> wrote:


nice, thanks - applied it in the form below to tip/sched/urgent.

	Ingo

------------------>
commit 6b8464474776dccf619283ee5510b0b795382dfb
Author: Oleg Nesterov <oleg@tv-sign.ru>
Date:   Fri Jun 20 18:32:20 2008 +0400

    sched: refactor wait_for_completion_timeout()
    
    Simplify the code and fix the boundary condition of
    wait_for_completion_timeout(,0).
    
    We can kill the first __remove_wait_queue() as well.
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/sched.c b/kernel/sched.c
index 577f160..bebf978 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4398,32 +4398,20 @@ do_wait_for_common(struct completion *x, long timeout, int state)
 			     signal_pending(current)) ||
 			    (state == TASK_KILLABLE &&
 			     fatal_signal_pending(current))) {
-				__remove_wait_queue(&x->wait, &wait);
-				return -ERESTARTSYS;
+				timeout = -ERESTARTSYS;
+				break;
 			}
 			__set_current_state(state);
 			spin_unlock_irq(&x->wait.lock);
 			timeout = schedule_timeout(timeout);
 			spin_lock_irq(&x->wait.lock);
-
-			/*
-			 * If the completion has arrived meanwhile
-			 * then return 1 jiffy time left:
-			 */
-			if (x->done && !timeout) {
-				timeout = 1;
-				break;
-			}
-
-			if (!timeout) {
-				__remove_wait_queue(&x->wait, &wait);
-				return timeout;
-			}
-		} while (!x->done);
+		} while (!x->done && timeout);
 		__remove_wait_queue(&x->wait, &wait);
+		if (!x->done)
+			return timeout;
 	}
 	x->done--;
-	return timeout;
+	return timeout ?: 1;
 }
 
 static long __sched
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: wait_for_completion_timeout() spurious failure under h ..., Ingo Molnar, (Fri Jun 20, 8:21 am)