Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) CFS Scheduler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 1.  OVERVIEW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) CFS stands for "Completely Fair Scheduler," and is the new "desktop" process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) scheduler implemented by Ingo Molnar and merged in Linux 2.6.23.  It is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) replacement for the previous vanilla scheduler's SCHED_OTHER interactivity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 80% of CFS's design can be summed up in a single sentence: CFS basically models
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) an "ideal, precise multi-tasking CPU" on real hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) "Ideal multi-tasking CPU" is a (non-existent  :-)) CPU that has 100% physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) power and which can run each task at precise equal speed, in parallel, each at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 1/nr_running speed.  For example: if there are 2 tasks running, then it runs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) each at 50% physical power --- i.e., actually in parallel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) On real hardware, we can run only a single task at once, so we have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) introduce the concept of "virtual runtime."  The virtual runtime of a task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) specifies when its next timeslice would start execution on the ideal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) multi-tasking CPU described above.  In practice, the virtual runtime of a task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) is its actual runtime normalized to the total number of running tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 2.  FEW IMPLEMENTATION DETAILS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) ==============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) In CFS the virtual runtime is expressed and tracked via the per-task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) p->se.vruntime (nanosec-unit) value.  This way, it's possible to accurately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) timestamp and measure the "expected CPU time" a task should have gotten.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) [ small detail: on "ideal" hardware, at any time all tasks would have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)   p->se.vruntime value --- i.e., tasks would execute simultaneously and no task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)   would ever get "out of balance" from the "ideal" share of CPU time.  ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) CFS's task picking logic is based on this p->se.vruntime value and it is thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) very simple: it always tries to run the task with the smallest p->se.vruntime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) value (i.e., the task which executed least so far).  CFS always tries to split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) up CPU time between runnable tasks as close to "ideal multitasking hardware" as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) Most of the rest of CFS's design just falls out of this really simple concept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) with a few add-on embellishments like nice levels, multiprocessing and various
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) algorithm variants to recognize sleepers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 3.  THE RBTREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) ==============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) CFS's design is quite radical: it does not use the old data structures for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) runqueues, but it uses a time-ordered rbtree to build a "timeline" of future
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) task execution, and thus has no "array switch" artifacts (by which both the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) previous vanilla scheduler and RSDL/SD are affected).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) CFS also maintains the rq->cfs.min_vruntime value, which is a monotonic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) increasing value tracking the smallest vruntime among all tasks in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) runqueue.  The total amount of work done by the system is tracked using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) min_vruntime; that value is used to place newly activated entities on the left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) side of the tree as much as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) The total number of running tasks in the runqueue is accounted through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) rq->cfs.load value, which is the sum of the weights of the tasks queued on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) runqueue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) CFS maintains a time-ordered rbtree, where all runnable tasks are sorted by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) p->se.vruntime key. CFS picks the "leftmost" task from this tree and sticks to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) As the system progresses forwards, the executed tasks are put into the tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) more and more to the right --- slowly but surely giving a chance for every task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) to become the "leftmost task" and thus get on the CPU within a deterministic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) amount of time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) Summing up, CFS works like this: it runs a task a bit, and when the task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) schedules (or a scheduler tick happens) the task's CPU usage is "accounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) for": the (small) time it just spent using the physical CPU is added to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) p->se.vruntime.  Once p->se.vruntime gets high enough so that another task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) becomes the "leftmost task" of the time-ordered rbtree it maintains (plus a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) small amount of "granularity" distance relative to the leftmost task so that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) do not over-schedule tasks and trash the cache), then the new leftmost task is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) picked and the current task is preempted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 4.  SOME FEATURES OF CFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) ========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) CFS uses nanosecond granularity accounting and does not rely on any jiffies or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) other HZ detail.  Thus the CFS scheduler has no notion of "timeslices" in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) way the previous scheduler had, and has no heuristics whatsoever.  There is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) only one central tunable (you have to switch on CONFIG_SCHED_DEBUG):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)    /proc/sys/kernel/sched_min_granularity_ns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) which can be used to tune the scheduler from "desktop" (i.e., low latencies) to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) "server" (i.e., good batching) workloads.  It defaults to a setting suitable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) for desktop workloads.  SCHED_BATCH is handled by the CFS scheduler module too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) Due to its design, the CFS scheduler is not prone to any of the "attacks" that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) exist today against the heuristics of the stock scheduler: fiftyp.c, thud.c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) chew.c, ring-test.c, massive_intr.c all work fine and do not impact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) interactivity and produce the expected behavior.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) The CFS scheduler has a much stronger handling of nice levels and SCHED_BATCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) than the previous vanilla scheduler: both types of workloads are isolated much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) more aggressively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) SMP load-balancing has been reworked/sanitized: the runqueue-walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) assumptions are gone from the load-balancing code now, and iterators of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) scheduling modules are used.  The balancing code got quite a bit simpler as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 5. Scheduling policies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) CFS implements three scheduling policies:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)   - SCHED_NORMAL (traditionally called SCHED_OTHER): The scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)     policy that is used for regular tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)   - SCHED_BATCH: Does not preempt nearly as often as regular tasks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)     would, thereby allowing tasks to run longer and make better use of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)     caches but at the cost of interactivity. This is well suited for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)     batch jobs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)   - SCHED_IDLE: This is even weaker than nice 19, but its not a true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)     idle timer scheduler in order to avoid to get into priority
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)     inversion problems which would deadlock the machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) SCHED_FIFO/_RR are implemented in sched/rt.c and are as specified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) POSIX.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) The command chrt from util-linux-ng 2.13.1.1 can set all of these except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) SCHED_IDLE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 6.  SCHEDULING CLASSES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) The new CFS scheduler has been designed in such a way to introduce "Scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) Classes," an extensible hierarchy of scheduler modules.  These modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) encapsulate scheduling policy details and are handled by the scheduler core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) without the core code assuming too much about them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) sched/fair.c implements the CFS scheduler described above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) sched/rt.c implements SCHED_FIFO and SCHED_RR semantics, in a simpler way than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) the previous vanilla scheduler did.  It uses 100 runqueues (for all 100 RT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) priority levels, instead of 140 in the previous scheduler) and it needs no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) expired array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) Scheduling classes are implemented through the sched_class structure, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) contains hooks to functions that must be called whenever an interesting event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) This is the (partial) list of the hooks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  - enqueue_task(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)    Called when a task enters a runnable state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)    It puts the scheduling entity (task) into the red-black tree and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)    increments the nr_running variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  - dequeue_task(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)    When a task is no longer runnable, this function is called to keep the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)    corresponding scheduling entity out of the red-black tree.  It decrements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)    the nr_running variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  - yield_task(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)    This function is basically just a dequeue followed by an enqueue, unless the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)    compat_yield sysctl is turned on; in that case, it places the scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)    entity at the right-most end of the red-black tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  - check_preempt_curr(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)    This function checks if a task that entered the runnable state should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)    preempt the currently running task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  - pick_next_task(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)    This function chooses the most appropriate task eligible to run next.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  - set_curr_task(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)    This function is called when a task changes its scheduling class or changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)    its task group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  - task_tick(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)    This function is mostly called from time tick functions; it might lead to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)    process switch.  This drives the running preemption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 7.  GROUP SCHEDULER EXTENSIONS TO CFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) =====================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) Normally, the scheduler operates on individual tasks and strives to provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) fair CPU time to each task.  Sometimes, it may be desirable to group tasks and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) provide fair CPU time to each such task group.  For example, it may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) desirable to first provide fair CPU time to each user on the system and then to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) each task belonging to a user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) CONFIG_CGROUP_SCHED strives to achieve exactly that.  It lets tasks to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) grouped and divides CPU time fairly among such groups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) CONFIG_RT_GROUP_SCHED permits to group real-time (i.e., SCHED_FIFO and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) SCHED_RR) tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) CONFIG_FAIR_GROUP_SCHED permits to group CFS (i.e., SCHED_NORMAL and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) SCHED_BATCH) tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)    These options need CONFIG_CGROUPS to be defined, and let the administrator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)    create arbitrary groups of tasks, using the "cgroup" pseudo filesystem.  See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)    Documentation/admin-guide/cgroup-v1/cgroups.rst for more information about this filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) When CONFIG_FAIR_GROUP_SCHED is defined, a "cpu.shares" file is created for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) group created using the pseudo filesystem.  See example steps below to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) task groups and modify their CPU share using the "cgroups" pseudo filesystem::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	# mount -t tmpfs cgroup_root /sys/fs/cgroup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	# mkdir /sys/fs/cgroup/cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	# mount -t cgroup -ocpu none /sys/fs/cgroup/cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	# cd /sys/fs/cgroup/cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	# mkdir multimedia	# create "multimedia" group of tasks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	# mkdir browser		# create "browser" group of tasks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	# #Configure the multimedia group to receive twice the CPU bandwidth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	# #that of browser group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	# echo 2048 > multimedia/cpu.shares
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	# echo 1024 > browser/cpu.shares
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	# firefox &	# Launch firefox and move it to "browser" group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	# echo <firefox_pid> > browser/tasks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	# #Launch gmplayer (or your favourite movie player)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	# echo <movie_player_pid> > multimedia/tasks