Reduce rbtree boiler plate by using the new helper function.
Unified · Split
| @@ -531,12 +531,15 @@ static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime) · 530 unmodified lines | |||
| 531 | return min_vruntime; | 531 | return min_vruntime; |
| 532 | } | 532 | } |
| 533 | 533 | ||
| 534 | static inline int entity_before(struct sched_entity *a, | 534 | static inline bool entity_before(struct sched_entity *a, |
| 535 | struct sched_entity *b) | 535 | struct sched_entity *b) |
| 536 | { | 536 | { |
| 537 | return (s64)(a->vruntime - b->vruntime) < 0; | 537 | return (s64)(a->vruntime - b->vruntime) < 0; |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | #define __node_2_se(node) \ | ||
| 541 | rb_entry((node), struct sched_entity, run_node) | ||
| 542 | |||
| 540 | static void update_min_vruntime(struct cfs_rq *cfs_rq) | 543 | static void update_min_vruntime(struct cfs_rq *cfs_rq) |
| 541 | { | 544 | { |
| 542 | struct sched_entity *curr = cfs_rq->curr; | 545 | struct sched_entity *curr = cfs_rq->curr; |
| @@ -552,8 +555,7 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) · 9 unmodified lines | |||
| 552 | } | 555 | } |
| 553 | 556 | ||
| 554 | if (leftmost) { /* non-empty tree */ | 557 | if (leftmost) { /* non-empty tree */ |
| 555 | struct sched_entity *se; | 558 | struct sched_entity *se = __node_2_se(leftmost); |
| 556 | se = rb_entry(leftmost, struct sched_entity, run_node); | ||
| 557 | 559 | ||
| 558 | if (!curr) | 560 | if (!curr) |
| 559 | vruntime = se->vruntime; | 561 | vruntime = se->vruntime; |
| @@ -569,37 +571,17 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) · 9 unmodified lines | |||
| 569 | #endif | 571 | #endif |
| 570 | } | 572 | } |
| 571 | 573 | ||
| 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 | |||
| 572 | /* | 579 | /* |
| 573 | * Enqueue an entity into the rb-tree: | 580 | * Enqueue an entity into the rb-tree: |
| 574 | */ | 581 | */ |
| 575 | static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) | 582 | static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) |
| 576 | { | 583 | { |
| 577 | struct rb_node **link = &cfs_rq->tasks_timeline.rb_root.rb_node; | 584 | rb_add_cached(&se->run_node, &cfs_rq->tasks_timeline, __entity_less); |
| 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); | ||
| 603 | } | 585 | } |
| 604 | 586 | ||
| 605 | static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) | 587 | 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 | |||
| 614 | if (!left) | 596 | if (!left) |
| 615 | return NULL; | 597 | return NULL; |
| 616 | 598 | ||
| 617 | return rb_entry(left, struct sched_entity, run_node); | 599 | return __node_2_se(left); |
| 618 | } | 600 | } |
| 619 | 601 | ||
| 620 | static struct sched_entity *__pick_next_entity(struct sched_entity *se) | 602 | 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 | |||
| 624 | if (!next) | 606 | if (!next) |
| 625 | return NULL; | 607 | return NULL; |
| 626 | 608 | ||
| 627 | return rb_entry(next, struct sched_entity, run_node); | 609 | return __node_2_se(next); |
| 628 | } | 610 | } |
| 629 | 611 | ||
| 630 | #ifdef CONFIG_SCHED_DEBUG | 612 | #ifdef CONFIG_SCHED_DEBUG |
| @@ -635,7 +617,7 @@ struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq) · 4 unmodified lines | |||
| 635 | if (!last) | 617 | if (!last) |
| 636 | return NULL; | 618 | return NULL; |
| 637 | 619 | ||
| 638 | return rb_entry(last, struct sched_entity, run_node); | 620 | return __node_2_se(last); |
| 639 | } | 621 | } |
| 640 | 622 | ||
| 641 | /************************************************************** | 623 | /************************************************************** |