Chapter 2: Process Management and Scheduling
computed assysctl_sched_latency/sysctl_sched_min_granularityeach time one of the values is
changed.
__sched_perioddetermines the length of the latency period, which is usually just
sysctl_sched_latency, but is extended linearly if more processes are running. In this case, the
period length is
sysctl_sched_latency×
nr_running
sched_nr_latency
.
Distribution of the time among active processes in one latency period is performed by considering the rel-
ative weights of the respective tasks. The slice length for a given process as represented by a schedulable
entity is computed as follows:
kernel/sched_fair.c
static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
u64 slice = __sched_period(cfs_rq->nr_running);
slice *= se->load.weight;
do_div(slice, cfs_rq->load.weight);
return slice;
}
Recall that the run queue load weight accumulates the load weights of all active processes on the queue.
The resulting time slice is given in real time, but the kernel sometimes also needs to know the equivalent
in virtual time.
kernel/sched_fair.c
static u64 __sched_vslice(unsigned long rq_weight, unsigned long nr_running)
{
u64 vslice = __sched_period(nr_running);
vslice *= NICE_0_LOAD;
do_div(vslice, rq_weight);
return vslice;
}
static u64 sched_vslice(struct cfs_rq *cfs_rq)
{
return __sched_vslice(cfs_rq->load.weight, cfs_rq->nr_running);
}
Recall that a real-time intervaltimefor a process with a givenweighthas the length
time×
NICE_0_LOAD
weight
,
and this is also used to transfer the latency interval portion.
Now we have everything in place to discuss the various methods that must be implemented by CFS to
interact with the global scheduler.