public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] sched: make sure sched-priority after invoke idle_balance()
@ 2014-02-14  4:54 Michael wang
  2014-02-14 12:38 ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Michael wang @ 2014-02-14  4:54 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar; +Cc: LKML

Since idle_balance() will release rq-lock for a while, there is a chance that
RT/DL tasks will be enqueued and ask for the resched, the func used to be
invoked ahead of pick_next_task(), which will make sure we drop into the
bottom-half inside pick_next_task().

Now since idle_balance() was done inside pick_next_task_fair(), pick_next_task()
can no longer make sure the priority, the worst case is that we will going to
pick the pulled fair task while there is RT/DL on rq which actually should be
picked up.

This patch will prevent this happen by some rechecking after idle_balance(), it
utilize the resched-flag for the case when RT/DL task was enqueued but don't ask
for resched (will that ever happened?).

CC: Ingo Molnar <mingo@kernel.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Michael Wang <wangyun@linux.vnet.ibm.com>
---
 kernel/sched/fair.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 235cfa7..ce67514 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4776,6 +4776,16 @@ simple:
 
 idle:
 #ifdef CONFIG_SMP
+	/*
+	 * We came here only when there is no more tasks on rq (top-half of
+	 * pick_next_task()), and we are now going to pull some fair entities.
+	 *
+	 * Since prev is still the current on rq, clear it's resched-flag so
+	 * we would be able to know when we got a new resched-request during
+	 * idle_balance(), check below for more details.
+	 */
+	clear_tsk_need_resched(prev);
+
 	idle_enter_fair(rq);
 	/*
 	 * We must set idle_stamp _before_ calling idle_balance(), such that we
@@ -4784,7 +4794,18 @@ idle:
 	rq->idle_stamp = rq_clock(rq);
 	if (idle_balance(rq)) { /* drops rq->lock */
 		rq->idle_stamp = 0;
-		goto again;
+		/*
+		 * Before we start to pick one of the pulled fair entities, take
+		 * care if some RT/DL tasks has been enqueued during the time
+		 * we release rq-lock inside idle_balance().
+		 *
+		 * In such cases, since clear_tsk_need_resched() was done
+		 * already, need_resched() will imply the request to sched-in
+		 * the enqueued RT/DL tasks, so don't 'goto again' to make sure
+		 * the priority.
+		 */
+		if (rq->nr_running == rq->cfs.h_nr_running || !need_resched())
+			goto again;
 	}
 #endif
 
-- 
1.7.9.5


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

end of thread, other threads:[~2014-02-18  2:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-14  4:54 [RFC PATCH] sched: make sure sched-priority after invoke idle_balance() Michael wang
2014-02-14 12:38 ` Peter Zijlstra
2014-02-17  3:31   ` Michael wang
2014-02-17 11:24     ` Peter Zijlstra
2014-02-18  2:42       ` Michael wang

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