From cbb658990449df002eb9775f0b5ad104a7114b5f Mon Sep 17 00:00:00 2001 From: Dima Zavin Date: Tue, 28 Sep 2010 17:24:51 -0700 Subject: sched: normalize sleeper's vruntime during group change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Dima Zavin --- kernel/sched_fair.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'kernel/sched_fair.c') diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index db3f674ca49d..6ded59f453c0 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c @@ -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 }; -- cgit v1.2.3