public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Galbraith <efault@gmx.de>
To: Jayson King <dev@jaysonking.com>
Cc: linux-kernel@vger.kernel.org, a.p.zijlstra@chello.nl, mingo@elte.hu
Subject: Re: problem with "sched: revert back to per-rq vruntime"?
Date: Wed, 31 Dec 2008 17:26:13 +0100	[thread overview]
Message-ID: <1230740773.6412.21.camel@marge.simson.net> (raw)
In-Reply-To: <495A788B.3010001@jaysonking.com>

On Tue, 2008-12-30 at 13:37 -0600, Jayson King wrote:
> Here's some times using bash, for example. Let me know if there are some 
> other tests I can do.
> 

> [jayson@atlas tmp]$ time bash -i -c 'exit'
> exit
> 
> real    0m0.753s
> user    0m0.011s
> sys     0m0.011s

Yeah, it's b0rked.  The problem is that we call sched_slice() before the
new task's load weight has been added to the runqueue.  

Normally this doesn't cause horrible problems, but when there is a +nice
hog on the runqueue, the lighter the hog, and/or heavier the victim...

[  160.489402] bash:5858 vslice: 3840000000 weight: 1024 rq_weight: 15 inv_weight: 268435456

...the closer the victim's vruntime gets to the middle of next week.

Not-signed-off diag hack.

diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 5ad4440..3254213 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -449,13 +449,34 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
 }
 
 /*
+ * A freshly forked task's load weight has not yet been added to the runqueue,
+ * so we can't call calc_delta_weight() and get sane results.  Therefore, we roll
+ * our own so place_entity() can place this task in the right spot.  The runqueue
+ * weight and nr_running will be updated when the task is enqueued.
+ */
+static u64 sched_initial_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
+{
+	u64 slice = __sched_period(cfs_rq->nr_running + 1);
+
+	for_each_sched_entity(se) {
+		struct load_weight lw = cfs_rq->load;
+
+		lw.weight += se->load.weight;
+		lw.inv_weight = 0;
+		slice = calc_delta_mine(slice, se->load.weight, &lw);
+	}
+
+	return slice;
+}
+
+/*
  * We calculate the vruntime slice of a to be inserted task
  *
  * vs = s/w
  */
 static u64 sched_vslice(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
-	return calc_delta_fair(sched_slice(cfs_rq, se), se);
+	return calc_delta_fair(sched_initial_slice(cfs_rq, se), se);
 }
 
 /*



  reply	other threads:[~2008-12-31 16:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-29 22:02 problem with "sched: revert back to per-rq vruntime"? Jayson King
2008-12-29 22:11 ` Jayson King
2008-12-30 19:37 ` Jayson King
2008-12-31 16:26   ` Mike Galbraith [this message]
2008-12-31 20:17     ` Jayson King
2009-01-01  7:46       ` [patch] " Mike Galbraith
2009-01-02  0:14         ` Jayson King
2009-01-02 11:16           ` Mike Galbraith
2009-01-02 20:38             ` Jayson King
2009-01-05  7:54             ` Peter Zijlstra
  -- strict thread matches above, loose matches on Subject: below --
2008-12-29  8:23 Jayson King

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=1230740773.6412.21.camel@marge.simson.net \
    --to=efault@gmx.de \
    --cc=a.p.zijlstra@chello.nl \
    --cc=dev@jaysonking.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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