€•ÊŠŒ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Œ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.”…””}”(hhôhž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”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hµhjhž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%hjhž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.”…””}”(hj=hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h K)hj9ubah}”(h]”h ]”h"]”h$]”h&]”uh1j7hŸh¯h K)hjhž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.”…””}”(hjQhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h K-hjhž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.”…””}”(hj_hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h K3hjhž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”…””}”(hjxhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hµhjuhž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 KAhjuhž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 KGhjuhž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 KKhjuhž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 KRhjuhž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žhubj8)”}”(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 Kehjóubah}”(h]”h ]”h"]”h$]”h&]”uh1j7hŸ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.”…””}”(hj hž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.”…””}”(hjhž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.”…””}”(hj5hž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.”…””}”(hjChž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”…””}”(hj\hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hµhjYhžhhŸh¯h Kubh×)”}”(hŒ)CFS implements three scheduling policies:”h]”hŒ)CFS implements three scheduling policies:”…””}”(hjjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h KhjYhžhubj8)”}”(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&]”uh1jhj~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&]”uh1jhj~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&]”uh1jhj~ubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1j|hŸh¯h Kƒhjxubah}”(h]”h ]”h"]”h$]”h&]”uh1j7hŸh¯h KƒhjYhž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 KhjYhž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’hjYhž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µhjýhž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.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h Kšhjýhžhubh×)”}”(hŒ:sched/fair.c implements the CFS scheduler described above.”h]”hŒ:sched/fair.c implements the CFS scheduler described above.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h KŸhjýhž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¡hjýhž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.”…””}”(hj8hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h K¦hjýhžhubh×)”}”(hŒ(This is the (partial) list of the hooks:”h]”hŒ(This is the (partial) list of the hooks:”…””}”(hjFhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h Kªhjýhžhubj8)”}”(hXZ- 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 is basically just a dequeue followed by an enqueue, unless the compat_yield sysctl is turned on; in that case, it places the scheduling entity at the right-most end of the red-black tree. - 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(...)”…””}”(hj_hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h K¬hj[ubh×)”}”(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.”…””}”(hjmhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h K®hj[ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjXubj‚)”}”(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²hjubh×)”}”(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´hjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjXubj‚)”}”(hŒÛyield_task(...) This function is basically just a dequeue followed by an enqueue, unless the compat_yield sysctl is turned on; in that case, it places the scheduling entity at the right-most end of the red-black tree. ”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 is basically just a dequeue followed by an enqueue, unless the compat_yield sysctl is turned on; in that case, it places the scheduling entity at the right-most end of the red-black tree.”h]”hŒÉThis function is basically just a dequeue followed by an enqueue, unless the compat_yield sysctl is turned on; in that case, it places the scheduling entity at the right-most end of the red-black tree.”…””}”(hj¹hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h Kºhj§ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjXubj‚)”}”(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&]”uh1jhjXubj‚)”}”(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Ãhjóubh×)”}”(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Åhjóubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjXubj‚)”}”(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(...)”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h KÇhjubh×)”}”(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Éhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjXubj‚)”}”(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(...)”…””}”(hjChžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h KÌhj?ubh×)”}”(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.”…””}”(hjQhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖhŸh¯h KÎhj?ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjXubeh}”(h]”h ]”h"]”h$]”h&]”jÑjÒuh1j|hŸh¯h K¬hjTubah}”(h]”h ]”h"]”h$]”h&]”uh1j7hŸh¯h K¬hjýhž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”…””}”(hj|hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hµhjyhž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×hjyhž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Ýhjyhž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àhjyhž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ãhjyhžhubj8)”}”(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&]”uh1j7hŸh¯h Kæhjyhž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êhjyhž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îhjyhž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”j2Œ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®jjjjjrjojÑjÎjVjSjúj÷jvjsjÿjüuŒ nametypes”}”(jˆj‰j‰jr‰jщjV‰jú‰jv‰jÿ‰uh}”(h®h²jh²jhÅjojjÎjujSjÔj÷jYjsjýjüjyuŒ 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.