Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


requeue_task_rt(rq, p);
set_tsk_need_resched(p);
}
}

Thesched_setschedulersystem call must be used to convert a process into a real-time process. This call
is not discussed at length because it performs only the following simple tasks:

❑ It removes the process from its current queue usingdeactivate_task.
❑ It sets the real-time priority and the scheduling class in the task data structure.
❑ It reactivates the task.

If the process was not previously on any run queue, only the scheduling class and the new priority value
need be set; deactivation and reactivation are unnecessary.

Note that changing the scheduler class or priority is only possible without constraints if the
sched_setschedulersystem call is performed by a process with root rights (or, equivalently, the
capabilityCAP_SYS_NICE). Otherwise, the following conditions apply:

❑ The scheduling class can only be changed fromSCHED_NORMALtoSCHED_BATCHor vice versa. A
change toSCHED_FIFOis impossible.
❑ Only the priority of processes with the same UID or EUID as the EUID of the caller can be
changed. Additionally, the priority may only be decreased, but not increased.

2.8 Scheduler Enhancements


So far, we have only considered scheduling on real-time systems — naturally, Linux can do slightly
better. Besides support for multiple CPUs, the kernel also provides several other enhancements that
relate to scheduling, discussed in the following sections. Notice, however, that these enhancements add
much complexity to the scheduler, so I will mostly consider simplified situations that illuminate the
essential principle, but do not account for all boundary cases and scheduling oddities.

2.8.1 SMP Scheduling


On multiprocessor systems, the kernel must consider a few additional issues in order to ensure good
scheduling:

❑ The CPU load must be shared as fairly as possible over the available processors. It makes little
sense if one processor is responsible for three concurrent applications while another has only the
idle task to deal with.
❑ Theaffinityof a task to certain processors in the system must be selectable. This makes it possible,
for example, to bind a compute-intensive application to the first three CPUs on a 4-CPU system
while the remaining (interactive) processes run on the fourth CPU.
Free download pdf