Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


the parametersysctl_sched_child_runs_first. As the name might suggest, it determined if a newly
created child process should run before the parent. This is usually beneficial, especially if the child per-
forms anexecsystem call afterward. The default setting is 1, but this can be changed via/proc/sys/
kernel/sched_child_runs_first.

Initially, the function performs the usual statistics update withupdate_currand then employs the pre-
viously discussedplace_entity:

kernel/sched_fair.c
static void task_new_fair(struct rq *rq, struct task_struct *p)
{
struct cfs_rq *cfs_rq = task_cfs_rq(p);
struct sched_entity *se = &p->se, *curr = cfs_rq->curr;
int this_cpu = smp_processor_id();

update_curr(cfs_rq);
place_entity(cfs_rq, se, 1);
...

In this case,place_entityis, however, called withinitialset to 1, which amounts to computing the
initialvruntimewithsched_vslice_add. Recall that this determines theportion of the latency interval
that belongs to the process, but converted to virtual time. This is the scheduler’s initial debt to the process.

kernel/sched_fair.c
if (sysctl_sched_child_runs_first && curr->vruntime < se->vruntime) {
swap(curr->vruntime, se->vruntime);
}

enqueue_task_fair(rq, p, 0);
resched_task(rq->curr);
}

If the virtual run time of the parent (represented bycurr) is less than the virtual run time of the child, this
would mean that the parent runs before the child — recall that small virtual run times favor left positions
in the red-black tree. If the child is supposed to run before the parent, the virtual run times of both need
to be swapped.

Afterward, the child is enqueued into the run queue as usual, and rescheduling is requested.

2.7 The Real-Time Scheduling Class


As mandated by the POSIX standard, Linux supports two real-time scheduling classes in addition to
‘‘normal‘‘ processes. The structure of the scheduler enables real-time processes to be integrated into the
kernel without any changes in the core scheduler — this is a definitive advantage of scheduling classes.^31

Now is a good place to recall some of the facts discussed a long time ago. Real-time processes can be iden-
tified by the fact that they have ahigherpriority than normal processes — accordingly, theirstatic_prio
value is alwayslowerthan that of normal processes, as shown in Figure 2-14. Thert_taskmacro is

(^31) The completely fair scheduler needs to be aware of real-time processes in the wake-up preemption code, but this requires only very
little effort.

Free download pdf