public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Williams <pwil3058@bigpond.net.au>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Con Kolivas <kernel@kolivas.org>, Nick Piggin <npiggin@suse.de>,
	Mike Galbraith <efault@gmx.de>,
	Arjan van de Ven <arjan@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	caglar@pardus.org.tr, Willy Tarreau <w@1wt.eu>,
	Gene Heskett <gene.heskett@gmail.com>
Subject: Re: [patch] CFS scheduler, v3
Date: Fri, 20 Apr 2007 10:10:45 +1000	[thread overview]
Message-ID: <46280505.4020605@bigpond.net.au> (raw)
In-Reply-To: <20070418175017.GA5250@elte.hu>

Ingo Molnar wrote:
> 
>  - bugfix: use constant offset factor for nice levels instead of 
>    sched_granularity_ns. Thus nice levels work even if someone sets 
>    sched_granularity_ns to 0. NOTE: nice support is still naive, i'll 
>    address the many nice level related suggestions in -v4.

I have a suggestion I'd like to make that addresses both nice and 
fairness at the same time.  As I understand the basic principle behind 
this scheduler it to work out a time by which a task should make it onto 
the CPU and then place it into an ordered list (based on this value) of 
tasks waiting for the CPU.  I think that this is a great idea and my 
suggestion is with regard to a method for working out this time that 
takes into account both fairness and nice.

First suppose we have the following metrics available in addition to 
what's already provided.

rq->avg_weight_load /* a running average of the weighted load on the CPU */
p->avg_cpu_per_cycle /* the average time in nsecs that p spends on the 
CPU each scheduling cycle */

where a scheduling cycle for a task starts when it is placed on the 
queue after waking or being preempted and ends when it is taken off the 
CPU either voluntarily or after being preempted.  So 
p->avg_cpu_per_cycle is just the average amount of time p spends on the 
CPU each time it gets on to the CPU.  Sorry for the long explanation 
here but I just wanted to make sure there was no chance that "scheduling 
cycle" would be construed as some mechanism being imposed on the scheduler.)

We can then define:

effective_weighted_load = max(rq->raw_weighted_load, rq->avg_weighted_load)

If p is just waking (i.e. it's not on the queue and its load_weight is 
not included in rq->raw_weighted_load) and we need to queue it, we say 
that the maximum time (in all fairness) that p should have to wait to 
get onto the CPU is:

expected_wait = p->avg_cpu_per_cycle * effective_weighted_load / 
p->load_weight

Calculating p->avg_cpu_per_cycle costs one add, one multiply and one 
shift right per scheduling cycle of the task.  An additional cost is 
that you need a shift right to get the nanosecond value from value 
stored in the task struct. (i.e. the above code is simplified to give 
the general idea).  The average would be number of cycles based rather 
than time based and (happily) this simplifies the calculations.

If the expected time to get onto the CPU (i.e. expected_wait plus the 
current time) for p is earlier than the equivalent time for the 
currently running task then preemption of that task would be justified.

I appreciate that the notion of basing the expected wait on the task's 
average cpu use per scheduling cycle is counter intuitive but I believe 
that (if you think about it) you'll see that it actually makes sense.

Peter
PS Some reordering of calculation order within the expressions might be 
in order to keep them within the range of 32 bit arithmetic and so avoid 
64 bit arithmetic on 32 bit machines.
-- 
Peter Williams                                   pwil3058@bigpond.net.au

"Learning, n. The kind of ignorance distinguishing the studious."
  -- Ambrose Bierce

  parent reply	other threads:[~2007-04-20  0:10 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-18 17:50 [patch] CFS scheduler, v3 Ingo Molnar
2007-04-18 21:26 ` William Lee Irwin III
2007-04-18 21:33   ` Ingo Molnar
2007-04-20 19:24   ` Christoph Lameter
2007-04-20 19:26     ` Siddha, Suresh B
2007-04-20 19:29     ` William Lee Irwin III
2007-04-20 19:33       ` Christoph Lameter
2007-04-20 19:38         ` William Lee Irwin III
2007-04-20 19:44           ` Christoph Lameter
2007-04-20 20:03             ` William Lee Irwin III
2007-04-20 20:11               ` Siddha, Suresh B
2007-04-24 17:39                 ` Christoph Lameter
2007-04-24 17:42                   ` Siddha, Suresh B
2007-04-24 17:47                     ` Christoph Lameter
2007-04-24 17:50                       ` Siddha, Suresh B
2007-04-24 17:55                         ` Christoph Lameter
2007-04-24 18:06                           ` Siddha, Suresh B
2007-04-20  0:10 ` Peter Williams [this message]
2007-04-20  4:48   ` Willy Tarreau
2007-04-20  6:02     ` Peter Williams
2007-04-20  6:21       ` Peter Williams
2007-04-20  7:26       ` Willy Tarreau
2007-04-20  6:46   ` Ingo Molnar
2007-04-20  7:32     ` Peter Williams
2007-04-20 12:28       ` Peter Williams
2007-04-21  8:07         ` Peter Williams
2007-04-20 13:15   ` William Lee Irwin III
2007-04-21  0:23     ` Peter Williams
2007-04-21  5:07       ` William Lee Irwin III
2007-04-21  5:38         ` Peter Williams
2007-04-21  7:32           ` Peter Williams
2007-04-21  7:54             ` Ingo Molnar
2007-04-21  8:33               ` William Lee Irwin III
2007-04-21  8:57                 ` Ingo Molnar
2007-04-21 16:23                   ` William Lee Irwin III
2007-04-21 10:37               ` Peter Williams
2007-04-21 12:21                 ` Peter Williams
2007-04-20 14:21   ` Peter Williams
2007-04-20 14:33     ` Ingo Molnar

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=46280505.4020605@bigpond.net.au \
    --to=pwil3058@bigpond.net.au \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=caglar@pardus.org.tr \
    --cc=efault@gmx.de \
    --cc=gene.heskett@gmail.com \
    --cc=kernel@kolivas.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=npiggin@suse.de \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=w@1wt.eu \
    /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