Rtos Faq Vector

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 56

RTOS Concepts & Definitions

An Overview With Practicals


Using 8051/ARM Architecture
AGENDA
• What is an OS ?
• Why OS is Primarily Required ?
• What is General Purpose OS (GPOS) ?
• What is Embedded System ?
• What is Embedded OSes ?
• What is Real Time Operating System ( RTOS)
?
• Non RTS vs RTS
• Soft RTS vs Hard RTS
• What makes an OS an RTOS ?
• What is a Re-entrant Function
• What is meant by Porting of RTOS ?
• What is BSP(Board Support Package) ?
Discussion
• What is an OS ?
An Operating System(OS) is a control
program used for managing the resources
of an computing system and provide a
platform in the form of a Command
Line(CLI)/Graphical User Interface (GUI) for
conveniently using the system without
bothering about the underlying details of
hardware operations.
OR
• An OS is simply an interface between the
USER & the Computing Hardware.
• E.g: Windows,UNIX,Linux,MAC – General
Purpose Operating System.
Why OS is Required Primarily
?
• To Ensure that CPU is never idle, &
increase percentage of effective utilization.
• A Single Process/Application which is
single tasking/threaded may sometimes be
unable to keep the CPU really engaged
optimally,even though capable design wise
BUT constrained by Application (Software).
• Hence Solution is Multi-Tasking/Multi-
Threading via an OS.
What is GPOS ?
• A GPOS is an OS which has a lot of
PARAPHERNALIA(modules/packages/su
pport) to support the requirements of
varieties of End-Users from various walk
of Life (from small Kids to Aged People)
who would like to use
Desktops,Laptops,Tablets,Smart Phones.
OS as a Service Provider
• Task/Thread/Process Scheduling based
on some Scheduling Policies
• Memory Management
• File Management
• I/O Devices Management
• Inter Task/Thread/Process
Communication for exchange of
information
• Synchronization between tasks when
dealing with shared resources.
OS Components
• Life Cycle of Task/Thread/Process
(States)
• Scheduler
• Dispatcher
• Event Management
• Inter Task Com & Synchronization
What is a Scheduler ?
• The scheduler is the part of the kernel
responsible for deciding which task
should be executing at any particular
time.
• The scheduling policy is the algorithm
used by the scheduler to decide which
task to execute at any point in time.
• E.g RRS,PBS, RMS ,CS,SJF,MLFBQ,
What is a dispatcher
• The dispatcher is comes after the scheduler.
• It gives control of the CPU to the process
selected by the scheduler.
AGENDA
• What is Super Loop Architecture ?
• What is an Embedded Operating System
(Embedded OS) ?
• What is Real Time Operating System
( RTOS) ?
• What is Real Time System (RTS) ?
• Non RTS vs RTS
• Soft SRTS vs Hard RTS
What is Super Loop
Architecture ?
What is Embedded OS ?
• Embedded OS is an OS customized for
size & services required for a specific
embedded system which requires multi-
tasking capability.
What is a Real Time Operating
System (RTOS) ?
• A Real Time Operating System is an
Embedded Operating System but further
customized for size & services required &
a well optimized for time
contraints/deadlines in output deliveries for
the specific embedded system.
What is Real-Time system?

• A system in which the correctness of the computation not


only depends upon the logical correctness of the
computation but also upon the time at which the result is
produced.
• Computation is performed during the actual time that an
external process occurs, in order that the computation results
may be used to control, monitor, or respond in a timely
manner to the external process
• A real-time system responds in a (timely) predictable way to
unpredictable external stimuli arrivals
What is Hard RealTime
• A system where all the critical tasks are highly
deterministic.
• Late response is considered to be a wrong
response. Hence all the real time tasks not only
produce logically correct result, but also their
delivery time is predictable.
• OS used in Mission-critical systems, like
automotive, avionics, space missions, medical
equipment are supposed to be hard real time.
What is Soft-realtime
• A system where miss in task deadline is
not a Catastrophe(disaster / Hazard), but
possible a reduction in quality.
• Home appliance, real video streaming,
set-top box (in DTH ) in television,mobile
phones,etc.
• What makes an OS an RTOS ?
• What is a Re-entrant Function
• What is meant by Porting of RTOS ?
• What is BSP(Board Support Package) ?
What makes OS a RTOS?
• RTOS has to ROMable preferably.
• RTOS has to be scalable preferably.
• RTOS Has to be configurable.
• RTOS Has to be deterministic.
• RTOS Has to support predictability.
• RTOS has to support multi-threaded and
preemptive.
• Scheduling of multiple threads must be
preferably priority based, can use round-robin,
or cooperative scheduling also.
• Should provide predictable thread
synchronization.
• Priority Inheritance must exist through dynamic
priority management.
• Interrupt Latency , Interrupt Response and
Interrupt Recovery must be calculable.
• Every system call’s maximum time of
completion should provided/known for a given
target’s specification.
• System interrupt levels must be known to the
developer of the system.
What is Reentrant function?

• A function/Sub-routine when invoked


simultaneously or nested or interleaved should
not interfere with each other.
• Shares same copy of code but different copies of
data for protection.
• Usually use local variables. Global and static
variables are discouraged.
• Particularly useful in implementation of
recursive functions and Interrupt handling.
What is Porting of RTOs ?
RTOS contains two parts:
one is processor specific codes & another
one is processor independent codes.
Porting means write the above two parts in
to ur device which is going to be ported &
change the processor specific codes
inorder to support the independent part of
RTOS code.
Porting is divided into two types:
1. Architecture Porting which ports the
context switch and interrupts to
the OS
2. Board porting which is concerned to
board support package and device
drivers
What is BSP?

• A Platform dependent package (in form of


source code or binary files) provided by RTOS
developers to build the RT-Kernel on a
Customized hardware platform .
• Sometimes it is a collection of drivers and HALs
(Hardware Abstraction Layer).
• It also largely depends on OEM’s (Original
Equipment Manufacturer) hardware
specification.
What is TCB?

• A Task’s context need to be saved when context switch


occurs in a multi-tasking environment.
• The data structure for saving is called as Task Control
Block or TCB.
• TCB mainly contains the following
– Thread ID of execution, that is, the task's program counter
– the CPU registers and (optionally) floating-point registers
– a stack for dynamic variables and function calls
– I/O assignments for standard input, output, and error
– a delay timer
– a time-slice timer
– etc
What is Critical Section?

• A section of code in a program , while


executing , no other program should
execute.
• All interrupts must be disabled while
Critical Section code is executing
including the Scheduler interrupt.
What is a Deadlock/Deadly Embrace?

• A deadlock is a situation wherein two or more


task are waiting fo resources held by the each
other. .
Necessary Conditions for
Deadlock
• Mutual exclusion: resources cannot be shared.
• Hold and wait: processes request resources
incrementally, and hold on to what they've got.
• No preemption: resources cannot be forcibly
taken from processes.
• Circular wait: circular chain of waiting, in which
each process is waiting for a resource held by
the next process in the chain.
Strategies for dealing with
Deadlock

• ignore the problem altogether.


• detection and recovery
• avoidance by careful resource allocation
• prevention by structurally negating one of
the four necessary conditions.
Deadlock Avoidance
• Acquire all resources before proceeding
• Acquire resource in an order and release
in reverse order
• Change priorities dynamically if required &
possible
• enable watch dog timer as an anticipation
for dead lock.
Interrupts

• Hardware mechanism to inform the CPU that an


asynchronous event has occurred
• The ISR processes the event and returns to
– the background in a foreground/ background system
– the interrupted task for a non preemptive kernel
– the highest priority task ready to run for a preemptive
kernel
Interrupt Timings
TIME

Context Context

TASK saved restored


Background

Interrupt

Latency

User ISR code


Interrupt

Request ISR Interrupt

Recovery

Interrupt Response
TIME
ISR entry
Context ISR exit Context
function
saved function restored
TASK A Task A

Interrupt

Latency

User ISR code


Interrupt
Interrupt
Request ISR Recovery

Interrupt Response Task B

Interrupt

Recovery
Interrupt Latency

• Interrupt latency is the sum of the maximum


amount of time interrupts are disabled and the
time to start executing the first instruction in the
ISR

• The longer the interrupts are disabled, the higher


the interrupt latency
Interrupt Response

• Time between the reception of the interrupt and


the start of the user code that handles the interrupt

• For a foreground background system and non


preemptive kernel = interrupt latency + time to
save the CPU’s context

• For a preemptive kernel = interrupt latency + the


time to save the CPU’s context + execution time of
the kernel ISR entry function
Interrupt Recovery

• Time required for the processor to return to the


interrupted code
• For a foreground/background system and non
preemptive kernel = time to restore the CPU’s context +
time to execute the return from interrupt instruction

• For a preemptive kernel = time to determine if a higher


priority task is ready + time to restore the CPU’s context of
the highest priority task + time to execute the return from
interrupt instruction
Priority Inversion Problem

Priority inversion is an undesirable situation in which a


higher priority task gets blocked (waits for CPU) for more
time than that it is supposed to, by lower priority tasks.

Example:
• Let T1 , T2 , and T3 be the three periodic tasks with
decreasing order of priorities.
• Let T1 and T3 share a resource “S”.
Makes a A higherResource S is
available and T1
priority task
Priority Inversion example
request for
resource S and waits for ais scheduled
gets blocked lower priority here
T1 task
Highest T1 T1
priority
T2 completes

L1
Preempted by
higher priority T3 completes
T2 T3 is the T2
task T1
Medium only
priority active Preempted by
task higher K3
priority
K1 K2 task T2
T3 T3 T3 T3
Least
priority 0

T1 and T3
share
resource Total blocking time for task T1 = (K1+K2+K3) + (L1)
S
Priority Inheritance Protocol
• priority inheritance protocol—ensures that
the priority level of the lower priority task
that has acquired the mutex is raised to that of
the higher priority task that has requested the
mutex when inversion happens. The priority of
the raised task is lowered to its original value
after the task releases the mutex that the higher
priority task requires.
Priority Ceiling Protocol
• ceiling priority protocol—ensures that the priority
level of the task that acquires the mutex is
automatically set to the highest priority of all
possible tasks that might request that mutex when
it is first acquired until it is released.
• Similarly to the ceiling priority protocol, the priority
of every task is known in the priority ceiling
protocol. The resources that every task requires
are also known before execution. The current
priority ceiling for a running system at any time is
the highest priority ceiling of all resources in use
at that time.
Priority Inversion - Real-world
Example
• Mars Pathfinder mission (July 4, 1997)
• VxWorks (real-time OS), preemptive priority scheduling of threads
(e.g., RMS)

• Priority inversion involving three threads:


– Information bus task (T1), meteorological data gathering task
(T3), communication task (T2). Priority order: T1>T2>T3
– Shared resource: information bus (used mutex)

• Same situation as described in the previous example had


occurred
• Findings: Priority ceiling protocol was found to be disabled
initially, then it was enabled online and the problem was corrected
What is meant by a jitter ?
• Timing error of a task over subsequent
iterations of a program or loop is referred
to as jitter.
• Hard RTOS are optimized to minimize
jitter the most.
What is a clock tick ?
• A clock tick is a special interrupt that
occurs periodically. This interrupt can be
viewed as the system's heartbeat.
• The time between interrupts is application
specific and is generally between 10 and
200 mS.
• The clock tick interrupt allows a kernel to
delay tasks for an integral number of clock
ticks and to provide timeouts when tasks
are waiting for events to occur.
• The faster the tick rate, the higher the
overhead imposed on the system.
Types of RTOs
Traditional/RealTime Executive RTOs

• Were meant for MMU-less, restricted on chip/off


chip memory processors.
• Supports flat/linear address space with no
memory protection between the kernel and
applications,
• Have small memory and size footprint as both the
OS and applications are bundled into a single
image.
• All software running on the system should be
foolproof.
• There is no overhead of system calls,
message passing, or copying of data.
• Applications or kernel modules cannot be
dynamically added to the system.
What is a micro kernel ?
• Suited for processors having MMU/MMU less.
• If CPU supports modes, the micro kernel is the only
software executing at most privileged level
(supervisor/kernel mode).
• The microkernel makes use of a small OS that provides
the very basic service (scheduling, interrupt handling,
message passing)
• And the rest of the kernel subsystem (file system, device
drivers, networking stack) runs as applications in user
space.
• Must support well-defined APIs for
communication with the OS as well as
robust message-passing schemes.
What is Monolithic Kernel ?

• Clear Distinction between the user and kernel space.


• User space normally cannot access the system
hardware nor can it execute privileged instructions.
• Using special entry points (provided by hardware), an
application can enter the kernel mode from user space.
• User space programs operate on a virtual address
hence corruption of another application’s or the
kernel’s memory avoided.
• Support dynamic loading of separately compiled kernel
modules or applications without bringing down the
system.
Few more questions
• Explain what is scalable and configurable feature in RTOS.
• Why the virtual memory may be absent in RT Kernels?
• What is advantage if virtual memory is absent ?
• What is the advantage of Micro-kernel?
• How to reduce latency?
• What is priority inheritance?
• What is priority inversion ?
• What is watchdog timer?
• What is clock tick of an RTOs ?
• What is a task,resource,context switching… ?

You might also like