Remove duplicate code from sched_fair.c
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()
Signed-off-by Balbir Singh <[email protected]>
---
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
@@ -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
Ingo Molnar
AppliedQuoted 4 lines · Balbir Singh
yield_task_fairhas some duplicate code, that can be replaced withrb_last(). This code reusesrb_nextand removes the duplicate code. As a side effect, we don't do anrb_entryfor each node as we walk along the path.
thanks, applied.
Ingo