Skip to contentSkip to conversation

Remove duplicate code from sched_fair.c

PATCH Applied Balbir Singh 2 participants 2 messages Feb 22, 2008

lore
Share & tools
lore
#0 lore raw

yield_task_fair has some duplicate code, that can be replaced with rb_last(). This code reuses rb_next and removes the duplicate code. As a side effect, we don't do an rb_entry for each node as we walk along the path.

Comments, flames?

Description
-----------

pick_task_entity() duplicates existing code. This functionality can be easily obtained using rb_last(). Avoid code duplication by using rb_last()

---

 kernel/sched_fair.c |   15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
kernel/sched_fair.c renamed from kernel/sched_fair.c~use-existing-code-in-sched-yield +6 -9
diff -puN kernel/sched_fair.c~use-existing-code-in-sched-yield kernel/sched_fair.c
@@ -301,16 +301,13 @@ static struct sched_entity *__pick_next_
 
 static inline struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq)
 {
-	struct rb_node **link = &cfs_rq->tasks_timeline.rb_node;
-	struct sched_entity *se = NULL;
-	struct rb_node *parent;
-
-	while (*link) {
-		parent = *link;
-		se = rb_entry(parent, struct sched_entity, run_node);
-		link = &parent->rb_right;
-	}
+	struct rb_node *last;
+	struct sched_entity *se;
 
+	last = rb_last(&cfs_rq->tasks_timeline);
+	if (!last)
+		return NULL;
+	se = rb_entry(last, struct sched_entity, run_node);
 	return se;
 }
 

_

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
Applied
#1 lore raw
Quoted 4 lines · Balbir Singh

yield_task_fair has some duplicate code, that can be replaced with rb_last(). This code reuses rb_next and removes the duplicate code. As a side effect, we don't do an rb_entry for each node as we walk along the path.

thanks, applied.

Ingo