Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


Note thatSCHED_IDLEis, despite its name,notresponsible to schedule the idle task. The
kernel provides a separate mechanism for this purpose.
❑ SCHED_RRandSCHED_FIFOare used to implement soft real-time processes.SCHED_RRimple-
ments a round robin method, whileSCHED_FIFOuses a first in, first out mechanism. These
are not handled by the completely fair schedulerclass, but by the real-time scheduler class,
which is discussed in Section 2.7 in greater length.

The auxiliary functionrt_policyis used to decide if a given scheduling policy belongs to the
real-time class (SCHED_RRandSCHED_FIFO)ornot.task_has_rt_policydetermines this prop-
erty for a given task.
kernel/sched.c
static inline int rt_policy(int policy)
static inline int task_has_rt_policy(struct task_struct *p)
❑ cpus_allowedis a bit field used on multiprocessor systems to restrict the CPUs on which a pro-
cess may run.^22
❑ run_listandtime_sliceare required for the round-robin real-time scheduler, but not for the
completely fair scheduler.run_listis a list head used to hold the process on a run list, while
time_slicespecifies the remaining time quantum during which the process may use the CPU.

TheTIF_NEED_RESCHEDflag discussed above is just as important for the scheduler as the specific sched-
uler elements held in the task structure. If this flag isset for an active process, the scheduler knows that
the CPU is to be withdrawn from the process — either voluntarily or by force — and granted to a new
process.

SchedulerClasses


Scheduler classes provide the connection between the generic scheduler and individual scheduling
methods. They are represented by several function pointers collected in a special data structure. Each
operation that can be requested by the global scheduler is represented by one pointer. This allows for cre-
ation of the generic scheduler without any knowledge about the internal working of different scheduler
classes.

Without extensions required for multiprocessor systems (I will come back to these later), the structure
looksasfollows:

<sched.h>
struct sched_class {
const struct sched_class *next;

void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup);
void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
void (*yield_task) (struct rq *rq);

void (*check_preempt_curr) (struct rq *rq, struct task_struct *p);

struct task_struct * (*pick_next_task) (struct rq *rq);
void (*put_prev_task) (struct rq *rq, struct task_struct *p);

(^22) The bitmap can be set using thesched_setaffinitysystem call.

Free download pdf