Data Structures Used by the Scheduler
Recall from the section "Identifying a Process" in
Chapter 3 that the process
list links all process descriptors, while the runqueue lists link the
process descriptors of all runnable processes—that is, of those in a
TASK_RUNNING state—except the
swapper process (idle process).
The runqueue Data Structure
The runqueue data structure
is the most important data structure of the Linux 2.6 scheduler. Each
CPU in the system has its own runqueue; all runqueue structures are stored in the
runqueues per-CPU variable (see the
section "Per-CPU
Variables" in Chapter
5). The this_rq( ) macro
yields the address of the runqueue of the local CPU, while the
cpu_rq(n) macro yields the address
of the runqueue of the CPU having index n.
Table 7-4
lists the fields included in the runqueue data structure; we will discuss
most of them in the following sections of the chapter.
Table 7-4. The fields of the runqueue structure
Type | Name | Description |
|---|---|---|
spinlock_t | | Spin lock protecting the lists of processes |
unsigned long | | Number of runnable processes in the runqueue lists |
unsigned long | cpu_load | CPU load factor based on the average number of processes in the runqueue |
unsigned long | | Number of process switches performed by the CPU |
unsigned long | | Number of processes that were
previously in the runqueue lists and are now sleeping in
|
unsigned long ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access