Chapter 2: Process Management and Scheduling
2.6 The Completely Fair Scheduling Class
All information that the core scheduler needs to know about the completely fair scheduler is contained
infair_sched_class:kernel/sched_fair.c
static const struct sched_class fair_sched_class = {
.next = &idle_sched_class,
.enqueue_task = enqueue_task_fair,
.dequeue_task = dequeue_task_fair,
.yield_task = yield_task_fair,.check_preempt_curr = check_preempt_wakeup,.pick_next_task = pick_next_task_fair,
.put_prev_task = put_prev_task_fair,
...
.set_curr_task = set_curr_task_fair,
.task_tick = task_tick_fair,
.task_new = task_new_fair,
};We have seen in the previous discussion when these functions are called by the main scheduler and will
examine in the following how they are implemented for CFS.2.6.1 Data Structures
First, I need to introduce how the CFS run queue looks. Recall that an instance is embedded into each
per-CPU run queue of the main scheduler:kernel/sched.c
struct cfs_rq {
struct load_weight load;
unsigned long nr_running;u64 min_vruntime;struct rb_root tasks_timeline;
struct rb_node *rb_leftmost;struct sched_entity *curr;
}The individual elements have the following meaning:❑ nr_runningcounts the number of runnable processes on the queue, andloadmaintains the
cumulative load values of them all. Recall that you have already encountered the load calcu-
lation in Section 2.5.3.
❑ min_vruntimetracks the minimum virtual run time of all processes on the queue. This value
forms the basis to implement the virtual clock associated with a run queue. The name is slightly
confusing becausemin_vruntimecan actually be bigger than thevruntimesetting of the leftmost