[PATCH] sched/fair: Fix update_min_vruntime() to get proper min_vruntime

From: Byungchul Park
Date: Mon Sep 05 2016 - 23:22:26 EST


Commit 97a7142 'sched/fair: Make update_min_vruntime() more readable'
introduces a bug that cfs_rq gets a wrong min_vruntime if
!cfs_rq->rb_leftmost && cfs_rq->curr. This fixes it and makes it more
readable and simple.

Signed-off-by: Byungchul Park <byungchul.park@xxxxxxx>
---
kernel/sched/fair.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index a6820b3..0a5f666b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -462,21 +462,20 @@ static inline int entity_before(struct sched_entity *a,

static void update_min_vruntime(struct cfs_rq *cfs_rq)
{
- u64 vruntime = cfs_rq->min_vruntime;
-
- if (cfs_rq->rb_leftmost) {
- struct sched_entity *se = rb_entry(cfs_rq->rb_leftmost,
- struct sched_entity,
- run_node);
+ u64 vruntime = U64_MAX;

- vruntime = se->vruntime;
- }
+ if (cfs_rq->rb_leftmost)
+ vruntime = rb_entry(cfs_rq->rb_leftmost,
+ struct sched_entity,
+ run_node)->vruntime;

if (cfs_rq->curr)
vruntime = min_vruntime(vruntime, cfs_rq->curr->vruntime);

/* ensure we never gain time by being placed backwards. */
- cfs_rq->min_vruntime = max_vruntime(cfs_rq->min_vruntime, vruntime);
+ if (vruntime != U64_MAX)
+ cfs_rq->min_vruntime = max_vruntime(cfs_rq->min_vruntime, vruntime);
+
#ifndef CONFIG_64BIT
smp_wmb();
cfs_rq->min_vruntime_copy = cfs_rq->min_vruntime;
--
1.9.1