Chapter 7. Scheduling policies for RHEL for Real Time
In real-time, the scheduler is the kernel component that determines the runnable thread to run. Each thread has an associated scheduling policy and a static scheduling priority, known as sched_priority
. The scheduling is preemptive and therefore the currently running thread stops when a thread with a higher static priority gets ready to run. The running thread then returns to the waitlist
for its static priority.
All Linux threads have one of the following scheduling policies:
-
SCHED_OTHER
orSCHED_NORMAL
: is the default policy. -
SCHED_BATCH
: is similar toSCHED_OTHER
, but with incremental orientation. -
SCHED_IDLE
: is the policy with lower priority thanSCHED_OTHER
. -
SCHED_FIFO
: is the first in and first out real-time policy. -
SCHED_RR
: is the round-robin real-time policy. -
SCHED_DEADLINE
: is a scheduler policy to prioritize tasks according to the job deadline. The job with the earliest absolute deadline runs first.
7.1. Scheduler policies
The real-time threads have higher priority than the standard threads. The policies have scheduling priority values that range from the minimum value of 1 to the maximum value of 99.
The following policies are critical to real-time:
SCHED_OTHER
orSCHED_NORMAL
policyThis is the default scheduling policy for Linux threads. It has a dynamic priority that is changed by the system based on the characteristics of the thread.
SCHED_OTHER
threads have nice values between 20, which is the highest priority and 19, which is the lowest priority. The default nice value forSCHED_OTHER
threads is 0.SCHED_FIFO
policyThreads with
SCHED_FIFO
run with higher priority overSCHED_OTHER
tasks. Instead of using nice values,SCHED_FIFO
uses a fixed priority between 1, which is the lowest and 99, which is the highest. ASCHED_FIFO
thread with a priority of 1 always schedules first over aSCHED_OTHER
thread.SCHED_RR
policyThe
SCHED_RR
policy is similar to theSCHED_FIFO
policy. The threads of equal priority are scheduled in a round-robin fashion.SCHED_FIFO
andSCHED_RR
threads run until one of the following events occurs:- The thread goes to sleep or waits for an event.
A higher-priority real-time thread gets ready to run.
Unless one of the above events occurs, the threads run indefinitely on the specified processor, while the lower-priority threads remain in the queue waiting to run. This might cause the system service threads to be resident and prevent being swapped out and fail the filesystem data flushing.
SCHED_DEADLINE
policyThe
SCHED_DEADLINE
policy specifies the timing requirements. It schedules each task according to the task’s deadline. The task with the earliest deadline first (EDF) schedule runs first.The kernel requires
runtime⇐deadline⇐period
to be true. The relation between the required options isruntime⇐deadline⇐period
.
7.2. Parameters for SCHED_DEADLINE policy
Each SCHED_DEADLINE
task is characterized by period
, runtime
, and deadline
parameters. The values for these parameters are integers of nanoseconds.
Table 7.1. SCHED_DEADLINE parameters
Parameter | Description |
---|---|
|
For example, if a video processing task has 60 frames per second to process, a new frame is queued for service every 16 milliseconds. Therefore, the |
|
For example, if a video processing tool can take, in the worst case, five milliseconds to process an image, the |
|
For example, if a task needs to deliver the processed frame within ten milliseconds, the |