CFS: sched-design-CFS.txt - ambiguity about leftmost
PATCH 1/1 CFS: sched-design-CFS.txt - ambiguity about leftmost
Hello,
I felt the description of the leftmost task a bit ambiguous. Is it the leftmost task in the rbtree?
or did u mean the "most leftout task" in the task list? If it is so then this patch should correct the leftmost task as "most leftout task". NACK it if I'm wrong. Just trying to help. :)
Changes "leftmost task" to "most leftout task".
Signed-off by: Pranith Kumar D<[email protected]>
sched-design-CFS.txt 2007-05-22 12:11:35.000000000 +0530 renamed from sched-design-CFS.txt.orig 2007-05-22 12:04:43.000000000 +0530 +0 -0
@@ -37,9 +37,9 @@ the task schedules (or a scheduler tick
'accounted for': the (small) time it just spent using the physical CPU is deducted from p->wait_runtime. [minus the 'fair share' it would have gotten anyway]. Once p->wait_runtime gets low enough so that another -task becomes the 'leftmost task' (plus a small amount of 'granularity' -distance relative to the leftmost task so that we do not over-schedule -tasks and trash the cache) then the new leftmost task is picked and the +task becomes the 'most leftout task' (plus a small amount of 'granularity' +distance relative to the most leftout task so that we do not over-schedule +tasks and trash the cache) then the new most leftout task is picked and the current task is preempted.
The rq->fair_clock value tracks the 'CPU time a runnable task would have @@ -47,10 +47,10 @@ fairly gotten, had it been runnable duri rq->fair_clock values we can accurately timestamp and measure the 'expected CPU time' a task should have gotten. All runnable tasks are sorted in the rbtree by the "rq->fair_clock - p->wait_runtime" key, and -CFS picks the 'leftmost' task and sticks to it. As the system progresses +CFS picks the 'most leftout' task and sticks to it. As the system progresses forwards, newly woken tasks are put into the tree more and more to the right - slowly but surely giving a chance for every task to become the -'leftmost task' and thus get on the CPU within a deterministic amount of +'most leftout task' and thus get on the CPU within a deterministic amount of time.
Some implementation details:
Quoted 3 lines · Pranith Kumar D
Hello,
I felt the description of the leftmost task a bit ambiguous. Is it the leftmost task in the rbtree?
yeah, the leftmost task in the rbtree.
Quoted 3 lines
or did u mean the "most leftout task" in the task list? If it is so then this patch should correct the leftmost task as "most leftout task". NACK it if I'm wrong. Just trying to help. :)
feel free to make it less ambigious. FYI, i recently changed the text (not released yet, change attached below), if you change it then please send a patch against this version. Thanks,
Ingo
Documentation/sched-design-CFS.txt +52 -40
@@ -1,20 +1,59 @@ -[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS] -i'm pleased to announce the first release of the "Modular Scheduler Core -and Completely Fair Scheduler [CFS]" patchset: +this is the CFS scheduler. - http://redhat.com/~mingo/cfs-scheduler/ +80% of CFS's design can be summed up in a single sentence: CFS basically +models an "ideal, precise multi-tasking CPU" on real hardware. -This project is a complete rewrite of the Linux task scheduler. My goal -is to address various feature requests and to fix deficiencies in the -vanilla scheduler that were suggested/found in the past few years, both -for desktop scheduling and for server scheduling workloads. +"Ideal multi-tasking CPU" is a (non-existent :-) CPU that has 100% +physical power and which can run each task at precise equal speed, in +parallel, each at 1/nr_running speed. For example: if there are 2 tasks +running then it runs each at 50% physical power - totally in parallel. + +On real hardware, we can run only a single task at once, so while that +one task runs the other tasks that are waiting for the CPU are at a +disadvantage - the current task gets an unfair amount of CPU time. In +CFS this fairness imbalance is expressed and tracked via the per-task +p->wait_runtime (nanosec-unit) value. "wait_runtime" is the amount of +time the task should now run on the CPU for it become completely fair +and balanced. + +( small detail: on 'ideal' hardware, the p->wait_runtime value would + always be zero - no task would ever get 'out of balance' from the + 'ideal' share of CPU time. ) + +CFS's task picking logic is based on this p->wait_runtime value and it +is thus very simple: it always tries to run the task with the largest +p->wait_runtime value. In other words, CFS tries to run the task with +the 'gravest need' for more CPU time. So CFS always tries to split up +CPU time between runnable tasks as close to 'ideal multitasking +hardware' as possible. + +Most of the rest of CFS's design just falls out of this really simple +concept, with a few add-on embellishments like nice levels, +multiprocessing and various algorithm variants to recognize sleepers. + +In practice it works like this: the system runs a task a bit, and when +the task schedules (or a scheduler tick happens) the task's CPU usage is +'accounted for': the (small) time it just spent using the physical CPU +is deducted from p->wait_runtime. [minus the 'fair share' it would have +gotten anyway]. Once p->wait_runtime gets low enough so that another +task becomes the 'leftmost task' (plus a small amount of 'granularity' +distance relative to the leftmost task so that we do not over-schedule +tasks and trash the cache) then the new leftmost task is picked and the +current task is preempted. + +The rq->fair_clock value tracks the 'CPU time a runnable task would have +fairly gotten, had it been runnable during that time'. So by using +rq->fair_clock values we can accurately timestamp and measure the +'expected CPU time' a task should have gotten. All runnable tasks are +sorted in the rbtree by the "rq->fair_clock - p->wait_runtime" key, and +CFS picks the 'leftmost' task and sticks to it. As the system progresses +forwards, newly woken tasks are put into the tree more and more to the +right - slowly but surely giving a chance for every task to become the +'leftmost task' and thus get on the CPU within a deterministic amount of +time. -[ QuickStart: apply the patch, recompile, reboot. The new scheduler - will be active by default and all tasks will default to the - SCHED_NORMAL interactive scheduling class. ] - -Highlights are: +Some implementation details: - the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy
@@ -78,30 +117,3 @@ Highlights are: iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result. -the core scheduler got smaller by more than 700 lines: - - kernel/sched.c | 1454 ++++++++++++++++------------------------------------------------ - 1 file changed, 372 insertions(+), 1082 deletions(-) - -and even adding all the scheduling modules, the total size impact is -relatively small: - - 18 files changed, 1454 insertions(+), 1133 deletions(-) - -most of the increase is due to extensive comments. The kernel size -impact is in fact a small negative: - - text data bss dec hex filename - 23366 4001 24 27391 6aff kernel/sched.o.vanilla - 24159 2705 56 26920 6928 kernel/sched.o.CFS - -(this is mainly due to the benefit of getting rid of the expired array -and its data structure overhead.) - -thanks go to Thomas Gleixner and Arjan van de Ven for review of this -patchset. - -as usual, any sort of feedback, bugreports, fixes and suggestions are -more than welcome, - - Ingo
PATCH 1/1 CFS: sched-design-CFS.txt - ambiguity about leftmost and some formatting
Hi,
The document is very clear and explains the basic mechanism of CFS very well.
But, i find that the descriptions are a bit up and down. I mean, u use leftmost and rightmost before mentioning that CFS uses rbtree.( which comes much later).
In the following patch I mentioned the rbtree, the first time you talked about 'leftmost'. Also i did some basic formatting. Hope its not a pain. :)
Signed-off by:Pranith Kumar D<[email protected]>
/Documentation/sched-design-CFS.txt 2007-05-22 14:46:38.000000000 +0530 renamed from /Documentation/sched-design-CFS.txt.orig 2007-05-22 14:33:27.000000000 +0530 +1 -1
@@ -1,20 +1,20 @@ -this is the CFS scheduler. +This is the CFS scheduler.
80% of CFS's design can be summed up in a single sentence: CFS basically models an "ideal, precise multi-tasking CPU" on real hardware.
-"Ideal multi-tasking CPU" is a (non-existent :-) CPU that has 100% +"Ideal multi-tasking CPU" is a (non-existent :-)) CPU that has 100% physical power and which can run each task at precise equal speed, in parallel, each at 1/nr_running speed. For example: if there are 2 tasks running then it runs each at 50% physical power - totally in parallel.
On real hardware, we can run only a single task at once, so while that -one task runs the other tasks that are waiting for the CPU are at a +one task runs, the other tasks that are waiting for the CPU are at a disadvantage - the current task gets an unfair amount of CPU time. In CFS this fairness imbalance is expressed and tracked via the per-task p->wait_runtime (nanosec-unit) value. "wait_runtime" is the amount of -time the task should now run on the CPU for it become completely fair +time the task should now run on the CPU for it to become completely fair and balanced.
( small detail: on 'ideal' hardware, the p->wait_runtime value would @@ -37,10 +37,10 @@ the task schedules (or a scheduler tick 'accounted for': the (small) time it just spent using the physical CPU is deducted from p->wait_runtime. [minus the 'fair share' it would have gotten anyway]. Once p->wait_runtime gets low enough so that another -task becomes the 'leftmost task' (plus a small amount of 'granularity' -distance relative to the leftmost task so that we do not over-schedule -tasks and trash the cache) then the new leftmost task is picked and the -current task is preempted.
+task becomes the 'leftmost task' of the time-ordered rbtree it maintains +(plus a small amount of 'granularity' distance relative to the leftmost +task so that we do not over-schedule tasks and trash the cache) then the +new leftmost task is picked and the current task is preempted.
The rq->fair_clock value tracks the 'CPU time a runnable task would have fairly gotten, had it been runnable during that time'. So by using @@ -64,7 +64,7 @@ Some implementation details:
replacement for the vanilla scheduler's SCHED_OTHER interactivity code.
- i'd like to give credit to Con Kolivas for the general approach here:
+ I'd like to give credit to Con Kolivas for the general approach here:
he has proven via RSDL/SD that 'fair scheduling' is possible and that it results in better desktop scheduling. Kudos Con!
@@ -92,17 +92,17 @@ Some implementation details:
setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.
- due to its design, the CFS scheduler is not prone to any of the
+ Due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected behavior.
- the CFS scheduler has a much stronger handling of nice levels and
+ The CFS scheduler has a much stronger handling of nice levels andSCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.
- ( another rdetail: due to nanosec accounting and timeline sorting,
+ ( another detail: due to nanosec accounting and timeline sorting, sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )
Re: [PATCH] CFS: sched-design-CFS.txt - ambiguity about leftmost and some formatting
Quoted 8 lines · Pranith Kumar D
The document is very clear and explains the basic mechanism of CFS very well. But, i find that the descriptions are a bit up and down. I mean, u use leftmost and rightmost before mentioning that CFS uses rbtree.( which comes much later).
In the following patch I mentioned the rbtree, the first time you talked about 'leftmost'. Also i did some basic formatting. Hope its not a pain. :)
thanks - but the patch is whitespace damaged and wont apply:
patch: **** malformed patch at line 10: 80% of CFS's design can be
that's because the leading space got stripped by your mailer.
Ingo
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH] CFS: sched-design-CFS.txt - ambiguity about leftmost and some formatting
Quoted 127 lines · Ingo Molnar
one chunk still fails:
patching file
Documentation/sched-design-CFS.txtHunk #1 FAILED at 1.
1 out of 4 hunks FAILED -- saving rejects to fileDocumentation/sched-design-CFS.txt.reji've attached my current version of sched-design-CFS.txt.
Ingo
------------------------------------------------------------------------
this is the CFS scheduler.
80% of CFS's design can be summed up in a single sentence: CFS basically models an "ideal, precise multi-tasking CPU" on real hardware.
"Ideal multi-tasking CPU" is a (non-existent :-) CPU that has 100% physical power and which can run each task at precise equal speed, in parallel, each at 1/nr_running speed. For example: if there are 2 tasks running then it runs each at 50% physical power - totally in parallel.
On real hardware, we can run only a single task at once, so while that one task runs the other tasks that are waiting for the CPU are at a disadvantage - the current task gets an unfair amount of CPU time. In CFS this fairness imbalance is expressed and tracked via the per-task
p->wait_runtime(nanosec-unit) value. "wait_runtime" is the amount of time the task should now run on the CPU for it become completely fair and balanced.( small detail: on 'ideal' hardware, the
p->wait_runtimevalue would
always be zero - no task would ever get 'out of balance' from the 'ideal' share of CPU time. )CFS's task picking logic is based on this
p->wait_runtimevalue and it is thus very simple: it always tries to run the task with the largestp->wait_runtimevalue. In other words, CFS tries to run the task with the 'gravest need' for more CPU time. So CFS always tries to split up CPU time between runnable tasks as close to 'ideal multitasking hardware' as possible.Most of the rest of CFS's design just falls out of this really simple concept, with a few add-on embellishments like nice levels, multiprocessing and various algorithm variants to recognize sleepers.
In practice it works like this: the system runs a task a bit, and when the task schedules (or a scheduler tick happens) the task's CPU usage is 'accounted for': the (small) time it just spent using the physical CPU is deducted from
p->wait_runtime. [minus the 'fair share' it would have gotten anyway]. Oncep->wait_runtimegets low enough so that another task becomes the 'leftmost task' (plus a small amount of 'granularity' distance relative to the leftmost task so that we do not over-schedule tasks and trash the cache) then the new leftmost task is picked and the current task is preempted.The
rq->fair_clockvalue tracks the 'CPU time a runnable task would have fairly gotten, had it been runnable during that time'. So by usingrq->fair_clockvalues we can accurately timestamp and measure the 'expected CPU time' a task should have gotten. All runnable tasks are sorted in the rbtree by the "rq->fair_clock-p->wait_runtime" key, and CFS picks the 'leftmost' task and sticks to it. As the system progresses forwards, newly woken tasks are put into the tree more and more to the right - slowly but surely giving a chance for every task to become the 'leftmost task' and thus get on the CPU within a deterministic amount of time.Some implementation details:
- the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy details and are handled by the scheduler core without the core code assuming about them too much.
-
sched_fair.cimplements the 'CFS desktop scheduler': it is a replacement for the vanilla scheduler'sSCHED_OTHERinteractivity code.i'd like to give credit to Con Kolivas for the general approach here:
he has proven via RSDL/SD that 'fair scheduling' is possible and that it results in better desktop scheduling. Kudos Con!The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a
kernel/sched_sd.cmodule as well, if Con is interested in such an approach. ]CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).
CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of 'timeslices' and has no heuristics whatsoever. There is only one central tunable:
/proc/sys/kernel/sched_granularity_nswhich can be used to tune the scheduler from 'desktop' (low latencies) to 'server' (good batching) workloads. It defaults to a setting suitable for desktop workloads.
SCHED_BATCHis handled by the CFS scheduler module too.due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler:fiftyp.c,thud.c,chew.c,ring-test.c,massive_intr.call work fine and do not impact interactivity and produce the expected behavior.the CFS scheduler has a much stronger handling of nice levels and
SCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.( another rdetail: due to nanosec accounting and timeline sorting,
sched_yield()support is very simple under CFS, and in fact under CFSsched_yield()behaves much better than under any other scheduler i have tested so far. )-
sched_rt.cimplementsSCHED_FIFOandSCHED_RRsemantics, in a simpler way than the vanilla scheduler does. It uses 100 runqueues (for all 100 RT priority levels, instead of 140 in the vanilla scheduler) and it needs no expired array.
Quoted 6 lines
- reworked/sanitized SMP load-balancing: the runqueue-walking assumptions are gone from the load-balancing code now, and iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result.
This should work. ( praying...)
Signed-off by: Pranith Kumar D <[email protected]>
/Documentation/sched-design-CFS.txt 2007-05-22 16:06:38.000000000 +0530 renamed from /Documentation/sched-design-CFS.txt.orig 2007-05-22 16:06:58.000000000 +0530 +1 -1
@@ -1,20 +1,20 @@ -this is the CFS scheduler. +This is the CFS scheduler.
80% of CFS's design can be summed up in a single sentence: CFS basically models an "ideal, precise multi-tasking CPU" on real hardware.
-"Ideal multi-tasking CPU" is a (non-existent :-) CPU that has 100% +"Ideal multi-tasking CPU" is a (non-existent :-)) CPU that has 100% physical power and which can run each task at precise equal speed, in parallel, each at 1/nr_running speed. For example: if there are 2 tasks running then it runs each at 50% physical power - totally in parallel.
On real hardware, we can run only a single task at once, so while that -one task runs the other tasks that are waiting for the CPU are at a +one task runs, the other tasks that are waiting for the CPU are at a disadvantage - the current task gets an unfair amount of CPU time. In CFS this fairness imbalance is expressed and tracked via the per-task p->wait_runtime (nanosec-unit) value. "wait_runtime" is the amount of -time the task should now run on the CPU for it become completely fair +time the task should now run on the CPU for it to become completely fair and balanced.
( small detail: on 'ideal' hardware, the p->wait_runtime value would @@ -37,10 +37,10 @@ the task schedules (or a scheduler tick 'accounted for': the (small) time it just spent using the physical CPU is deducted from p->wait_runtime. [minus the 'fair share' it would have gotten anyway]. Once p->wait_runtime gets low enough so that another -task becomes the 'leftmost task' (plus a small amount of 'granularity' -distance relative to the leftmost task so that we do not over-schedule -tasks and trash the cache) then the new leftmost task is picked and the -current task is preempted.
+task becomes the 'leftmost task' of the time-ordered rbtree it maintains +(plus a small amount of 'granularity' distance relative to the leftmost +task so that we do not over-schedule tasks and trash the cache) then the +new leftmost task is picked and the current task is preempted.
The rq->fair_clock value tracks the 'CPU time a runnable task would have fairly gotten, had it been runnable during that time'. So by using @@ -64,7 +64,7 @@ Some implementation details:
replacement for the vanilla scheduler's SCHED_OTHER interactivity code.
- i'd like to give credit to Con Kolivas for the general approach here:
+ I'd like to give credit to Con Kolivas for the general approach here:
he has proven via RSDL/SD that 'fair scheduling' is possible and that it results in better desktop scheduling. Kudos Con!
@@ -92,7 +92,7 @@ Some implementation details:
setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.
- due to its design, the CFS scheduler is not prone to any of the
+ Due to its design, the CFS scheduler is not prone to any of the
'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected
@@ -102,7 +102,7 @@ Some implementation details:
SCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.
- ( another rdetail: due to nanosec accounting and timeline sorting,
+ ( another detail: due to nanosec accounting and timeline sorting,
sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )
Re: [PATCH] CFS: sched-design-CFS.txt - ambiguity about leftmost and some formatting
In reply to Ingo MolnarQuoted 11 lines · Ingo Molnar
Quoted 8 lines · Pranith Kumar D
The document is very clear and explains the basic mechanism of CFS very well. But, i find that the descriptions are a bit up and down. I mean, u use leftmost and rightmost before mentioning that CFS uses rbtree.( which comes much later).
In the following patch I mentioned the rbtree, the first time you talked about 'leftmost'. Also i did some basic formatting. Hope its not a pain. :)
Quoted 5 lines
thanks - but the patch is whitespace damaged and wont apply:
patch: **** malformed patch at line 10: 80% of CFS's design can be
that's because the leading space got stripped by your mailer.
i have applied your last resent patch and it should show up in -v14. Thanks!
Ingo