sched: normalize sleeper's vruntime during group change
authorDima Zavin <dima@android.com>
Wed, 29 Sep 2010 00:24:51 +0000 (17:24 -0700)
committerColin Cross <ccross@android.com>
Mon, 4 Oct 2010 19:08:04 +0000 (12:08 -0700)
If you switch the cgroup of a sleeping thread, its vruntime does
not get adjusted correctly for the difference between the
min_vruntime values of the two groups.

This patch adds a new callback, prep_move_task, to struct sched_class
to give sched_fair the opportunity to adjust the task's vruntime
just before setting its new group. This allows us to properly normalize
a sleeping task's vruntime when moving it between different cgroups.

More details about the problem:
  http://lkml.org/lkml/2010/9/28/24

Cc: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Dima Zavin <dima@android.com>
include/linux/sched.h
kernel/sched.c
kernel/sched_fair.c

index cc9c126397fdbd03e85640243986acce5caf79ae..6e3dd4fef93c1c699f9f74d599e7f56c886bc646 100644 (file)
@@ -1073,6 +1073,7 @@ struct sched_class {
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
        void (*moved_group) (struct task_struct *p, int on_rq);
+       void (*prep_move_group) (struct task_struct *p, int on_rq);
 #endif
 };
 
index 5e1142e7b9a7a712f812036432342adb26dde067..17c6925e2016f7f385e2de651a389d97975ab21d 100644 (file)
@@ -8309,6 +8309,11 @@ void sched_move_task(struct task_struct *tsk)
        if (unlikely(running))
                tsk->sched_class->put_prev_task(rq, tsk);
 
+#ifdef CONFIG_FAIR_GROUP_SCHED
+       if (tsk->sched_class->prep_move_group)
+               tsk->sched_class->prep_move_group(tsk, on_rq);
+#endif
+
        set_task_rq(tsk, task_cpu(tsk));
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
index db3f674ca49dbe93a611716b650bb8c715464da3..6ded59f453c0787d7f5ef7ac00bb9a65cf6d29a0 100644 (file)
@@ -3827,10 +3827,21 @@ static void set_curr_task_fair(struct rq *rq)
 static void moved_group_fair(struct task_struct *p, int on_rq)
 {
        struct cfs_rq *cfs_rq = task_cfs_rq(p);
+       struct sched_entity *se = &p->se;
 
        update_curr(cfs_rq);
        if (!on_rq)
-               place_entity(cfs_rq, &p->se, 1);
+               se->vruntime += cfs_rq->min_vruntime;
+}
+
+static void prep_move_group_fair(struct task_struct *p, int on_rq)
+{
+       struct cfs_rq *cfs_rq = task_cfs_rq(p);
+       struct sched_entity *se = &p->se;
+
+       /* normalize the runtime of a sleeping task before moving it */
+       if (!on_rq)
+               se->vruntime -= cfs_rq->min_vruntime;
 }
 #endif
 
@@ -3883,6 +3894,7 @@ static const struct sched_class fair_sched_class = {
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
        .moved_group            = moved_group_fair,
+       .prep_move_group        = prep_move_group_fair,
 #endif
 };