Module 5
Module 5
DESIGN
MODULE-6
REAL-TIME OPERATING
SYSTEM
When a fighter jet control system runs on GPOS encountered a hill, and
you attempted to avoid… CSE3006 -EMBEDDED SYSTEM DESIGN
MODULE-6 5
RTOS - INTRODUCTION
NEED FOR RTOS
While you drive your car at high speed, suddenly collided with another vehicle if
airbag activation system runs on EOS opens only after 10 sec….
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 6
RTOS - INTRODUCTION
WHAT IS RTOS?
“Real time in operating systems is the ability of the OS to
provide a required level of service in a bounded response
time.” - POSIX Standard 1003.1
“A real-time operating system (RTOS) is an operating
system (OS) intended to serve real-time application
requests.” - Wikipedia
“RTOS: Any OS where interrupts are guaranteed to be
handled within a certain specified time, there by making it
suitable for control hardware in embedded system & time
critical applications.” - Dictionary.com
A
MODULE-6 real-time operating system
CSE3006 -EMBEDDED (RTOS)
SYSTEM DESIGN is an operating7
RTOS - INTRODUCTION
RTOS - FEATURES
Multitasking and Pre-emptibility: An RTOS must be multi-
tasked and pre-emptible to support multiple tasks in real-
time applications.
Task Priority: In RTOS, pre-emption capability is achieved by
assigning individual task with the appropriate priority level.
Inter Task Communication: For multiple tasks to communicate
in a timely manner and to ensure data integrity among each
other, reliable and sufficient inter-task communication and
synchronization mechanisms are required.
Priority Inheritance: To allow applications with stringent
priority requirements
MODULE-6 to -EMBEDDED
CSE3006 be implemented,
SYSTEM DESIGN RTOS must have a8
RTOS - INTRODUCTION
RTOS - FEATURES
Control of Memory Management: To ensure predictable
response to an interrupt, an RTOS should provide way for
task to lock its code and data into real memory.
MODULE-6
Interrupt dispatch latency:
CSE3006 -EMBEDDEDThe
SYSTEMtime
DESIGN from the last instruction9
RTOS - INTRODUCTION
RTOS - CHARACTERISTICS
Consistenc
Reliability
y
Predictabi
Scalability lity
Performa
nce
Examples:
Missile Navigation Systems
Vehicle Air Bags Control
MODULE-6
Nuclear Power Plant Control
CSE3006 -EMBEDDED SYSTEM DESIGN 11
RTOS - INTRODUCTION
RTOS - TYPES
FIRM RTOS tolerates a low occurrence of missing a deadline.
Examples:
Robot in car assembly section
Food processing control system
Weather monitoring system
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 12
RTOS - INTRODUCTION
RTOS - TYPES
SOFT RTOS allows for frequently missed deadlines, and as
long as tasks are timely executed their results continue to
have value.
Even the soft real time systems cannot miss the deadline for
every task or process according to the priority it should meet
the deadline. (Best effort system)
Examples:
Multimedia transmission & reception
Digital cameras & mobile phones
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 13
RTOS - INTRODUCTION
RTOS - APPLICATIONS
Mars Curiosity Rover, Uses VxWorks (For Split-second decision taking) and µc/os-II (For
MODULE-6 CSE3006Sample Analysis)
-EMBEDDED SYSTEM DESIGN 15
RTOS - INTRODUCTION
RTOS - APPLICATIONS
F-35 Fighter aircraft uses a Integrity DO-178B, a POSIX based RTOS developed by Green
MODULE-6 Hills Software
CSE3006 -EMBEDDED SYSTEM DESIGN 16
RTOS - INTRODUCTION
RTOS - APPLICATIONS
International medical technology group Elekta is basing its new generations of equipment
MODULE-6 on the-EMBEDDED
CSE3006 LynxOS-SE (RTOS)
SYSTEM DESIGN 17
RTOS - INTRODUCTION
RTOS - APPLICATIONS
ThreadX RTOS is used by HP (All Printers) & Honeywell (Advanced security systems) in
MODULE-6
consumer electronics devices
CSE3006 -EMBEDDED SYSTEM DESIGN 18
RTOS - INTRODUCTION
RTOS IN EMBEDDED MARKET
Applications
RTOS
BSP
Hardware
Microlithic Kernel
Hybrid Kernel
BASIS FOR
COMPARISO MONOLITHIC KERNEL MICROKERNEL HYBRID KERNEL
N
Basic In monolithic kernel, both In microkernel user services Hybrid kernel is a kernel
user services and kernel and kernel, services are kept in combining aspects from
services are kept in the separate address space. both Monolithic and
same address space. Microkernel designs
Size larger than microkernel Microkernel are smaller in size. smaller than monolithic
kernel
Execution Fast execution. Slow execution. Moderate speed
Extendible The monolithic kernel is The microkernel is easily Dynamically loadable
hard to extend. extendible. module
Security If a service crashes, the If a service crashes, it does It depends on service
whole system crashes in effect on working of called
monolithic kernel. microkernel.
Code To write a monolithic kernel, To write a microkernel, less Moderate code size
more code is required. code is required.
Example Linux, BSDs, Windows QNX, Symbian, L4Linux, Windows NT and above,
(95,98,Me), Solaris, OS-9, Singularity, K42, Integrity, Mac OS X, BeOS, ReactOS,
MODULE-6 AIX, HP-UX, DOS. PikeOS,. SYSTEM DESIGN
ECE4003-EMBEDDED Syllable. 27
RTOS - ARCHITECTURE
KERNEL
An RTOS generally avoids implementing the kernel as a
monolithic program.
The kernel is developed instead as a micro-kernel with added
configurable functionalities like scheduling, Managing
memory protection and IPC.
All other basic services can be made part of user space and
can be run in the form of servers.
This implementation gives resulting benefit in increase
system configurability, as each embedded application
requires a specific set of system services with respect to its
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 28
RTOS - ARCHITECTURE
RTOS – ARCHITECTURE
QNX Microkernel
Microkernel Model
While building the BSP image the user would specify which
graphics driver to include based in his choice of hardware.
BSP is supposed to perform the following operations
Initialize the processor
Initialize the bus
Initialize the interrupt controller
Initialize the clock
Initialize the RAM settings
MODULE-6
Load and run bootCSE3006
loader fromSYSTEM
-EMBEDDED flashDESIGN 31
PERFORMANCE
METRICS OF RTOS
Memory:
How much ROM and RAM does the kernel need and how is this
affected by options and configuration?
Factors that affect the memory footprint includes static or dynamic
configuration of Kernel, number of instruction related to processor,
global variable declaration etc.,
With the help of optimization setting in embedded compilers code
size can be reduced, but that will most likely affect performance.
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 33
PERFORMANCE METRICS OF RTOS
RTOS PERFORMANCE METRICS
Latency:
Interrupt latency: It is the sum of the hardware dependent time,
which depends on the interrupt controller as well as the type of the
interrupt, and the OS induced overhead.
Ideally, it should include the best and worst case scenarios.
To measure a time interval, like interrupt latency, with any accuracy,
requires a suitable instrument and the best tool to use is an
oscilloscope.
Scheduling latency: Being real time, the efficiency at which threads
or tasks are scheduled is of some importance and the scheduler is at
the core of an RTOS.
It is hard to get a clear picture of performance, as there is a wide
MODULE-6
variation in the techniques employed to make measurements and in34
CSE3006 -EMBEDDED SYSTEM DESIGN
PERFORMANCE METRICS OF RTOS
RTOS PERFORMANCE METRICS
Performance of kernel services:
An RTOS is likely to have many API (application program interface)
calls, probably numbering into the hundreds.
For most RTOSes, there are four key categories of service call:
Threading services
Synchronization services
Inter-process communication services
MODULE-6
Memory services CSE3006 -EMBEDDED SYSTEM DESIGN 35
PERFORMANCE METRICS OF RTOS
RTOS CONSIDERATIONS
What are the real-time capabilities? Is it soft or hard real-time interrupt
handling
What is the target processor, and does it support the RTOS you have in
mind?
38
Sufficient test:
If test is passed, then task are definitely schedulable
If test is not passed, tasks may be schedulable but not
necessarily
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 47
SCHEDULABILITY ANALYSIS
SCHEDULABILITY TEST
Necessary test
( )
𝑁
𝐶𝑖
𝑈 =∑ ≤1
𝑖 =1 𝑃𝑖
N B(N)
1 1.0
Sufficient test (Utilization Bound test)
2 0.828
3 0.779
( )
𝑁 1
𝐶𝑖 4 0.756
𝑈=∑ ≤ 𝑁 (2 −1) 𝑁
5 0.743
𝑖 =1 𝑃𝑇 𝑖 6 0.734
∞ 0.693
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 48
REAL TIME
SCHEDULING
Pre-emptive Algorithm:
Shortest remaining Time First(SRTF)
Round Robin(RR)
Priority(Pre-emptive)
Rate Monotonic Scheduling (RMS)
Earliest Deadline First (EDF)
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 52
REAL TIME SCHEDULING
RATE MONOTONIC SCHEDULING(RMS)
Concept: Task with the shortest period executes with the
highest priority.
Working :
Rate-monotonic is a fixed priority based scheduling.
The scheduling scheme is pre-emptive; it ensures that a
task is pre-empted if another task with a shorter period is
expected to run.
Used in embedded systems where the nature of the
scheduling is deterministic.
Consider three tasks with a period Task-1(10ms), Task-
MODULE-6
2(15ms), Task-3 (20ms), then as per RMS priority of the53
CSE3006 -EMBEDDED SYSTEM DESIGN
REAL TIME SCHEDULING
RATE MONOTONIC SCHEDULING(RMS) – EXAMPLE-1
Consider set of task running on a Automotive control system
as follows
Speed measurement Task (T1): C=20ms, P=100ms,
D=100ms
ABS control Task (T2): C=40ms, P=150ms, D=150ms
Fuel injection Task (T3): C=100ms, P=350ms,
Necessary Test
D=350ms Sufficient Test
Other software
( )
1
with soft deadlines e.g. audio, air
𝑁
condition
𝐶 etc.,
( )
𝑁
𝐶𝑖 𝑈=∑
𝑖
≤ 𝑁 (2 𝑁 −1)
𝑈 =∑ ≤1 𝑃𝑇 𝑖
𝑖 =1 𝑃𝑖 𝑖=1
U=(20/100)+(40/150)+(100/350) B(3)=0.779
= 0.2 + 0.2666 + 0.2857 = 0.7517 ≤ 1 U=0.7517 ≤ B(3) ≤
1 passes Sufficient
Since given task set
Necessary Test is passed hence given task set must be tested
test we may conclude it is definitely
under sufficient test to conclude the Schedulability. But, if
schedulable under RMS
necessary test is failed we may conclude given task set is
definitely not schedulable by any scheduling algorithm.
MODULE-6 CSE3006 -EMBEDDED SYSTEM DESIGN 54
REAL TIME SCHEDULING
RATE MONOTONIC SCHEDULING(RMS) – EXAMPLE-1
This is only for the first periods. But this is enough to conclude that the task set is schedulable
MODULE-6
REAL TIME SCHEDULING
RATE MONOTONIC SCHEDULING(RMS) – EXAMPLE-2
( ) ( )
𝑁 1
𝑁
𝐶𝑖 𝐶𝑖
𝑈 =∑ ≤1 𝑈=∑ 𝑁
≤ 𝑁 (2 −1)
𝑖 =1 𝑃𝑖 𝑖=1 𝑃𝑇 𝑖
U=(1/3)+(1/5)+(1/6)+(2/10)=0.89 B(4)=0.756
9≤1
Necessary Test is passed hence given task set must be tested The given task set fails in the Sufficient
under sufficient test to conclude the Schedulability. But, if test due to U=0.899 > B(4) we can’t
necessary test is failed we may conclude given task set is conclude precisely whether given task set
definitely not schedulable by any scheduling algorithm. is schedulable or not under RMS
MODULE-6
REAL TIME SCHEDULING
RATE MONOTONIC SCHEDULING(RMS) – EXAMPLE-3
( ) ( )
𝑁 1
𝑁
𝐶𝑖 𝐶𝑖
𝑈 =∑ ≤1 𝑈=∑ 𝑁
≤ 𝑁 (2 −1)
𝑖 =1 𝑃𝑖 𝑖=1 𝑃𝑇 𝑖
U=(10/30)+(15/40)+(5/50)=0.808 B(3)=0.779
≤1
Necessary Test is passed hence given task set must be tested The given task set fails in the Sufficient
under sufficient test to conclude the Schedulability. But, if test due to U=0.808 > B(3) we can’t
necessary test is failed we may conclude given task set is conclude precisely whether given task set
definitely not schedulable by any scheduling algorithm. is schedulable or not under RMS
MODULE-6
REAL TIME SCHEDULING
RATE MONOTONIC SCHEDULING(RMS) - PROs & CONs
PROs:
Simple to understand
Easy to implement (static/fixed priority assignment)
Stable: though some of the lower priority tasks fail to
meet deadlines, others may meet deadlines
CONs:
Lower CPU utilization
Requires D=T
Only deal with independent tasks
Non-precise Schedulability analysis
( )
𝑁
𝐶𝑖
𝑈 =∑ ≤1
𝑖 =1 𝑃𝑖
U=(1/4)+(2/5)+(2/7)
= 0.25 + 0.4+ 0.2857
= 0.935 ≤ 1
T1
T2
T3
MODULE-6
REAL TIME SCHEDULING
EARLIEST DEADLINE FIRST (EDF) – EXAMPLE-1
T1
T2
T3
Although given task set failed to schedule under RMS, it can scheduled by EDF
MODULE-6
REAL TIME SCHEDULING
EARLIEST DEADLINE FIRST (EDF) – EXAMPLE-2
( )
𝑁
𝐶𝑖
𝑈 =∑ ≤1
𝑖 =1 𝑃𝑖
U=(1/3)+(1/5)+(1/6)+(2/10)=0.89
9≤1
Necessary Test is passed hence given task set must be
schedulable by EDF
T1
T2
T3
MODULE-6
REAL TIME SCHEDULING
EARLIEST DEADLINE FIRST (EDF) – EXAMPLE-3
Necessary Test
( )
𝑁
𝐶𝑖
𝑈 =∑ ≤1
𝑖 =1 𝑃𝑖
U= (5/20)+(10/40)+(40/80)
= 0.25 + 0.25 + 0.5 = 1 ≤ 1
If cumulative CPU utilization is 1 then the CPU will be utilized 100% without
idle condition
T1
T2
T3
At time instance 80ms all 3 tasks are having same deadline. When multiple
tasks having deadline at same instance of a time then one of the task will be
MODULE-6 chosen randomly and get executed.
REAL TIME SCHEDULING
EARLIEST DEADLINE FIRST (EDF) - PROs & CONs
PROs:
It works for all types of tasks: periodic or non periodic
Simple Schedulability test
Best CPU utilization
Optimal scheduling algorithm
CONs:
Difficult to implement due to the dynamic priority-
assignment.
Any task could get the highest priority even if the task is
not important
MODULE-6 Non stable because if anySYSTEM
CSE3006 -EMBEDDED taskDESIGN
fails to meet its deadline,69