Handling New Tasks

The last operation of the completely fair scheduler that we need to consider is the hook function that is called when new tasks are created: task_new_fair. The behavior of the function is controllable with the parameter sysctl_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 performs an exec system 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 with update_curr and then employs the previously discussed place_entity:

kernel/sched_fair.c static void task_new_fair(struct rq *rq, struct {

struct cfs_rq *cfs_rq = task_cfs_rq(p); struct sched_entity *se = &p->se, *curr int this_cpu = smp_processor_id();

In this case, place_entity is, however, called with initial set to 1, which amounts to computing the initial vruntime with sched_vslice_add. Recall that this determines the portion 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 by curr) 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.

Continue reading here: The Real Time Scheduling Class

Was this article helpful?

0 0