Re: CFS: some bad numbers with Java/database threading [FIXED]

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Ingo Molnar
Date: Wednesday, September 19, 2007 - 1:26 pm

* Ingo Molnar <mingo@elte.hu> wrote:


find below the fix that puts yielding tasks to the rightmost position in 
the rbtree. I have not tested it extensively yet, but it appears to work 
on x86. (i tested yield using interactive tasks and they get hurt now 
under load - but this would be expected.)

	Ingo

---------------------->
Subject: sched: make yield more agressive
From: Ingo Molnar <mingo@elte.hu>

make sys_sched_yield() more agressive, by moving the yielding task
to the last position in the rbtree.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/sched.c      |    5 +----
 kernel/sched_fair.c |   39 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 9 deletions(-)

Index: linux/kernel/sched.c
===================================================================
--- linux.orig/kernel/sched.c
+++ linux/kernel/sched.c
@@ -4550,10 +4550,7 @@ asmlinkage long sys_sched_yield(void)
 	struct rq *rq = this_rq_lock();
 
 	schedstat_inc(rq, yld_cnt);
-	if (unlikely(rq->nr_running == 1))
-		schedstat_inc(rq, yld_act_empty);
-	else
-		current->sched_class->yield_task(rq, current);
+	current->sched_class->yield_task(rq, current);
 
 	/*
 	 * Since we are going to call schedule() anyway, there's
Index: linux/kernel/sched_fair.c
===================================================================
--- linux.orig/kernel/sched_fair.c
+++ linux/kernel/sched_fair.c
@@ -902,14 +902,43 @@ static void dequeue_task_fair(struct rq 
 static void yield_task_fair(struct rq *rq, struct task_struct *p)
 {
 	struct cfs_rq *cfs_rq = task_cfs_rq(p);
+	struct rb_node **link = &cfs_rq->tasks_timeline.rb_node;
+	struct sched_entity *rightmost, *se = &p->se;
+	struct rb_node *parent;
 
-	__update_rq_clock(rq);
 	/*
-	 * Dequeue and enqueue the task to update its
-	 * position within the tree:
+	 * Are we the only task in the tree?
 	 */
-	dequeue_entity(cfs_rq, &p->se, 0);
-	enqueue_entity(cfs_rq, &p->se, 0);
+	if (unlikely(cfs_rq->nr_running == 1))
+		return;
+	/*
+	 * Find the rightmost entry in the rbtree:
+	 */
+	do {
+		parent = *link;
+		link = &parent->rb_right;
+	} while (*link);
+
+	rightmost = rb_entry(parent, struct sched_entity, run_node);
+	/*
+	 * Already in the rightmost position?
+	 */
+	if (unlikely(rightmost == se))
+		return;
+
+	/*
+	 * Minimally necessary key value to be last in the tree:
+	 */
+	se->fair_key = rightmost->fair_key + 1;
+
+	if (cfs_rq->rb_leftmost == &se->run_node)
+		cfs_rq->rb_leftmost = rb_next(&se->run_node);
+	/*
+	 * Relink the task to the rightmost position:
+	 */
+	rb_erase(&se->run_node, &cfs_rq->tasks_timeline);
+	rb_link_node(&se->run_node, parent, link);
+	rb_insert_color(&se->run_node, &cfs_rq->tasks_timeline);
 }
 
 /*

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

Messages in current thread:
CFS: some bad numbers with Java/database threading, Antoine Martin, (Wed Sep 12, 4:10 pm)
Re: some bad numbers with Java/database threading, Nick Piggin, (Wed Sep 12, 4:33 pm)
RE: some bad numbers with Java/database threading, David Schwartz, (Thu Sep 13, 12:18 am)
Re: CFS: some bad numbers with Java/database threading, Ingo Molnar, (Thu Sep 13, 4:24 am)
Re: some bad numbers with Java/database threading, Antoine Martin, (Thu Sep 13, 12:02 pm)
RE: some bad numbers with Java/database threading, David Schwartz, (Thu Sep 13, 2:47 pm)
Re: CFS: some bad numbers with Java/database threading, Ingo Molnar, (Fri Sep 14, 1:32 am)
Re: CFS: some bad numbers with Java/database threading, Satyam Sharma, (Fri Sep 14, 3:06 am)
Re: CFS: some bad numbers with Java/database threading, Satyam Sharma, (Fri Sep 14, 9:01 am)
Re: CFS: some bad numbers with Java/database threading, Satyam Sharma, (Fri Sep 14, 9:08 am)
Re: CFS: some bad numbers with Java/database threading, Antoine Martin, (Mon Sep 17, 5:17 am)
Re: CFS: some bad numbers with Java/database threading [FIXED], Ingo Molnar, (Wed Sep 19, 1:26 pm)
Re: CFS: new java yield graphs, Antoine Martin, (Tue Sep 25, 6:46 pm)
Re: CFS: new java yield graphs, Ingo Molnar, (Thu Sep 27, 1:35 am)