CHAPTER FOUR
REAL TIME OPERATING SYSTEM
(RTOS)
REAL TIME OPERATING SYSTEM
(RTOS)
Real-time Operating Systems
scheduling policies,
Context switching mechanisms,
inter-process communication
• message passing and
• shared memory communications
GENERAL PURPOSE OPERATING
SYSTEM
GENERAL PURPOSE OPERATING
SYSTEM
GENERAL PURPOSE OPERATING
SYSTEM
Real Time Operating System(RTOS)
What is real time operating system(RTOS)?
Are systems in which the correctness of the system
depends on the logical result of computation and also
on the time at which the results are produced.
It is intended to serve real-time applications
Are time bounded system
If the timing constraints of the system are not met
system failure is said to have occurred
REAL TIME OPERATING SYSTEM (RTOS)
is an operating system (OS) intended to serve real-time
application, process data without buffering delays.
is a program that schedules execution in a timely manner,
manages system resources, and provides a consistent
foundation for developing application code.
Good RTOS are scalable in order to meet different sets of
requirements for different applications.
Real Time Operating System(RTOS)
Hard Real Time System
• Failure to meet deadlines is fatal
• A system that meets the deadline all the time(100%),
even under worst case system load.
• Missing a deadline even in a single time may result
in a fatal consequence.
• Used in life safety system, where a task need to be
performed with in a particular time frame.
• example: Flight Control System
Real Time Operating System(RTOS)
Soft Real Time System
• Late completion of jobs is undesirable but not fata
• Missing the deadline may lower the quality of the
service but are not result in catastrophic damage
• System performance degrades as more & more jobs
miss deadlines.
• Systems that does not guarantee meeting deadlines,
but, offer the best effort to meet the deadline.
• Example: Online Databases, DVD player
Key Characteristics of an RTOS
Some of the more common attributes are
reliability,
predictability,
performance,
scalability.
Key Characteristics of an RTOS
Reliability:
Embedded systems must be reliable.
Although different degrees of reliability might be
acceptable, in general, a reliable system is one that is
available (continues to provide service) and does not fail.
Key Characteristics of an RTOS
Predictability:
meeting time requirements is key to ensuring proper
operation.
The RTOS used in this case needs to be predictable to a certain
degree.
The term deterministic describes RTOS with predictable
behavior, in which the completion of operating system calls
occurs within known timeframes.
Key Characteristics of an RTOS
Performance
An embedded system must perform fast enough to fulfill
its timing requirements.
The more deadlines to be met-and the shorter the time
between them-the faster the system's CPU must be.
Although underlying hardware can dictate a system's
processing power, its software can also contribute to
system performance.
Key Characteristics of an RTOS
Scalability
Because RTOS can be used in a wide variety of embedded
systems, they must be able to scale up or down to meet
application-specific requirements.
Depending on how much functionality is required, an
RTOS should be capable of adding or deleting modular
components, including file systems and protocol stacks
The scheduler
A scheduler is a critical component of RTOS responsible
for managing and allocating system resources to different
tasks or processes.
It’s job is carried out based on predefined priorities and
scheduling policies.
The primary goal of the scheduler is to ensure that tasks
meet their deadlines and execute in a timely manner
according to their requirements.
The scheduler
Multitasking
how does a scheduler handle multiple schedulable
entities that need to run simultaneously?
Multitasking is the ability of the operating system to
handle multiple activities within set deadlines.
many threads of execution appear to be running
concurrently;
The scheduler determines which task to execute next
based on priorities and scheduling policies.
The scheduler
Multitasking
allowing for the efficient utilization of system resources
and responsiveness to various events
The CPU time is shared among multiple tasks, with each
task receiving a portion of CPU time to execute its code.
The scheduler allocates CPU time to tasks based on their
priorities and the scheduling algorithm employed by the
RTOS.
Context switching
The actual process of changing from one task to another task is
called context switching.
The mechanism by which the RTOS switches between
tasks, saving the state of the currently running task and
restoring the state of the next task to be executed.
Context switches occur when a task's time slice expires, a
higher priority task becomes ready to run, or when an
interrupt occurs.
Context switching
Each task has its context, which is the state of the CPU
registers required each time it is scheduled to run.
Context switching
Every time a new task is created, the
kernel also creates and maintains an
associated task control block (TCB).
TCBs are system data structures that
the kernel uses to maintain task-specific
information.
TCBs contain everything a kernel needs
to know about a particular task.
Context switching
The time it takes for the scheduler to switch from one task to
another task is the context switch time.
Every time an application makes a system call, the scheduler
has an opportunity to determine if it needs to switch contexts.
When the scheduler determines a context switch is necessary,
it relies on an associated module, called the dispatcher, to
make that switch happen
Context Switching
The Dispatcher
The dispatcher is the part of the scheduler that performs
context switching and changes the flow of execution.
The dispatcher initiates context switches when a higher
priority task becomes ready to run, a lower priority task
voluntarily yields control, or when an interrupt occurs.
When a context switch occurs, the dispatcher saves the
state of the currently running task, including CPU registers,
program counter, and other relevant information into a
task control block.
Scheduling Policy (Algorithms)
Non-preemptive scheduling:
Non-preemptive Scheduling is used when a process terminates,
or a process switches from running to the waiting state.
In this scheduling, once the resources (CPU cycles) are allocated
to a process, the process holds the CPU till it gets terminated or
reaches a waiting state.
Non-preemptive scheduling does not interrupt a process running
CPU in the middle of the execution.
Instead, it waits till the process completes its CPU burst time, and
then it can allocate the CPU to another process.
Scheduling Policy (Algorithms)
Preemptive scheduling
Preemptive scheduling is used when a process switches
from running state to ready state or from the waiting state
to ready state.
The resources (mainly CPU cycles) are allocated to the
process for a limited amount of time and then taken away
the process is again placed back in the ready queue if that
process still has CPU burst time remaining.
That process stays in the ready queue till it gets its next
chance to execute
Scheduling Policy (Algorithms)
RTOS task scheduling algorithms consider the following factors
for its scheduling decision:
a) Task priority: Each task in an RTOS is assigned a priority.
Higher-priority tasks are always scheduled to run before
lower-priority tasks.
b) Task deadline: Some RTOS task scheduling algorithms also
consider the deadlines of tasks when making scheduling
decisions.
For example, a deadline-based scheduling algorithm might
give priority to tasks that are closer to their deadlines.
Scheduling Policy (Algorithms)
c) Task execution time: Some RTOS task scheduling
algorithms also consider the estimated execution time of
tasks when making scheduling decisions. This can help to
ensure that all tasks are scheduled to complete within
their deadlines.
d) Resource availability: Some tasks may require
resources, such as memory or peripherals. The RTOS
scheduler will only schedule tasks if the required
resources are available
Scheduling Policy (Algorithms)
The scheduler determines which task runs by following a
scheduling algorithm (also known as scheduling policy).
Most kernels today supports common scheduling algorithms:
Priority-based scheduling
round-robin scheduling
preemptive priority-based scheduling,
Deadline-based scheduling
Scheduling Policy (Algorithms)
a) Priority-based scheduling: This is the most common type of
RTOS task scheduling algorithm. It simply assigns a priority
to each task and schedules the task with the highest priority
to run first.
b) Round-robin scheduling: This algorithm gives each task an
equal amount of time to run, regardless of its priority. This
can be useful for tasks that need to be executed periodically,
but it can also lead to missed deadlines for higher-priority
tasks.
Scheduling Policy (Algorithms)
Scheduling Policy (Algorithms)
c) Preemptive Priority-Based Scheduling
most real-time kernels use preemptive priority-based
scheduling by default.
Allow the RTOS to interrupt a running task and switch to a
higher-priority task.
This is important for ensuring that critical tasks meet their
deadlines, even if lower-priority tasks are already running.
Scheduling Policy (Algorithms)
Scheduling Policy (Algorithms)
Scheduling Policy (Algorithms)
d) Deadline-based scheduling:
This algorithm schedules tasks based on their deadlines.
Tasks with earlier deadlines are scheduled to run first.
This algorithm can help to ensure that all tasks meet their
deadlines, but it can be complex to implement.
Inter-process communication
An operating system provides interprocess communication to
allow processes to exchange information.
Interprocess communication is useful for creating cooperating
processes.
There are several mechanisms for inter-process
communication such as
Share memory communication and
Message passing
Shared Memory
Processes that share memory can
exchange data by writing and reading
shared variables.
As an example, consider two
processes P and Q that share some
variable S. Then P can communicate
information to Q by writing new data
in S, which Q can then read
Message Passing
Processes communicate with each
other by exchanging messages.
A process may send information to a
port, from which another process may
receive information.
The sending and receiving processes
can be on the same or different
computers connected via a
communication medium
Thank You!