History

rbtree, sched/fair: Use rb_add_cached()

Reduce rbtree boiler plate by using the new helper function.

Peter Zijlstra committed 6 years ago

Commit bf9be9a1 parent 2d24dd51 file · +14 −32Browse files

Unified · Split

kernel/sched/fair.c+14−32
@@ -531,12 +531,15 @@ static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime) · 530 unmodified lines
531531 return min_vruntime;
532532 }
533533
534−static inline int entity_before(struct sched_entity *a,
534+static inline bool entity_before(struct sched_entity *a,
535535 struct sched_entity *b)
536536 {
537537 return (s64)(a->vruntime - b->vruntime) < 0;
538538 }
539539
540+#define __node_2_se(node) \
541+ rb_entry((node), struct sched_entity, run_node)
542+
540543 static void update_min_vruntime(struct cfs_rq *cfs_rq)
541544 {
542545 struct sched_entity *curr = cfs_rq->curr;
@@ -552,8 +555,7 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) · 9 unmodified lines
552555 }
553556
554557 if (leftmost) { /* non-empty tree */
555− struct sched_entity *se;
556− se = rb_entry(leftmost, struct sched_entity, run_node);
558+ struct sched_entity *se = __node_2_se(leftmost);
557559
558560 if (!curr)
559561 vruntime = se->vruntime;
@@ -569,37 +571,17 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) · 9 unmodified lines
569571 #endif
570572 }
571573
574+static inline bool __entity_less(struct rb_node *a, const struct rb_node *b)
575+{
576+ return entity_before(__node_2_se(a), __node_2_se(b));
577+}
578+
572579 /*
573580 * Enqueue an entity into the rb-tree:
574581 */
575582 static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
576583 {
577− struct rb_node **link = &cfs_rq->tasks_timeline.rb_root.rb_node;
578− struct rb_node *parent = NULL;
579− struct sched_entity *entry;
580− bool leftmost = true;
581−
582− /*
583− * Find the right place in the rbtree:
584− */
585− while (*link) {
586− parent = *link;
587− entry = rb_entry(parent, struct sched_entity, run_node);
588− /*
589− * We dont care about collisions. Nodes with
590− * the same key stay together.
591− */
592− if (entity_before(se, entry)) {
593− link = &parent->rb_left;
594− } else {
595− link = &parent->rb_right;
596− leftmost = false;
597− }
598− }
599−
600− rb_link_node(&se->run_node, parent, link);
601− rb_insert_color_cached(&se->run_node,
602− &cfs_rq->tasks_timeline, leftmost);
584+ rb_add_cached(&se->run_node, &cfs_rq->tasks_timeline, __entity_less);
603585 }
604586
605587 static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
@@ -614,7 +596,7 @@ struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq) · 8 unmodified lines
614596 if (!left)
615597 return NULL;
616598
617− return rb_entry(left, struct sched_entity, run_node);
599+ return __node_2_se(left);
618600 }
619601
620602 static struct sched_entity *__pick_next_entity(struct sched_entity *se)
@@ -624,7 +606,7 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se) · 3 unmodified lines
624606 if (!next)
625607 return NULL;
626608
627− return rb_entry(next, struct sched_entity, run_node);
609+ return __node_2_se(next);
628610 }
629611
630612 #ifdef CONFIG_SCHED_DEBUG
@@ -635,7 +617,7 @@ struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq) · 4 unmodified lines
635617 if (!last)
636618 return NULL;
637619
638− return rb_entry(last, struct sched_entity, run_node);
620+ return __node_2_se(last);
639621 }
640622
641623 /**************************************************************

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t