APIs Related to the Completely Fair Scheduler
CFS (Completely Fair Scheduler), as the name suggests, aims to schedule fairly. It is one of the mainline schedulers and a typical O(1) scheduler.
Structures
CompletelyFairScheduler: implements theSchedulertrait and is the main driver of the CFS algorithm.FairSchedEntity- Important fields
cfs_rq: the CFS run queue this entity belongs to.my_cfs_rq: anOption.Nonewhen the entity is a single process; if the entity is a group, it must point to that group's private run queue. That queue can nest further and form a tree.pcb: thePCBof this entity. If the entity is a group, thisWeakpointer does not point to anything.
- Important fields
FairSchedEntity is the most important CFS structure. It represents one scheduling entity: a process, a group, or a user. In the CFS queue it is always just one entity. Upper layers can group processes into one entity (group scheduling) without changing the algorithm.
CFS is organized as a tree. Each entity is a node in a cfs_rq. If the entity is not a single process (for example a process group), it keeps its own cfs_rq. After nesting, every leaf is a single process. Later documents explain CFS around this tree.
See the source for the full field list. The important fields of the run queue are:
CfsRunQueue: the queue that holdsFairSchedEntityobjects. It can hang under the per-CPUCpuRunQueue, or as a child of anotherFairSchedEntity.- Important fields
entities: red-black tree of scheduling entitiescurrent: the entity currently running
- Important fields