An Engineer's Blog

Back

Task Scheduler in Real-time OSes (Part 2)Blur image

Overview#

This article is part 2 of an overview series specifically about the Scheduler in a Real-time Operating System (RTOS). Examples of such systems can be found in almost anything from automotive application such as airbags, emergency breaks to avionics, and also infotainment, multi-media systems like video playback and QoS in web servers.

Read Part 1: Task Scheduler in RTOS

Static Scheduling#

As mentioned, predictability for an RTOS is an important characteristic and Static Scheduling provides just that, the ability to schedule, optimize for the tasks at runtime with very low complexity. Although, this also means that every modification requires execution of the scheduling algorithm again.

Taxonomy of Static Scheduling Taxonomy of Static Scheduling binded with Priority Scheduling Scheme. Different methodologies include timeslice, periodicity, and priority

For Static Scheduling, all parameters of all the tasks are assumed knownn in which the Scheduler built a schedule based on this information. This characterstic makes it simplier to schedule by timeslice based on task arrival pattern since there will be no change throughout the schedules.

Clock-Driven Scheduling#

Clock-Driven Scheduling is a Static Scheduling mechanism that consist of the following characteristics:

  • Schedule is created off-line at compile time
  • Precedence is treated explicitly between tasks
  • Scheduler operates when timer expires, i.e. Timer interrupt

Following is example of Clock-Driven Scheduling with a timeslice of Scheduling time t=1st=1s and three tasks T1T_1 , T2T_2 , T3T_3 scheduled at compile time.

Task (TT)Period (PP)Execution Time (EtE_t)Deadline (DD)
T1T_1313
T2T_2414
T3T_310210

Table of Schedule for 3 Tasks with their Execution Time, Period and Deadline

Before any scheduling, a concept of CPU Utilization is important since tasks with fast period and long execution time will occupy a large amount of CPU resources.

CPU Utilization is defined as the sum of all tasks’ Execution times Ei\sum E_i divided by their Periods Pi\sum P_i. If the sum is greater than 1, then the system is guaranteed not feasible.

Utilization=i=1nEiPiUtilization = \sum_{i=1}^{n}\frac{E_i}{P_i}

For this example of 3 Tasks, U=13+14+15=0.78U = \frac{1}{3} + \frac{1}{4} + \frac{1}{5} = 0.78, and thus the system will not be unfeasible. It does not mean the system is feasible yet, this point will be discussed in the schedule plot.

On the following plot, the Scheduler generates and allocates Tasks with start-of-task one direction arrow (\uparrow) and end-of-task small dot (.) at the end of Execution Time (filled range).

Clock-Driven Scheduling of three tasks at one second timeslice

Task T1T_1, T2T_2, T3T_3 and Processor P0P_0 plotted on Scheduling time (t) x-axis in 20 seconds

  1. On the first line of Task 1, the timer interrupts the system at time 0 and T1T_1 is selected. The job of T1T_1 is then executed through out its Et1E_{t1} and come to a stop at t=1t=1 then the next task is up.
    • Side note: similarly the second and third lines of Task 2 and 3 respectively.
  2. Since T3T_3 start-of-task is t=1t=1, it takes control next.
    • Side note: there is no concept of priority yet, the only determinants are which Task available and ready.
  3. At time t=3t=3, the Scheduler selects T1T_1 eventhough T2T_2 also starts at t=3t=3. That is because Task 3 Period is P3=4P_3=4 and thus not executed until the next timeslice t=4t=4.

Acknowledgement#

This series is heavily influenced by a Coursera online course created by the EIT-Digital University in Turku, Finland as part of the on-campus course on Real-Time Systems given in their Embedded Systems Master’s curriculum.

Task Scheduler in Real-time OSes (Part 2)
https://tin.ng/blog/2020-06-05--task-scheduler-in-rtos-part-2
Author Tin Nguyen
Published at June 5, 2020
Comment seems to stuck. Try to refresh?✨