Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


kernel/sched_fair.c
static void
set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
/* ’current’ is not kept within the tree. */
if (se->on_rq) {
__dequeue_entity(cfs_rq, se);
}
...

No processes running?

Leftmost task in red-black tree available?

pick_next_task_fair

pick_next_entity

set_next_entity

return

__pick_next_entity

Figure 2-21: Code flow diagram forpick_next_task_fair.

The currently executing processisnotkeptontherunqueue,so__dequeue_entityremoves it from
the red-black tree, setting theleftmostpointer to the next leftmost task if the current task has been the
leftmost one. Notice that in our case, the process has been on the run queue for sure, but this need not be
the case whenset_next_entityis called from different places.

Although the process is not contained in the red-black tree anymore, the connection between process and
run queue is not lost, becausecurrmarks it as the running one now:

kernel/sched_fair.c
cfs_rq->curr = se;
se->prev_sum_exec_runtime = se->sum_exec_runtime;
}

Because the process is now the currently active one, the real time spent on the CPU will be charged
tosum_exec_runtime, so the kernel preserves the previous setting inprev_sum_exec_runtime.Note
thatsum_exec_runtimeisnotreset in the process. The differencesum_exec_runtime - prev_sum_
exec_runtimedoes therefore denote the real time spent executing on a CPU.

2.6.5 Handling the Periodic Tick


This aforementioned difference is important when the periodic tick is handled. The formally responsible
function istask_tick_fair, but the real work is done inentity_tick. Figure 2-22 presents the code flow
diagram.
Free download pdf