{
        struct sched_dl_entity *dl_se = &p->dl;
 
-       return dl_rq->rb_leftmost == &dl_se->rb_node;
+       return dl_rq->root.rb_leftmost == &dl_se->rb_node;
 }
 
 void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime)
 
 void init_dl_rq(struct dl_rq *dl_rq)
 {
-       dl_rq->rb_root = RB_ROOT;
+       dl_rq->root = RB_ROOT_CACHED;
 
 #ifdef CONFIG_SMP
        /* zero means no -deadline tasks */
 
        dl_rq->dl_nr_migratory = 0;
        dl_rq->overloaded = 0;
-       dl_rq->pushable_dl_tasks_root = RB_ROOT;
+       dl_rq->pushable_dl_tasks_root = RB_ROOT_CACHED;
 #else
        init_dl_bw(&dl_rq->dl_bw);
 #endif
 static void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
 {
        struct dl_rq *dl_rq = &rq->dl;
-       struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_node;
+       struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_root.rb_node;
        struct rb_node *parent = NULL;
        struct task_struct *entry;
-       int leftmost = 1;
+       bool leftmost = true;
 
        BUG_ON(!RB_EMPTY_NODE(&p->pushable_dl_tasks));
 
                        link = &parent->rb_left;
                else {
                        link = &parent->rb_right;
-                       leftmost = 0;
+                       leftmost = false;
                }
        }
 
-       if (leftmost) {
-               dl_rq->pushable_dl_tasks_leftmost = &p->pushable_dl_tasks;
+       if (leftmost)
                dl_rq->earliest_dl.next = p->dl.deadline;
-       }
 
        rb_link_node(&p->pushable_dl_tasks, parent, link);
-       rb_insert_color(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
+       rb_insert_color_cached(&p->pushable_dl_tasks,
+                              &dl_rq->pushable_dl_tasks_root, leftmost);
 }
 
 static void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
        if (RB_EMPTY_NODE(&p->pushable_dl_tasks))
                return;
 
-       if (dl_rq->pushable_dl_tasks_leftmost == &p->pushable_dl_tasks) {
+       if (dl_rq->pushable_dl_tasks_root.rb_leftmost == &p->pushable_dl_tasks) {
                struct rb_node *next_node;
 
                next_node = rb_next(&p->pushable_dl_tasks);
-               dl_rq->pushable_dl_tasks_leftmost = next_node;
                if (next_node) {
                        dl_rq->earliest_dl.next = rb_entry(next_node,
                                struct task_struct, pushable_dl_tasks)->dl.deadline;
                }
        }
 
-       rb_erase(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
+       rb_erase_cached(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
        RB_CLEAR_NODE(&p->pushable_dl_tasks);
 }
 
 static inline int has_pushable_dl_tasks(struct rq *rq)
 {
-       return !RB_EMPTY_ROOT(&rq->dl.pushable_dl_tasks_root);
+       return !RB_EMPTY_ROOT(&rq->dl.pushable_dl_tasks_root.rb_root);
 }
 
 static int push_dl_task(struct rq *rq);
                dl_rq->earliest_dl.next = 0;
                cpudl_clear(&rq->rd->cpudl, rq->cpu);
        } else {
-               struct rb_node *leftmost = dl_rq->rb_leftmost;
+               struct rb_node *leftmost = dl_rq->root.rb_leftmost;
                struct sched_dl_entity *entry;
 
                entry = rb_entry(leftmost, struct sched_dl_entity, rb_node);
 static void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
 {
        struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
-       struct rb_node **link = &dl_rq->rb_root.rb_node;
+       struct rb_node **link = &dl_rq->root.rb_root.rb_node;
        struct rb_node *parent = NULL;
        struct sched_dl_entity *entry;
        int leftmost = 1;
                }
        }
 
-       if (leftmost)
-               dl_rq->rb_leftmost = &dl_se->rb_node;
-
        rb_link_node(&dl_se->rb_node, parent, link);
-       rb_insert_color(&dl_se->rb_node, &dl_rq->rb_root);
+       rb_insert_color_cached(&dl_se->rb_node, &dl_rq->root, leftmost);
 
        inc_dl_tasks(dl_se, dl_rq);
 }
        if (RB_EMPTY_NODE(&dl_se->rb_node))
                return;
 
-       if (dl_rq->rb_leftmost == &dl_se->rb_node) {
-               struct rb_node *next_node;
-
-               next_node = rb_next(&dl_se->rb_node);
-               dl_rq->rb_leftmost = next_node;
-       }
-
-       rb_erase(&dl_se->rb_node, &dl_rq->rb_root);
+       rb_erase_cached(&dl_se->rb_node, &dl_rq->root);
        RB_CLEAR_NODE(&dl_se->rb_node);
 
        dec_dl_tasks(dl_se, dl_rq);
 static struct sched_dl_entity *pick_next_dl_entity(struct rq *rq,
                                                   struct dl_rq *dl_rq)
 {
-       struct rb_node *left = dl_rq->rb_leftmost;
+       struct rb_node *left = rb_first_cached(&dl_rq->root);
 
        if (!left)
                return NULL;
  */
 static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu)
 {
-       struct rb_node *next_node = rq->dl.pushable_dl_tasks_leftmost;
+       struct rb_node *next_node = rq->dl.pushable_dl_tasks_root.rb_leftmost;
        struct task_struct *p = NULL;
 
        if (!has_pushable_dl_tasks(rq))
        if (!has_pushable_dl_tasks(rq))
                return NULL;
 
-       p = rb_entry(rq->dl.pushable_dl_tasks_leftmost,
+       p = rb_entry(rq->dl.pushable_dl_tasks_root.rb_leftmost,
                     struct task_struct, pushable_dl_tasks);
 
        BUG_ON(rq->cpu != task_cpu(p));