Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


More than one process running?

Latency limit exceeded?

entity_tick

update_curr

resched_task

Check_preempt_tick

Figure 2-22: Code flow diagram forentity_tick.

First of all, the statistics are — as always — updated usingupdate_curr.Ifthenr_runningcounter of
the queue indicates that fewer than two processes are runnable on the queue, nothing needs to be done.
If a process is supposed to be preempted, there needs to be at least another one thatcouldpreempt it.
Otherwise, the decision is left tocheck_preempt_tick:

kernel/sched_fair.c
static void
check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
{
unsigned long ideal_runtime, delta_exec;

ideal_runtime = sched_slice(cfs_rq, curr);
delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
if (delta_exec > ideal_runtime)
resched_task(rq_of(cfs_rq)->curr);
}

The purpose of the function is to ensure that no process runs longer than specified by its share of
the latency period. This length of this share in real-time is computed insched_slice,andthereal-
time interval during which the process has been running on the CPU is given bysum_exec_runtime


  • prev_sum_exec_runtimeas explained above. The preemption decision is thus easy: If the task has been
    running for longer than the desired time interval, a reschedule is requested withresched_task.Thissets
    theTIF_NEED_RESCHEDflag in the task structure, and the core scheduler will initiate a rescheduling at the
    next opportune moment.


2.6.6 Wake-up Preemption


When tasks are woken up intry_to_wake_upandwake_up_new_task, the kernel uses
check_preempt_currto see if the new task can preempt the currently running one. Notice that
the core scheduler is not involved in this process! For completely fair handled tasks, the functioncheck_
preempt_wakeupperforms the desired check.
Free download pdf