Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

RTOS Scheduling: Comparative Study

An “Operating Systems” (ECEN 427)” Project Report by

Nayera Hisham Elsaady 18100036


Nourhan Salim 18101619
Ahmed Ayman Abo Elmagd 18100767
Ahmed Amr Elwardany 18100440

Submitted in partial fulfilment for the requirements of the ECEN 427 project to

Dr. Eman Gewish

Fall 2021
2

RTOS Scheduling: Comparative Study


Ahmed Abo Almagd, Ahmed Elwardany, Nayera Elsaady & Nourhan Salim
School of Engineering and Applied Sciences, Nile University, Cairo, Egypt

Abstract— With the advancements in the industry of


operating systems and embedded systems, the complexity of
the functionality and the criticality of logical results while , where AT is the arrival time at the ready queue.
meeting hard deadlines makes real-time operating systems
(RTOS) the best well-structured systems to meet all these
market criteria. RTOS targets high performance while dealing
 Response time: the time the process takes from the
with time constraints in the most efficient way. Scheduling ready queue/state till it starts execution in the CPU.
focuses on how all tasks are queued and in what order are they RT =Turnaround−Burst Time [2]
executed, and thus the performance is based on providing the
right sequence and time for each task. This paper will serve as Scheduling algorithms assigned priorities to the processes
a comparative study between the most used scheduling based on internal or external criteria. Internal priority
algorithms in RTOS: Earliest Deadline First (EDF), Rate policies are based on memory usage, I/O usage, deadline,
Monotonic Scheduling (RMS), and Fixed Priority (FP) and other technicalities. External could be as defined in [6]
scheduling. The written C code for each algorithm will be where the tasks are given a user-defined priority depending
burned on an ATMEGA-32 and then test cases will be used for
on his preference. Scheduling algorithms are classified
performance comparison.
based on various parameters, location-based algorithms
Keywords— RTOS, Scheduling algorithm, EDF, RMS, FP. could be centralized, decentralized, global, distributed,
partitioned, ...etc. [7,8]. They also could be classified based
A. INTRODUCTION
on how the resources are allocated for each process, and
The advancement in technology leads to an increased how processes are dealt with, switched, and queued with the
dependency on embedded systems, and it becomes more execution time. The two main types in this category are
essential every day to focus studies and research efforts on preemptive and non-preemptive [8].
that field. Real-Time Operating Systems (RTOS) are used in For RTOS however, due to the criticality of meeting the
real-time applications for embedded systems and target specified hard deadlines, priority policies are classified into
versatile tasks. Any Operating System (OS) provides a static and dynamic priority scheduling. In static priority,
platform between the hardware and the software and each task is given a specific priority that is fixed throughout
consists of multiple functions to tie between them, but the processing. Dynamic priority changes each task’s
unlike the common operating systems, RTOS focuses on priority-based [9-11]. The most famous RTOS static
real-time results achieved within hard deadlines, like its scheduling technique is Rate-Monotonic Scheduling (RMS).
usage in the automobile industry [1-3]. Thus, the main The most used dynamic technique is the Earliest Deadline
system function in RTOS is scheduling. For each required First (EDF) scheduling. For RTOS scheduling, static
task, based on its given priority and deadline, the system’s algorithms are used more as the system’s main priority is
scheduler uses different algorithms to provide the best time delivery optimization.
efficiency, while prioritizing the delivery time constraints The paper’s target is to implement the chosen three
and achieving logical and critical results [4]. scheduling algorithms in C and provide a comparative study
Scheduling in RTOS targets high performance with based on their performance. The written codes will then be
minimum delays and interrupt latencies, and while the burned on an ATMEGA-32, and real-life test cases will be
processor/microcontroller of the embedded system is used to compare their performance.
concerned with the execution time, the OS scheduling is
concerned with [5]: B. SCHEDULING ALGORITHMS
 Throughput: the number of processes done within a EDF is the most used dynamic scheduling technique.
time unit. Such claim is further fortified due to some specific
 Turnaround time: the time the process takes from its properties which the EDF scheduling algorithm has, which
submission/start point to its completion point. include [12,13]:
 Burst time: the total processing time taken for the CPU  EDF scheduling algorithm is an optimal dynamic
to execute the process. priority scheduling algorithm.
 Waiting time: the time each task spends waiting for its  It assigns tasks with a shorter deadline and a higher
turn in execution in the ready queue, which is priority.
calculated through:  It executes the job that has the earliest deadline.
[1]  The non-preemptive type of the EDF (NP-EDF)
WT =task arrival timeat CPU− AT scheduling algorithm does not allow preemptions,
3

meaning that a job with the earliest deadline is executed C. METHODOLOGY


first which results, leading to missing deadlines. If the
D. Code Structure:
preemptions are not allowed, the arriving high priority
task cannot preempt the currently running low priority Each algorithm is implemented in a C code that is
task which should not be the case in real-time operating constructed in a layered architecture. The layered
systems. architecture used is basic and follows the diagram below. It
 The fully preemptive type of the EDF (FP-EDF) consists of: Microcontroller Abstraction Layer (MCAL),
scheduling algorithm fully allows preemptions. This Hardware Abstraction Layer (HAL), RTOS stack,
means that high-priority tasks are permitted to preempt Application Layer (APP), and Libraries (LIB).
the currently executing low priority task. With that
being said FP-EDF performs better than NP-EDF when
it comes to meeting deadlines [4].
The most basic scheduling algorithm is the Fixed Priority
Preemptive Scheduling algorithm (FP). Priority Scheduling
is a method of scheduling process that is reliant on priority.
In this algorithm, the scheduler selects the tasks to work as
per their assigned priority. The processes with higher
priority will be executed first, whereas jobs with equal
priorities will be executed using a round-robin or FCFS type
of queue execution. Priority is assigned based on memory
requirements, time requirements, etc. The major
characteristics of priority scheduling can be categorized as Fig. 1. Schematic of the Layered architecture Used
the following [14,15]:
E. MCAL
 It schedules processes based on priority. The MCAL is a layer that allows the software module
 If two jobs having the same priority are ready to be access for the used hardware microcontroller unit (MCU)
executed, it works on an FCFS basis. drivers. For simplicity, it is the layer used to tie the
 A number is assigned to each process that indicates its software with the MCU’s modules and devices for the
priority level. inputs and outputs. The MCAL layer in the implementation
 The lower the number that the task has, the higher the consists of three parts: Digital Input and output (DIO), Port,
priority becomes. and Global Interrupt Enable (GIE).
 Since this algorithm is the preemptive type of priority The DIO targets the programming phase to identify and
scheduling, then if a newer process arrives, that is control the input and output pins of the used MCU. For
having a higher priority than the currently running basic usage, the DIO part will consist of three files,
process, then the currently running process is interface, program and register. The program file
preempted. is the C file and the other two are headers. The register file
identifies the registers and locations that will be used to load
Branching from the FP scheduling, RMS revolves around
and store data from the MCU. The interface file is used to
a simple rule which is to assign priorities to different tasks
identify the functions used for the targeted components. The
according to their period. The priority of a task is inversely
program file contains the targeted implementation that will
proportional to its period. The task with the shortest period
be used.
will get assigned the highest priority and a task with the
The PORT part is used to control the state and moods of
longest period will have the lowest priority in the execution
the inputs and outputs. It also has interface,
queue. Since the period of a task does not change, its
program, and register files. There are two extra
priority will not change over time either, meaning that RMS
can be considered a fixed priority algorithm. The priorities header files which are config and private. The
are decided before the start of execution and they stay fixed config file is considered the settings of the functions that
throughout the entire execution process [16-18]. will be used. It defines the rules of how the functions will be
RMS depends on preemption. Preemption will only work. The private file is used by the original software
happen on a certain processor when a higher priority task coder as function prototypes that he will only use. GIE, as
blocks a lower priority task from being executed. This its name, controls and enables the interrupt system in the
blocking occurs due to priority level differences of different MCU. It has interface, program and register files.
tasks in a certain set of tasks. For elaboration, if a task with F. HAL
a shorter period comes during execution it will gain a higher
priority and can block or preemptive currently running tasks The HAL is a software layer that ties the software and the
[19]. controller with the other used hard devices. Each
4

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

J. RESULTS AND ANALYSIS


A. Hardware Implementation
To apply and test both algorithms, the written codes are
burned on the ATMEGA-32 – the chosen MCU. The used
components and thus chosen processes are LED, LCD,
buzzer, and DC motor. The components are all connected
(see Fig. 2) and each algorithm will be burned on the MCU Fig. 4. EDF algorithm Gantt chart
in its own trial. Each trail will then be monitored based on
how the scheduler managed the given tasks. The testing will
also depend on the calculation of the turnaround time and
waiting time to compare the performance of both
algorithms.

Fig. 5. RMS algorithm Gantt chart

Fig. 6. FP algorithm Gantt chart


The WT for each algorithm was also calculated to further
evaluate the performance. For the EDF, the calculations
Fig. 3. Circuit implementation of the burned code on the MCU with the
connected devices. were as follows:
B. Test bench Regarding P1, calculation at different time intervals will be
The table below shows the assumed and calculated values done at 0, 3, 6, 9.
for the burst time, arrival time and periods. The deadlines in
the EDF for each process are assumed a range from 0 till the At 0: WT = 0 - 0 = 0
period value. The Gantt charts describe the scheduling
process. WT = 3 - 3 = 0
At 3:
Table 1. Priority queue structure for EDF and RMS.
Process Burst Time Period AT At 6: WT = 6 – 6 = 0
P1 (LED) 702 usec 3 secs 0
P2 (LCD) 69.5 ms 2 secs 0 At 5: WT = 9 – 9 = 0
P3 (Motor) 0.5 secs 4 secs 0
P4 (Buzzer) 4 secs 8 secs 0 From the previous equations, it is concluded that P1 had 0
waiting time on average.
Table 2. Priority queue structure for FP.
Process Burst Time Period Priority AT For P2, the same method will be applied but at time
P1 (LED) 702 usec 3 secs 3 0 intervals 0, 2, 4, 6, 8, 10.
P2 (LCD) 69.5 ms 2 secs 1 0
P3 (Motor) 0.5 secs 4 secs 4 0 At 0: W T = 702 µs – 0 = 702 µs
P4 (Buzzer) 4 secs 8 secs 2 0
At 2: W T = 2 – 2 = 0 sec

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

702 µ s+ 702 µ s At 10: 0


Avg = = 234 µs
6 Avg = 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

[4] C. Keerthanaa and M. Poongothai, “Improved priority based


scheduling algorithm for real time embedded systems,” 2016
International Conference on Circuit, Power and Computing
Technologies (ICCPCT), Mar. 2016, Doi:
10.1109/iccpct.2016.7530188.
[5] “Operating System Concepts – 10th edition,” Os-book.com,
2018.
[6] A. Elkarashily, A. Ezzat, O. Salah, and M. Ahmed, “RTOS
scheduling with user-defined priorities,” ResearchGate, Apr.
18, 2020.
[7] Sang Cheol Kim and S. Lee, “Decentralized task scheduling
for a fixed priority multicore embedded RTOS,”
ResearchGate, Jun. 2013.
[8] J. Donga, M. S. Holia, and N. M. Patel, “The Classification
and Comparative Study of Real-Time Task Scheduling
Algorithms Based on Various Parameters,” ResearchGate,
2021.
[9] G. Gracioli, A. A. Fröhlich, R. Pellizzoni, and S.
Fischmeister, “Implementation and evaluation of global and
partitioned scheduling in a real-time OS,” Real-Time
Systems, vol. 49, no. 6, pp. 669–714, May 2013, doi:
10.1007/s11241-013-9183-3.
[10] Jaydev Teraiya and A. Shah, “Analysis of Dynamic and Static
Scheduling Algorithms in Soft Real-Time System with Its
Implementation,” ResearchGate, 2020.
[11] B. Andersson, S. Baruah, and J. Jonsson, “Static-priority
scheduling on multiprocessors,” Proceedings 22 nd IEEE Real-
Time Systems Symposium (RTSS 2001) (Cat.
No.01PR1420), 2022, doi: 10.1109/real.2001.990610.
[12] Giorgio C. Buttazzo, Marko Bertogna and Gang Yao (2013),
‘‘Limited Preemptive Scheduling for Real-Time Systems. A
Survey,’’ IEEE Transactions On Industrial Informatics, Vol.
9, No. 1,pp-.3-15.
[13] Omara, FA and Arafa, MM (2010), ‘Genetic algorithms for
task scheduling problem’, Journal of Parallel and Distributed
Computing Vol.70, No. 1, pp. 13-22.
[14] R. I. Davis, “A review of fixed priority and EDF scheduling
for hard real-time Uniprocessor Systems,” ACM SIGBED
Review, vol. 11, no. 1, pp. 8–19, Aug. 2013.
[15] R. J. Bril, S. Altmeyer, M. M. H. P. Heuvel, R. I. Davis, and
M. Behnam, “Integrating cache-related pre-emption delays
into analysis of fixed priority scheduling with pre-emption
thresholds,” 2014 IEEE Real-Time Systems Symposium, vol.
53(4), pp. 403–466, Jan. 2017.
[16] R. Oshana, DSP software development techniques for
embedded and real-time systems. Amsterdam:
Elsevier/Newnes, 2006.
[17] Xueqiao Li, Shuang Liang, and Yuan Chen, “Research and
improvement of rate-monotonic scheduling algorithm,” 2010
International Conference on Computer, Mechatronics, Control
and Electronic Engineering, Aug. 2010.
[18] Y. Li, T. Liu, J. Zhu, X. Wang, M. Duan, and Y. Wang,
“Comprehensive study of schedulability tests and optimal
design for rate-monotonic scheduling,” Computer
Communications, vol. 173, pp. 107–119, May 2021.
[19] R. Mall, Real time systems: Theory and practice. New Delhi:
Pearson Education, 2008.

You might also like