0% found this document useful (0 votes)
0 views37 pages

Chapter Three

Uploaded by

tommili867
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)
0 views37 pages

Chapter Three

Uploaded by

tommili867
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/ 37

Chapter Three

Software Frameworks for Real-time


and Embedded Systems

1 Compiled by Yilu
Module Outline
✓ Real-time OS: definitions, Characteristics, functionality, structure and
support for applications
✓ Features of a RTOS
✓ General and specific microprocessors
✓ Inter process communication
✓ Real time task scheduling
✓ RTOS support for semaphores, queues, and events
✓ Dynamic allocation of tasks
✓ Scheduling: Cyclic scheduling, Priority-based scheduling
✓ Multi-tasking and Concurrency issue
✓ Fault- tolerance
✓ Synchronization techniques: Centralized clock synchronization, Distributed
clock synchronization
Compiled
2 by Yilu
✓ Handling resource sharing and dependencies
Real Time Operating System (RTOS)

➢ RTOS?
1. A RTOS is an OS that guarantees a certain capability within a
specified time constraint.
2. OS is a system program that provides an interface between
application programs and the computer system (hardware).
3. The applications where dependability that a certain task will finish
before a particular deadline is just as obtaining the correct results.
4. Besides meeting deadlines, RTOS must also be able to respond
predictably to unpredictable events and process multiple events
concurrently
Compiled by Yilu 3
Cntd…

➢ RTOS is key to many embedded systems today and, provides a software

platform upon which to build applications.

➢ Not all embedded systems are designed with an RTOS. Some embedded

systems with relatively simple hardware or a small amount of software

application code might not require an RTOS.

➢ Many embedded systems with moderate-to-large software applications

require some form of scheduling, and these systems require an RTOS.

➢ Although, some functional similarities exist between RTOS and General

Purpose Operating System (GPOS), many differences occur as well.


Compiled by Yilu 4
Characteristics of a RTOS
❑ RTOS generally have the following characteristics:

1. Small footprint. Compared to general OS, RTOS are lightweight.

2. High performance. RTOS are typically fast and responsive.

3. Determinism. Repeating inputs end in the same output.

4. Safety and security: Safety-critical and security standards are typically the

highest priority, as RTOS are frequently used in critical systems.

5. Priority-based scheduling: Tasks that are assigned a high priority are

executed first followed by lower-priority jobs.


6. Timing information: RTOS are responsible for timing and providing
Compiled by Yilu 5
application programming interface
Cntd…
➢ Some core functional similarities between a RTOS and GPOS
❖ Software and hardware resource management,
❖ Some level of multitasking
❖ Providing of underlying OS services to applications, and
❖ Abstracting the hardware from the software application
➢ Some key functional differences that set RTOS apart from GPOS
❖ Better reliability in embedded application contexts
❖ The ability to scale up or down to meet application needs,
❖ Faster performance,
❖ Reduced memory requirements,
❖ Support for diskless embedded systems by allowing executables to
boot and run from ROM or RAM, and
❖ Compiled by Yilu
Better portability to different hardware platforms 6
Structure of RTOS
➢ Basic Structure is similar to regular OS but, in addition, it provides
mechanisms to allow real time scheduling of tasks.

➢ Though RTOSs may or may not increase the speed of execution, they can
provide much more precise and predictable timing characteristics than
general-purpose OS.

Compiled by Yilu 7
Cntd…
➢ The heart of a real-time OS (and the heart of every OS) is the kernel.
➢ A kernel is the central core of an OS, and it takes care of all the OS jobs:
1. Booting
2. Task Scheduling
3. Standard Function Libraries
➢ In an embedded system, frequently the kernel will boot the system,
initialize the ports and the global data items.
➢ Then, it will start the scheduler and instantiate any hardware timers that
need to be started.
➢ After all that, the Kernel basically gets neglected out of memory, and the
scheduler will start running the child tasks.
Compiled by Yilu 8
Basic Kernel Services

➢ The "kernel" of a RTOS provides an "abstraction layer" that hides from


application software from the hardware from details of the processor upon
which the application software will run.

➢ The Kernel provides

▪ An interrupt handler

▪ Task scheduler

▪ Resource sharing flags and

▪ Memory management

Compiled by Yilu 9
Basic functions of RTOS

❑ The following are some of the basic function of RTOS


➢ Task Management
➢ Interrupt handling
➢ Memory management
➢ Exception handling
➢ Task synchronization
➢ Task scheduling
➢ Time management

1. Task Management
➢A task is a unit of execution or unit of work in a software application.
➢ Have timing constraints for tasks
➢ Each task a triplet: (execution time, period, deadline)
➢ Can be initiated any time during
Compiled by Yilu
the period 10
Cntd…
2. Interrupt handling

3. Memory management 4. Exception handling


➢ When a task is created the RTOS
➢ Standard techniques:
simply returns an already
❖ System calls with error
initialized memory location.
➢ when a task dies, the RTOS returns code
the memory location to the pool Compiled by Yilu ❖ Fault-tolerance 11
Applications of RTOS
Real-time systems are used in:
➢ Airlines reservation system.
➢ Air traffic control system.
➢ Systems that provide immediate updating.
➢ Defense application systems like RADAR.
➢ Networked Multimedia Systems
➢ Command Control Systems
➢ Internet Telephony
➢ Anti-lock Brake Systems
➢ Heart Pacemaker etc…
Compiled by Yilu 12
Features of RTOS

❖ Important features of RTOS:

➢ Occupy very less memory

➢ Consume fewer resources

➢ Response times are highly predictable

➢ Unpredictable environment

➢ The Kernel saves the state of the interrupted task and then
determines which task it should run next.

➢ The Kernel restores the state of the task and passes control of
the CPU for that task.
Compiled by Yilu 13
General and specific microprocessors

❑ General and Microprocessors


➢ The system designer created to produce large numbers microprocessors for a
variety of applications.
➢ Advantages:
▪ Easy to design and use
▪ Design time is low
▪ Design cost is low
▪ Re programmability
➢ Disadvantages:
▪ Performance is not very good
▪ Size is high
▪ They consume much power
Compiled by Yilu 14
Specific purpose microprocessor

❑ Specific Purpose Microprocessor


➢ An embedded designer creates a single-purpose processor by designing a
custom digital circuit for one program.
➢ Advantages:
▪ Performance is very good
▪ Small size (exact to fit one solution)
▪ Consume little power
➢ Disadvantages:
▪ not very easy to design and design time is high
▪ Design cost is thus higher
▪ Reprogramming is difficult
▪ Limited flexibility: not easy to make changes
▪ e.g., 1. Application-specific integrated circuit (ASIC),
2. application-specific standard product
Compiled by Yilu (ASSP) 15
Context switching mechanisms
❑ A context switch
➢ process switch or a task switch
➢ switching of the CPU from one process/task to another
➢ It is an essential feature of multitasking OS
How multitasking is working with single CPU?
➢ A multitasking OS
▪ CPU simultaneously execute multiple tasks
▪ it is an illusion of concurrency
▪ It is achieved by means of context switching
Task: decomposed application into small, schedulable, and sequential program units
 governed by three time-critical properties;
 Release time
 Deadline
 Execution time
Compiled by Yilu 16
Cntd…
❑ Each task may exist in following states

➢ Dormant: Task doesn’t require CPU time

➢ Ready: Task is ready to go active state, waiting processor time

➢ Active: Task is running

➢ Suspended: Task put on hold temporarily

➢ Pending: Task waiting for resource.

Compiled by Yilu 17
Cntd…
❑ What happened during switching ?

➢ Context of the to-be-suspended task will be saved.

➢ Context of the to-be-executed task will be retrieved

❑ Task Control block(TCB):

➢ Task uses TCBs to remember its context.

➢ Accessible only by RTOS

➢ Information on TCB could be


Task_ID
Task_State
Task_Priority
Task_Stack_Pointer
Task_Prog _Counter

Compiled by Yilu 18
Inter-process communication
➢ Tasks usually need to communicate and synchronize with each other for

different reasons such as:


 Accessing a shared resource

 To signal the occurrence of events to each other

➢ RTOS provides inbuilt inter-task primitives , which are kernel objects that

facilitate these synchronization and communication

➢ Examples of such objects include:

❖ Semaphores

❖ Message queues

❖ Signal and so on
Compiled by Yilu 19
Cntd…
❑ Semaphores is a kernel object that one or more tasks can acquire or release for :
 Mutual exclusion
 Signaling the occurrence of an event
 Synchronizing activities among tasks
➢ Semaphores have
➢ An associated semaphore control block (SCB),
➢ A unique ID,
➢ A user-assigned value (binary or a count), and
➢ A task-waiting list.
➢ There are two types
 Binary semaphores (0 or 1)
 If value =0 => semaphore is not available
 If value = 1 => semaphore available
 Counting semaphores (>= 0)
Compiled by Yilu 20
 uses a count to allow it to be acquired or released multiple times.
Real time task scheduling
❑ The two major groups are run-time and pre-run-time schedulers.
A. Run time Scheduler is referred to priority based schedulers where the decision
of which task will execute next is computed dynamically at run time.
B. Pre-run-time schedulers are those which computation work about the execution
line is done previous to run-time.
▪ These are also known as cyclic or clock driven schedulers.
A. Priority-based Scheduling is based in the idea that each task in the systems is
assigned a priority according to some decision base.

➢ Consistent with priority, the task will be assigned for execution while the system
is running.
➢ The main question here is, which factor do we use to assign the priorities?
❖ priority-based algorithms, dynamic-priority and static-priority scheduling.
Compiled by Yilu 21
Cntd…
B. Cyclic scheduling (also known as clock-driven, pre-run time)
➢ This schedule is computed off-line before the system begins to execute, and the
computation is based on the knowledge of the release times and resource
requirements of all the jobs for all times.
➢ It offers, general advantages for deterministic systems, in which release times and
job demands don’t vary or vary slightly with time.
➢ But the problem is what happens with those systems in which the future work
load is relatively unpredictable?

❑ Scheduling policies: keeping record of the state of each task and allocates the
CPU to one of them
➢ Scheduler is responsible for time-sharing of CPU among tasks.
Compiled by Yilu 22
Cntd…

➢ More information about the tasks are required


➢ Number of tasks
➢ Resource Requirements
➢ Execution time
➢ Deadlines
➢ Scheduling algorithms
❖ Clock Driven Scheduling
❖ Weighted Round Robin Scheduling
❖ Priority Scheduling
1. Clock Driven Scheduling
➢ All parameters about jobs (execution time/deadline) known in advance.
➢ Schedule can be computed at some regular time instances.
➢ Minimal runtime overhead
➢ Not suitable for many applications
Compiled by Yilu 23
➢ Time driven and for hard realtime system.
Cntd…

2. Weighted Round Robin Scheduling


 Jobs scheduled in FIFO manner
 Time quantum given to jobs is proportional to it’s weight
 Example use : High speed switching network : Job A can run only after Job B.
3. Priority Scheduling
 Processor never left idle when there are ready tasks
 Processor allocated to processes according to priorities
 Priorities
 Static - at design time
 Dynamic - at runtime
 Earliest Deadline First (EDF
 Least Slack Time First (LSF): slack = relative deadline – execution left
 Rate Monotonic Scheduling (RMS): is an optimal fixed-priority policy where
the higher the frequency (1/period) of a task, the higher is its priority.
 Tasks priority inversely proportional to it’s period.
Compiled by Yilu 24
Message passing and shared memory communications

❑ Message Passing is a form of communication used in inter process


communication.
➢ Communication is made by the sending of messages to recipients.
➢ Each process should be able to name the other processes.
➢ The producer typically uses send() system call to send messages,
➢ and the consumer uses receive() system call to receive messages.
➢ synchronous or asynchronous,
➢ Could either be between processes running on a single machine,
➢ Could be done over the networked machine.

❑ Message Queue: kernels provide an object called a message queue

➢ a buffer-like object through which tasks send and receive messages to communicate

and synchronize with each others


➢ Used to place task send or received messages
Compiled by Yilu 25
Cntd…
➢ Message queues have
 an associated message queue control block (QCB),
 a name,
 a unique ID,
 memory buffers,
 a message queue length,
 a maximum message length,
❑ Shared Memory communication
➢ Is an OS provided abstraction
➢ allows a memory region to be simultaneously accessed by multiple programs
➢ One process will create an area in RAM which other processes can access
➢ Since both processes can access the shared memory area like regular working
memory, this is a very fast way of communication
➢ It is less powerful, as for example the communicating processes must be running
Compiled by Yilu 26
on the same machine
Dynamic allocation of tasks
➢ Task in real time system, the system is subjected to real time.
i.e, response should be guaranteed within a specified time constraint.
➢ There are two types in real time systems task allocation: Periodic and
dynamic allocation tasks
➢ Periodic tasks: jobs are release in at a regular interval and repeats itself
after a fixed time interval.
➢ Dynamic Tasks:
➢ It is a class of task allocation in which the task is a dynamic process and
may need to be continuously adjusted in response to changes in the task
environment.
❖ It is more efficient

Compiled by Yilu 27
Multi-tasking and Concurrency issue

➢ Multitasking is the capability of the OS of running several applications at


the same time.
➢ When CPU resources are over-committed, the OS schedules the different
active processes by performing a process switch at regular time intervals,
distributing the available CPU cycles according to a well-defined priority
policy.
➢ Multitasking is the natural execution model of single or multiprocessor
systems.
➢ Switching among different processes naturally induces an execution
overhead.
➢ For a system to be real-time, there must be a guaranteed time frame where
within a task must execute.
➢ In a multitasking RTOS: the task scheduling, switching and execution
elements are key to the effectiveness of bythe
Compiled Yilu OS in real-time requirements. 28
What is concurrency in real time systems?
➢ Concurrency is the execution of the multiple instructions at the same time.
➢ It happens in the OS when there are several process threads running in parallel.
➢ The running process threads always communicate with each other through shared
memory or message passing.
➢ Concurrency in sharing of resources result in problems like deadlocks and
resources starvation.

Compiled by Yilu 29
Fault tolerance

➢ Fault tolerance refers to the ability of a system (computer, network,


cloud cluster, etc.) to continue operating without interruption when one
or more of its components fail.
➢ Systems employ backup elements that take the place of the failed
component to ensure there's no loss in productivity for your business.
➢ Fault tolerance can be achieved by either hardware or software or time
redundancy.
➢ Safety-critical applications have strict time and cost constraints, which
means that not only faults have to be tolerated but also the constraints
should be satisfied.

Compiled by Yilu 30
Synchronization techniques: Centralized clock synchronization, Distributed clock
synchronization

❑ Distributed System is a collection of computers connected via the high


speed communication network.
➢ In the distributed system, the hardware and software components
communicate and coordinate their actions by message passing.
➢ Each node can share their resources with other nodes.
➢ So, there is need of proper allocation of resources to preserve the state of
resources and help coordinate between the several processes.
➢ To resolve such conflicts, synchronization is used.
❑ Synchronization in distributed systems is achieved via clocks.
➢ The physical clocks are used to adjust the time of nodes.
➢ Each node in the system can share its local time with other nodes in the
system.
Compiled by Yilu 31
Cntd…

❑ The time is set based on UTC (Universal Time Coordination).


❑ UTC is used as a reference time clock for the nodes in the system.
➢ There are 2 types of clock synchronization algorithms: Centralized
and Distributed.
A. Centralized clock synchronization
➢ It is the one in which a time server is used as a reference.
➢ The single time server propagates its time to the nodes and all the nodes
adjust the time accordingly.
➢ It is dependent on single time server so if that node fails, the whole
system will lose synchronization.
➢ E.g., of centralized are-Passive Time Server, Active Time Server etc.
Compiled by Yilu 32
Cntd…

B. Distributed clock synchronization


➢ It is the one in which there is no centralized time server present.
➢ The nodes adjust their time by using their local time and then, taking the
average of the differences of time with other nodes.
➢ Distributed algorithms overcome the issue of centralized algorithms
like the scalability and single point failure.
➢ Examples of Distributed algorithms are:
▪ Global Averaging Algorithm,
▪ Localized Averaging Algorithm,
▪ NTP (Network time protocol) etc.

Compiled by Yilu 33
Handling resource sharing and dependencies: Priorities and reentrancy, Resource
sharing protocols

➢ Most the different task scheduling algorithms that the different tasks in a

system are all independent.

➢ However, that is rarely the case in real-life applications.

➢ Tasks often have explicit dependencies specified among themselves,

however implicit dependencies are more common.

➢ Tasks might become inter dependent for several reasons.

➢ A common form of dependency arises when one task needs the results of

another task to proceed with its computations.

➢ Resource sharing protocols (Home work)


Compiled by Yilu 34
Cntd…

❑ Some of the basic resource sharing protocols are


A. Priority Inheritance Protocol (PIP) is a technique which is used for sharing
critical resources among different tasks.
➢ This allows the sharing of critical resources among different tasks without
the occurrence of unbounded priority inversions.
➢ Basic Concept of PIP : is that when a task goes through priority inversion,
the priority of the lower priority task which has the critical resource is
increased by the priority inheritance mechanism.
➢ It allows this task to use the critical resource as early as possible without
going through the prevention.
➢ It avoids the unbounded priority inversion.
Compiled by Yilu 35
Cntd…

B. Highest Locker Protocol (HLP) is a critical resource sharing protocol that is


an extension of PIP.
➢ It was introduced to overcome the limitations of PIP.
➢ In this critical resource sharing protocol, every critical resource is assigned a
ceiling priority value.
C. Priority Ceiling Protocol (PCP) is an extension of PIP and HLP.
➢ It solves the problem of unbounded priority inversion of PIP, deadlock and
chain blocking of HLP and also minimizes the inheritance-related inversion
which was an also a limitation of HLP.
➢ It is not a greedy approach like PIP.
➢ In PCP, it is possible that a task may be denied for access although the
resources is free. Compiled by Yilu 36
End of Chapter Three
Any Question???

Compiled by Yilu 37

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy