Rtos Lec4
Rtos Lec4
Mansoura University
Faculty of Computers and Information Sciences
Department of Computer Science
Second Semester- 2024-2025
DR. MOHAMMED
LECTURE 4
Fundamentals of
Realtime Operating Systems [RTOS]
1
07/03/2025
INTRODUCTION
An Operating System (OS) provides interface between computer and computer user.
It manages the use and implementation of applications software.
OS is responsible for operating CPU, controlling I/O devices, handling the working
of application programs and managing and retrieving information.
A Real Time Operating System (RTOS) is the type of operating system that is
designed to serve real time applications or embedded applications.
RTOS provides solution for temporal as well as logical correctness of a program.
In addition to the basic functions provided by general purpose operating systems,
RTOS provides mechanisms to allow real time scheduling of tasks.
The important RTOS concepts are queues, inter-process communication, interrupt
management, software timers, semaphores, mutex, etc.
RTOS can be either:
Hard Real Time Operating Systems necessarily perform the task within the given specified
deadline. A formal guarantee of always meeting the hard deadline is required.
Firm Real time: These type of RTOS also need to follow the deadlines. However, missing a
deadline may not have big impact but could cause undesired affects, like a huge reduction in
quality of a product.
3
Soft Real Time Operating Systems are the RTOS that perform task almost in the specified
deadline. They do not guarantee a hard deadline. Task can be performed even after the time
has elapsed.
GPOS VS RTOS
Kernel's operation may or may not be preempted. Kernel's operation can be preempted.
2
07/03/2025
CHARACTERISTICS/REQUIREMENTS OF RTOS
Interrupt management that keeps the system reactivity but without causing unbounded delays on process execution due to unimportant interrupts.
Memory management. That avoids the unpredictable memory access operations.
RTOS ARCHITECTURES
3
07/03/2025
RTOS ARCHITECTURES
RTOS COMPONENTS
4
07/03/2025
A RTS usually is usually responsible for performing many real-time tasks of varied
importance concurrently,
It is important to define the deadlines for these realtime tasks and define their relative
importance in the system.
This leads us to the concept of priority, where priority determines the importance of a
task in a system.
In a real-time system, every real task has an assigned priority. The higher the priority, the
better is the chance of the task executing and meeting its deadline.
Using priorities of each task in a system, a scheme that allows coherent operation of a
system can be advised .
By preventing the low priority task from doing their work when higher priority task wants
to do its work, we can maintain coherency of operations.
A real-time task with higher priority can preempt low priority task(s).
9
This privilege given to a higher priority task to perform its job even when other low
priority tasks are performing their jobs is known as preemption.
10
5
07/03/2025
11
12
12
6
07/03/2025
13
13
Solution : Disable all interrupts but timer interrupts, and handle devices by special,
timer-activated kernel routines
Advantages
unbounded delays due to interrupt driver eliminated
periodic device routines can be estimated in advance
hardware details encapsulated in dedicated routines
Disadvantages
degradation of processor performance (still busy waiting within I/0 routines)
more inter-process communication than first solution
kernel has to be modified when adding devices
14
14
7
07/03/2025
Solution : Enable external interrupts and reduce the drivers to the least possible size
Driver only activates proper task to take care of device
The task executes under direct control of OS, just like any other task
User tasks may have higher priority than device tasks
Advantages
busy wait eliminated
unbounded delays due to unexpected device handling dramatically reduced ( not eliminated!)
remaining unbounded overhead may be estimated relatively precisely
State of the art!
15
15
IMPORTANT DEFINITIONS
16
8
07/03/2025
EXAMPLE
17
17
Non-preemtable calls could delay the execution of critical activities → system may
miss hard deadline
All system calls have to be characterized by bounded execution time
Solution: each kernel primitive should be preemptable!
18
18
9
07/03/2025
END
Thanks 19
19
Mansoura University
Faculty of Computers and Information Sciences
Department of Computer Science
Second Semester- 2024-2025
DR. MOHAMMED
20
20
10
07/03/2025
LECTURE 5
21
21
SCHEDULAR IN RTOS
The main job of the operating system scheduler is to decide what tasks should run and at what
time each task should run.
Scheduling algorithms of general-purpose operating systems are nondeterministic because the
correctness of the system does not depend on the order in which every task is executed.
In these general operating systems, the scheduler is intended to provide optimal
performance, optimal usage of resources, and fairness in resource assignment.
In contrast, in real-time operating systems, the scheduler must restrict the nondeterminism
associated with the concurrent system, and must provide the means to predict the worst-case
temporal behavior of the task set.
A real-time system is composed of several concurrent activities that are normally implemented
as tasks.
To schedule these tasks, real-time operating systems use scheduling algorithms to decide
the order of execution of the tasks and the amount of time assigned to each task.
The scheduler in RTOS maintains a priority queue (ranked list according to the priorities) of all
the tasks in system.
By the means of preemption, the RTOS’ scheduler enforces the ranked list by allowing or
disallowing any particular task to perform its job at any given time. 22
Hence the typical scheme employed for scheduler in real time system is called Priority based
Preemptive Scheduling Scheme.
22
11
07/03/2025
SCHEDULAR IN RTOS
23
In real time operating systems(RTOS) most of the tasks are periodic in nature.
Periodic data mostly comes from sensors, servo control, and real-time monitoring
systems.
In real time operating systems, these periodic tasks utilize most of the processor
computation power.
A real-time control system consists of many concurrent periodic tasks having
individual timing constraints.
The scheduling algorithms are used to determine which task is going to execute when
more than one task is available in the ready queue.
The operating system must guarantee that each task is activated at its proper rate and
meets its deadline.
24
24
12
07/03/2025
25
26
26
13
07/03/2025
27
28
28
14
07/03/2025
SCHEDULABILITY TEST/CONDITION
A schedulability test defines a mathematical condition that is used to verify whether the
task set meets its temporal restrictions for a given scheduling algorithm, i.e. a feasible
schedule exists. The inputs of the test are the temporal parameters of the task set..
A test is said to be sufficient in the sense that a task set is schedulable if it satisfies the test.
However, if the task set does not satisfy the sufficient test, it is not known whether the task
set can be schedulable using that scheduling algorithm. In other words:
If test is passed, then tasks are definitely schedulable
If test is not passed, tasks may be schedulable, but not necessarily
A test is said to be necessary if all schedulable task sets satisfy the test. Otherwise, if a
given task set satisfies the test, we cannot say that it is schedulable. In other word:
If test is passed, tasks may be schedulable, but not necessarily
If test is not passed, tasks are definitely not schedulable
Exact tests provide a necessary and sufficient condition. The inexact schedulability
tests provide only a sufficient (but not necessary) schedulability condition. In other words:
The task set is schedulable if and only if it passes the test. 29
29
A 25 10
A static/Off-line algorithm
B 25 8
A clock-driven (time-driven) scheduling algorithm
C 50 5
Construction of a cyclic executive is equivalent to bin
packing D 50 4
30
30
15
07/03/2025
STATIC SCHEDULING
ROUND ROBIN OR CYCLIC EXECUTION SCHEDULAR
OBSERVATIONS
The procedures share a common address space and can thus pass data between
themselves.
This data does not need to be protected (via semaphores, mutexes, for example) because
concurrent access is not possible
All ‘task’ periods must be a multiple of the minor cycle time
31
31
STATIC SCHEDULING
ROUND ROBIN OR CYCLIC EXECUTION SCHEDULAR
DISADVANTAGES
32
32
16
07/03/2025
Assumptions
Tasks are periodic
No aperiodic or sporadic tasks
Job (instance) deadline = end of period
No resource constraints
Tasks are preemptable
33
Schedulability Condition
A given task set of n tasks is scheduled under rate monotonic scheduling
Algorithm, if it satisfies the following equation:
Where Ck is the execution time and Tk is the period of task k and n is the number of tasks.
The term n(21/n -1) approaches ln 2, (0.69 as n ).
This condition is sufficient, but not necessary.
34
34
17
07/03/2025
EXAMPLE -1
35
35
EXAMPLE 1 [CONT.]
1. According to RM scheduling algorithm task with shorter period has higher priority so T1 has
high priority, T2 has intermediate priority and T3 has lowest priority. At t=0 all the tasks are
released. Now T1 has highest priority so it executes first till t=0.5.
2. At t=0.5 task T2 has higher priority than T3 so it executes first for one-time units till t=1.5.
After its completion only one task is remained in the system that is T3, so it starts its execution
and executes till t=3.
3. At t=3 T1 releases, as it has higher priority than T3 so it preempts or blocks T3 and starts it
execution till t=3.5. After that the remaining part of T3 executes.
4. At t=4 T2 releases and completes it execution as there is no task running in the system at this
time.
5. At t=6 both T1 and T3 are released at the same time but T1 has higher priority due to shorter
period so it preempts T3 and executes till t=6.5, after that T3 starts running and executes till
t=8.
6. At t=8 T2 with higher priority than T3 releases so it preempts T3 and starts its execution.
7. At t=9 T1 is released again and it preempts T3 and executes first and at t=9.5 T3 executes its36
remaining part. Similarly, the execution goes on.
36
18
07/03/2025
EXAMPLE -2
For the Task set: Ti = (ci, pi), where T1 = (2,4) and T2 = (4,8)
Schedulability check:
U=2/4 + 4/8 = 0.5 + 0.5 = 1.0
URM =2(√2 -1) = 0. 82
U>URM ====>> CONDITION FAILED
However,
Active Tasks : Active Tasks :
Active Tasks : Active Tasks :
{T2} {T2, T1}
{T1, T2} {T2}
37
38
19
07/03/2025
EXAMPLE 3
39
39
EXAMPLE 3 [CONT.]
• At T=0 both T1 and T2 are available, but deadline (T2) < deadline (T1). So T2 gets CPU and
gets executed till T=2. Now T2 will be available at T=5.
• At T=2 only T1 is available so T1 gets executed till T=4. Now T1 will be available at T=7.
• At T=4 to T=5 CPU remains idle as not task is available for execution.
• At T=5 only T2 is available so T2 gets executed till T=7. Now T2 will be available at T=7.
• At T=7 only T1 is available so T1 gets executed till T=9. Now T1 will be available at T=14.
• At T=9 to T=10 CPU remains idle as not task is available for execution.
• At T=10 only T2 is available so T2 gets executed till T=12. Now T2 will be available at T=15.
• At T=12 to T=14 CPU remains idle as not task is available for execution.
• At T=14 only T1 is available so T1 gets executed till T=15. Still 1 unit of work for T1 is
remaining.
• At T=15 both T1 and T2 are available, but deadline (T2) < deadline (T1). So T2 gets CPU and
gets executed till T=17. Now T2 will be available at T=20. 40
40
20
07/03/2025
Advantages :
• Optimal for Static Priority Scheduling.
• Performs well in case of availability of tasks having longer period but shorter deadline.
• Good performance in case of overload.
Disadvantages :
• Implementation is complex.
• It is a time taking process.
41
41
END
Thanks 42
42
21