提交 bfd8258d 编写于 作者: P Peter Zijlstra 提交者: Yunying Sun

rbtree, sched/fair: Use rb_add_cached()

mainline inclusion
from mainline-v5.12-rc1
commit bf9be9a1
category: feature
feature: SPR PMU uncore support
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5BECO

Intel-SIG: commit bf9be9a1 rbtree, sched/fair: Use rb_add_cached()
This commit is backported as a dependency for SPR PMU uncore support.

-------------------------------------

Reduce rbtree boiler plate by using the new helper function.
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: NIngo Molnar <mingo@kernel.org>
Acked-by: NDavidlohr Bueso <dbueso@suse.de>
Signed-off-by: NYunying Sun <yunying.sun@intel.com>
上级 2e12faa2
......@@ -510,12 +510,15 @@ static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime)
return min_vruntime;
}
static inline int entity_before(struct sched_entity *a,
static inline bool entity_before(struct sched_entity *a,
struct sched_entity *b)
{
return (s64)(a->vruntime - b->vruntime) < 0;
}
#define __node_2_se(node) \
rb_entry((node), struct sched_entity, run_node)
static void update_min_vruntime(struct cfs_rq *cfs_rq)
{
struct sched_entity *curr = cfs_rq->curr;
......@@ -531,8 +534,7 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
}
if (leftmost) { /* non-empty tree */
struct sched_entity *se;
se = rb_entry(leftmost, struct sched_entity, run_node);
struct sched_entity *se = __node_2_se(leftmost);
if (!curr)
vruntime = se->vruntime;
......@@ -548,37 +550,17 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
#endif
}
static inline bool __entity_less(struct rb_node *a, const struct rb_node *b)
{
return entity_before(__node_2_se(a), __node_2_se(b));
}
/*
* Enqueue an entity into the rb-tree:
*/
static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
struct rb_node **link = &cfs_rq->tasks_timeline.rb_root.rb_node;
struct rb_node *parent = NULL;
struct sched_entity *entry;
bool leftmost = true;
/*
* Find the right place in the rbtree:
*/
while (*link) {
parent = *link;
entry = rb_entry(parent, struct sched_entity, run_node);
/*
* We dont care about collisions. Nodes with
* the same key stay together.
*/
if (entity_before(se, entry)) {
link = &parent->rb_left;
} else {
link = &parent->rb_right;
leftmost = false;
}
}
rb_link_node(&se->run_node, parent, link);
rb_insert_color_cached(&se->run_node,
&cfs_rq->tasks_timeline, leftmost);
rb_add_cached(&se->run_node, &cfs_rq->tasks_timeline, __entity_less);
}
static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
......@@ -593,7 +575,7 @@ struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq)
if (!left)
return NULL;
return rb_entry(left, struct sched_entity, run_node);
return __node_2_se(left);
}
static struct sched_entity *__pick_next_entity(struct sched_entity *se)
......@@ -603,7 +585,7 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se)
if (!next)
return NULL;
return rb_entry(next, struct sched_entity, run_node);
return __node_2_se(next);
}
#ifdef CONFIG_SCHED_DEBUG
......@@ -614,7 +596,7 @@ struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq)
if (!last)
return NULL;
return rb_entry(last, struct sched_entity, run_node);
return __node_2_se(last);
}
/**************************************************************
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册