mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mike Galbraith <efault@gmx.de>
To: Dima Zavin <dmitriyz@google.com>
Cc: "Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@elte.hu>, "Arve Hjønnevåg" <arve@google.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: broken behavior in cfs when moving threads between cgroups
Date: Wed, 29 Sep 2010 08:42:07 +0200	[thread overview]
Message-ID: <1285742527.7440.295.camel@marge.simson.net> (raw)
In-Reply-To: <1285728812.7440.141.camel@marge.simson.net>

On Wed, 2010-09-29 at 04:53 +0200, Mike Galbraith wrote:

> ..but, as you noted, moving out then _back_ at forced 0 lag would result
> in bogus vruntime deltas, so lag must be preserved.  The sleeper's
> vruntime has to be set to relative before it's cfs_rq is changed, then
> back to absolute in moved_group_fair() I suppose.

I bent it up like so.

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 53eb33c..d2b06a9 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1073,7 +1073,7 @@ struct sched_class {
 					 struct task_struct *task);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-	void (*moved_group) (struct task_struct *p, int on_rq);
+	void (*moved_group) (struct task_struct *p, int on_rq, int leaving);
 #endif
 };
 
diff --git a/kernel/sched.c b/kernel/sched.c
index 1ab8394..7001d5a 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -8358,11 +8358,16 @@ 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->moved_group)
+		tsk->sched_class->moved_group(tsk, on_rq, 1);
+#endif
+
 	set_task_rq(tsk, task_cpu(tsk));
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
 	if (tsk->sched_class->moved_group)
-		tsk->sched_class->moved_group(tsk, on_rq);
+		tsk->sched_class->moved_group(tsk, on_rq, 0);
 #endif
 
 	if (unlikely(running))
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 9b5b4f8..81885ae 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -3824,13 +3824,23 @@ static void set_curr_task_fair(struct rq *rq)
 }
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-static void moved_group_fair(struct task_struct *p, int on_rq)
+static void moved_group_fair(struct task_struct *p, int on_rq, int leaving)
 {
 	struct cfs_rq *cfs_rq = task_cfs_rq(p);
 
 	update_curr(cfs_rq);
-	if (!on_rq)
-		place_entity(cfs_rq, &p->se, 1);
+
+	/*
+	 * For runnable tasks, vruntime normalization is handled globally by
+	 * dequeue_entity().  task_waking_fair() normalizes sleepers in the
+	 * wakeup path (to allow lag to grow while sleeping), so we have to
+	 * normalize before the task exits it's old cfs_rq, and prepare for
+	 * the impending normalization before that happens.
+	 */
+	if (!on_rq && leaving)
+		p->se.vruntime -= cfs_rq->min_vruntime;
+	else if (!on_rq)
+		p->se.vruntime += cfs_rq->min_vruntime;
 }
 #endif
 



  reply	other threads:[~2010-09-29  6:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-28  6:07 Dima Zavin
2010-09-28  8:17 ` Mike Galbraith
2010-09-28 22:57   ` Dima Zavin
2010-09-28 23:23     ` Dima Zavin
2010-09-29  2:53     ` Mike Galbraith
2010-09-29  6:42       ` Mike Galbraith [this message]
2010-09-29  6:45         ` Dima Zavin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1285742527.7440.295.camel@marge.simson.net \
    --to=efault@gmx.de \
    --cc=arve@google.com \
    --cc=dmitriyz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®