Task Scheduling

A scheduler, in the context of operating systems, simply decides what task is executed at a given instance of time. Often it is one of the most critical components of any operating system. Usually, GPOSs and RTOSs have different preferences for scheduling decisions, so multiple scheduler implementations have been developed for both cases. Having this distinction between the categories is important, as the design goals are so different.

When designing real-time systems, the most appropriate scheduling algorithm always depends on the situation. Perhaps the simplest, yet still useful, available real-time scheduling algorithm can be thought of as being the fixed-priority preemptive scheduling algorithm, as illustrated in Real-Time Scheduling Principle [6]. In this scheduling scheme, every task gets a static priority assigned to them at the design phase. During the system operation, the scheduler simply guarantees that the current task always has the highest possible priority. As the scheduling is preemptive, it means that even a task that is in the middle of executing something can be briefly aborted to let another higher priority task execute instead.

Figure 1. Real-Time Scheduling Principle [6]

Compared to the previously mentioned fixed-priority preemptive scheduling algorithm the Linux scheduler is a bit more complicated, but fundamentally it handles real-time tasks quite similarly. The Linux scheduler implements several scheduling policies which can be divided into non-real-time and real-time scheduling groups. Normal applications typically execute with one of the non-real-time policies, and they will always have lower priority than tasks running with any of the real-time policies. The Linux scheduler supports three distinct real-time policies that can be assigned to any task requiring a real-time priority.

  • SCHED_FIFO: a task running with this policy gets to execute until it finishes and voluntarily preempts, or a higher priority task preempts it.
  • SCHED_RR: tasks are only allowed to run at maximum with a specified time slice before being preempted if not preempted by higher-priority task.
  • SCHED_DEADLINE: is a policy implementing a task execution deadline-based scheduling algorithm.

All tasks executing with any of the real-time policies have a static real-time priority as signed to them. With SCHED_FIFO or SCHED_RR policies, this priority can be between 1 (low) and 99 (high). A task with SCHED_DEADLINE is always executed with an effective priority of 100 having the highest priority possible. Any task executed with higher priority will always have precedence over another task with lower priority. With these policies, it is possible to carefully design the execution of a real-time system to meet even demanding timing requirements.