0% found this document useful (0 votes)
24 views24 pages

Rtes09 - Rtos3

Uploaded by

mzmegastorm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views24 pages

Rtes09 - Rtos3

Uploaded by

mzmegastorm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

EEE440

Real Time Embedded


Systems
Real Time Operating System
Muhammad Kamran Fiaz ([email protected])
We learned so far

 RTES Introduction
 Categories of the RTES
 Properties & Components
 Hardware
 RTOS
Today’s topics

 Real Time Operating System Concepts


RTOS Kernel

 Why General Purpose OS not workable in real time embedded systems?


 it takes too much space and contains too many functions that may not be
necessary for a specific real-time application.
 It is not configurable, and its inherent timing uncertainty offers no guarantee to
system response time.
 Therefore, a general-purpose OS is not suitable for real-time embedded systems

 We need RTOS for real time systems


Characteristics of RTOS Design

 The timing behavior of the OS must be predictable. For all services provided
by the OS, the upper bound on the execution time must be known. Some
of these services include OS calls and interrupt handling.
 The OS must manage the timing and scheduling, and the scheduler must
be aware of task deadlines.
 The OS must be fast. For example, the overhead of context switch should
be short. A fast RTOS helps take care of soft real-time constraints of a system
as well as guarantees hard deadlines
RTOS Overview
RTOS Kernel

 A real-time kernel is software that manages the time and resources of a


microprocessor or microcontroller and provides indispensable services such
as task scheduling and interrupt handling to applications.
 In embedded systems, a small amount of code called board support
package (BSP) is implemented for a given board that conforms to a given
OS. It is commonly built with a bootloader that contains the minimal device
support to load the OS and device drivers for all the devices on the board.
RTOS Kernel
Clocks and Timers

 Hardware Timer to interrupt when the required time is up


 taskDelay ()
Scheduling

 Priority Scheduling
 EDF
 RM
 Preemption
Scheduling

 First Come First Serve


 Round Robin

 Are these above schemes applicable for Real Time Systems


Inter-Task Communication

 A task can not call another task


 Tasks exchange information
 Through message passing
 Through memory sharing
 Real time signals
 Mutex
 Semaphore objects
Inter Task Communication

 In an RTOS, a task (process) can not call another task


 Tasks exchange information
 How?
 Message Passing
 Memory Sharing
 Real Time Signals
 Mutex
 Semaphore
Real Time Signals

 Software Interrupts.
 When a child process terminates, a signal is sent to the parent
 Synchronous and asynchronous notifications
 Waking a process after the WAIT state
 Memory Violation
Mutex

 Mutual Exclusion Object


 One Resource, multiple threads take turns sharing the same resource
wait (mutex);
.....
Critical Section
.....
signal (mutex);

 Mutex is just simple locks obtained before entering its critical section and
then releasing it.
 Since only one thread is in its critical section at any given time, there are no
race conditions, and data always remain consistent.
Semaphore

 Semaphores are counters used for controlling access to resources shared


among processes or threads. The value of a semaphore is the number of units
of the resource that are currently available.
 There are two basic operations on semaphores.
 One is to atomically increment the counter.
 The other is to wait until the counter is non-null and atomically decrement it.
 A semaphore tracks only how many resources are free.
 It does not keep track of which of the resources are free.
Binary Semaphore

 A binary semaphore acts similarly to a mutex, which is used in the case when a
resource can only be used by at most one task at any time.

 The value of a semaphore ranges between 0and 1.


 It is similar to mutex lock, but mutex is a locking mechanism, whereas the
semaphore is a signaling mechanism.
Advantages of Semaphore

 It allows more than one thread to access the critical section.


 Semaphores are machine-independent.
 Semaphores are implemented in the machine-independent code of the
microkernel.
 They do not allow multiple processes to enter the critical section.
 As there is busy and waiting in semaphore, there is never wastage of
process time and resources.
 They are machine-independent, which should be run in the machine-
independent code of the microkernel.
 They allow flexible management of resources.
Disadvantages of Semaphore

 One of the biggest limitations of a semaphore is priority inversion.


 The operating system has to keep track of all calls to wait and signal
semaphore.
 Their use is never enforced, but it is by convention only.
 The Wait and Signal operations require to be executed in the correct order to
avoid deadlocks in semaphore.
 Semaphore programming is a complex method, so there are chances of not
achieving mutual exclusion.
 It is also not a practical method for large scale use as their use leads to loss of
modularity.
 Semaphore is more prone to programmer error
 It may cause deadlock or violation of mutual exclusion due to programmer
error.
Difference between Mutex and
Semaphore
 The basic difference between semaphore and mutex is that semaphore is
a signalling mechanism, i.e. processes perform wait() and signal() operation
to indicate whether they are acquiring or releasing the resource.
 In contrast, a mutex is a locking mechanism, and the process has to
acquire the lock on a mutex object if it wants to acquire the resource.
Difference between Mutex and
Semaphore
Mutex Semaphore
The mutex is a locking mechanism, as Semaphore is a signalling mechanism
to acquire a resource, a process as wait() and signal() operations
needs to lock the mutex object, and performed on the semaphore variable
while releasing a resource process has indicate whether a process is
to unlock the mutex object. acquiring or releasing the resource.
A mutex is an object. Semaphore is an integer variable.
Mutex allows multiple program Semaphore allows multiple program
threads to access a single resource threads to access a finite instance of
but not simultaneously. resources.
Mutex object lock is released only by Semaphore value can be changed
the process that has acquired the lock by any process acquiring or releasing
on the mutex object. the resource by performing wait() and
signal() operation.
Difference between Mutex and
Semaphore
Mutex Semaphore
Mutex is not categorized further. The semaphore can be categorized
into counting semaphore and binary
semaphore.
The mutex object is locked or Semaphore value is modified using
unlocked by the process of requesting wait() and signal() operation apart
or releasing the resource. from initialization.
If a mutex object is already locked, Suppose the process acquires all the
then the process desiring to acquire resources, and no resource is free. In
resource waits and get queued by the that case, the process desiring to
system till the resource is released and acquire resource performs wait()
the mutex object gets unlocked. operation on semaphore variable and
blocks itself till the count of
semaphore become greater than 0.
Mutex vs Semaphore
Next Lecture

 Memory Sharing

You might also like