Unit Ii
Unit Ii
Unit Ii
RTOS
A real-time operating system is an operating system
intended to serve real-time applications that
process data as it comes in, typically without buffer
delays. Processing time requirements are measured in
tenths of seconds or shorter increments of time
A RTOS has an advanced algorithm for scheduling.
Scheduler flexibility enables a wider
Key factors in a real-time OS are minimal
interrupt latency and minimal
thread switching latency
a real-time OS is valued more for how quickly or how
predictably it can respond than for the amount of
work it can perform in a given period of time
RTOS USES
Airlines reservation system.
Air traffic control system.
Systems that provide immediate updating.
Used in any system that provides up to date and
minute information on stock prices.
Defense application systems like RADAR.
Networked Multimedia Systems.
Command Control Systems
RTOS NAMES
eCos
LynxOS
QNX
RTLinux
Symbian OS
VxWorks
Windows CE
MontaVista Linux
RTOS
RTOSes apart from GPOSes include:
better reliability in embedded application contexts,
the ability to scale up or down to meet application
needs,
faster performance,
reduced memory requirements,
scheduling policies tailored for real-time embedded
systems,
support for diskless embedded systems by allowing
executables to boot and run from ROM or RAM, and
better portability to different hardware platforms.
High-level view of an RTOS
RTOS COMPONENTS
1.Scheduler-is contained within each kernel and follows
a set of algorithms that determines which task executes
when. Some common examples of scheduling algorithms
include round-robin and preemptive scheduling.
Process and events
2.Objects-are special kernel constructs that help
developers create applications for real-time
embedded systems. Common kernel objects include
tasks, semaphores, and message queues.
3.Services-are operations that the kernel performs on
an object or, generally operations such as timing,
interrupt handling, and resource management
RTOS COMPONENT DIAGRAM
Scheduler
The scheduler is at the heart of every kernel
schedulable entities,
multitasking,
context switching,
dispatcher, and
Schedulable Entities
A schedulable entity is a kernel object that can
compete for execution time on a system, based
on a predefined scheduling algorithm
Tasks and processes are all examples of
schedulable entities found in most kernels
A task is an independent thread of execution
that contains a sequence of independently
schedulable instructions
Events and process are entities
Semaphores and message queue are not
schedulable entities IPC objects for process sync
Multitasking
preemptive priority-based
scheduling, and
round-robin scheduling.
preemptive priority-based scheduling
Real-time kernels generally support 256 priority
levels, in which 0 is the highest and 255 the lowest.
Some kernels appoint the priorities in reverse order,
where 255 is the highest and 0 the lowest
Timer management,
Interrupt handling,
Device I/O, and
Memory management
Key Characteristics of an RTOS
reliability
predictability
performance
compactness and
scalability
Reliability
Task definition
Task states and scheduling
Typical task operations
Typical task structure and
Task coordination and concurrency
Defining a Task
A task is schedulable
the task is able to
compete for execution
time on a system, based
on a predefined schedule
Specifically, upon
creation, each task has
an associated name, a
unique ID, a priority (if
part of a preemptive
scheduling plan), a task
control block (TCB), a
stack, and a task routine
Examples of system tasks include
Initialization or startup task—initializes the system
and creates and starts system tasks
1.create---------------------create a task
2.delete---------------------delete a task
1.Run to Completion
{
Initialize the application;----services, kernel OBJ
Create endless loop tasks
Create kernel object
Delete objects
}
EndlessLoop
{
Initialization code()
LoopForever
{
Body of the loop
Blocking calls
}
}
Semaphores
Def-A semaphore (sometimes called a
semaphore token) is a kernel object that one or
more threads of execution can acquire or
release for the purposes of synchronization or
mutual exclusion
defining a semaphore,
typical semaphore operations, and
common semaphore use
Defining Semaphores
Binary Semaphores
Counting Semaphores
Mutual Exclusion (Mutex)
Semaphores
Defining Semaphores
operations
1.down 2.up
Wait(S)
While s<=0;no loop Signal(S)
S--; {
} S++;
• }
Binary Semaphores
A binary semaphore can
have a value of either 0 or
1
When a binary
semaphore’s value is 0,
the semaphore is
considered unavailable
(or empty); when the
value is 1, the binary
semaphore is considered
available (or full )
Binary semaphore S1,S2
S1=1,S2=0;
Wait(S1) Signal(S1)
C--; wait(S1)
If(c<0) c++;
{ if(c<=0)
Signal(S1); //block Signal(s2);
Wait(S2); //process suspend else Signal(S1);
}//sleep mode
Down,p wait Up v,signal
Counting Semaphores
A counting semaphore uses a
count to allow it to be acquired
or released multiple times
.When creating a counting
semaphore, assign the
semaphore a count that denotes
the number of semaphore
tokens it has initially.
If the initial count is 0, the
counting semaphore is created
in the unavailable state. If the
count is greater than 0, the
semaphore is created in the
available state, and the number
of tokens it has equals its count
Mutual Exclusion (Mutex) Semaphores
A mutual exclusion
(mutex) semaphore is a
special binary
semaphore that supports
ownership, recursive
access, task deletion
safety, and one or more
protocols for avoiding
problems inherent to
mutual exclusion
Differences
BINARY SEMAPHORES MUTEX
Operation Description
Create Creates a semaphore
Delete Deletes a semaphore
Operation Description
Flush Unblocks all tasks waiting on a semaphore
Operation Description
Show info
Show general information about semaphore
wait-and-signal synchronization
multiple-task wait-and-signal synchronization
credit-tracking synchronization
single shared-resource-access synchronization
recursive shared-resource-access synchronization,
and
multiple shared-resource-access synchronization
wait-and-signal synchronization
Two tasks can
communicate for the
purpose of
synchronization without
exchanging data. For
example, a binary
semaphore can be used
between two tasks to
coordinate the transfer
of execution control
tWaitTask()
{
Acquire the binary semaphore token
}
tSignal Task()
{
Release binary semaphore token
}
multiple-task wait-and-signal synchronization
tSinkTask ()
{
:
Receive message from message queue
:
}
Interlocked, One-Way Data Communication
tSinkTask ()
{
:
Receive message from message queue Give binary semaphore
:
}
Interlocked, Two-Way Data Communication
Sometimes data must
flow bidirectionally
between tasks, which is
called interlocked, two-
way data communication.
This form of
communication can be
useful when designing a
client/server-based
system
tClientTask ()
{
:
Send a message to the requests queue Wait for message from the
server queue
:
}
tServerTask ()
{
:
Receive a message from the requests queue Send a message to the
client queue
:
}
Broadcast Communication
Some message-queue
implementations allow
developers to broadcast a
copy of the same
message to multiple
tasks
tBroadcastTask ()
{
:
Send broadcast message to queue
:
}
Note: similar code for tSignalTasks 1, 2, and 3.
tSignalTask ()
{
:
Receive message on queue
:
}