Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


❑ loadprovides a measure for the current load on the run queue. The queue load is essentially
proportional to the number of currently active processes on the queue, where each process is
additionally weighted by its priority. The speed of the virtual per-run queue clock is based on
this information. Since computing the load and other related quantities is an important com-
ponent of the scheduling algorithm, I devote Section 2.5.3 below to a detailed discussion of the
mechanisms involved.
❑ cpu_loadallows for tracking the load behavior back into the past.
❑ cfsandrtare the embedded sub-run queues for the completely fair and real-time scheduler,
respectively.
❑ currpoints to the task structure of the process currently running.
❑ idlepoints to the task structure of the idle process called when no other runnable process is
available — the idle thread.
❑ clockandprev_raw_clockare used to implement the per-run queue clock. The value ofclock
is updated each time the periodic scheduler is called. Additionally, the kernel provides the stan-
dard functionupdate_rq_clockthat is called from many places in the scheduler that manipulate
the run queue, for instance, when a new task is woken up inwakeup_new_task.

All run queues of the system are held in therunqueuesarray, which contains an element for each CPU in
the system. On single-processor systems, there is, of course, just one element because only one run queue
is required.

kernel/sched.c
static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);

The kernel also defines a number of convenient macros, which are self-explanatory.

kernel/sched.c
#define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
#define this_rq() (&__get_cpu_var(runqueues))
#define task_rq(p) cpu_rq(task_cpu(p))
#define cpu_curr(cpu) (cpu_rq(cpu)->curr)

SchedulingEntities


Since the scheduler can operate with more general entities than tasks, an appropriate data structure is
required to describe such an entity. It is defined as follows:

<sched.h>
struct sched_entity {
struct load_weight load; /* for load-balancing */
struct rb_node run_node;
unsigned int on_rq;

u64 exec_start;
u64 sum_exec_runtime;
u64 vruntime;
u64 prev_sum_exec_runtime;
...
}
Free download pdf