Professional Documents
Culture Documents
RTOS Scheduling: Comparative Study: An "Operating Systems" (ECEN 427) " Project Report by
RTOS Scheduling: Comparative Study: An "Operating Systems" (ECEN 427) " Project Report by
Submitted in partial fulfilment for the requirements of the ECEN 427 project to
Fall 2021
2
component that will be used with the MCU will have its would function, the RMS and EDF algorithms are explained
own files within the HAL layer. The target is for the MCU below.
to distribute tasks for each of these devices, and to monitor
the scheduling process for each of these tasks. Algorithm 1: EDF Scheduling Algorithm
1 Task arrival
G. RTOS Stack 2 Sort tasks based on their deadline ascendingly:
The RTOS layer connects all layers together. It consists for i = 0 to i < n:
mainly of RTOS-related files and timer-related files. Since for j = 0 to j < (n – i – 1):
RTOS’s main working principle depends on real-time if task [j] deadline< task [j+1] deadline
action, it is needed to identify how the time concept works. Swap task [j] and task [j+1]
The timer is a counter that translates the time concept to End if
count on the hardware level. The timer has interface, config, End for
private, register and program files. End for
RTOS defines the states to handle each task; 3 Assign priorities based on their index after sorting
new/inactive, ready, running, waiting, and terminated (see i.e., tasks with earliest deadlines have higher priorities
figure 2 for elaboration). Then there are functions that create 4 Dispatch tasks based on their priority list:
tasks, starts RTOS, suspend tasks, resume tasks, and delete for i = 0 to i < n:
tasks. The RTOS has config, interface, private and program if task status is enables
files. The scheduler structure is found in the private file as it Invoke task function
only concerns the programmer to know the basic layering 8 End if
and structure of the scheduler and the OS. Any other user 9 End for
would only be concerned with how to handle the tasks and Algorithm 2: RM Scheduling Algorithm
change their states to reach his target goal. Private file
contains the structure of the task type that has period, burst 1 Task arrival
time, status, and arrival time information. The configuration 2 Sort tasks based on their periodicity ascendingly:
file used in RTOS as it is interested in how many tasks there for i = 0 to i < n:
are and the type of scheduling algorithm. And in the for j = 0 to j < (n – i – 1):
program file connecting all files and writing algorithms by if task [j] period < task [j+1] period
making an array that contains tasks by giving them indexes Swap task [j] and task [j+1]
from 0 to n where n is the number of tasks, and their End if
priority depends on the index of the task. The highest End for
priority has the least index. End for
3 Assign priorities based on their index after sorting
i.e., tasks with earliest deadlines have higher priorities
4 Dispatch tasks based on their priority list:
for i = 0 to i < n:
if task status is enables
Invoke task function
8 End if
9 End for
For each of the algorithms, the testing is made by
Fig. 2. RTOS main process state model defining or assuming multiple variables for the four
H. APP processes: LED, LCD, DC motor, and buzzer. The burst
time was hand calculated by the average program execution
The APP layer is the interface layer. It is the last top layer
time for each of the functions based on the component. For
that uses all the below layers for the intended application to
the FP, the priorities are assigned by the user, while in the
work. In this case, the finalized function callings, and task
EDF and RMS, the priorities are calculated based on the
distribution and management are all in the main file in the
algorithm’s functionality whether based on the deadline
APP layer.
specification or the periodicity. The arrival time is zero for
I. Scheduling all process in all algorithms, and the periods are user-
For each of the used algorithms, the scheduler defined as well.
functionality is defined in the RTOS program C file. Each
algorithm has its own scheduler identified. Aside from the
FP algorithm, which is considered how any basic scheduler
5
At 4: W T = 4 – 4 = 0 sec
6
At 6: W T = (6+702 µs ) - 6 = 702 µs At 4: 0
At 8: WT = 8 - 8 = 0 At 6: 0
At 10: W T = 10 – 10 = 0 At 8: 0
Same as the previous 2 processes, P3 will be calculated at For P3, time intervals will be 0, 4, 8
time intervals 0, 4, 8, 12
At 0: 69.5 ms+0.7 ms
At 0: W T = (702 µs + 69.5 ms ) - 0 = 70..2 ms
At 4: 69.9 ms
At 4: W T = (4+ 69.5ms)-4 = 69.5 ms
At 8: (69.5 + 0.7) ms
At 8: W T = (8+ 69.5ms)-8 = 69.5 ms
Avg = 69.96 ms.
At 12: W T = (12+702 µs, 69.4 ms)-12 = 70..2 ms
As for the waiting time for the FP algorithm it wasn’t
calculatable as all tasks except P4 didn’t execute and missed
(70.2+69.5+69.5+70.2) ms its deadline.
Avg = = 69.85 ms
4 C. CONCLUSION
For P4, the time intervals will be 0, 8 In conclusion, the three Preemptive RTOS scheduling
algorithms were implemented from scratch using a layered
architecture to run on an ATMEGA32 microcontroller. Real
At 0: W T = (70.2 ms + 0.5 ) + 0= 0.57 s test cases that were ranging in burst time were chosen to
show how each algorithm would fare with a fixed arrival
time of zero. It was found that the Fixed priority hogged the
At 8: W T = ( 69.5ms+ 0.5) - 4 = 0.5695 ms CPU across the timeline while dynamically assigned
priorities fixed the hogging of the CPU by 1 task. Also, it
For the RMS algorithm, the calculations were as follows: was found that fixing the arrival time solved the problem of
overloading the CPU. The FP algorithm functionality
For P1: depends on how the priotieites for each task are given, and
so it would be a perfect selection for safety applications,
At 0: W T = 69.5 ms - 0 = 69.5 ms otherwise it is not the most efficient. As for the RMS and
EDF, since the arrival time was zero for all cases, and with
At 3: WT = 0 the variation in each task’s burst time, both algorithms
provided equvilent performance, with the fourth task (the
longest one) being interuppeted multiple times but got
At 6: W T = 69.5 ms executed. However, with moderation, the RMS and EDF
would provide good results for specific user-defined
At 9: WT = 0 application.
REFERENCES
At 12: W T = 41.7 ms
[1] Pahini A. Trivedi, “Real Time Operating System (RTOS)
With Its Effective Scheduling Techniques,” undefined, 2014.
For P2, the time intervals will be 0, 2, 4, 6, 8, 10
[2] Karunakar Pothuganti, A. Haile, and Swathi Pothuganti, “A
At 0: 0 Comparative Study of Real Time Operating Systems for
Embedded Systems,” ResearchGate, Jun. 2016.
At 2: 0 [3] P. Hambarde, R. Varma, and S. Jha, “The Survey of Real
Time Operating System: RTOS,” IEEE Xplore, Jan. 01, 2014.
7