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

01 SB 072010004900064

Uploaded by

rakshitavlnaik
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 views96 pages

01 SB 072010004900064

Uploaded by

rakshitavlnaik
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/ 96

Unit – IV

Real Time Operating


System – RTOS

Topic – 1
Introduction to RTOS
Real Time Operating System - RTOS
 A real time is the time which continuously increments at regular intervals after
the start of the system and time for all the activities at different instances take
that time as a reference in the system.
 An RTOS is multitasking OS for the applications which needs to meet timely
deadlines and functioning in real time constraints.
 Real time constraint means a time interval between occurrence of an event and
system expected response to the event.
 An RTOS is an OS for response time-controlled and event-controlled processes
and these processes has predictable latencies.
 RTOS has many OS services, these enables design of software for a large
number of embedded systems.
Real Time Operating System - RTOS
 An RTOS, is a system installed within our embedded system product or
operating environment to gather and synthesize information as it comes in.
 It connects related terminals or points of entry to create a network or a central
point where all your operations can be monitored.
 With this information and data, decision making is significantly simplified and
made more accurate.
Real Time Operating System - RTOS
 RTOS Srtucture :
Characteristics of RTOS
Deterministic:
 Operations are performed at fixed, predetermined times or within
predetermined time intervals.
 Concerned with how long the OS delays before acknowledging an interrupt.

Responsive:
 How long, after acknowledgement, it takes the operating system to service the
interrupt.
 Includes amount of time to begin execution of the interrupt.
 Includes the amount of to perform the interrupt.
Characteristics of RTOS
User Control:
 User specifies the priority.
 Specify Paging.
 What and which processes must always reside in main memory.
 Disks algorithms to use.
 Rights of processes.

Reliability:
 Degradation of performance may have unfortunate consequences.
 Attempt either to correct the problem or minimize its effects while continuing
to run.
 Most critical, high priority task execute.
Characteristics of RTOS
Fail – Soft Operation:
 Ability of a system to fail in such a way as to preserve as much capability and
data as possible.
 RTOS tries to correct the problem or minimize its effects while continuing to
run.
 Stable RTOS.
 Fast context switch.
 Small size.
 Ability to respond to external interrupts quickly.
 Multitasking with Interprocess communication tools such as semaphores,
signals and events.
 Special alarms and timeouts.
Characteristics of RTOS
Fail – Soft Operation:
 Use of special sequential files that can accumulate data at a fast rate.
 Preemptive scheduling based on priority.
 Minimization of intervals during which interrupts are disabled.
 Delay tasks for fixed amount of time.
RTOS - Services
1. Basic OS Functions – Performs activities like, Process Management, Resource
Management, Device Management, I/O and Network Management.
2. Process Priorities Management (Priority Allocation) – User level priorities
allocation , called static or real time priorities. The real time priorities are
higher than dynamically allocated priorities to the OS functions.
3. Process Priorities Management (Priority Inheritance) – Priorities
inheritance enables a shared resource in low priority task. E.g. LCD display,
be used by high priority task first. An intermediate priority task will not
preempt the low priority task.
RTOS - Services
4. Process Management (Preemption) – The RTOS kernel preempt a lower
priority process by a message or event for which it is waiting to run as soon
as higher priority process takes place.
5. Process Predictability – A predictable timing behavior of the system and a
predictable task synchronization with minimum jitter (ie. Difference
between best case and worst case latencies).
6. Memory Management (Protection) – In RTOS threads of application program
can run in kernel space. So provides protection against memory
management.
7. Memory Management (MMU) – Memory management is done by either
disabling the use of MMU and Virtual Memory or by using memory locks.
Locking stops the page swapping between physical memory and disk.
RTOS - Services
8. Memory Allocation – In RTOS, the memory allocation is fast when there are
fixed length memory blocks allocations happens.
9. RTOS Scheduling and Interrupt latency control functions – Real time task
scheduling and interrupt latency control and use of timers and system
clocks.
10. Timer Functions and Time Management – Provides for timer functions.
There is a time allocation and de-allocation to attain efficiency in given
timing constraints.
11. Asynchronous IO Functions – Permits asynchronous IOs, which mean IOs
without blocking a task.
RTOS - Services
12. IPC Synchronization Functions – Synchronization of tasks with IPCs are
provided. (Semaphores, Mailboxes, Message Queues, Pipes, Sockets and
RPCs).
13. Spin Locks – Spin locks for critical section handling activities.
14. Time Slicing – Time slicing of the execution of processes which have equal
priority.
15. Hard and Soft Real Time Operability – Ability to work with the activity
which would be Hard real time or Soft real time operations.
Basic Design Using an RTOS
 An embedded system with a single CPU can run only one process at a time.
 An RTOS is used in embedded systems to facilitates the following.
1. An RTOS provides running the user threads in kernel space so that they
execute fast.
2. An RTOS provides effective handling of the ISRs (Interrupt Service Routine),
device drivers, ISTs (Interrupt Service Thread), tasks or threads and the
disabling and enabling of interrupts in the user mode critical section codes.
RTOS provides effective handling of such a situation.
3. An RTOS provides memory allocation and de-allocation functions in fixed
time and blocks of memory and restricting the memory accesses only for
the stack and other critical memory blocks.
Basic Design Using an RTOS
4. An RTOS provides for effectively scheduling and running and blocking of the
tasks in cases of many tasks.
5. I/O management with devices , files, mailboxes, pipes, and sockets becomes
simple using an RTOS.
6. Effective management of the multiple states of the CPU and internal and
external physical or virtual devices.
Classification of RTOS
 A real time operating system specifies the maximum time that is known /
needed for every operation that is performed.
 On the basis of tolerance degree, RTOS is classified into 3 categories,
1. Hard Real Time Operating System
2. Soft Real Time Operating System
3. Firm Real Time Operating System

 Depending upon the nature of application RTOS are designed.


Classification of RTOS

Hard real time Firm real time Soft real time

Zero degree of Unacceptable quality Reduction in quality


tolerance reduction and reduction is
acceptable
e.g. ABS, EBD, e.g. Food processing
Air bag control plant control system e.g. Mobile phones,
Digital cameras.
Hard Real Time Systems
 Hard real time systems are those which strictly monitors to each task for its
deadlines.
 When an event occurs, it should be serviced within the predictable time at all
times in a given hard real time system.
 The preemption period for the hard real time task in a worst case should be
less than a few microseconds.
 A hard RTOS is one, which has predictable performance with no deadline miss.
 They will respond at a time t = 0.
 They are generally preferred for use cases involving mission critical
applications.
 E.g. Air Bag Controls, EBD, ABS, Drones, Robotics etc.
Soft Real Time Systems
 The RTOS can usually meet time-constrained deadlines.
 In this pre-emption period is usually within a few milliseconds.
 Soft RTOS is a type of OS where certain deadlines may be missed, they will
respond at a time t = 0+.
 These are not constrained to extreme rule.
 The critical time of the soft real time may be delayed to some extend.
 The expected latency between the tasks and time constraints may be deviated.
 The preemption period for a soft real time task is about few milliseconds.
 e.g. Mobile phones, Digital cameras, Orchestra playing robots.
Firm Real Time Systems
 RTOS has certain time constraints, which are not strict and may cause
undesired yet acceptable effects.
 This type of RTOS has certain time constraints which are not strict and it may
cause undesirable effect.
 Example for Firm RTOS is automated visual inspection in industrial
automation. This system examines and detects the defected parts of assembly
line.
 This type is also called event response system.
 RTOS based systems is a time critical system where most of the tasks are
completed in time so that most of the deadly events are reduced.
Common Terms used in RTOS
 Task : A set of related tasks that are jointly able to provide some system
functionality.
 Job : A job is a small piece of work that can be assigned to a processor, and that
may or may not require resources.
 Release time of a Job : It’s a time of a job at which job becomes ready for
execution.
 Execution time of a Job : It’s a time taken by a job to finish it’s execution.
 Deadline of a Job : It’s a time by which a job should finish its execution.
 Processors : They are also known as active resources, and are important for
the execution of a job.
Common Terms used in RTOS
 Relative Deadline : It is the allowable response time of a job is called its
relative deadline.
 Response Time of a Job : It is the length of time from the release time of a job
when the instant finishes.
 Absolute Deadline : This is the relative deadline, which also includes its
release time.
Features of RTOS
 Occupy very less memory.
 Consumes 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.
Factors for Selecting RTOS
 Here are essential factors that you need to consider for selecting RTOS.
 Performance : Performance is the most important factor required to be
considered while selecting for an RTOS.
 Middleware : If there is no middleware support in RTOS in, then the issue of
time taken integration of processes occurs.
 Error-free : RTOS are error free. There is no chance of getting an error while
performing the task.
 Embedded system usage : Programs of RTOS are of small size, so we widely
use RTOS for embedded systems.
 Maximum consumption : We can achieve maximum consumption with the
help of RTOS.
Factors for Selecting RTOS
 Task shifting : Shifting time of the task is very less.
 Unique features : A good RTOS should be capable, and it has some extra
features like how it operates to execute a command, efficient protection of
memory of the system, etc.
 24/7 performance : RTOS is ideal for those applications which require to run
24/7.
GPOS v/s RTOS

General Purpose OS Real Time OS

It is used for Desktop PCs and Laptops. It is only applied to the Embedded
Applications.
Process-Based Scheduling. Time-Based Scheduling used like
Round Robin Scheduling.
Interrupt latency is not considered as Interrupt lag in minimal, which is
important as in RTOS. measured in few microseconds.
No priority inversion mechanism is The priority inversion mechanism is
present in the system. current. So it can not modify by the
system.
Kernel’s operation may or may not be Kernel’s operation can be preempted.
preempted.
Predictability guarantees with some No predictability guarantees.
delay.
Advantages of RTOS
1. Optimizes the System.
2. Links all system and subsystems together.
3. Shows activeness of processes and procedures.
4. Reduces Errors.
5. A memory slot from RTOS makes easier to track changes or activities.
6. Scalable.
7. User-Friendly.
8. Computing environment responds to rapid inputs in a given period of time.
9. Real-time Scheduling
10. Responsive and instantaneous.
11. Reactive.
Disadvantages of RTOS
1. RTOS can run minimal tasks together, and it concentrates only on those
applications which contain an errors so that it can avoid them.
2. RTOS is the system that concentrates on a few tasks. Therefore, it is really
hard for system to do multi-tasking.
3. Specific drivers are required for the RTOS so that it can offer fast response
time to interrupt signals, which helps to maintain its speed.
4. Plenty of resources are used by RTOS, which makes this system expensive.
5. The task which have a low priority need to wait for a long time as the RTOS
maintain the accuracy of the program, which are under execution.
6. Minimum switching of tasks is done in RTOS.
7. It uses complex algorithms which is difficult to understand.
8. RTOS uses lot of resources, which sometimes not suitable for the system.
Applications of RTOS
 Airlines Reservation System.
 Air Traffic Control System.
 Systems that provide immediate updating.
 Used in any systems that provides up to date and minute information on stock
prices.
 Defense application systems like Radar.
 Networked Multimedia Systems.
 Command Control Systems.
 Internet Telephony.
 Anti-Lock Brake System, Air Bag System, Power Windows, etc.
 Heart Pacemakers.
Applications of RTOS
 In case of devices that are used to save lives, such as automatic opening of a
parachute .
 Live TV broadcast systems.
 RTOS is a program that was designed for CPU usability management for
microcontrollers.
 It helps in enhancing the CPU efficiency in the management of processes or
tasks.
Applications of RTOS
 Avionics  VoIP Phones, PDA’s
 Data Acquisition  Set-top Boxes
 Digital Controllers  Automotive Systems
 Defense Systems
 Industrial Process Control
 Cell Phones
 MP3 Players
 Game Console
 Network Boxes
 On Demand Servers
 Embedded Devices
Unit – IV
Real Time Operating
System – RTOS

Topic – 2
Introduction to RTS
Real Time Systems
 RTS (Real Time Systems) are those which must produce correct responses
within a definite time limit.
 RTS is any information processing system that has to respond to externally
generated signals within a finite and specified period.
 A RTS is a computer system where the correct functioning of the system
depends on the results produced and the time at which they are produced.
 A system, where correct timing behavior is strongly related to functionality,
performance and reliability.
 A computer system is a real-time one if it explicitly manages resources in order
to meet timing constraints.
 A RTS is a system where correctness depends not only on the logical result of
computation but also on the time at which the results are produced.
Real Time Systems
In real time systems,
 Timing of actions is essential: Compare with table tennis, air bag, engine
control and music.
 Age of data is essential: Compare with a weather report, sample data, compute,
actuate.
 Different consequences depending on context.
 Different types of timing requirements needed and delay need not be
controlled.
Real Time Systems

Requirements on a Real Time Systems
 Sufficiently fast processing, communication, etc.
 Predictable resource sharing and timing.
 Real Time systems span several domains of computer science.
 They are defense and space systems, networked multimedia systems,
embedded automotive electronics etc.
 In a real time system the correctness of the system behaviour depends not only
on the logical results of the computations, but also on the physical instant at
which these results are produced.
 A real time system changes its state as a function of physical time.
 Based on this real time system can be decomposed into a set of subsystems, i.e.,
the controlled object, the real-time computer system and the human operator.
Requirements on a Real Time Systems
 A real-time computer system must react to stimuli from the controlled object
within time intervals dictated by its environment.
 The instant at which a result is produced is called a deadline.
 If the result has utility even after the deadline has passed, the deadline is
classified as soft, otherwise it is firm.
 If a catastrophe could result if a firm deadline is missed, the deadline is hard.
Characteristics of Real Time Systems
 Characteristics distinguish Real-Time Systems from Non Real-Time Systems.
 These characteristics may or may not be applicable to every RTS.

 Time Constraints: Every real time task is associated with some time
constraints, and set a deadlines are associated with tasks. Timing constraints like
delay and duration are also to be considered while designing the system.

 New Correctness Criterion: In RTS, correctness implies not only logical


correctness of the results, but the time at which the results are produced is
important. A logically correct result produced after the deadline would be
considered as an incorrect result.
Characteristics of Real Time Systems
 Embedded: Majority of RTS are embedded in nature. An embedded computer
system is physically embedded in its environment and often controls it.

 Safety Criticality: In non real time systems safety and reliability are
independent issues. But in many RTS these two issues are intricately bound
together making them safety critical.

 Concurrency: The RTS must process data from all the sensors concurrently,
otherwise signals may be lost and the system may malfunction. As different
sensors can get different input parameters for a system, so they work to be a
concurrent system.
Characteristics of Real Time Systems
 Task Criticality: Task criticality is a measure of the cost of failure of a task.
Task criticality is determined by examining how critical are the results produced
by the task to the proper functioning of the system.

 Custom Hardware: a RTS is implemented on custom hardware that is


specifically designed and developed for the purpose. E.g. Cell phones does not
use traditional Microprocessors.

 Reactive: RTS are often reactive. A reactive system is one in which an on-going
interaction between the computer and the environment is maintained.
Characteristics of Real Time Systems
 Stability: Under overload conditions, RTS need to continue to meet the
deadlines of the most critical tasks, though the deadlines of the non-critical tasks
may not be met.

 Exception Handling: Many RTS work round-the-clock and often operate


without human operation. E.g. small automated chemical plant that is set up to
work non-stop. When there is no human operators taking corrective actions on a
failure, becomes difficult. A failure should be detected and the system should
continue to operate in a gracefully degraded mode rather that shutting off
completely.
Characteristics of Real Time Systems
 Large and Complex: Vary from few Hundred lines of code for small
application, RTS should also stand for the larger lines of code for Space Station
related projects.

 Concurrent Control of Separate System Components: Devices operate in


parallel in the real world, better to model this parallelism by concurrent entities
in the program.
Applications of Real Time Systems
 Industrial Applications
 Medical
 Peripheral Equipments
 Automotive and Transportation
 Telecommunication Applications
 Aerospace
 Internet and Multimedia Applications
 Consumer Electronics
 Defense Applications
 Sports e.g Ball Tracking, Snickometer, Hawk-Eye etc.
 Miscellaneous Applications e.g Ticket Reservation System etc.
Temporal Parameters of Real Time Process

 The workload on processors consists of jobs, each of which is a unit of work to


be allocated processor time and other resources.
 The number of tasks (or jobs) in the system is one such parameter.
 In many embedded systems, the number of tasks is fixed as long as the system
remains in an operation mode.
 Each process or task or job Ji is characterized by its temporal parameters,
functional parameters, resource parameters, and interconnection parameters.
 Its temporal parameters tell us its timing constraints and behavior.
 The release time, absolute deadline, and relative deadline of a job Ji ; these are
temporal parameters.
Temporal Parameters of Real Time Process
 We will use ri , di, and Di , respectively, to denote them and call the time interval
(ri , di )1 between the release time and absolute deadline of the job Ji its feasible
interval.

Fixed, Jittered, and Sporadic Release Times


 In many systems, we do not know exactly when each job will be released.
 In other words, we do not know the actual release time ri of each job Ji ; only
that ri is in a range [ri − , ri +].
 Ri can be as early as the earliest release time ri − and as late as the latest
release time ri +.
Fixed, Jittered, and Sporadic Release Times

 The release time may not be exactly known, only the range may be known [ri-
ri+].
 When only the range of ri is known then this range is called release time.
 Indeed, some models assume that only the range of ri is known and call this
range the jitter in ri, or release- time jitter.
 If the jitter is negligible, then the actual release time of the job is given by either
earliest or the latest release time.
 This release time of the job is called fixed release time.
 Almost every real-time system is required to respond to external events which
occur at random instants of time.
 When such an event occurs, the system executes a set of jobs in response.
Fixed, Jittered, and Sporadic Release Times
 The release times of these jobs are not known until the event triggering them
occurs.
 These jobs are called sporadic jobs or aperiodic jobs because they are released
at random time Instants.
Execution Time:
 Another temporal parameter of a job, Ji , is its execution time, ei.
 ei is the amount of time required to complete the execution of Ji when it
executes alone and has all the resources it requires.
 The execution time depends on the complexity of the job, speed of processor
but not on how the job is scheduled.
 The execution time may vary. It can be known in terms of maximum and
minimum value of time required to compute each job.
Other Types of Dependencies for Real Time
Tasks
 These extensions include temporal distance, OR jobs, conditional branches, and
pipeline.
Temporal Dependency:
 Some jobs may be constrained to complete within a certain amount of time
relative to one another.
 We call the difference in the completion times of two jobs the temporal
distance between them.
AND/OR Precedence Constraints:
 Classical model for a job precedence would not always works properly.
 So it is necessary to be specific, we call such jobs AND jobs and dependencies
among them AND precedence constraints.
Other Types of Dependencies for Real Time
Tasks
 In contrast, an OR job is one which can begin execution at or after its release
time provided one or some of its immediate predecessors has been completed.
Conditional Branches:
 In the classical model, all the immediate successors of a job must be executed,
an outgoing edge from every vertex expresses an AND constraints.
 This convention makes it inconvenient to represent conditional execution of
jobs.
Functional Parameters
 Functional parameters are preemptivity, criticality, optional interval, and laxity
type.
Preemptivity of Jobs:
 A job is preemptable if its execution can be suspended at any time to allow the
execution of other jobs and later on, can be resumed from the point of
suspension.
 A job is nonpreemtable if it must be executed from start to completion without
interruption.
Criticality of Jobs:
 In any system, jobs are not equally important.
 The importance of a job is a positive number that indicates how critical the job
is with respect to other jobs.
Functional Parameters

 The more the critical job is, the larger is the importance.
 The term priority and weight are often used to refer to importance, the more
importance a job, the higher its priority or the larger it weight.

Optional Executions:
 It is often possible to structure an application so that some jobs or portions of
jobs are optional.
 If an optional job or a portion of a job completes late or is not executed at all,
the system performance may degrade but nevertheless function satisfactorily.
 In contrast, jobs and portions of jobs that are not optional are mandatory.
Functional Parameters

Laxity Type and Laxity Function:


 The laxity type of a job indicates whether its timing constraints are soft or
hard.
 As mentioned earlier, in real-time systems, the laxity type of a job is sometimes
supplemented by a usefulness functions.
Resource Parameters
 In addition to a Processor, a job may also requires some recourses.
 The resource parameters of each job gives the type of processor and the units
of each resource type required by the job and the time intervals during its
execution when the units are required.
 These parameters provide the information that is needed to support resource
management decisions.
Preemptivity of Resources :
 Resource parameter is preemptivity.
 A resource is non-preemptable if each unit of the resource is constrained to be
used serially.
 Once a unit of a non-preemptable resource is allocated to a job, other jobs
needing the unit must wait until the job completes its use.
Resource Parameters
 Otherwise if jobs can use every unit of resource in an interleaved fashion, the
resource is preemptable.
 The lock on the data object in a database is an example of non-preemptable
resource.

Resource Graph:
 The configuration of the resources using a resource graph.
 In a resource graph, there is a vertex Ri for every processor or resource Ri in
the system.
 While edges in task graphs represent different types of dependencies among
jobs, edges in a resource graph represent the relationship among resources.
Resource Parameters
Scheduling Hierarchy:
 The application system is represented by a task graph f, exemplified by the
graph on the top of the diagram.
 This graph gives the processor time and resource requirements of jobs, the
timing constraints of each job, and the dependencies of jobs.

Schedulers and Scheduling:


 Jobs are scheduled and allocated resources according to a chosen set of
scheduling algorithm and resource access control protocols.
 The module which implements these algorithms is called the scheduler.
Resource Parameters
Feasibility, Optimality and Performance Measure:
 A valid schedule is a feasible schedule if every job completes by its deadline.
 Hard real time applications is their ability to find visible schedules of the given
application system whenever such a schedules exist.
 Hence a hard real time scheduling algorithm is optimal.
 A performance measure that captures this trade-off is the invalid rate, which is
the sum of the miss and loss rates and give the percentage of all jobs that do not
produce a useful result.
Unit – IV
Real Time Operating
System – RTOS

Topic – 3
Real Time Tasks
Real Time Task and Task States
Real Time Task and Task States
Real Time Task and Task States
Real Time Task and Task States
Real Time Task and Task States
Types of Real Time Tasks

 A real time task for which quantitative expressions of time are needed to
describe its behavior.
 The quantitative expression of time usually appears in the form of a constraint
on the time at which the task produces results.
 The most frequently occurring time constraint is a deadline constraint which is
used to express that a task is required to complete its results within some
deadline.
 Real time tasks can be classified into the following three broad categories.
 Real time task classified into either hard, soft, or firm real time task depending
on the consequences of the task missing its deadline.
Types of Real Time Tasks

 It is not necessary that all task of a real time application belongs to the same
category.
 It is possible that different task of real time system can belong to different
categories.
Hard Real Time Tasks
 A hard real time task that is constrained to produce its results within certain
predefined time bounds.
 The system is considered to have failed whenever any of it's hard real time
tasks does not produce its required result before the specified time bound.
 Example 1: The robot continuously carries out a number of activities including
communication with the host system, logging all completed activities, sensing
the environment to detect any obstacle present, tracking the object of interest,
path planning, effecting next move etc.
 Example 2: An Anti Missile system consists of following critical activities. It
must first detect all incoming missiles, properly position the anti missile gun,
and then fire to destroy the incoming missile before the incoming missile can do
any damage.
Hard Real Time Tasks
 All these tasks are hard real time in nature and the anti Missile system would
be considered to have failed, if any of its tasks fails to complete before the
corresponding deadlines.
 Applications having hard real time tasks are typically safety-critical.
 Any failure of the real time task including its failure to meet the associated
deadlines would result in severe consequences.
 This makes hard real time tasks extremely critical.
 For hard real time tasks in practical system, the time bounds usually range
from several microseconds to a few milliseconds.
 A hard real time task need to be completed within the shortest time possible,
but it is really required that the task must complete within the specified time
bound.
Firm Real Time Tasks

 Every firm real time task is associated with some predefined deadline before
which it is required to produce its results.
 Unlike hard real time task, even when a firm real time task does not complete
within its deadline, the system does not fail.
 The late results are merely discarded.
 The utility of these results computed by a firm real time task becomes zero
after the deadline.
 Firm real time task typically found in multimedia applications.
 Example 1: Video Conferencing – Video and audio are converted into packets,
these packets may travel from same or separate route through the network, and
also some of these packets may get delayed. These late incoming packets are
simply discarded and no processing would be done during live streaming.
Firm Real Time Tasks

 Example 2: Satellite based Tracking of Enemy Movements – Satellite that takes


the pictures of an enemy territory and beams it to a ground station computer
frame by frame. These computers works on these live frames to identify the
positional difference of different objects of interest. Comparison is done in
between current and previous frames. When ground computer is overloaded, a
new image may be received even before an older image is taken up for
processing. In this case, the older image is of not much use. Hence these images
may be discarded and the recently received image could be processed.
Soft Real Time Tasks

 Soft real time tasks also have time bounds associated with them.
 Unlike hard and firm real time tasks, the timing constraints on soft real time
tasks are not expressed as absolute values.
 Instead, the constraints are expressed either in terms of average response
times required.
 Example 1: Web Browsing – Normally after an URL is clicked, the
corresponding webpage is fetched and displayed within a couple of seconds on
the average. When it takes several minutes to display a requested page, we still
do not consider the system to have failed, but merely express that the
performance of the system has degraded.
Soft Real Time Tasks

 By analyzing the impact of the failure of a soft real time task to meet its
deadline.
 Missed deadlines of soft real time tasks do not result in system failure.
 The utility of the results produced by soft real time task falls continuously with
time after expiry of the deadline.
 The utility of the results produced are 100% if produced before the deadlines.
 After the deadline is passed the utility of the results slowly falls off with time.
 For soft real time tasks that typically occur in practical applications, the time
bounds usually range from a fraction of a second to a few seconds.
Unit – IV
Real Time Operating
System – RTOS

Topic – 4
Real Time Scheduling
Precedence Constraints and Data Dependency

 Data and control dependencies among jobs may constrain the order in which
they can execute.
 In classical scheduling theory, the jobs are said to have precedence constraints
if they are constrained to execute in some order.
 Otherwise, if the jobs can execute in any order, they are said to be independent.
 Example, we consider queries to an information server. Suppose that before
each query is processed and the requested information retrieved, its
authorization to access the requested information is first checked. The retrieval
job cannot begin execution until the authentication job completes. The
communication job that forwards the information to the requester cannot begin
until the retrieval job completes.
Precedence Constraints and Data Dependency

 Example, Similarly, in a communication system, the jobs that generate an


acknowledgement of a message and transmit the acknowledgement message
cannot begin until the job that receives and processes the message completes.
Approaches to Real Time Scheduling

 Scheduling is the method by which tasks are given access to system resources
and the need for a scheduling algorithms arises from the requirement for most
modern systems to perform multitasking.
 Scheduling is the heart of any computer system since it contain decision of
giving resources between possible tasks.
 Sharing of computer resources between multiple tasks is also called as
scheduling.
 Optimum resource sharing depends on the efficient scheduling of competing
users and system tasks for the processor, which renders task scheduling, an
important aspect of a multiprogramming operating system.
Criterion for Comparing CPU Scheduling
Algorithms

 CPU Utilization: Percent of time that the CPU is busy executing a task.
 Throughput: Number of tasks that are completed per unit time.
 Response Time: Amount of time it takes from when a request was submitted
until the first response occurs.
 Waiting Time: The amount of time before a task starts after first entering the
ready queue.
 Turnaround Time: Amount of time to execute a particular task from the time
of submission through the time of completion.
 Fairness: Make sure each process gets a fair share of the CPU. It is desirable to
Maximize CPU utilization, Maximize throughput, Minimize turnaround time,
Minimize waiting time, Minimize response time.
Types of Scheduling

 In real-time systems scheduling algorithms are classified into two categories:


Static Algorithm and Dynamic Algorithm.
 Dynamic algorithm assigns priorities at runtime. This algorithm allows
switching of priorities between tasks.
 Static algorithm assigns priorities at design time. All assigned priorities remain
fixed throughout the execution of task.
 Static Scheduling Algorithm have two types:
1. Rate Monolithic: Task have to be periodic in nature and deadline must be
equal to its period.
2. Deadline Monolithic: All the runtime tasks based on their deadline is
known as deadline monolithic.
Types of Scheduling

 Dynamic Scheduling Algorithm have two types:


1. Least Slack Time First: Tasks are scheduled according to their slack, the
smaller the slack, the higher the priority. Slack is computed by using the
difference between the deadline, the ready time and the run time.
2. Earliest Deadline First: This is most commonly used. Here priorities are
dynamically reassigned at runtime based on the time still available for each
task to reach its next deadline.
Real Time Scheduling

 A hard real time system must execute a set of concurrent real time tasks in a
such a way that all time critical tasks meet their specified deadlines.
 Every task needs computational and data resources to complete the job.
 The scheduling problem is concerned with the allocation of the resources to
satisfy the timing constraints.
Real Time Scheduling

 Real time scheduling can be categorized into hard v/s soft.


 Hard real time scheduling can be used for soft real time scheduling.
 Hard real time scheduling can be broadly classified into two types: Static and
Dynamic.
 In static scheduling, the scheduling decisions are made at compile time.
 Dynamic scheduling makes its scheduling decisions at run time, selecting one
out of the current set of ready tasks.
 Dynamic schedulers are flexible and adaptive.
 Preemptive or nonpreemptive scheduling of tasks if possible with Static and
dynamic scheduling.
Real Time Scheduling

 In preemptive scheduling, the currently executing task will be preempted upon


arrival of a higher priority task.
 In nonpreemptive scheduling, the currently executing task will be preempted
until completion.
Static Scheduling Algorithms
 Static or fixed priority scheduling is a scheduling algorithm commonly used in
real time system.
 With fixed priority preemptive scheduling, the scheduler ensures that at any
given time, the processor executes the highest priority task of all the tasks that
are currently ready to execute.
 In static scheduling, scheduling decisions are made during compile time.
 This assumes parameters of all the tasks is known prior and builds a schedule
based on this.
 Once a schedule is made, it cannot be modified online.
 Static scheduling is generally not recommended for dynamic systems.
 Applications like process control can benefit from this scheduling, where
sensor data rates of all tasks are known before hand.
Static Scheduling Algorithms

1. Clock Driven Approach:


 When scheduling is clock driven (also called as time driven), decisions on what
jobs execute at what times are made at specific time instants.
 These instants are chosen in prior before the system begins execution.
 In a system that uses clock driven scheduling, all the parameters of hard real-
time jobs are fixed and known.
Static Scheduling Algorithms

2. Weighted Round Robin Approach:


 The Round Robin approach is commonly used for scheduling time shared
applications.
 When jobs are scheduled on a Round Robin basis, every job joins a FIFO queue
when it becomes ready for execution.
 The job at the head of the queue executes for at most one time slice.
 If the job does not complete by the end of the time slice, it is preempted and
placed at the end of the queue to wait for its next turn.
Static Scheduling Algorithms

3. Priority Driven Approach:


 Most scheduling algorithms used in non Real Time systems are priority driven.
 Examples include the FIFO and LIFO algorithms, which assign priorities to jobs
according to their release times,
 And the SETF (Shortest Execution Time First) and LETF (Longest Execution
Time First) algorithms, which assign priorities on the basis of job execution
times.
Dynamic Scheduling Algorithms

 A Dynamic priority scheduler is more efficient in meeting deadlines required


for time critical application processes.
 While designing a real time scheduling algorithm the following conditions were
imposed and satisfied.
 The task set is feasible, in the sense that all tasks execute after their release
time and finish before their deadlines.
 The task is set schedulable, and the schedule ability criteria is met.
 Schedulability test used by dynamic schedulers to determine whether a given
set of ready tasks can be scheduled to meet their deadlines.
 Different scheduling algorithms and their Schedulability criteria is as follows.
Dynamic Scheduling Algorithms

1. Rate Monotonic Algorithm:


 Rate Monolithic algorithm is a dynamic preemptive algorithm based on static
priorities.
 The rate monolithic algorithm assigns static priorities based on task periods.
 Here task period is the time after which the task repeats and inverse of period
is task arrival rate.
 E.g. a task with a period of 10ms repeats itself after every 10ms.
 The task with the shortest period gets the highest priority, and the task with
the longest period gets the lowest static priority.
 At the run time, the dispatcher selects the task with the highest priority for
execution.
Dynamic Scheduling Algorithms

1. Rate Monotonic Algorithm:


 According to Rate Monolithic Algorithm a set of periodic, independent task can
be scheduled to meet their deadlines.
 If the sum of their utilization factors of the n tasks is given as follows,
Σ (Ci / Ti) ≤ U (n) = n(21/b-1)
 Where,
Ci = worst-case task execution time of task
Ti = period of task
U(n) = Utilization bound for n tasks
Dynamic Scheduling Algorithms

2. Earliest Deadline-First (EDF) Algorithm:


 EDF algorithm is an optimal dynamic preemptive algorithm based on dynamic
priorities.
 In this after any significant event, the task with the earliest deadline is assigned
the highest dynamic priority.
 A significant event in a system can be blocking of a task, invocation of a task,
completion of a task etc.
 The processor utilization can up to 100% with EDF, even when the task periods
are not multiple of the smallest period.
 The dispatcher operates in the same way as the dispatcher for the Rate
Monolithic Algorithm.
Dynamic Scheduling Algorithms

2. Earliest Deadline-First (EDF) Algorithm:


 EDF is very simple and famous algorithm that the earlier the deadline, the
higher the priority.
 The scheduler operates when each processor task is completed or when a task
wakes up in the ready queue.
Dynamic Scheduling Algorithms

3. Latest Release Time First (LRT) Algorithm:


 LRT determines that the later the release time is, the higher the priority is.
 This is the opposite of EDF.
 LRT considers the release time and relative deadlines and schedules jobs in the
reverse order, starting from the latest deadline among all jobs.
 If LRT schedules the same task, the result is same to which is scheduled by EDF.
Dynamic Scheduling Algorithms

4. Least Slack Time First (LST) Algorithm:


 LST algorithm follows a rule that the smaller slack time, the higher priority.
 The slack time means the remaining spare time (di – ei r – t) at the current
time.
 The ei r represents the time required to complete the remaining work of a task.
It can be considered to be the optimal algorithm for a single processor.
Dynamic v/s Static System

 Jobs that are ready for execution are placed in a priority queue common to all
processors.
 When a processor is available, the job at the head of the queue executes on the
processor.
 A multiprocessor system is a dynamic system, because jobs are dynamically
dispatched to processors.
 Another approach to scheduling in multiprocessor and distributed systems is
to partition the jobs in the subsystem and assign and bind the subsystem
statically to the processors.
 Jobs are moved among processors only when the system must be reconfigured,
when the operation mode of the system changes or processor fails.
Dynamic v/s Static System

 Such a system is called a static system, because the system is statically


configured.
 If jobs on different processors are dependent, the schedulers on the processors
must synchronize the jobs according to some synchronization and resource
access control protocol.
 Except for the constraints which are imposed, the jobs on each processor are
scheduled by themselves.
Offline v/s Online Scheduling
 Clock driven scheduler typically makes use of a pre-computed schedule of all
hard real time jobs.
 This schedule is computed offline before the system begins to execute, and the
computation is based on the knowledge of the release times and processor time
or resource requirements of all the jobs for all times.
 When the operation mode of the system changes, the new schedule specifying
when each job in the new mode executes is also pre computed and stored for
use.
 In this case, scheduling is done offline, and the pre computed schedule are
offline schedulers.
 The disadvantage of offline scheduling is inflexibility.
 This approach is possible only when the system is deterministic.
Offline v/s Online Scheduling

 If the scheduler makes each scheduling decision without knowledge about the
jobs that will be released in the future is called as online scheduling algorithm.
 The parameter of each job become known to the online scheduler only after
the job is released.
 Online scheduling is the only option in a system whose future workload is
unpredictable.
 Online scheduler can accommodate dynamic variation in user demands and
resource availability.
Scheduling Sporadic Jobs in Priority Driven Systems
 Sporadic jobs may arrive at any instant.
 Their execution times may vary widely, and their deadlines are arbitrary.
 It is impossible for some sporadic jobs to meet their deadlines no matter what
algorithm use to schedule them.
 The only alternatives are,
1. To reject the sporadic jobs that cannot complete in time.
2. To accept all sporadic jobs and allow some of them to complete late.
 The ready periodic jobs are placed in the periodic task queue, ordered by their
priorities.
 Each accepted sporadic job is assigned a priority and is placed in a priority
queue.
 Each newly arrived a periodic job is placed in the periodic job queue.
Scheduling Sporadic Jobs in Priority Driven Systems
 Newly arrived sporadic jobs are inserted into a waiting queue.
 The periodic job and sporadic job scheduling algorithms are solutions to the
following problems,
1. Based on the execution time and deadline of each newly arrived sporadic
job, the scheduler decides whether to accept or reject the job. If it accepts
the job, it schedules the job so that the job completes in time without
causing periodic tasks and previously accepted sporadic jobs to miss their
deadlines. The problem are how to do the acceptance test and how to
schedule the accepted sporadic jobs.
2. The scheduler tries to complete each periodic job as soon as possible. The
problem is how to do so without causing periodic tasks and accepted
sporadic jobs to miss their deadlines.

You might also like