€•ÓŠŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ./translations/zh_CN/scheduler/sched-design-CFS”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ./translations/zh_TW/scheduler/sched-design-CFS”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ./translations/it_IT/scheduler/sched-design-CFS”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ./translations/ja_JP/scheduler/sched-design-CFS”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ./translations/ko_KR/scheduler/sched-design-CFS”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ./translations/pt_BR/scheduler/sched-design-CFS”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ./translations/sp_SP/scheduler/sched-design-CFS”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒtarget”“”)”}”(hŒ.. _sched_design_CFS:”h]”h}”(h]”h ]”h"]”h$]”h&]”Œrefid”Œsched-design-cfs”uh1hµh´Khhh²hh³ŒH/var/lib/git/docbuild/linux/Documentation/scheduler/sched-design-CFS.rst”ubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒ CFS Scheduler”h]”hŒ CFS Scheduler”…””}”(hhËh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhhÆh²hh³hÃh´KubhÅ)”}”(hhh]”(hÊ)”}”(hŒ 1. OVERVIEW”h]”hŒ 1. OVERVIEW”…””}”(hhÜh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhhÙh²hh³hÃh´K ubhŒ paragraph”“”)”}”(hXvCFS stands for "Completely Fair Scheduler," and is the "desktop" process scheduler implemented by Ingo Molnar and merged in Linux 2.6.23. When originally merged, it was the replacement for the previous vanilla scheduler's SCHED_OTHER interactivity code. Nowadays, CFS is making room for EEVDF, for which documentation can be found in Documentation/scheduler/sched-eevdf.rst.”h]”hX€CFS stands for “Completely Fair Scheduler,†and is the “desktop†process scheduler implemented by Ingo Molnar and merged in Linux 2.6.23. When originally merged, it was the replacement for the previous vanilla scheduler’s SCHED_OTHER interactivity code. Nowadays, CFS is making room for EEVDF, for which documentation can be found in Documentation/scheduler/sched-eevdf.rst.”…””}”(hhìh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K hhÙh²hubhë)”}”(hŒ‡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.”h]”hŒ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.”…””}”(hhúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KhhÙh²hubhë)”}”(hX$"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 --- i.e., actually in parallel.”h]”hX(“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 --- i.e., actually in parallel.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KhhÙh²hubhë)”}”(hXlOn real hardware, we can run only a single task at once, so we have to introduce the concept of "virtual runtime." The virtual runtime of a task specifies when its next timeslice would start execution on the ideal multi-tasking CPU described above. In practice, the virtual runtime of a task is its actual runtime normalized to the total number of running tasks.”h]”hXpOn real hardware, we can run only a single task at once, so we have to introduce the concept of “virtual runtime.†The virtual runtime of a task specifies when its next timeslice would start execution on the ideal multi-tasking CPU described above. In practice, the virtual runtime of a task is its actual runtime normalized to the total number of running tasks.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KhhÙh²hubeh}”(h]”Œoverview”ah ]”h"]”Œ 1. overview”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´K ubhÅ)”}”(hhh]”(hÊ)”}”(hŒ2. FEW IMPLEMENTATION DETAILS”h]”hŒ2. FEW IMPLEMENTATION DETAILS”…””}”(hj/h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj,h²hh³hÃh´K#ubhë)”}”(hŒÙIn CFS the virtual runtime is expressed and tracked via the per-task p->se.vruntime (nanosec-unit) value. This way, it's possible to accurately timestamp and measure the "expected CPU time" a task should have gotten.”h]”hŒßIn CFS the virtual runtime is expressed and tracked via the per-task p->se.vruntime (nanosec-unit) value. This way, it’s possible to accurately timestamp and measure the “expected CPU time†a task should have gotten.”…””}”(hj=h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K%hj,h²hubhŒ block_quote”“”)”}”(hŒßSmall detail: on "ideal" hardware, at any time all tasks would have the same p->se.vruntime value --- i.e., tasks would execute simultaneously and no task would ever get "out of balance" from the "ideal" share of CPU time. ”h]”hë)”}”(hŒÞSmall detail: on "ideal" hardware, at any time all tasks would have the same p->se.vruntime value --- i.e., tasks would execute simultaneously and no task would ever get "out of balance" from the "ideal" share of CPU time.”h]”hŒêSmall detail: on “ideal†hardware, at any time all tasks would have the same p->se.vruntime value --- i.e., tasks would execute simultaneously and no task would ever get “out of balance†from the “ideal†share of CPU time.”…””}”(hjQh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K)hjMubah}”(h]”h ]”h"]”h$]”h&]”uh1jKh³hÃh´K)hj,h²hubhë)”}”(hXDCFS's task picking logic is based on this p->se.vruntime value and it is thus very simple: it always tries to run the task with the smallest p->se.vruntime value (i.e., the task which executed least so far). CFS always tries to split up CPU time between runnable tasks as close to "ideal multitasking hardware" as possible.”h]”hXJCFS’s task picking logic is based on this p->se.vruntime value and it is thus very simple: it always tries to run the task with the smallest p->se.vruntime value (i.e., the task which executed least so far). CFS always tries to split up CPU time between runnable tasks as close to “ideal multitasking hardware†as possible.”…””}”(hjeh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K-hj,h²hubhë)”}”(hŒÇ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.”h]”hŒÉ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.”…””}”(hjsh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K3hj,h²hubeh}”(h]”Œfew-implementation-details”ah ]”h"]”Œ2. few implementation details”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´K#ubhÅ)”}”(hhh]”(hÊ)”}”(hŒ3. THE RBTREE”h]”hŒ3. THE RBTREE”…””}”(hjŒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj‰h²hh³hÃh´K:ubhë)”}”(hXCFS's design is quite radical: it does not use the old data structures for the runqueues, but 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 previous vanilla scheduler and RSDL/SD are affected).”h]”hX'CFS’s design is quite radical: it does not use the old data structures for the runqueues, but 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 previous vanilla scheduler and RSDL/SD are affected).”…””}”(hjšh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kcfs.min_vruntime value, which is a monotonic increasing value tracking the smallest vruntime among all tasks in the runqueue. The total amount of work done by the system is tracked using min_vruntime; that value is used to place newly activated entities on the left side of the tree as much as possible.”h]”hXKCFS also maintains the rq->cfs.min_vruntime value, which is a monotonic increasing value tracking the smallest vruntime among all tasks in the runqueue. The total amount of work done by the system is tracked using min_vruntime; that value is used to place newly activated entities on the left side of the tree as much as possible.”…””}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KAhj‰h²hubhë)”}”(hŒ£The total number of running tasks in the runqueue is accounted through the rq->cfs.load value, which is the sum of the weights of the tasks queued on the runqueue.”h]”hŒ£The total number of running tasks in the runqueue is accounted through the rq->cfs.load value, which is the sum of the weights of the tasks queued on the runqueue.”…””}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KGhj‰h²hubhë)”}”(hX›CFS maintains a time-ordered rbtree, where all runnable tasks are sorted by the p->se.vruntime key. CFS picks the "leftmost" task from this tree and sticks to it. As the system progresses forwards, the executed 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.”h]”hX£CFS maintains a time-ordered rbtree, where all runnable tasks are sorted by the p->se.vruntime key. CFS picks the “leftmost†task from this tree and sticks to it. As the system progresses forwards, the executed 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.”…””}”(hjÄh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KKhj‰h²hubhë)”}”(hX;Summing up, CFS works like this: it 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 added to p->se.vruntime. Once p->se.vruntime gets high enough so that another 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.”h]”hXISumming up, CFS works like this: it 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 added to p->se.vruntime. Once p->se.vruntime gets high enough so that another 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.”…””}”(hjÒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KRhj‰h²hubeh}”(h]”Œ the-rbtree”ah ]”h"]”Œ 3. the rbtree”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´K:ubhÅ)”}”(hhh]”(hÊ)”}”(hŒ4. SOME FEATURES OF CFS”h]”hŒ4. SOME FEATURES OF CFS”…””}”(hjëh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjèh²hh³hÃh´K^ubhë)”}”(hXCFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of "timeslices" in the way the previous scheduler had, and has no heuristics whatsoever. There is only one central tunable:”h]”hXCFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of “timeslices†in the way the previous scheduler had, and has no heuristics whatsoever. There is only one central tunable:”…””}”(hjùh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K`hjèh²hubjL)”}”(hŒ&/sys/kernel/debug/sched/base_slice_ns ”h]”hë)”}”(hŒ%/sys/kernel/debug/sched/base_slice_ns”h]”hŒ%/sys/kernel/debug/sched/base_slice_ns”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kehjubah}”(h]”h ]”h"]”h$]”h&]”uh1jKh³hÃh´Kehjèh²hubhë)”}”(hŒìwhich can be used to tune the scheduler from "desktop" (i.e., low latencies) to "server" (i.e., good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.”h]”hŒôwhich can be used to tune the scheduler from “desktop†(i.e., low latencies) to “server†(i.e., good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kghjèh²hubhë)”}”(hŒ‚In case CONFIG_HZ results in base_slice_ns < TICK_NSEC, the value of base_slice_ns will have little to no impact on the workloads.”h]”hŒ‚In case CONFIG_HZ results in base_slice_ns < TICK_NSEC, the value of base_slice_ns will have little to no impact on the workloads.”…””}”(hj-h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kkhjèh²hubhë)”}”(hXDue 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.”h]”hXDue 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.”…””}”(hj;h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Knhjèh²hubhë)”}”(hŒ¯The CFS scheduler has a much stronger handling of nice levels and SCHED_BATCH than the previous vanilla scheduler: both types of workloads are isolated much more aggressively.”h]”hŒ¯The CFS scheduler has a much stronger handling of nice levels and SCHED_BATCH than the previous vanilla scheduler: both types of workloads are isolated much more aggressively.”…””}”(hjIh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kshjèh²hubhë)”}”(hŒæSMP load-balancing has been reworked/sanitized: 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.”h]”hŒæSMP load-balancing has been reworked/sanitized: 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.”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kwhjèh²hubeh}”(h]”Œsome-features-of-cfs”ah ]”h"]”Œ4. some features of cfs”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´K^ubhÅ)”}”(hhh]”(hÊ)”}”(hŒ5. Scheduling policies”h]”hŒ5. Scheduling policies”…””}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjmh²hh³hÃh´Kubhë)”}”(hŒ)CFS implements three scheduling policies:”h]”hŒ)CFS implements three scheduling policies:”…””}”(hj~h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Khjmh²hubjL)”}”(hXü- SCHED_NORMAL (traditionally called SCHED_OTHER): The scheduling policy that is used for regular tasks. - SCHED_BATCH: Does not preempt nearly as often as regular tasks would, thereby allowing tasks to run longer and make better use of caches but at the cost of interactivity. This is well suited for batch jobs. - SCHED_IDLE: This is even weaker than nice 19, but its not a true idle timer scheduler in order to avoid to get into priority inversion problems which would deadlock the machine. ”h]”hŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒgSCHED_NORMAL (traditionally called SCHED_OTHER): The scheduling policy that is used for regular tasks. ”h]”hë)”}”(hŒfSCHED_NORMAL (traditionally called SCHED_OTHER): The scheduling policy that is used for regular tasks.”h]”hŒfSCHED_NORMAL (traditionally called SCHED_OTHER): The scheduling policy that is used for regular tasks.”…””}”(hj›h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kƒhj—ubah}”(h]”h ]”h"]”h$]”h&]”uh1j•hj’ubj–)”}”(hŒÏSCHED_BATCH: Does not preempt nearly as often as regular tasks would, thereby allowing tasks to run longer and make better use of caches but at the cost of interactivity. This is well suited for batch jobs. ”h]”hë)”}”(hŒÎSCHED_BATCH: Does not preempt nearly as often as regular tasks would, thereby allowing tasks to run longer and make better use of caches but at the cost of interactivity. This is well suited for batch jobs.”h]”hŒÎSCHED_BATCH: Does not preempt nearly as often as regular tasks would, thereby allowing tasks to run longer and make better use of caches but at the cost of interactivity. This is well suited for batch jobs.”…””}”(hj³h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K†hj¯ubah}”(h]”h ]”h"]”h$]”h&]”uh1j•hj’ubj–)”}”(hŒ²SCHED_IDLE: This is even weaker than nice 19, but its not a true idle timer scheduler in order to avoid to get into priority inversion problems which would deadlock the machine. ”h]”hë)”}”(hŒ±SCHED_IDLE: This is even weaker than nice 19, but its not a true idle timer scheduler in order to avoid to get into priority inversion problems which would deadlock the machine.”h]”hŒ±SCHED_IDLE: This is even weaker than nice 19, but its not a true idle timer scheduler in order to avoid to get into priority inversion problems which would deadlock the machine.”…””}”(hjËh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K‹hjÇubah}”(h]”h ]”h"]”h$]”h&]”uh1j•hj’ubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jh³hÃh´KƒhjŒubah}”(h]”h ]”h"]”h$]”h&]”uh1jKh³hÃh´Kƒhjmh²hubhë)”}”(hŒKSCHED_FIFO/_RR are implemented in sched/rt.c and are as specified by POSIX.”h]”hŒKSCHED_FIFO/_RR are implemented in sched/rt.c and are as specified by POSIX.”…””}”(hjíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Khjmh²hubhë)”}”(hŒTThe command chrt from util-linux-ng 2.13.1.1 can set all of these except SCHED_IDLE.”h]”hŒTThe command chrt from util-linux-ng 2.13.1.1 can set all of these except SCHED_IDLE.”…””}”(hjûh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K’hjmh²hubeh}”(h]”Œscheduling-policies”ah ]”h"]”Œ5. scheduling policies”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´KubhÅ)”}”(hhh]”(hÊ)”}”(hŒ6. SCHEDULING CLASSES”h]”hŒ6. SCHEDULING CLASSES”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjh²hh³hÃh´K˜ubhë)”}”(hXThe new CFS scheduler has been designed in such a way to introduce "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 too much about them.”h]”hXThe new CFS scheduler has been designed in such a way to introduce “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 too much about them.”…””}”(hj"h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kšhjh²hubhë)”}”(hŒ:sched/fair.c implements the CFS scheduler described above.”h]”hŒ:sched/fair.c implements the CFS scheduler described above.”…””}”(hj0h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KŸhjh²hubhë)”}”(hŒósched/rt.c implements SCHED_FIFO and SCHED_RR semantics, in a simpler way than the previous vanilla scheduler did. It uses 100 runqueues (for all 100 RT priority levels, instead of 140 in the previous scheduler) and it needs no expired array.”h]”hŒósched/rt.c implements SCHED_FIFO and SCHED_RR semantics, in a simpler way than the previous vanilla scheduler did. It uses 100 runqueues (for all 100 RT priority levels, instead of 140 in the previous scheduler) and it needs no expired array.”…””}”(hj>h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K¡hjh²hubhë)”}”(hŒ¡Scheduling classes are implemented through the sched_class structure, which contains hooks to functions that must be called whenever an interesting event occurs.”h]”hŒ¡Scheduling classes are implemented through the sched_class structure, which contains hooks to functions that must be called whenever an interesting event occurs.”…””}”(hjLh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K¦hjh²hubhë)”}”(hŒ(This is the (partial) list of the hooks:”h]”hŒ(This is the (partial) list of the hooks:”…””}”(hjZh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kªhjh²hubjL)”}”(hX#- enqueue_task(...) Called when a task enters a runnable state. It puts the scheduling entity (task) into the red-black tree and increments the nr_running variable. - dequeue_task(...) When a task is no longer runnable, this function is called to keep the corresponding scheduling entity out of the red-black tree. It decrements the nr_running variable. - yield_task(...) This function yields the CPU by moving the currently running task's position back in the runqueue, so that other runnable tasks get scheduled first. - wakeup_preempt(...) This function checks if a task that entered the runnable state should preempt the currently running task. - pick_next_task(...) This function chooses the most appropriate task eligible to run next. - set_next_task(...) This function is called when a task changes its scheduling class, changes its task group or is scheduled. - task_tick(...) This function is mostly called from time tick functions; it might lead to process switch. This drives the running preemption. ”h]”j‘)”}”(hhh]”(j–)”}”(hŒ¤enqueue_task(...) Called when a task enters a runnable state. It puts the scheduling entity (task) into the red-black tree and increments the nr_running variable. ”h]”(hë)”}”(hŒenqueue_task(...)”h]”hŒenqueue_task(...)”…””}”(hjsh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K¬hjoubhë)”}”(hŒCalled when a task enters a runnable state. It puts the scheduling entity (task) into the red-black tree and increments the nr_running variable.”h]”hŒCalled when a task enters a runnable state. It puts the scheduling entity (task) into the red-black tree and increments the nr_running variable.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K®hjoubeh}”(h]”h ]”h"]”h$]”h&]”uh1j•hjlubj–)”}”(hŒ½dequeue_task(...) When a task is no longer runnable, this function is called to keep the corresponding scheduling entity out of the red-black tree. It decrements the nr_running variable. ”h]”(hë)”}”(hŒdequeue_task(...)”h]”hŒdequeue_task(...)”…””}”(hj™h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K²hj•ubhë)”}”(hŒ©When a task is no longer runnable, this function is called to keep the corresponding scheduling entity out of the red-black tree. It decrements the nr_running variable.”h]”hŒ©When a task is no longer runnable, this function is called to keep the corresponding scheduling entity out of the red-black tree. It decrements the nr_running variable.”…””}”(hj§h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K´hj•ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j•hjlubj–)”}”(hŒ¦yield_task(...) This function yields the CPU by moving the currently running task's position back in the runqueue, so that other runnable tasks get scheduled first. ”h]”(hë)”}”(hŒyield_task(...)”h]”hŒyield_task(...)”…””}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K¸hj»ubhë)”}”(hŒ”This function yields the CPU by moving the currently running task's position back in the runqueue, so that other runnable tasks get scheduled first.”h]”hŒ–This function yields the CPU by moving the currently running task’s position back in the runqueue, so that other runnable tasks get scheduled first.”…””}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kºhj»ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j•hjlubj–)”}”(hŒwakeup_preempt(...) This function checks if a task that entered the runnable state should preempt the currently running task. ”h]”(hë)”}”(hŒwakeup_preempt(...)”h]”hŒwakeup_preempt(...)”…””}”(hjåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K½hjáubhë)”}”(hŒiThis function checks if a task that entered the runnable state should preempt the currently running task.”h]”hŒiThis function checks if a task that entered the runnable state should preempt the currently running task.”…””}”(hjóh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´K¿hjáubeh}”(h]”h ]”h"]”h$]”h&]”uh1j•hjlubj–)”}”(hŒ[pick_next_task(...) This function chooses the most appropriate task eligible to run next. ”h]”(hë)”}”(hŒpick_next_task(...)”h]”hŒpick_next_task(...)”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KÂhjubhë)”}”(hŒEThis function chooses the most appropriate task eligible to run next.”h]”hŒEThis function chooses the most appropriate task eligible to run next.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KÄhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1j•hjlubj–)”}”(hŒ~set_next_task(...) This function is called when a task changes its scheduling class, changes its task group or is scheduled. ”h]”(hë)”}”(hŒset_next_task(...)”h]”hŒset_next_task(...)”…””}”(hj1h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KÆhj-ubhë)”}”(hŒiThis function is called when a task changes its scheduling class, changes its task group or is scheduled.”h]”hŒiThis function is called when a task changes its scheduling class, changes its task group or is scheduled.”…””}”(hj?h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KÈhj-ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j•hjlubj–)”}”(hŒ’task_tick(...) This function is mostly called from time tick functions; it might lead to process switch. This drives the running preemption. ”h]”(hë)”}”(hŒtask_tick(...)”h]”hŒtask_tick(...)”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KËhjSubhë)”}”(hŒ~This function is mostly called from time tick functions; it might lead to process switch. This drives the running preemption.”h]”hŒ~This function is mostly called from time tick functions; it might lead to process switch. This drives the running preemption.”…””}”(hjeh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KÍhjSubeh}”(h]”h ]”h"]”h$]”h&]”uh1j•hjlubeh}”(h]”h ]”h"]”h$]”h&]”jåjæuh1jh³hÃh´K¬hjhubah}”(h]”h ]”h"]”h$]”h&]”uh1jKh³hÃh´K¬hjh²hubeh}”(h]”Œscheduling-classes”ah ]”h"]”Œ6. scheduling classes”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´K˜ubhÅ)”}”(hhh]”(hÊ)”}”(hŒ%7. GROUP SCHEDULER EXTENSIONS TO CFS”h]”hŒ%7. GROUP SCHEDULER EXTENSIONS TO CFS”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjh²hh³hÃh´KÔubhë)”}”(hXPNormally, the scheduler operates on individual tasks and strives to provide fair CPU time to each task. Sometimes, it may be desirable to group tasks and provide fair CPU time to each such task group. For example, it may be desirable to first provide fair CPU time to each user on the system and then to each task belonging to a user.”h]”hXPNormally, the scheduler operates on individual tasks and strives to provide fair CPU time to each task. Sometimes, it may be desirable to group tasks and provide fair CPU time to each such task group. For example, it may be desirable to first provide fair CPU time to each user on the system and then to each task belonging to a user.”…””}”(hjžh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KÖhjh²hubhë)”}”(hŒ€CONFIG_CGROUP_SCHED strives to achieve exactly that. It lets tasks to be grouped and divides CPU time fairly among such groups.”h]”hŒ€CONFIG_CGROUP_SCHED strives to achieve exactly that. It lets tasks to be grouped and divides CPU time fairly among such groups.”…””}”(hj¬h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KÜhjh²hubhë)”}”(hŒWCONFIG_RT_GROUP_SCHED permits to group real-time (i.e., SCHED_FIFO and SCHED_RR) tasks.”h]”hŒWCONFIG_RT_GROUP_SCHED permits to group real-time (i.e., SCHED_FIFO and SCHED_RR) tasks.”…””}”(hjºh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kßhjh²hubhë)”}”(hŒXCONFIG_FAIR_GROUP_SCHED permits to group CFS (i.e., SCHED_NORMAL and SCHED_BATCH) tasks.”h]”hŒXCONFIG_FAIR_GROUP_SCHED permits to group CFS (i.e., SCHED_NORMAL and SCHED_BATCH) tasks.”…””}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kâhjh²hubjL)”}”(hŒôThese options need CONFIG_CGROUPS to be defined, and let the administrator create arbitrary groups of tasks, using the "cgroup" pseudo filesystem. See Documentation/admin-guide/cgroup-v1/cgroups.rst for more information about this filesystem. ”h]”hë)”}”(hŒóThese options need CONFIG_CGROUPS to be defined, and let the administrator create arbitrary groups of tasks, using the "cgroup" pseudo filesystem. See Documentation/admin-guide/cgroup-v1/cgroups.rst for more information about this filesystem.”h]”hŒ÷These options need CONFIG_CGROUPS to be defined, and let the administrator create arbitrary groups of tasks, using the “cgroup†pseudo filesystem. See Documentation/admin-guide/cgroup-v1/cgroups.rst for more information about this filesystem.”…””}”(hjÚh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´KåhjÖubah}”(h]”h ]”h"]”h$]”h&]”uh1jKh³hÃh´Kåhjh²hubhë)”}”(hŒíWhen CONFIG_FAIR_GROUP_SCHED is defined, a "cpu.shares" file is created for each group created using the pseudo filesystem. See example steps below to create task groups and modify their CPU share using the "cgroups" pseudo filesystem::”h]”hŒôWhen CONFIG_FAIR_GROUP_SCHED is defined, a “cpu.shares†file is created for each group created using the pseudo filesystem. See example steps below to create task groups and modify their CPU share using the “cgroups†pseudo filesystem:”…””}”(hjîh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hêh³hÃh´Kéhjh²hubhŒ literal_block”“”)”}”(hXs# mount -t tmpfs cgroup_root /sys/fs/cgroup # mkdir /sys/fs/cgroup/cpu # mount -t cgroup -ocpu none /sys/fs/cgroup/cpu # cd /sys/fs/cgroup/cpu # mkdir multimedia # create "multimedia" group of tasks # mkdir browser # create "browser" group of tasks # #Configure the multimedia group to receive twice the CPU bandwidth # #that of browser group # echo 2048 > multimedia/cpu.shares # echo 1024 > browser/cpu.shares # firefox & # Launch firefox and move it to "browser" group # echo > browser/tasks # #Launch gmplayer (or your favourite movie player) # echo > multimedia/tasks”h]”hXs# mount -t tmpfs cgroup_root /sys/fs/cgroup # mkdir /sys/fs/cgroup/cpu # mount -t cgroup -ocpu none /sys/fs/cgroup/cpu # cd /sys/fs/cgroup/cpu # mkdir multimedia # create "multimedia" group of tasks # mkdir browser # create "browser" group of tasks # #Configure the multimedia group to receive twice the CPU bandwidth # #that of browser group # echo 2048 > multimedia/cpu.shares # echo 1024 > browser/cpu.shares # firefox & # Launch firefox and move it to "browser" group # echo > browser/tasks # #Launch gmplayer (or your favourite movie player) # echo > multimedia/tasks”…””}”hjþsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1jüh³hÃh´Kíhjh²hubeh}”(h]”Œ!group-scheduler-extensions-to-cfs”ah ]”h"]”Œ$7. group scheduler extensions to cfs”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´KÔubeh}”(h]”(Œ cfs-scheduler”hÂeh ]”h"]”(Œ cfs scheduler”Œsched_design_cfs”eh$]”h&]”uh1hÄhhh²hh³hÃh´KŒexpect_referenced_by_name”}”jh·sŒexpect_referenced_by_id”}”hÂh·subeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÃuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hÉNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jFŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÃŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”hÂ]”h·asŒnameids”}”(jhÂjjj)j&j†jƒjåjâjjjgjj jŠj‡jjuŒ nametypes”}”(jˆj‰j)‰j†‰jå‰jj‰j‰jЉj‰uh}”(hÂhÆjhÆj&hÙjƒj,jâj‰jgjèj jmj‡jjjuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”hŒsystem_message”“”)”}”(hhh]”hë)”}”(hhh]”hŒ6Hyperlink target "sched-design-cfs" is not referenced.”…””}”hj°sbah}”(h]”h ]”h"]”h$]”h&]”uh1hêhj­ubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”ŒINFO”Œsource”hÃŒline”Kuh1j«ubaŒ transformer”NŒ include_log”]”Œ decoration”Nh²hub.