Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rbtree, sched/fair: Use rb_add_cached()

Reduce rbtree boiler plate by using the new helper function.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Davidlohr Bueso <dbueso@suse.de>

authored by

Peter Zijlstra and committed by
Ingo Molnar
bf9be9a1 2d24dd57

+14 -32
+14 -32
kernel/sched/fair.c
··· 531 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 535 struct sched_entity *b) 536 536 { 537 537 return (s64)(a->vruntime - b->vruntime) < 0; 538 538 } 539 + 540 + #define __node_2_se(node) \ 541 + rb_entry((node), struct sched_entity, run_node) 539 542 540 543 static void update_min_vruntime(struct cfs_rq *cfs_rq) 541 544 { ··· 555 552 } 556 553 557 554 if (leftmost) { /* non-empty tree */ 558 - struct sched_entity *se; 559 - se = rb_entry(leftmost, struct sched_entity, run_node); 555 + struct sched_entity *se = __node_2_se(leftmost); 560 556 561 557 if (!curr) 562 558 vruntime = se->vruntime; ··· 571 569 #endif 572 570 } 573 571 572 + static inline bool __entity_less(struct rb_node *a, const struct rb_node *b) 573 + { 574 + return entity_before(__node_2_se(a), __node_2_se(b)); 575 + } 576 + 574 577 /* 575 578 * Enqueue an entity into the rb-tree: 576 579 */ 577 580 static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) 578 581 { 579 - struct rb_node **link = &cfs_rq->tasks_timeline.rb_root.rb_node; 580 - struct rb_node *parent = NULL; 581 - struct sched_entity *entry; 582 - bool leftmost = true; 583 - 584 - /* 585 - * Find the right place in the rbtree: 586 - */ 587 - while (*link) { 588 - parent = *link; 589 - entry = rb_entry(parent, struct sched_entity, run_node); 590 - /* 591 - * We dont care about collisions. Nodes with 592 - * the same key stay together. 593 - */ 594 - if (entity_before(se, entry)) { 595 - link = &parent->rb_left; 596 - } else { 597 - link = &parent->rb_right; 598 - leftmost = false; 599 - } 600 - } 601 - 602 - rb_link_node(&se->run_node, parent, link); 603 - rb_insert_color_cached(&se->run_node, 604 - &cfs_rq->tasks_timeline, leftmost); 582 + rb_add_cached(&se->run_node, &cfs_rq->tasks_timeline, __entity_less); 605 583 } 606 584 607 585 static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) ··· 596 614 if (!left) 597 615 return NULL; 598 616 599 - return rb_entry(left, struct sched_entity, run_node); 617 + return __node_2_se(left); 600 618 } 601 619 602 620 static struct sched_entity *__pick_next_entity(struct sched_entity *se) ··· 606 624 if (!next) 607 625 return NULL; 608 626 609 - return rb_entry(next, struct sched_entity, run_node); 627 + return __node_2_se(next); 610 628 } 611 629 612 630 #ifdef CONFIG_SCHED_DEBUG ··· 617 635 if (!last) 618 636 return NULL; 619 637 620 - return rb_entry(last, struct sched_entity, run_node); 638 + return __node_2_se(last); 621 639 } 622 640 623 641 /**************************************************************