Commit bfb06889 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

sched/fair: replace cfs_rq->rb_leftmost

... with the generic rbtree flavor instead. No changes
in semantics whatsoever.

Link: http://lkml.kernel.org/r/20170719014603.19029-8-dave@stgolabs.netSigned-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b10d43f9
...@@ -530,7 +530,7 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) ...@@ -530,7 +530,7 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
SPLIT_NS(cfs_rq->exec_clock)); SPLIT_NS(cfs_rq->exec_clock));
raw_spin_lock_irqsave(&rq->lock, flags); raw_spin_lock_irqsave(&rq->lock, flags);
if (cfs_rq->rb_leftmost) if (rb_first_cached(&cfs_rq->tasks_timeline))
MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime; MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime;
last = __pick_last_entity(cfs_rq); last = __pick_last_entity(cfs_rq);
if (last) if (last)
......
...@@ -513,6 +513,7 @@ static inline int entity_before(struct sched_entity *a, ...@@ -513,6 +513,7 @@ static inline int entity_before(struct sched_entity *a,
static void update_min_vruntime(struct cfs_rq *cfs_rq) static void update_min_vruntime(struct cfs_rq *cfs_rq)
{ {
struct sched_entity *curr = cfs_rq->curr; struct sched_entity *curr = cfs_rq->curr;
struct rb_node *leftmost = rb_first_cached(&cfs_rq->tasks_timeline);
u64 vruntime = cfs_rq->min_vruntime; u64 vruntime = cfs_rq->min_vruntime;
...@@ -523,10 +524,9 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) ...@@ -523,10 +524,9 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
curr = NULL; curr = NULL;
} }
if (cfs_rq->rb_leftmost) { if (leftmost) { /* non-empty tree */
struct sched_entity *se = rb_entry(cfs_rq->rb_leftmost, struct sched_entity *se;
struct sched_entity, se = rb_entry(leftmost, struct sched_entity, run_node);
run_node);
if (!curr) if (!curr)
vruntime = se->vruntime; vruntime = se->vruntime;
...@@ -547,10 +547,10 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) ...@@ -547,10 +547,10 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
*/ */
static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
{ {
struct rb_node **link = &cfs_rq->tasks_timeline.rb_node; struct rb_node **link = &cfs_rq->tasks_timeline.rb_root.rb_node;
struct rb_node *parent = NULL; struct rb_node *parent = NULL;
struct sched_entity *entry; struct sched_entity *entry;
int leftmost = 1; bool leftmost = true;
/* /*
* Find the right place in the rbtree: * Find the right place in the rbtree:
...@@ -566,36 +566,23 @@ static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) ...@@ -566,36 +566,23 @@ static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
link = &parent->rb_left; link = &parent->rb_left;
} else { } else {
link = &parent->rb_right; link = &parent->rb_right;
leftmost = 0; leftmost = false;
} }
} }
/*
* Maintain a cache of leftmost tree entries (it is frequently
* used):
*/
if (leftmost)
cfs_rq->rb_leftmost = &se->run_node;
rb_link_node(&se->run_node, parent, link); rb_link_node(&se->run_node, parent, link);
rb_insert_color(&se->run_node, &cfs_rq->tasks_timeline); rb_insert_color_cached(&se->run_node,
&cfs_rq->tasks_timeline, leftmost);
} }
static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
{ {
if (cfs_rq->rb_leftmost == &se->run_node) { rb_erase_cached(&se->run_node, &cfs_rq->tasks_timeline);
struct rb_node *next_node;
next_node = rb_next(&se->run_node);
cfs_rq->rb_leftmost = next_node;
}
rb_erase(&se->run_node, &cfs_rq->tasks_timeline);
} }
struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq) struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq)
{ {
struct rb_node *left = cfs_rq->rb_leftmost; struct rb_node *left = rb_first_cached(&cfs_rq->tasks_timeline);
if (!left) if (!left)
return NULL; return NULL;
...@@ -616,7 +603,7 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se) ...@@ -616,7 +603,7 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se)
#ifdef CONFIG_SCHED_DEBUG #ifdef CONFIG_SCHED_DEBUG
struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq) struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq)
{ {
struct rb_node *last = rb_last(&cfs_rq->tasks_timeline); struct rb_node *last = rb_last(&cfs_rq->tasks_timeline.rb_root);
if (!last) if (!last)
return NULL; return NULL;
...@@ -9312,7 +9299,7 @@ static void set_curr_task_fair(struct rq *rq) ...@@ -9312,7 +9299,7 @@ static void set_curr_task_fair(struct rq *rq)
void init_cfs_rq(struct cfs_rq *cfs_rq) void init_cfs_rq(struct cfs_rq *cfs_rq)
{ {
cfs_rq->tasks_timeline = RB_ROOT; cfs_rq->tasks_timeline = RB_ROOT_CACHED;
cfs_rq->min_vruntime = (u64)(-(1LL << 20)); cfs_rq->min_vruntime = (u64)(-(1LL << 20));
#ifndef CONFIG_64BIT #ifndef CONFIG_64BIT
cfs_rq->min_vruntime_copy = cfs_rq->min_vruntime; cfs_rq->min_vruntime_copy = cfs_rq->min_vruntime;
......
...@@ -426,8 +426,7 @@ struct cfs_rq { ...@@ -426,8 +426,7 @@ struct cfs_rq {
u64 min_vruntime_copy; u64 min_vruntime_copy;
#endif #endif
struct rb_root tasks_timeline; struct rb_root_cached tasks_timeline;
struct rb_node *rb_leftmost;
/* /*
* 'curr' points to currently running entity on this cfs_rq. * 'curr' points to currently running entity on this cfs_rq.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment