You are on page 1of 797

BITSPilani

Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 1)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : An Introduction
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
1-3
Outline of the course
Swati Keskar
Introduction to Real-Time Systems
Modeling of Real-time Systems
Defining Workload with/without resources
Scheduling approaches
Implementation and design issues of Real-Time Systems
Performance analysis and fault tolerance issues
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Swati Keskar
1-4
Introduction
Definition
Misconceptions about RTS
Classification of RTS
A reference model
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Books
April 1, 2014
Swati Keskar
1-5
Real-Time systems by Jane W.S. Liu
Stankovic John A. Misconceptions about Real-Time
Computing: A serious problem for Next-Generation Systems
IEEE transactions on Computer, Oct 1988, pp 10-19
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014
Swati Keskar
1-6
Examples
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014
Swati Keskar
1-7
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014
Swati Keskar
1-8
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014
Swati Keskar
1-9
Types of Systems
A real-time system is required to complete its work and
deliver its services on a timely basis
Embedded Systems
Control systems
Real Time systems
Distributed Systems
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014
Swati Keskar
10
What is Real-Time System?
What is system?
What is control system?
What is computer control system?
Real-time systems, we are discussing here, are Real-time
computer control systems
Any system where a timely response by the computer
to external stimuli is vital is a real-time system
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 11
Nature of The System
Controlled system
Controller
environment
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 12
Concept of Failure and success
Timely response means a real-time system runs tasks that
have deadlines
By deadline task must be done
If task is not done by deadline then what?
Sometimes if you do not succeed, failure is not bearable
Sometimes if you do not succeed, no damage is done
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 13
Definitions
A system where correct timing behaviour 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
Real-time system is one whose logical correctness is based on
both the correctness of outputs and their timeliness
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 14
Definitions contd.
A Real-time system is a system that must satisfy explicit
response-time constraints or risk severe consequences,
including failure.
A Real-time system is one in which the correctness of the
system depends not only on the logical results, but also on the
time at which the results are produced
A system that is synchronous with the interacting
environment
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 15
What is important
Timing of action
Age of data
Different consequences depending on context
Different timing requirements
Delays to be controlled
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 16
Requirements on a computer
Sufficiently fast
Predictable resource sharing and timing
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 17
Time related activities
Timing constraints and deadlines
Clock based activities like sampling data at particular
frequencies
Event based activities
Interactive activities like ATM cash withdrawals
Concurrency
Real-Time clock
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 18
Misconceptions about RTS
Real-Time Systems are fast systems
There is no science in Real-time System Design, it is
performance engineering
Advances in supercomputer will take care of Real-Time
requirements
Real-time programming is assembly coding, priority interrupt
programming
The problems in RT design have all been solved in other areas
of computer science
It is not meaningful to talk about guaranteeing real-time
performance
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 19
Classification of RTS
Each unit of work that is scheduled and executed by the
system is JOB
Jobs can be periodic, aperiodic and sporadic in nature
A set of related jobs which jointly provide some system
function is TASK
RELEASE TIME of a job is the instant of time at which the
job becomes available for execution
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 20
The DEADLINE of a job is the instant of time by which its
execution is required to be completed.
RESPONSE TIME is the length of time from the release time of
the job to the instant when it completes.
Classification of RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 21
Hard Real-Time Systems
Soft Real-Time Systems
Depending on hard/soft real-time constraints, criticality of jobs,
usefulness of late results and deterministic nature of the job
Firm Real-Time Systems
Classification of RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 22
Classification contd
Reactive or embedded systems
Organic systems
Loosely coupled or semidetached
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 23
Classification contd
Application wise classification
Purely cyclic
Mostly cyclic
Asynchronous but somewhat predictable
Asynchronous and unpredictable
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 24
Some examples of Hard RTS
Air traffic control
Aircraft navigation system
Military operations such as raids, vigilance, tracking
Space operations
Car control System
Car engine management
Critical health monitoring systems
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 25
Online transaction systems
Multimedia applications
Electronic games
Interactive database management such as air ticket booking
Some examples of Soft RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 26
Reference Model of RTS
Three major elements of a real-time system are
A Workload Model
A Resource Model
Algorithms
In third element, algorithms for scheduling and resource
management are included
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 27
Resources
Processors
Servers and active resources such as computers, transmission
links, disks etc
Resources means passive resources
Memory, sequence numbers, mutexes and database locks
(semaphores) etc
Reusable resources
Plentiful resources
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 28
Real-Time Workload
Each job J
i
is characterized by
Temporal Parameters
Functional Parameters
Resource Parameters
Interconnection Parameters
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 29
Temporal Parameters
Release time r
i
Fixed, jittered and sporadic release times
Deadline
Absolute deadline d
i
, relative deadline D
i
Execution time e
i
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 30
Periodic Task Model
Each computation or data transmission that is executed
repeatedly at regular or semiregular time intervals in order to
provide a function of the system on a continuing basis
Periodic task T
i
has period P
i
which is the minimum length of
all time intervals between release times of consecutive jobs in
task T
i
At all times, the period and execution time of every periodic
task in the system are known
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 31
Classification of RTS
Each unit of work that is scheduled and executed by the
system is JOB
Jobs can be periodic, aperiodic and sporadic in nature
A set of related jobs which jointly provide some system
function is TASK
RELEASE TIME of a job is the instant of time at which the
job becomes available for execution
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 32
The DEADLINE of a job is the instant of time by which its
execution is required to be completed.
RESPONSE TIME is the length of time from the release time of
the job to the instant when it completes.
Classification of RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 33
Hard Real-Time Systems
Soft Real-Time Systems
Depending on hard/soft real-time constraints, criticality of jobs,
usefulness of late results and deterministic nature of the job
Firm Real-Time Systems
Classification of RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 34
Classification contd
Reactive or embedded systems
Organic systems
Loosely coupled or semidetached
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 35
Classification contd
Application wise classification
Purely cyclic
Mostly cyclic
Asynchronous but somewhat predictable
Asynchronous and unpredictable
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 36
Some examples of Hard RTS
Air traffic control
Aircraft navigation system
Military operations such as raids, vigilance, tracking
Space operations
Car control System
Car engine management
Critical health monitoring systems
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 37
Online transaction systems
Multimedia applications
Electronic games
Interactive database management such as air ticket booking
Some examples of Soft RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 38
Reference Model of RTS
Three major elements of a real-time system are
A Workload Model
A Resource Model
Algorithms
In third element, algorithms for scheduling and resource
management are included
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 39
Resources
Processors
Servers and active resources such as computers, transmission
links, disks etc
Resources means passive resources
Memory, sequence numbers, mutexes and database locks
(semaphores) etc
Reusable resources
Plentiful resources
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 40
Real-Time Workload
Each job J
i
is characterized by
Temporal Parameters
Functional Parameters
Resource Parameters
Interconnection Parameters
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 41
Temporal Parameters
Release time r
i
Fixed, jittered and sporadic release times
Deadline
Absolute deadline d
i
, relative deadline D
i
Execution time e
i
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 42
Periodic Task Model
Each computation or data transmission that is executed
repeatedly at regular or semiregular time intervals in order to
provide a function of the system on a continuing basis
Periodic task T
i
has period P
i
which is the minimum length of
all time intervals between release times of consecutive jobs in
task T
i
At all times, the period and execution time of every periodic
task in the system are known
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 43
TASKs in a system are denoted by T
1
,T
2
,.T
n
where as jobs in
a task T
i
are denoted by J
i
,
1
, J
i
,
2
,..J
i
,
k
PHASE of the task T
i
is the release time r
i
,
1
of the first job J
i
,
1
and denoted by
i
HYPERPERIOD H is the least common multiple of p
i
for
i =1, 2,..n
The number of jobs N in each hyperperiod is equal to

i=1 to n
H/ p
i
Periodic Task Model
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 44
UTILIZATIONis equal to the fraction of time a truly periodic
task keeps a processor busy
u
i
= e
i
/p
i
TPTAL UTILIZATIONU of all the tasks in the system is the sum
of the utilizations of the individual tasks in it
U = u
1
+u
2
+..u
i
Periodic Task Model
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 45
Aperiodic and sporadic jobs
Release times are not known a priori
In periodic task model, the workload generated in response to
unexpected events is captured by aperiodic and sporadic tasks
The interarrival times between consecutive jobs in such jobs
vary widely and can be arbitrarily small
A task is aperiodic if the jobs in it have either soft or no
deadlines
Sporadic jobs have hard deadline
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 46
Precedence
If jobs are constrained to execute in some order, they are said
to have precedence constraints. If not, jobs are independent
Precedence relation is denoted by <
Precedence graphs and task graphs are used to precedence
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 47
Dependencies
Data dependency
Temporal dependency
AND/OR precedence
Conditional branches
Pipeline relationship
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 48
Functional Parameters
Preemptivity of jobs
Criticality of jobs
Optional execution
Laxity type and laxity function
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 49
Resource parameters
Preemptivity of resources
Resource graph
A valid schedule is a feasible schedule if every job completes
by its deadline
A set of jobs is schedulable according to a scheduling
algorithm if when using the algorithm the scheduler always
produces a feasible schedule
A scheduling algorithm is optimal if the algorithm always
produces a feasible schedule
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduler
A scheduler is a module that allocates processors and
resources to jobs and tasks
It implements scheduling algorithms and resource access
protocols
April 1, 2014 Swati Keskar 50
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Valid Schedule
A schedule is an assignment of all the jobs in the
system on the available processors produced by the
scheduler
A valid schedule satisfies certain conditions
Every processor is assigned to at the most one job at any time
vice-a-versa
No job is scheduled before its release time
The total amount of processor time assigned to every job is
equal to its maximum execution time
All the constraints imposed on the job are satisfied
April 1, 2014 Swati Keskar 51
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Feasibility
A valid schedule is a feasible schedule if every job completes
by its deadline
A hard real-time scheduling algorithm is optimal if it always
produces a feasible schedule
Various performance measures are
- Maximum/average tardiness
- Lateness
- Response time
- The miss, loss and invalid rates
April 1, 2014 Swati Keskar 52
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 2)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : An Introduction
Modeling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Swati Keskar
1-55
Classification of RTS
A reference model
Misconceptions about RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 56
Requirements on a computer
Sufficiently fast
Predictable resource sharing and timing
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 57
Time related activities
Timing constraints and deadlines
Clock based activities like sampling data at particular
frequencies
Event based activities
Interactive activities like ATM cash withdrawals
Concurrency
Real-Time clock
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 58
Misconceptions about RTS
Real-Time Systems are fast systems
There is no science in Real-time System Design, it is
performance engineering
Advances in supercomputer will take care of Real-Time
requirements
Real-time programming is assembly coding, priority interrupt
programming
The problems in RT design have all been solved in other areas
of computer science
It is not meaningful to talk about guaranteeing real-time
performance
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 59
Classification of RTS
Each unit of work that is scheduled and executed by the
system is JOB
Jobs can be periodic, aperiodic and sporadic in nature
A set of related jobs which jointly provide some system
function is TASK
RELEASE TIME of a job is the instant of time at which the
job becomes available for execution
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 60
The DEADLINE of a job is the instant of time by which its
execution is required to be completed.
RESPONSE TIME is the length of time from the release time of
the job to the instant when it completes.
Classification of RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 61
Hard Real-Time Systems
Soft Real-Time Systems
Depending on hard/soft real-time constraints, criticality of jobs,
usefulness of late results and deterministic nature of the job
Firm Real-Time Systems
Classification of RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 62
Classification contd
Reactive or embedded systems
Organic systems
Loosely coupled or semidetached
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 63
Classification contd
Application wise classification
Purely cyclic
Mostly cyclic
Asynchronous but somewhat predictable
Asynchronous and unpredictable
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 64
Some examples of Hard RTS
Air traffic control
Aircraft navigation system
Military operations such as raids, vigilance, tracking
Space operations
Car control System
Car engine management
Critical health monitoring systems
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 65
Online transaction systems
Multimedia applications
Electronic games
Interactive database management such as air ticket booking
Some examples of Soft RTS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 66
Reference Model of RTS
Three major elements of a real-time system are
A Workload Model
A Resource Model
Algorithms
In third element, algorithms for scheduling and resource
management are included
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 67
Resources
Processors
Servers and active resources such as computers, transmission
links, disks etc
Resources means passive resources
Memory, sequence numbers, mutexes and database locks
(semaphores) etc
Reusable resources
Plentiful resources
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 68
Real-Time Workload
Each job J
i
is characterized by
Temporal Parameters
Functional Parameters
Resource Parameters
Interconnection Parameters
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 69
Temporal Parameters
Release time r
i
Fixed, jittered and sporadic release times
Deadline
Absolute deadline d
i
, relative deadline D
i
Execution time e
i
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 70
Periodic Task Model
Each computation or data transmission that is executed
repeatedly at regular or semiregular time intervals in order to
provide a function of the system on a continuing basis
Periodic task T
i
has period P
i
which is the minimum length of
all time intervals between release times of consecutive jobs in
task T
i
At all times, the period and execution time of every periodic
task in the system are known
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 71
TASKs in a system are denoted by T
1
,T
2
,.T
n
where as jobs in
a task T
i
are denoted by J
i
,
1
, J
i
,
2
,..J
i
,
k
PHASE of the task T
i
is the release time r
i
,
1
of the first job J
i
,
1
and denoted by
i
HYPERPERIOD H is the least common multiple of p
i
for
i =1, 2,..n
The number of jobs N in each hyperperiod is equal to

i=1 to n
H/ p
i
Periodic Task Model
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 72
UTILIZATIONis equal to the fraction of time a truly periodic
task keeps a processor busy
u
i
= e
i
/p
i
TPTAL UTILIZATIONU of all the tasks in the system is the sum
of the utilizations of the individual tasks in it
U = u
1
+u
2
+..u
i
Periodic Task Model
April 1, 2014 Swati Keskar 73
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 74
Aperiodic and sporadic jobs
Release times are not known a priori
In periodic task model, the workload generated in response to
unexpected events is captured by aperiodic and sporadic tasks
The interarrival times between consecutive jobs in such jobs
vary widely and can be arbitrarily small
A task is aperiodic if the jobs in it have either soft or no
deadlines
Sporadic jobs have hard deadline
April 1, 2014 Swati Keskar 75
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 76
Precedence
If jobs are constrained to execute in some order, they are said
to have precedence constraints. If not, jobs are independent
Precedence relation is denoted by <
Precedence graphs and task graphs are used to precedence
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 77
Dependencies
Data dependency
Temporal dependency
AND/OR precedence
Conditional branches
Pipeline relationship
April 1, 2014 Swati Keskar 78
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 79
Functional Parameters
Preemptivity of jobs
Criticality of jobs
Optional execution
Laxity type and laxity function
April 1, 2014 Swati Keskar 80
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 81
Resource parameters
Preemptivity of resources
Resource graph
A valid schedule is a feasible schedule if every job completes
by its deadline
A set of jobs is schedulable according to a scheduling
algorithm if when using the algorithm the scheduler always
produces a feasible schedule
A scheduling algorithm is optimal if the algorithm always
produces a feasible schedule
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduler
A scheduler is a module that allocates processors and
resources to jobs and tasks
It implements scheduling algorithms and resource access
protocols
April 1, 2014 Swati Keskar 82
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Valid Schedule
A schedule is an assignment of all the jobs in the
system on the available processors produced by the
scheduler
A valid schedule satisfies certain conditions
Every processor is assigned to at the most one job at any time
vice-a-versa
No job is scheduled before its release time
The total amount of processor time assigned to every job is
equal to its maximum execution time
All the constraints imposed on the job are satisfied
April 1, 2014 Swati Keskar 83
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Feasibility
A valid schedule is a feasible schedule if every job completes
by its deadline
A hard real-time scheduling algorithm is optimal if it always
produces a feasible schedule
Various performance measures are
- Maximum/average tardiness
- Lateness
- Response time
- The miss, loss and invalid rates
April 1, 2014 Swati Keskar 84
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
14/04/2012 Swati Keskar 85
Approaches to RT Scheduling
Clock-driven Scheduling
Round-Robin Scheduling
Priority-driven Scheduling
Dynamic and static systems
OFF-line and ON-line Scheduling
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 3)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Swati Keskar
1-88
A reference model
Common scheduling approaches
Clock-driven scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 89
Periodic Task Model
Each computation or data transmission that is executed
repeatedly at regular or semiregular time intervals in order to
provide a function of the system on a continuing basis
Periodic task T
i
has period P
i
which is the minimum length of
all time intervals between release times of consecutive jobs in
task T
i
At all times, the period and execution time of every periodic
task in the system are known
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 90
TASKs in a system are denoted by T
1
,T
2
,.T
n
where as jobs in
a task T
i
are denoted by J
i
,
1
, J
i
,
2
,..J
i
,
k
PHASE of the task T
i
is the release time r
i
,
1
of the first job J
i
,
1
and denoted by
i
HYPERPERIOD H is the least common multiple of p
i
for
i =1, 2,..n
The number of jobs N in each hyperperiod is equal to

i=1 to n
H/ p
i
Periodic Task Model
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 91
UTILIZATIONis equal to the fraction of time a truly periodic
task keeps a processor busy
u
i
= e
i
/p
i
TPTAL UTILIZATIONU of all the tasks in the system is the sum
of the utilizations of the individual tasks in it
U = u
1
+u
2
+..u
i
Periodic Task Model
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 92
Aperiodic and sporadic jobs
Release times are not known a priori
In periodic task model, the workload generated in response to
unexpected events is captured by aperiodic and sporadic tasks
The interarrival times between consecutive jobs in such jobs
vary widely and can be arbitrarily small
A task is aperiodic if the jobs in it have either soft or no
deadlines
Sporadic jobs have hard deadline
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 93
Precedence
If jobs are constrained to execute in some order, they are said
to have precedence constraints. If not, jobs are independent
Precedence relation is denoted by <
Precedence graphs and task graphs are used to precedence
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 94
Dependencies
Data dependency
Temporal dependency
AND/OR precedence
Conditional branches
Pipeline relationship
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 95
Functional Parameters
Preemptivity of jobs
Criticality of jobs
Optional execution
Laxity type and laxity function
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 96
Resource parameters
Preemptivity of resources
Resource graph
A valid schedule is a feasible schedule if every job completes
by its deadline
A set of jobs is schedulable according to a scheduling
algorithm if when using the algorithm the scheduler always
produces a feasible schedule
A scheduling algorithm is optimal if the algorithm always
produces a feasible schedule
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 97
Scheduler
A scheduler is a module that allocates processors and
resources to jobs and tasks
It implements scheduling algorithms and resource access
protocols
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 98
Valid Schedule
A schedule is an assignment of all the jobs in the system on the
available processors produced by the scheduler
A valid schedule satisfies certain conditions
Every processor is assigned to at the most one job at any time
vice-a-versa
No job is scheduled before its release time
The total amount of processor time assigned to every job is
equal to its maximum execution time
All the constraints imposed on the job are satisfied
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 99
Feasibility
A valid schedule is a feasible schedule if every job completes
by its deadline
A hard real-time scheduling algorithm is optimal if it always
produces a feasible schedule
Various performance measures are
- Maximum/average tardiness
- Lateness
- Response time
- The miss, loss and invalid rates
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 100
Approaches to RT Scheduling
Clock-driven Scheduling
Round-Robin Scheduling
Priority-driven Scheduling
Dynamic and static systems
OFF-line and ON-line Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 101
Effective Release Times
The effective release time of a job without
predecessor is equal to its given release time
The effective release time of a job with predecessors
is equal to the maximum value among its given
release time and the effective release times of all of
its predecessors
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 102
Effective Deadlines
The effective deadline of a job without successor is
equal to its given deadline
The effective deadline of a job with successor is
equal to the maximum value among its given release
time and the effective deadline of all of its successors
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
Clock-driven scheduling is effective only when the system is
deterministic (mainly cyclic), except with a limited number of
aperiodic and sporadic jobs
A restrictive model we will use is:
There are a fixed number of periodic tasks
Periodic task parameters are known a priori
Tasks are independent
April 1, 2014 103 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
The advantages of clock-driven scheduling are:
Simple to understand
Validation problem is simple
Precedence and dependency can be dealt with offline by
choice of the schedule
The disadvantages of clock-driven scheduling are:
High system overhead
Poor approach for varying temporal and
resource requirements
Difficult to design and difficult to change
April 1, 2014 104 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
Clock-driven scheduling is static and time-driven
In order to ensure that jobs meet their deadline is to
construct a static schedule of the jobs
This schedule specifies exactly when each job executes
As long as no job overruns, all deadlines are surely met
Because of off-line nature, complex and sophisticated
algorithms can be used
Aperiodic or sporadic jobs can be accommodated when
processor is idle
Also known as cyclic schedule
April 1, 2014 105 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A Static Schedule
A static schedule can be created as a pre-computed table:
Each entry is (t
k
, T(t
k
)) t
k
is a decision time and T(t
k
) is the
name of the task whose job should start at t
k
or I I indicates an
idle interval
April 1, 2014 106 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer-Driven Scheduling
When all parameters are known for all periodic tasks, the
tasks are scheduled statically off-line in order to meet all
deadlines
This approach is supported by (hardware) timers
During run-time the scheduler dispatches jobs according to
the static schedule
April 1, 2014 107 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
The scheduling decision times partition the time line into
intervals called frames.
Scheduling decisions are made only at the beginning of every
frame, there is no preemption within each frame
April 1, 2014 108 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
How to choose frame size
Frame size f is chosen by satisfying three frame size constraints
1. Frames should be sufficiently long so that every job can
start and complete its execution within a frame
f max (e
i
)
2. The frame size should be chosen such that it divides H
hyperperiod of the system
p
i
/f p
i
/f = 0
April 1, 2014 109 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
3. To make it possible for the scheduler to determine whether
every job completes it by its deadline, the frame size should
be sufficiently small so that between the release time and
deadline of every job, there is at least one frame
2f gcd (p
i
, f) D
i
How to choose frame size
April 1, 2014 110 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Task Description
A 4-tuple describes each task
(i, pi, ei, Di) (phase, period, execution time, and relative
deadline)
default: i = 0 and Di = pi defaults may not be shown: (pi, ei)
For example T1 = (2, 5, 2, 8)
First job is released and ready at time 2 First job must be
completed by time 10 Second job is released and ready at
time 7 Second job must be completed by time 15
April 1, 2014 111 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Let us solve one example
A periodic task set is given
T1(4,1) , T2 (5,1) , T3(20,2.5)
Two aperiodic jobs are to be scheduled A
1
(5,2) A
2
(13,1.5)
Find minimum response time
First find the total utilization U, it has to be less than one so that
processor is not overloaded
U = 1/4 + 1/5 +2.5/20
= 0.2+0.25+.125 = 0.575 <1
April 1, 2014 112 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example contd..
Now we have to choose frame size
1. According to first constraint
2. According to second constraint
3. By third constraint
April 1, 2014 113 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Network Flow Graph
A static schedule can be created by using some algorithms,
NFG is one of them
It contains vertices and directed edges
It has source and sink
April 1, 2014 114 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Job slices
Sometimes the given parameters of some task systems donot
meet all three frame size constraints
In such situation partition each job in a task that has longest
execution time into slices with smaller execution time
Again reapply the frame size constraints
April 1, 2014 115 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Summary
The process of constructing a cyclic schedule, we have to make
three kinds of design decisions
Choosing a frame size
Partitioning jobs into slices if required
Placing jobs/slices in the frames
April 1, 2014 116 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cyclic Executives
We have seen that the scheduling decisions are made only at
frame boundaries
This scheduler is modified to cyclic executive which executes a
single do loop
Each job slice is a procedure
Starting from the beginning of each frame, it executes in turn
the slices scheduled in the frame
April 1, 2014 117 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Handling Aperiodic Jobs
We assume that the operating system maintains a queue for
aperiodic jobs
When an aperiodic job is released it is added to the queue
When a processor become available for an aperiodic job one
is retrieved from the queue
April 1, 2014 118 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Aperiodic Jobs
Aperiodic jobs have two parameters, arrival time and
execution time, they have soft deadline
Though deadline is not specified, their response time matters
a lot
These jobs are scheduled in the background after all the job
slices with hard deadlines scheduled in each frame are
completed which is the slack time
The response time is improved by slack stealing in which slack
period in each frame is arranged at the start of frame
April 1, 2014 119 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Sporadic Jobs
Sporadic jobs are those jobs which are having hard deadline
An acceptance test is performed before accepting the
sporadic jobs, otherwise the job is rejected
Once accepted, they have to be scheduled before their
deadline
Sporadic jobs have three parameters, release time,
execution time and deadline
April 1, 2014 120 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Acceptance test in Clock-driven Scheduling
Once the Network Flow Graph or timing diagram is drawn,
prepare a table as follows. Let H=20 and F=2
April 1, 2014 121 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Now count slack in each frame and complete the slack time
table
If a sporadic job S(t,e,d) arrives, find out slack time between t
and d, if this slack time is greater than the execution time of
the job, accept the job
When next sporadic job comes, follow the same procedure,
but slack time calculation is to be modified to add the
execution time of the uncompleted accepted sporadic job
Acceptance test in Clock-driven Scheduling
April 1, 2014 122 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Practical Considerations
Handling frame overruns
Mode changes
General workloads and Multiprocessor scheduling
April 1, 2014 123 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 4)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Swati Keskar
1-126
Common scheduling approaches
Clock-driven scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 127
Approaches to RT Scheduling
Clock-driven Scheduling
Round-Robin Scheduling
Priority-driven Scheduling
Dynamic and static systems
OFF-line and ON-line Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 128
Effective Release Times
The effective release time of a job without
predecessor is equal to its given release time
The effective release time of a job with predecessors
is equal to the maximum value among its given
release time and the effective release times of all of
its predecessors
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 129
Effective Deadlines
The effective deadline of a job without successor is
equal to its given deadline
The effective deadline of a job with successor is
equal to the minimum value among its given release
time and the effective deadline of all of its successors
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
Clock-driven scheduling is effective only when the system is
deterministic (mainly cyclic), except with a limited number of
aperiodic and sporadic jobs
A restrictive model we will use is:
There are a fixed number of periodic tasks
Periodic task parameters are known a priori
Tasks are independent
April 1, 2014 130 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
The advantages of clock-driven scheduling are:
Simple to understand
Validation problem is simple
Precedence and dependency can be dealt with offline by
choice of the schedule
The disadvantages of clock-driven scheduling are:
High system overhead
Poor approach for varying temporal and
resource requirements
Difficult to design and difficult to change
April 1, 2014 131 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
Clock-driven scheduling is static and time-driven
In order to ensure that jobs meet their deadline is to
construct a static schedule of the jobs
This schedule specifies exactly when each job executes
As long as no job overruns, all deadlines are surely met
Because of off-line nature, complex and sophisticated
algorithms can be used
Aperiodic or sporadic jobs can be accommodated when
processor is idle
Also known as cyclic schedule
April 1, 2014 132 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A Static Schedule
A static schedule can be created as a pre-computed table:
Each entry is (t
k
, T(t
k
)) t
k
is a decision time and T(t
k
) is the
name of the task whose job should start at t
k
or I I indicates an
idle interval
April 1, 2014 133 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer-Driven Scheduling
When all parameters are known for all periodic tasks, the
tasks are scheduled statically off-line in order to meet all
deadlines
This approach is supported by (hardware) timers
During run-time the scheduler dispatches jobs according to
the static schedule
April 1, 2014 134 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
The scheduling decision times partition the time line into
intervals called frames.
Scheduling decisions are made only at the beginning of every
frame, there is no preemption within each frame
April 1, 2014 135 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
How to choose frame size
Frame size f is chosen by satisfying three frame size constraints
1. Frames should be sufficiently long so that every job can
start and complete its execution within a frame
f max (e
i
)
2. The frame size should be chosen such that it divides H
hyperperiod of the system
p
i
/f p
i
/f = 0
April 1, 2014 136 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
3. To make it possible for the scheduler to determine whether
every job completes it by its deadline, the frame size should
be sufficiently small so that between the release time and
deadline of every job, there is at least one frame
2f gcd (p
i
, f) D
i
How to choose frame size
April 1, 2014 137 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Task Description
A 4-tuple describes each task
(i, pi, ei, Di) (phase, period, execution time, and relative
deadline)
default: i = 0 and Di = pi defaults may not be shown: (pi, ei)
For example T1 = (2, 5, 2, 8)
First job is released and ready at time 2 First job must be
completed by time 10 Second job is released and ready at
time 7 Second job must be completed by time 15
April 1, 2014 138 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Let us solve one example
A periodic task set is given
T1(4,1) , T2 (5,1) , T3(20,2.5)
Two aperiodic jobs are to be scheduled A
1
(5,2) A
2
(13,1.5)
Find minimum response time
First find the total utilization U, it has to be less than one so that
processor is not overloaded
U = 1/4 + 1/5 +2.5/20
= 0.2+0.25+.125 = 0.575 <1
April 1, 2014 139 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example contd..
Now we have to choose frame size
1. According to first constraint
2. According to second constraint
3. By third constraint
April 1, 2014 140 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Network Flow Graph
A static schedule can be created by using some algorithms,
NFG is one of them
It contains vertices and directed edges
It has source and sink
April 1, 2014 141 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Job slices
Sometimes the given parameters of some task systems donot
meet all three frame size constraints
In such situation partition each job in a task that has longest
execution time into slices with smaller execution time
Again reapply the frame size constraints
April 1, 2014 142 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Summary
The process of constructing a cyclic schedule, we have to make
three kinds of design decisions
Choosing a frame size
Partitioning jobs into slices if required
Placing jobs/slices in the frames
April 1, 2014 143 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cyclic Executives
We have seen that the scheduling decisions are made only at
frame boundaries
This scheduler is modified to cyclic executive which executes a
single do loop
Each job slice is a procedure
Starting from the beginning of each frame, it executes in turn
the slices scheduled in the frame
April 1, 2014 144 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Handling Aperiodic Jobs
We assume that the operating system maintains a queue for
aperiodic jobs
When an aperiodic job is released it is added to the queue
When a processor become available for an aperiodic job one
is retrieved from the queue
April 1, 2014 145 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Aperiodic Jobs
Aperiodic jobs have two parameters, arrival time and
execution time, they have soft deadline
Though deadline is not specified, their response time matters
a lot
These jobs are scheduled in the background after all the job
slices with hard deadlines scheduled in each frame are
completed which is the slack time
The response time is improved by slack stealing in which slack
period in each frame is arranged at the start of frame
April 1, 2014 146 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Sporadic Jobs
Sporadic jobs are those jobs which are having hard deadline
An acceptance test is performed before accepting the
sporadic jobs, otherwise the job is rejected
Once accepted, they have to be scheduled before their
deadline
Sporadic jobs have three parameters, release time,
execution time and deadline
April 1, 2014 147 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Acceptance test in Clock-driven Scheduling
Once the Network Flow Graph or timing diagram is drawn,
prepare a table as follows. Let H=20 and F=2
April 1, 2014 148 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Now count slack in each frame and complete the slack time
table
If a sporadic job S(t,e,d) arrives, find out slack time between t
and d, if this slack time is greater than the execution time of
the job, accept the job
When next sporadic job comes, follow the same procedure,
but slack time calculation is to be modified to add the
execution time of the uncompleted accepted sporadic job
Acceptance test in Clock-driven Scheduling
April 1, 2014 149 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Practical Considerations
Handling frame overruns
Mode changes
General workloads and Multiprocessor scheduling
April 1, 2014 150 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 5)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Swati Keskar
1-153
Clock-driven scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 154
Effective Release Times
The effective release time of a job without
predecessor is equal to its given release time
The effective release time of a job with predecessors
is equal to the maximum value among its given
release time and the effective release times of all of
its predecessors
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 155
Effective Deadlines
The effective deadline of a job without successor is
equal to its given deadline
The effective deadline of a job with successor is
equal to the minimum value among its given release
time and the effective deadline of all of its successors
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
Clock-driven scheduling is effective only when the system is
deterministic (mainly cyclic), except with a limited number of
aperiodic and sporadic jobs
A restrictive model we will use is:
There are a fixed number of periodic tasks
Periodic task parameters are known a priori
Tasks are independent
April 1, 2014 156 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
The advantages of clock-driven scheduling are:
Simple to understand
Validation problem is simple
Precedence and dependency can be dealt with offline by
choice of the schedule
The disadvantages of clock-driven scheduling are:
High system overhead
Poor approach for varying temporal and
resource requirements
Difficult to design and difficult to change
April 1, 2014 157 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
Clock-driven scheduling is static and time-driven
In order to ensure that jobs meet their deadline is to
construct a static schedule of the jobs
This schedule specifies exactly when each job executes
As long as no job overruns, all deadlines are surely met
Because of off-line nature, complex and sophisticated
algorithms can be used
Aperiodic or sporadic jobs can be accommodated when
processor is idle
Also known as cyclic schedule
April 1, 2014 158 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A Static Schedule
A static schedule can be created as a pre-computed table:
Each entry is (t
k
, T(t
k
)) t
k
is a decision time and T(t
k
) is the
name of the task whose job should start at t
k
or I I indicates an
idle interval
April 1, 2014 159 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer-Driven Scheduling
When all parameters are known for all periodic tasks, the
tasks are scheduled statically off-line in order to meet all
deadlines
This approach is supported by (hardware) timers
During run-time the scheduler dispatches jobs according to
the static schedule
April 1, 2014 160 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Clock-Driven Scheduling
The scheduling decision times partition the time line into
intervals called frames.
Scheduling decisions are made only at the beginning of every
frame, there is no preemption within each frame
April 1, 2014 161 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
How to choose frame size
Frame size f is chosen by satisfying three frame size constraints
1. Frames should be sufficiently long so that every job can
start and complete its execution within a frame
f max (e
i
)
2. The frame size should be chosen such that it divides H
hyperperiod of the system
p
i
/f p
i
/f = 0
April 1, 2014 162 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
3. To make it possible for the scheduler to determine whether
every job completes it by its deadline, the frame size should
be sufficiently small so that between the release time and
deadline of every job, there is at least one frame
2f gcd (p
i
, f) D
i
How to choose frame size
April 1, 2014 163 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Task Description
A 4-tuple describes each task
(i, pi, ei, Di) (phase, period, execution time, and relative
deadline)
default: i = 0 and Di = pi defaults may not be shown: (pi, ei)
For example T1 = (2, 5, 2, 8)
First job is released and ready at time 2 First job must be
completed by time 10 Second job is released and ready at
time 7 Second job must be completed by time 15
April 1, 2014 164 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Let us solve one example
A periodic task set is given
T1(4,1) , T2 (5,1) , T3(20,2.5)
Two aperiodic jobs are to be scheduled A
1
(5,2) A
2
(13,1.5)
Find minimum response time
First find the total utilization U, it has to be less than one so that
processor is not overloaded
U = 1/4 + 1/5 +2.5/20
= 0.2+0.25+.125 = 0.575 <1
April 1, 2014 165 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example contd..
Now we have to choose frame size
1. According to first constraint
2. According to second constraint
3. By third constraint
April 1, 2014 166 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Network Flow Graph
A static schedule can be created by using some algorithms,
NFG is one of them
It contains vertices and directed edges
It has source and sink
April 1, 2014 167 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Job slices
Sometimes the given parameters of some task systems donot
meet all three frame size constraints
In such situation partition each job in a task that has longest
execution time into slices with smaller execution time
Again reapply the frame size constraints
April 1, 2014 168 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Summary
The process of constructing a cyclic schedule, we have to make
three kinds of design decisions
Choosing a frame size
Partitioning jobs into slices if required
Placing jobs/slices in the frames
April 1, 2014 169 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cyclic Executives
We have seen that the scheduling decisions are made only at
frame boundaries
This scheduler is modified to cyclic executive which executes a
single do loop
Each job slice is a procedure
Starting from the beginning of each frame, it executes in turn
the slices scheduled in the frame
April 1, 2014 170 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Handling Aperiodic Jobs
We assume that the operating system maintains a queue for
aperiodic jobs
When an aperiodic job is released it is added to the queue
When a processor become available for an aperiodic job one
is retrieved from the queue
April 1, 2014 171 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Aperiodic Jobs
Aperiodic jobs have two parameters, arrival time and
execution time, they have soft deadline
Though deadline is not specified, their response time matters
a lot
These jobs are scheduled in the background after all the job
slices with hard deadlines scheduled in each frame are
completed which is the slack time
The response time is improved by slack stealing in which slack
period in each frame is arranged at the start of frame
April 1, 2014 172 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Sporadic Jobs
Sporadic jobs are those jobs which are having hard deadline
An acceptance test is performed before accepting the
sporadic jobs, otherwise the job is rejected
Once accepted, they have to be scheduled before their
deadline
Sporadic jobs have three parameters, release time,
execution time and deadline
April 1, 2014 173 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Acceptance test in Clock-driven Scheduling
Once the Network Flow Graph or timing diagram is drawn,
prepare a table as follows. Let H=20 and F=2
April 1, 2014 174 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Now count slack in each frame and complete the slack time
table
If a sporadic job S(t,e,d) arrives, find out slack time between t
and d, if this slack time is greater than the execution time of
the job, accept the job
When next sporadic job comes, follow the same procedure,
but slack time calculation is to be modified to add the
execution time of the uncompleted accepted sporadic job
Acceptance test in Clock-driven Scheduling
April 1, 2014 175 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Practical Considerations
Handling frame overruns
Mode changes
General workloads and Multiprocessor scheduling
April 1, 2014 176 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 6)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Swati Keskar
1-179
Aperiodic jobs in Clock-driven scheduling
Priority-driven scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Summary
The process of constructing a cyclic schedule, we have to make
three kinds of design decisions
Choosing a frame size
Partitioning jobs into slices if required
Placing jobs/slices in the frames
April 1, 2014 180 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cyclic Executives
We have seen that the scheduling decisions are made only at
frame boundaries
This scheduler is modified to cyclic executive which executes a
single do loop
Each job slice is a procedure
Starting from the beginning of each frame, it executes in turn
the slices scheduled in the frame
April 1, 2014 181 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Handling Aperiodic Jobs
We assume that the operating system maintains a queue for
aperiodic jobs
When an aperiodic job is released it is added to the queue
When a processor become available for an aperiodic job one
is retrieved from the queue
April 1, 2014 182 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Aperiodic Jobs
Aperiodic jobs have two parameters, arrival time and
execution time, they have soft deadline
Though deadline is not specified, their response time matters
a lot
These jobs are scheduled in the background after all the job
slices with hard deadlines scheduled in each frame are
completed which is the slack time
The response time is improved by slack stealing in which slack
period in each frame is arranged at the start of frame
April 1, 2014 183 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Sporadic Jobs
Sporadic jobs are those jobs which are having hard deadline
An acceptance test is performed before accepting the
sporadic jobs, otherwise the job is rejected
Once accepted, they have to be scheduled before their
deadline
Sporadic jobs have three parameters, release time,
execution time and deadline
April 1, 2014 184 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Acceptance test in Clock-driven Scheduling
Once the Network Flow Graph or timing diagram is drawn,
prepare a table as follows. Let H=20 and F=2
April 1, 2014 185 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Now count slack in each frame and complete the slack time
table
If a sporadic job S(t,e,d) arrives, find out slack time between t
and d, if this slack time is greater than the execution time of
the job, accept the job
When next sporadic job comes, follow the same procedure,
but slack time calculation is to be modified to add the
execution time of the uncompleted accepted sporadic job
Acceptance test in Clock-driven Scheduling
April 1, 2014 186 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Practical Considerations
Handling frame overruns
Mode changes
General workloads and Multiprocessor scheduling
April 1, 2014 187 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Driven scheduling
Before starting the discussion, we assume that
The tasks are independent
There are no aperiodic and sporadic jobs
Job is ready for execution as soon as it is released
Jobs are preemptible and never suspends itself
Scheduling decisions are made immediately upon job
releases and completion
Context switch overhead is negligible
April 1, 2014 Swati Keskar 188
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
April 1, 2014 Swati Keskar 189
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Driven scheduling
It is an on-line scheduler, does not precompute the
schedule
It assigns the priorities to the job after they are released
and places the jobs in ready queue
Two main classifications
Fixed priority: assigns the same priority to all the jobs in
each task
Dynamic priority: assigns different priorities to the
individual jobs in each task
April 1, 2014 Swati Keskar 190
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fixed Priority Algorithms
Rate-Monotonic Algorithm RMA
shorter the period, the higher the priority i.e. higher the
rate of occurrence, higher the priority
Deadline-Monotonic Algorithm DMA
shorter the relative deadline, higher the priority
April 1, 2014 Swati Keskar 191
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Consider a task set T
1
(7,3) , T
2
(12,3), T
3
(20,5)
April 1, 2014 192 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dynamic Priority algorithms
Earliest Deadline First (EDF)
assigns the priority to individual jobs in the tasks
according to their absolute deadlines
Least Slack-Time-first (LST)
the scheduler checks the slacks of al the ready jobs
each time a new job is released then the smaller the
slack, the higher the priority
FIFO, LIFO etc
April 1, 2014 Swati Keskar 193
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulable Utilization
A scheduling algorithm can feasibly schedule any set of
periodic tasks on a processor if the total utilization of the
tasks is equal to or less than the schedulable utilization
of the algorithm
Higher the schedulable utilization of an algorithm , the
better the algorithm
A scheduling algorithm whose schedulable utilization is
equal to 1 is an optimal algorithm
April 1, 2014 Swati Keskar 194
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
EDF Algorithm
A system T of independent, preemptable tasks with
relative deadlines equal to their respective periods can
be feasibly scheduled on one processor if and only if its
total utilization is equal to or less than 1
e
k
U
EDF
= ---------------- 1
min(D
k
,p
k
)
April 1, 2014 Swati Keskar 195
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
RMA and DMA
A system of simply periodic, independent, preemptible
tasks whose relative deadlines are equal to or larger
than their periods is schedulable on one processor
according to the RM algorithm if and only if its total
utilization is equal to or less than 1
April 1, 2014 Swati Keskar 196
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulability Test
Schedulability test for tasks with short response times ie
where the response times of the jobs are smaller than or
equal to their respective periods
Every job completes before the next job in the same task
is released
We have to the critical instant
April 1, 2014 Swati Keskar 197
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Critical Instant
A critical instant of a task T
i
is a time instant which is
such that the job in T
i
released at the instant has the
maximum response time.
This maximum response time is called Worst Case
Execution Time and is denoted by W
i
Theorem: In a fixed priority system where every job
completes before the next job in the same task is
released, a critical instant of any task T
i
occurs when one
of its job J
i,c
is released at the same time with a job in
every higher priority task
April 1, 2014 Swati Keskar 198
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Time Demand Analysis
To determine whether a task can meet all its deadlines,
we have to compute the total demand for processor time
by a job released at a critical instant of the task and by
all the higher priority tasks at that critical instant
We will then check whether this demand can be met
before the deadline of the job
This test is called Time Demand analysis
W
i
(t) = e
i
+ t/p
k
e
k
for 0< t p
i
This W
i
(t) t for some t D
i
April 1, 2014 Swati Keskar 199
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
A task set T
1
(7,3); T
2
(12,3) and T
3
(20,5) is Given. It is
scheduled by using Rate Monotonic Algorithm. Check its
schedulability.
April 1, 2014 Swati Keskar 200
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Busy Interval
Here is a schedulability test for fixed-priority tasks with
arbitrary response time
When relative deadline are larger than their respective
periods, we have to determine the schedulability
Approach is find the busy interval and then apply time
demand analysis test
A level-
i
busy interval (t
0
,t ] starts at an instant t
0
when
All jobs in T
i
released before the instant have completed
A job in T
i
is released
The interval ends at the first instant t after to when all jobs
in T
i
released since t
0
are complete
April 1, 2014 Swati Keskar 201
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sufficient Schedulability condition
Schedulable utilization of RM and DM Algorithms for
tasks with D
i
= P
i
gives us a flexible design guidelines for
the choices of the periods and execution times of the
tasks
Theorem : A system of n independent, preemptible
periodic tasks with relative deadlines equal to their
respective periods can be feasibly scheduled on a
processor according to the RMA if its total utilization U is
less than or equal to
U
RM
(n) = n(2
1/n
-1) and U U
RM
April 1, 2014 Swati Keskar 202
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
U
RM
as a Function of Task Parameters
Schedulable utilization as a function task utilization
Schedulable utilization of simply periodic tasks
Period ratio
Values of periods
Tasks with arbitrary relative deadlines
April 1, 2014 Swati Keskar 203
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Practical Factors
Assumptions we have made at the starting are not
always valid. Considering the practical factors, blocking
and priority inversion has to be discussed
Nonpreemptivity
Self suspension
Context switches
Limited priority levels
Tick Scheduling
April 1, 2014 Swati Keskar 204
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Tick Scheduling
We are assuming that the scheduler is event-driven
This assumption is always not valid, sometimes the scheduler
is time-driven
Scheduling decisions are made at these time instants called
clock interrupts
This method is also called time-based scheduling and
scheduler executes only at clock interrupts
April 1, 2014 205 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
April 1, 2014 206 Swati Keskar
16/08/2010 207 Swati Keskar BITS Pilani
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Aperiodic and
Sporadic Jobs
We assume that the operating system maintains the priority
queue.
The ready periodic tasks are placed in the periodic task queue
according to their priority assigned by any one of the
algorithms
Each accepted sporadic job is assigned a priority and is placed
in priority queue
Each newly arrived aperiodic job is placed in the aperiodic job
queue
April 1, 2014 208 Swati Keskar
April 1, 2014 209 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Alternative approaches
Background execution
Polled execution
Interrupt driven execution
April 1, 2014 210 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Background Execution
Aperiodic jobs are scheduled and executed only at times
when there is no periodic or sporadic job ready for execution
Always produces correct schedules
Simple to implement
Drawback is that the execution of aperiodic jobs is delayed
and response time is prolonged
April 1, 2014 211 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Interrupt Driven Execution
Whenever an aperiodic job arrives, the execution of periodic
tasks are interrupted and the aperiodic job is executed.
In this case, aperiodic job may have the shortest possible
response time
But it has main disadvantage that if aperiodic job always
execute as soon as possible ,periodic task may miss some
deadlines
April 1, 2014 212 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Polling Server
A poller or polling server is a periodic task whose polling
period is p
s
and e
s
is its execution time
The poller is ready for execution periodically and is scheduled
together with the periodic tasks in the system
When it executes, it examines the aperiodic job queue
If the queue is nonempty, the poller executes the job at the
head of the queue
Server suspends its execution when either budget is
exhausted or when the queue becomes empty
April 1, 2014 213 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Polling Server
The main disadvantage of poling server is that if at the
beginning of a polling period the poller finds the aperiodic job
queue empty , it suspends immediately
It will not be ready for execution and able to examine the
queue again until the next polling period
April 1, 2014 214 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Periodic Server
The periodic server is nothing but a periodic task created for
the purpose of executing aperiodic jobs
It has period p
s
and execution time e
s
which is called as
execution budget or simply budget
The ratio u
s
= e
s
/p
s
is the size of the server
At the beginning of each period, the budget of the poller is set
to e
s
i.e. its budget is replenished
April 1, 2014 215 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Periodic Server
The periodic server is backlogged whenever the aperiodic job
queue is nonempty and there is at least an aperiodic job to be
executed by the server
The server is idle when the queue is empty
The server is eligible for execution only when it is backlogged
and budget
When the server is scheduled and executes aperiodic jobs, it
consumes its budget at the rate of one per unit time
The server budget becomes exhausted when the budget
becomes zero
April 1, 2014 216 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Bandwidth-preserving Servers
If we can preserve the execution budget of the poller when it
finds an empty queue and allow it to execute later in the
period if any aperiodic job arrives, we can improve the
response time of aperiodic job
Algorithms that improve the polling approach in ths manner
are called bandwidth preserving server algorithm
These are periodic servers, each type of server is defined by a
set of consumption and replenishment rules
April 1, 2014 217 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Types of bandwidth-preserving servers
Deferrable servers
Sporadic servers
Constant utilization/total bandwidth servers and weighted
fair-queuing servers
Bandwidth-preserving Servers
April 1, 2014 218 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Deferrable servers
Consumption rule: The execution budget of the server is
consumed at the rate of one per unit time whenever the
server executes
Replenishment rule : The execution budget of the server is set
to e
s
at time instants kp
k
for k = 0,1,2
April 1, 2014 219 Swati Keskar
April 1, 2014 220 Swati Keskar
April 1, 2014 221 Swati Keskar
April 1, 2014 222 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulability with deferrable Server
Time demand analysis can be used to determine whether all
the periodic tasks remain schedulable in the presence of a
deferrable server (highest priority)
The time demand function of the task T
i
in presence of
deferrable server is given by
April 1, 2014 223 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulable Utilization
Schedulability of a fixed-priority system in which a deferrable
server is scheduled at an arbitrary priority cannot be assured
Only exception is when the deferrable server has shortest
period in a system of n tasks and the system is scheduled rate-
monotonically
April 1, 2014 224 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Theorem for Schedulable Utilization
Consider a system of n independent, preemptible periodic
tasks whose periods satisfy the inequalities
p
s
< p
1
< p
2
< < p
n
< 2p
s
and p
n
> p
s
+ e
s
and whose relative
deadlines are equal to their respective periods.
This system is schedulable rate-monotonically with a
deferrable server (p
s
, e
s
) if their total utilization is less than or
equal to
April 1, 2014 225 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
When the servers period is arbitrary, we can use U
RM
(n) to
determine whether each periodic task T
i
is schedulable if the
periodic tasks and the server are scheduled rate-
monotonically
We can treat additional e
s
units of time as additional blocking
time of the task T
i
. T
i
is surely schedulable if
Theorem for Schedulable Utilization
April 1, 2014 226 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulability with deadline-driven systems
A periodic task T
i
in a system of n independent, preemptive
periodic tasks is schedulable with a deferrable server with
period ps, execution budget es and utilization us, according to
the EDF algorithm if
April 1, 2014 227 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sporadic Servers
Improved version of deferrable servers
The consumption and replenishment rules of this server
ensure that each sporadic server with period p
s
and budget e
s
never demands more processor time than the periodic task
(p
s
,e
s
) in any time interval
We can treat the sporadic server exactly like the periodic task
when we check for the schedulability of the system
A system of periodic tasks containing a sporadic server may be
schedulable while the same system containing a deferrable
server with same parameters is not
April 1, 2014 228 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Simple Sporadic Server
Consumption rules : at any time t after t
r
ie replenishment
time, the servers budget is consumed at the rate of 1 unit per
time until the budget is exhausted when either one of the
following conditions are not true
C1 : The server is executing
C2: The server has executed since t
r
and END <t where END
is the end of the latest busy interval
April 1, 2014 229 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Replenishment Rules
Replenishment rules of Simple Fixed-Priority-Sporadic server
are
R1 : Initially when the system begins execution and each time
when the budget is replenished, the execution budget = e
s
and t
r
= the current time
R2: At the time t
f
(first instant after t
r
when server begins
execution), if END = t
f
, t
e
= max( t
r
, BEGIN). If END < t
f,
t
e
=t
f
. The next replenishment time is set at t
e
+p
s
April 1, 2014 230 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Replenishment Rules
R3 : The next replenishment occurs at the next replenishment
time, except under the following conditions
If the next replenishment time t
e
+ p
s
is earlier than t
f
, the
budget is replenished as soon as it is exhausted
If the system T becomes idle before the next replenishment
time t
e
+ p
s
, and becomes busy again at tb, the budget is
replenished at min( t
e
+p
s
, t
b
).
April 1, 2014 231 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling of Sporadic Jobs
The scheduler performs an acceptance test on each sporadic
job upon its arrival
The acceptance tests are performed on sporadic jobs in the
EDF order
Once accepted, sporadic jobs are ordered among themselves
in the EDF order
April 1, 2014 232 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Acceptance Test
For deadline-driven system
For first sporadic job S (t,d,e), the scheduler accepts S if its
density e/(d-t) < 1-
For new sporadic jobs , the scheduler accepts the job S if
e / (d t) +
s,k
1- for all k = 1,2
April 1, 2014 233 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
For fixed-priority systems
For first sporadic job, find slack time

s,1
(t) = (d
s,1
-t)/p
s
e
s
e
s,1
0
For next sporadic jobs, the scheduler computes the slack

s,I
according to

s,i
(t) = (d
s,i
-t)/p
s
e
s
e
s,I
(e
s,k
-
s,k
) 0
Acceptance Test
April 1, 2014 234 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 7)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Priority-Driven Scheduling
Resource Access
Resource Access Control Protocol
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dynamic Priority algorithms
Earliest Deadline First (EDF)
assigns the priority to individual jobs in the tasks
according to their absolute deadlines
Least Slack-Time-first (LST)
the scheduler checks the slacks of al the ready jobs
each time a new job is released then the smaller the
slack, the higher the priority
FIFO, LIFO etc
April 1, 2014 Swati Keskar 238
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulable Utilization
A scheduling algorithm can feasibly schedule any set of
periodic tasks on a processor if the total utilization of the
tasks is equal to or less than the schedulable utilization
of the algorithm
Higher the schedulable utilization of an algorithm , the
better the algorithm
A scheduling algorithm whose schedulable utilization is
equal to 1 is an optimal algorithm
April 1, 2014 Swati Keskar 239
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
EDF Algorithm
A system T of independent, preemptable tasks with
relative deadlines equal to their respective periods can
be feasibly scheduled on one processor if and only if its
total utilization is equal to or less than 1
e
k
U
EDF
= ---------------- 1
min(D
k
,p
k
)
April 1, 2014 Swati Keskar 240
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
RMA and DMA
A system of simply periodic, independent, preemptible
tasks whose relative deadlines are equal to or larger
than their periods is schedulable on one processor
according to the RM algorithm if and only if its total
utilization is equal to or less than 1
April 1, 2014 Swati Keskar 241
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulability Test
Schedulability test for tasks with short response times ie
where the response times of the jobs are smaller than or
equal to their respective periods
Every job completes before the next job in the same task
is released
We have to the critical instant
April 1, 2014 Swati Keskar 242
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Critical Instant
A critical instant of a task T
i
is a time instant which is
such that the job in T
i
released at the instant has the
maximum response time.
This maximum response time is called Worst Case
Execution Time and is denoted by W
i
Theorem: In a fixed priority system where every job
completes before the next job in the same task is
released, a critical instant of any task T
i
occurs when one
of its job J
i,c
is released at the same time with a job in
every higher priority task
April 1, 2014 Swati Keskar 243
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Time Demand Analysis
To determine whether a task can meet all its deadlines,
we have to compute the total demand for processor time
by a job released at a critical instant of the task and by
all the higher priority tasks at that critical instant
We will then check whether this demand can be met
before the deadline of the job
This test is called Time Demand analysis
W
i
(t) = e
i
+ t/p
k
e
k
for 0< t p
i
This W
i
(t) t for some t D
i
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
A task set T
1
(7,3); T
2
(12,3) and T
3
(20,5) is Given. It is
scheduled by using Rate Monotonic Algorithm. Check its
schedulability.
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Busy Interval
Here is a schedulability test for fixed-priority tasks with
arbitrary response time
When relative deadline are larger than their respective
periods, we have to determine the schedulability
Approach is find the busy interval and then apply time
demand analysis test
A level-
i
busy interval (t
0
,t ] starts at an instant t
0
when
All jobs in T
i
released before the instant have completed
A job in T
i
is released
The interval ends at the first instant t after to when all jobs
in T
i
released since t
0
are complete
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sufficient Schedulability condition
Schedulable utilization of RM and DM Algorithms for
tasks with D
i
= P
i
gives us a flexible design guidelines for
the choices of the periods and execution times of the
tasks
Theorem : A system of n independent, preemptible
periodic tasks with relative deadlines equal to their
respective periods can be feasibly scheduled on a
processor according to the RMA if its total utilization U is
less than or equal to
U
RM
(n) = n(2
1/n
-1) and U U
RM
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
U
RM
as a Function of Task Parameters
Schedulable utilization as a function task utilization
Schedulable utilization of simply periodic tasks
Period ratio
Values of periods
Tasks with arbitrary relative deadlines
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Practical Factors
Assumptions we have made at the starting are not
always valid. Considering the practical factors, blocking
and priority inversion has to be discussed
Nonpreemptivity
Self suspension
Context switches
Limited priority levels
Tick Scheduling
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Tick Scheduling
We are assuming that the scheduler is event-driven
This assumption is always not valid, sometimes the scheduler
is time-driven
Scheduling decisions are made at these time instants called
clock interrupts
This method is also called time-based scheduling and
scheduler executes only at clock interrupts
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resources
Tasks cannot be independent in most systems as they
typically share common resources
Therefore tasks may need to suspend pending on some on
some later event which is dependent on other tasks
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Assumptions
Uniprocessor
Fixed No. of Tasks
All tasks are periodic
Context switch overhead times are minimal
Tasks are nonpreemptive when they hold resources
Tasks are not independent
Task priorities donot remain fixed
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resources
There can be types of reusable resources named
R
1
, R
2
,R

There are v
i
indistinguishable units of resource R
i
Resources are granted to the jobs on a nonpreemptive basis
and used in a mutually exclusive manner
Some resources have only one unit while some have many
units
Plentiful resources have no effect
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control
We assume a lock based concurrency control mechanism
When a job wants to use a resource, it executes a lock to
request them
The job continues its execution when it is granted the
requested resource
When job no longer needs the resource, it releases the
resource by executing an unlock
We call a segment of a job that begins at a lock and ends at a
matching unlock a critical section
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Mutual Exclusion
When a job wants to use
i
units of resource R
i
, it executes a
lock to request them
L (R
i
,
i
) U (R
i
,
i
)
If there are few resources and each has only 1 unit, we simply
call X, Y or Z or black shaded etc
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Critical Section
A segment of a job that begins at a lock and ends at a
matching unlock is a critical section denoted by
[ R, , e ] where e is maximum execution time of the
critical section
If [ R
5
, 4, 3 ] is given, it means that a job uses 4 units of R
5
and
execution time of this critical section is 3
What do you mean by [ R
1
;14 [R
4
,3; 9 [R
5
, 4 ; 3]]] ?
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Two jobs conflict with one another or have a resource conflict
, if some of the resources they require are of the same type
The jobs contend for a resource when one job requests a
resource that the other job already has
When the scheduler does not grant the resource to the job
requesting them, the job is blocked and loses the processor
It stays blocked until the scheduler grants the resource, it is
waiting for
Resource Access Control
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effect of Resource Contention
J
1
, J
2
, J
3
are three jobs whose feasible intervals are
(6,14) , (2,17] and (0,18] and their resource requirement is [
R; 2 ], [ R ; 4 ] and [ R; 4] respectively
See how resource contention delays the completion of higher
priority job
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effects
Priority Inversion
Time Anomalies
Deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control Protocol
Resource access control protocol is a set of rules that govern
When and under what conditions each request for resource is
granted
How jobs requiring resources are scheduled
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effects of Resource Contention
Resource contentions among the jobs can cause priority
inversion because the resources are allocated to the jobs on a
nonpreemptive basis
When priority inversion occurs, timing anomalies invariably
follow
Without good resource access control, the duration of a
priority inversion can be unbounded
nonpreemptivity of resource allocation can also lead to
deadlocks
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Deadlock
For example, there are two jobs which require resources X
and Y. The jobs are in deadlock when one of them holds X and
requests Y, while the other holds Y and requests for X
The condition that allow this circular wait of jobs for each
other is deadlock
No resource access control protocol can eliminate the priority
inversion and anomalous behavior caused by resource
contention
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control Protocols
Nonpreemptive critical section
Priority inheritance protocol
Priority ceiling protocol
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Assumptions
We assume that no other job suspends itself
Every job is preemptible on the processor
Job J
i
has distinct priority
i
Priorities are always assigned by integers, the smaller the
integer, the higher the priority
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Wait-For Graph
A path in a wait-for graph from a higher-priority job to a lower
priority job represents the fact that the farmer is directly
blocked by the latter
A cyclic path indicates a deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Bipartite Graph
Used to specify resource requirements of a system
There is a vertex for every job and every resource
Each vertex is named by the name of the job or resource it
represents
The integer next to each resource vertex R
i
gives v
i
of units of
the resource
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
NPCS Protocol
The way to control access of resources is to schedule all
critical sections on the processor nonpreemptively
NPCS is called so because no job is ever preempted when it
holds any resource deadlock can never occur
Uncontrolled priority inversion never occurs because Jh can
be blocked only if it is released when some lower priority job
is in a critical section
Once the blocking completes, all the resources are free
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking Time in NPCS
The blocking time b
i
(rc) due to resource conflict of a periodic
task T
i
in a fixed priority is equal to
b
i
(rc) = max (c
k
)
i+1 k n
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Advantages
Simplicity
The protocol does not need any prior knowledge about
resource requirement of the jobs
Simple to implement and can be used in fixed as well as
dynamic priority systems
Specially good when all the critical sections are shot and when
most of the jobs conflict with each other
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Disadvantages
Every job can be blocked by every lower-priority job that
requires some resource even when there is no resource
conflict between them
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance protocol
Used to avoid priority inversion
It requires the priority of a task gaining access to a shared
resource to dynamically inherit the priority of the highest
priority task sharing the resource, which blocks any medium
priority task
Assigned priority according to the scheduler
The current priority
l
(t) of a job J
l
may be raised to the
higher priority
h
(t) of another job J
l
This is priority inheritance
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rules of The Protocol
Scheduling Rule Ready jobs are scheduled on the processor
preemptively in a priority- driven manner
Allocation Rule When a job J request a resource R at time t
a- If R is free, it is allocated to J until J releases the
resource
b- If R is not free, the request is denied and J is
blocked
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance Rule
When the requesting job J becomes blocked, the job J
l
which
block J inherits the current priority (t) of J
The job J
l
executes at its inherited priority (t) until it releases
R
At that instant, the priority of J
l
returns to its original priority
In this case, the protocol ensures that the duration of priority
inversion is never longer than the duration of the outermost
CS each time a job is blocked
April 1, 2014
Example
Job r
i
e
i

i
Critical Section
J
1
7 3 1 [shaded;1]
J
2
5 3 2 [black;1]
J
3
4 2 3
J
4
2 6 4 [shaded 4[black
;1.5]]
J
5
0 6 5 [black;4]
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking Time in P-IP
There are two types of blocking
i- direct blocking
ii- priority-inheritance blocking
Worst-case response time for task i is
W
i
= e
i
+ b
i
+ I
i
Although P-I bounds the number of blocks a task may
experience, it does not prevent transitive blocking
Does not prevent deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Transitive Blocking
Chain of blocks
Process A is blocked by blocked process B, which is blocked by
process C
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Ceiling Protocol
Assumptions- The assigned priorities of all jobs are fixed and
the resource requirements of all jobs are known
Priority-ceiling of any resource R
i
is the highest priority of all
jobs that require R
i
, and is denoted by (R
i
)
Current ceiling priority (t) is equal to the highest priority
ceiling of the resource s that are in use at the time, if some
resources are in use
If all the resources are free at that time, the current ceiling
(t) is , a nonexisting priority level, that is lower than the
lowest priority of all jobs
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Rules of P-CP
A At its release time t, the current priority (t) of every job J is
equal to its assigned priority, the job remains at this priority
except under priority inheritance
B- Every ready job J is scheduled preemptively and in a priority
driven manner at its current priority (t)
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Allocation rules
Whenever a job J requests a resource R at time t
R is held by another job, Js request fails and J is blocked
If R is free
i If Js priority is higher than the current priority ceiling
(t), R is allocated to J
ii - If Js priority is not higher, R is allocated to J only if J is the
job holding the resources whose priority ceiling is equal to
(t), otherwise Js request is denied and J becomes blocked
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance Rule
When J becomes blocked, the job J
l
which blocks J inherits the
current priority (t) of J
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Comparison of P-IP and P-CP
P-I is greedy while P-C is not
The difference arises because of non-greedy nature of the P-c
protocol
It is possible for J to be blocked by a lower-priority job which
does not hold the requested resource
Deadlock never occur under P-CP
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Types of Blocking
Three types of blocking
A- direct blocking
B- Priority-Inheritance Blocking
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking contd
Avoidance blocking
(x) is equal to or higher than (t)
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Duration of Blocking
Whether as a cost of its ability of P-C protocol to prevent
deadlock, can cause a job to be blocked for a longer duration
than the priority-inheritance protocol
Theorem: When resource access of preemptive, priority-
driven jobs on one processor are controlled by the priority-
ceiling protocol, a job can be blocked for at most the duration
of one critical section
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Computation of Blocking Time
Example:
April 1, 2014
Computation for direct blocking
April 1, 2014
Priority-inheritance blocking
April 1, 2014
Avoidance blocking
April 1, 2014
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 8)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : Scheduling
Resource Access
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Schedulability Test
Practical Factors
Resource Access
Resource Access Control Protocol
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Time Demand Analysis
To determine whether a task can meet all its deadlines,
we have to compute the total demand for processor time
by a job released at a critical instant of the task and by
all the higher priority tasks at that critical instant
We will then check whether this demand can be met
before the deadline of the job
This test is called Time Demand analysis
W
i
(t) = e
i
+ t/p
k
e
k
for 0< t p
i
This W
i
(t) t for some t D
i
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
16/08/2010 297 Swati Keskar BITS Pilani
Example contd
16/08/2010 298 Swati Keskar BITS Pilani
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
A task set T
1
(7,3); T
2
(12,3) and T
3
(20,5) is Given. It is
scheduled by using Rate Monotonic Algorithm. Check its
schedulability.
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Busy Interval
Here is a schedulability test for fixed-priority tasks with
arbitrary response time
When relative deadline are larger than their respective
periods, we have to determine the schedulability
Approach is find the busy interval and then apply time
demand analysis test
A level-
i
busy interval (t
0
,t ] starts at an instant t
0
when
All jobs in T
i
released before the instant have completed
A job in T
i
is released
The interval ends at the first instant t after to when all jobs
in T
i
released since t
0
are complete
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sufficient Schedulability condition
Schedulable utilization of RM and DM Algorithms for
tasks with D
i
= P
i
gives us a flexible design guidelines for
the choices of the periods and execution times of the
tasks
Theorem : A system of n independent, preemptible
periodic tasks with relative deadlines equal to their
respective periods can be feasibly scheduled on a
processor according to the RMA if its total utilization U is
less than or equal to
U
RM
(n) = n(2
1/n
-1) and U U
RM
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
U
RM
as a Function of Task Parameters
Schedulable utilization as a function task utilization
Schedulable utilization of simply periodic tasks
Period ratio
Values of periods
Tasks with arbitrary relative deadlines
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Practical Factors
Assumptions we have made at the starting are not
always valid. Considering the practical factors, blocking
and priority inversion has to be discussed
Nonpreemptivity
Self suspension
Context switches
Limited priority levels
Tick Scheduling
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Tick Scheduling
We are assuming that the scheduler is event-driven
This assumption is always not valid, sometimes the scheduler
is time-driven
Scheduling decisions are made at these time instants called
clock interrupts
This method is also called time-based scheduling and
scheduler executes only at clock interrupts
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
April 1, 2014
16/08/2010 306 Swati Keskar BITS Pilani
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resources
Tasks cannot be independent in most systems as they
typically share common resources
Therefore tasks may need to suspend pending on some on
some later event which is dependent on other tasks
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Assumptions
Uniprocessor
Fixed No. of Tasks
All tasks are periodic
Context switch overhead times are minimal
Tasks are nonpreemptive when they hold resources
Tasks are not independent
Task priorities donot remain fixed
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resources
There can be types of reusable resources named
R
1
, R
2
,R

There are v
i
indistinguishable units of resource R
i
Resources are granted to the jobs on a nonpreemptive basis
and used in a mutually exclusive manner
Some resources have only one unit while some have many
units
Plentiful resources have no effect
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control
We assume a lock based concurrency control mechanism
When a job wants to use a resource, it executes a lock to
request them
The job continues its execution when it is granted the
requested resource
When job no longer needs the resource, it releases the
resource by executing an unlock
We call a segment of a job that begins at a lock and ends at a
matching unlock a critical section
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Mutual Exclusion
When a job wants to use
i
units of resource R
i
, it executes a
lock to request them
L (R
i
,
i
) U (R
i
,
i
)
If there are few resources and each has only 1 unit, we simply
call X, Y or Z or black shaded etc
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Critical Section
A segment of a job that begins at a lock and ends at a
matching unlock is a critical section denoted by
[ R, , e ] where e is maximum execution time of the
critical section
If [ R
5
, 4, 3 ] is given, it means that a job uses 4 units of R
5
and
execution time of this critical section is 3
What do you mean by [ R
1
;14 [R
4
,3; 9 [R
5
, 4 ; 3]]] ?
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Two jobs conflict with one another or have a resource conflict
, if some of the resources they require are of the same type
The jobs contend for a resource when one job requests a
resource that the other job already has
When the scheduler does not grant the resource to the job
requesting them, the job is blocked and loses the processor
It stays blocked until the scheduler grants the resource, it is
waiting for
Resource Access Control
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effect of Resource Contention
J
1
, J
2
, J
3
are three jobs whose feasible intervals are
(6,14) , (2,17] and (0,18] and their resource requirement is [
R; 2 ], [ R ; 4 ] and [ R; 4] respectively
See how resource contention delays the completion of higher
priority job
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effects
Priority Inversion
Time Anomalies
Deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control Protocol
Resource access control protocol is a set of rules that govern
When and under what conditions each request for resource is
granted
How jobs requiring resources are scheduled
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effects of Resource Contention
Resource contentions among the jobs can cause priority
inversion because the resources are allocated to the jobs on a
nonpreemptive basis
When priority inversion occurs, timing anomalies invariably
follow
Without good resource access control, the duration of a
priority inversion can be unbounded
nonpreemptivity of resource allocation can also lead to
deadlocks
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Deadlock
For example, there are two jobs which require resources X
and Y. The jobs are in deadlock when one of them holds X and
requests Y, while the other holds Y and requests for X
The condition that allow this circular wait of jobs for each
other is deadlock
No resource access control protocol can eliminate the priority
inversion and anomalous behavior caused by resource
contention
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control Protocols
Nonpreemptive critical section
Priority inheritance protocol
Priority ceiling protocol
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Assumptions
We assume that no other job suspends itself
Every job is preemptible on the processor
Job J
i
has distinct priority
i
Priorities are always assigned by integers, the smaller the
integer, the higher the priority
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Wait-For Graph
A path in a wait-for graph from a higher-priority job to a lower
priority job represents the fact that the farmer is directly
blocked by the latter
A cyclic path indicates a deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Bipartite Graph
Used to specify resource requirements of a system
There is a vertex for every job and every resource
Each vertex is named by the name of the job or resource it
represents
The integer next to each resource vertex R
i
gives v
i
of units of
the resource
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
NPCS Protocol
The way to control access of resources is to schedule all
critical sections on the processor nonpreemptively
NPCS is called so because no job is ever preempted when it
holds any resource deadlock can never occur
Uncontrolled priority inversion never occurs because Jh can
be blocked only if it is released when some lower priority job
is in a critical section
Once the blocking completes, all the resources are free
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking Time in NPCS
The blocking time b
i
(rc) due to resource conflict of a periodic
task T
i
in a fixed priority is equal to
b
i
(rc) = max (c
k
)
i+1 k n
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Advantages
Simplicity
The protocol does not need any prior knowledge about
resource requirement of the jobs
Simple to implement and can be used in fixed as well as
dynamic priority systems
Specially good when all the critical sections are shot and when
most of the jobs conflict with each other
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Disadvantages
Every job can be blocked by every lower-priority job that
requires some resource even when there is no resource
conflict between them
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance protocol
Used to avoid priority inversion
It requires the priority of a task gaining access to a shared
resource to dynamically inherit the priority of the highest
priority task sharing the resource, which blocks any medium
priority task
Assigned priority according to the scheduler
The current priority
l
(t) of a job J
l
may be raised to the
higher priority
h
(t) of another job J
l
This is priority inheritance
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rules of The Protocol
Scheduling Rule Ready jobs are scheduled on the processor
preemptively in a priority- driven manner
Allocation Rule When a job J request a resource R at time t
a- If R is free, it is allocated to J until J releases the
resource
b- If R is not free, the request is denied and J is
blocked
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance Rule
When the requesting job J becomes blocked, the job J
l
which
block J inherits the current priority (t) of J
The job J
l
executes at its inherited priority (t) until it releases
R
At that instant, the priority of J
l
returns to its original priority
In this case, the protocol ensures that the duration of priority
inversion is never longer than the duration of the outermost
CS each time a job is blocked
April 1, 2014
Example
Job r
i
e
i

i
Critical Section
J
1
7 3 1 [shaded;1]
J
2
5 3 2 [black;1]
J
3
4 2 3
J
4
2 6 4 [shaded 4[black
;1.5]]
J
5
0 6 5 [black;4]
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking Time in P-IP
There are two types of blocking
i- direct blocking
ii- priority-inheritance blocking
Worst-case response time for task i is
W
i
= e
i
+ b
i
+ I
i
Although P-I bounds the number of blocks a task may
experience, it does not prevent transitive blocking
Does not prevent deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Transitive Blocking
Chain of blocks
Process A is blocked by blocked process B, which is blocked by
process C
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Ceiling Protocol
Assumptions- The assigned priorities of all jobs are fixed and
the resource requirements of all jobs are known
Priority-ceiling of any resource R
i
is the highest priority of all
jobs that require R
i
, and is denoted by (R
i
)
Current ceiling priority (t) is equal to the highest priority
ceiling of the resource s that are in use at the time, if some
resources are in use
If all the resources are free at that time, the current ceiling
(t) is , a nonexisting priority level, that is lower than the
lowest priority of all jobs
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Rules of P-CP
A At its release time t, the current priority (t) of every job J is
equal to its assigned priority, the job remains at this priority
except under priority inheritance
B- Every ready job J is scheduled preemptively and in a priority
driven manner at its current priority (t)
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Allocation rules
Whenever a job J requests a resource R at time t
R is held by another job, Js request fails and J is blocked
If R is free
i If Js priority is higher than the current priority ceiling
(t), R is allocated to J
ii - If Js priority is not higher, R is allocated to J only if J is the
job holding the resources whose priority ceiling is equal to
(t), otherwise Js request is denied and J becomes blocked
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance Rule
When J becomes blocked, the job J
l
which blocks J inherits the
current priority (t) of J
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Comparison of P-IP and P-CP
P-I is greedy while P-C is not
The difference arises because of non-greedy nature of the P-c
protocol
It is possible for J to be blocked by a lower-priority job which
does not hold the requested resource
Deadlock never occur under P-CP
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Types of Blocking
Three types of blocking
A- direct blocking
B- Priority-Inheritance Blocking
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking contd
Avoidance blocking
(x) is equal to or higher than (t)
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Duration of Blocking
Whether as a cost of its ability of P-C protocol to prevent
deadlock, can cause a job to be blocked for a longer duration
than the priority-inheritance protocol
Theorem: When resource access of preemptive, priority-
driven jobs on one processor are controlled by the priority-
ceiling protocol, a job can be blocked for at most the duration
of one critical section
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Computation of Blocking Time
Example:
April 1, 2014
Computation for direct blocking
April 1, 2014
Priority-inheritance blocking
April 1, 2014
Avoidance blocking
April 1, 2014
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 9)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Resource Access Control Protocol
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Resource Access Control Protocol
Computing blocking time
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Two jobs conflict with one another or have a resource conflict
, if some of the resources they require are of the same type
The jobs contend for a resource when one job requests a
resource that the other job already has
When the scheduler does not grant the resource to the job
requesting them, the job is blocked and loses the processor
It stays blocked until the scheduler grants the resource, it is
waiting for
Resource Access Control
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effect of Resource Contention
J
1
, J
2
, J
3
are three jobs whose feasible intervals are
(6,14) , (2,17] and (0,18] and their resource requirement is [
R; 2 ], [ R ; 4 ] and [ R; 4] respectively
See how resource contention delays the completion of higher
priority job
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effects
Priority Inversion
Time Anomalies
Deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control Protocol
Resource access control protocol is a set of rules that govern
When and under what conditions each request for resource is
granted
How jobs requiring resources are scheduled
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effects of Resource Contention
Resource contentions among the jobs can cause priority
inversion because the resources are allocated to the jobs on a
nonpreemptive basis
When priority inversion occurs, timing anomalies invariably
follow
Without good resource access control, the duration of a
priority inversion can be unbounded
nonpreemptivity of resource allocation can also lead to
deadlocks
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Deadlock
For example, there are two jobs which require resources X
and Y. The jobs are in deadlock when one of them holds X and
requests Y, while the other holds Y and requests for X
The condition that allow this circular wait of jobs for each
other is deadlock
No resource access control protocol can eliminate the priority
inversion and anomalous behavior caused by resource
contention
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Resource Access Control Protocols
Nonpreemptive critical section
Priority inheritance protocol
Priority ceiling protocol
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Assumptions
We assume that no other job suspends itself
Every job is preemptible on the processor
Job J
i
has distinct priority
i
Priorities are always assigned by integers, the smaller the
integer, the higher the priority
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Wait-For Graph
A path in a wait-for graph from a higher-priority job to a lower
priority job represents the fact that the farmer is directly
blocked by the latter
A cyclic path indicates a deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Bipartite Graph
Used to specify resource requirements of a system
There is a vertex for every job and every resource
Each vertex is named by the name of the job or resource it
represents
The integer next to each resource vertex R
i
gives v
i
of units of
the resource
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
NPCS Protocol
The way to control access of resources is to schedule all
critical sections on the processor nonpreemptively
NPCS is called so because no job is ever preempted when it
holds any resource deadlock can never occur
Uncontrolled priority inversion never occurs because Jh can
be blocked only if it is released when some lower priority job
is in a critical section
Once the blocking completes, all the resources are free
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking Time in NPCS
The blocking time b
i
(rc) due to resource conflict of a periodic
task T
i
in a fixed priority is equal to
b
i
(rc) = max (c
k
)
i+1 k n
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Advantages
Simplicity
The protocol does not need any prior knowledge about
resource requirement of the jobs
Simple to implement and can be used in fixed as well as
dynamic priority systems
Specially good when all the critical sections are shot and when
most of the jobs conflict with each other
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Disadvantages
Every job can be blocked by every lower-priority job that
requires some resource even when there is no resource
conflict between them
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance protocol
Used to avoid priority inversion
It requires the priority of a task gaining access to a shared
resource to dynamically inherit the priority of the highest
priority task sharing the resource, which blocks any medium
priority task
Assigned priority according to the scheduler
The current priority
l
(t) of a job J
l
may be raised to the
higher priority
h
(t) of another job J
l
This is priority inheritance
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rules of The Protocol
Scheduling Rule Ready jobs are scheduled on the processor
preemptively in a priority- driven manner
Allocation Rule When a job J request a resource R at time t
a- If R is free, it is allocated to J until J releases the
resource
b- If R is not free, the request is denied and J is
blocked
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance Rule
When the requesting job J becomes blocked, the job J
l
which
block J inherits the current priority (t) of J
The job J
l
executes at its inherited priority (t) until it releases
R
At that instant, the priority of J
l
returns to its original priority
In this case, the protocol ensures that the duration of priority
inversion is never longer than the duration of the outermost
CS each time a job is blocked
April 1, 2014
Example
Job r
i
e
i

i
Critical Section
J
1
7 3 1 [shaded;1]
J
2
5 3 2 [black;1]
J
3
4 2 3
J
4
2 6 4 [shaded 4[black
;1.5]]
J
5
0 6 5 [black;4]
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking Time in P-IP
There are two types of blocking
i- direct blocking
ii- priority-inheritance blocking
Worst-case response time for task i is
W
i
= e
i
+ b
i
+ I
i
Although P-I bounds the number of blocks a task may
experience, it does not prevent transitive blocking
Does not prevent deadlock
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Transitive Blocking
Chain of blocks
Process A is blocked by blocked process B, which is blocked by
process C
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Ceiling Protocol
Assumptions- The assigned priorities of all jobs are fixed and
the resource requirements of all jobs are known
Priority-ceiling of any resource R
i
is the highest priority of all
jobs that require R
i
, and is denoted by (R
i
)
Current ceiling priority (t) is equal to the highest priority
ceiling of the resource s that are in use at the time, if some
resources are in use
If all the resources are free at that time, the current ceiling
(t) is , a nonexisting priority level, that is lower than the
lowest priority of all jobs
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Rules of P-CP
A At its release time t, the current priority (t) of every job J is
equal to its assigned priority, the job remains at this priority
except under priority inheritance
B- Every ready job J is scheduled preemptively and in a priority
driven manner at its current priority (t)
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Allocation rules
Whenever a job J requests a resource R at time t
R is held by another job, Js request fails and J is blocked
If R is free
i If Js priority is higher than the current priority ceiling
(t), R is allocated to J
ii - If Js priority is not higher, R is allocated to J only if J is the
job holding the resources whose priority ceiling is equal to
(t), otherwise Js request is denied and J becomes blocked
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Inheritance Rule
When J becomes blocked, the job J
l
which blocks J inherits the
current priority (t) of J
April 1, 2014
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Comparison of P-IP and P-CP
P-I is greedy while P-C is not
The difference arises because of non-greedy nature of the P-c
protocol
It is possible for J to be blocked by a lower-priority job which
does not hold the requested resource
Deadlock never occur under P-CP
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Types of Blocking
Three types of blocking
A- direct blocking
B- Priority-Inheritance Blocking
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking contd
Avoidance blocking
(x) is equal to or higher than (t)
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Duration of Blocking
Whether as a cost of its ability of P-C protocol to prevent
deadlock, can cause a job to be blocked for a longer duration
than the priority-inheritance protocol
Theorem: When resource access of preemptive, priority-
driven jobs on one processor are controlled by the priority-
ceiling protocol, a job can be blocked for at most the duration
of one critical section
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Computation of Blocking Time
Example:
April 1, 2014
Computation for direct blocking
April 1, 2014
Priority-inheritance blocking
April 1, 2014
Avoidance blocking
April 1, 2014
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 10)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Resource Access Control Protocol
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Resource Access Control Protocol
Computing blocking time
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Types of Blocking
Three types of blocking
A- direct blocking
B- Priority-Inheritance Blocking
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Blocking contd
Avoidance blocking
(x) is equal to or higher than (t)
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Duration of Blocking
Whether as a cost of its ability of P-C protocol to prevent
deadlock, can cause a job to be blocked for a longer duration
than the priority-inheritance protocol
Theorem: When resource access of preemptive, priority-
driven jobs on one processor are controlled by the priority-
ceiling protocol, a job can be blocked for at most the duration
of one critical section
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Computation of Blocking Time
Example:
April 1, 2014
Computation for direct blocking
April 1, 2014
Priority-inheritance blocking
April 1, 2014
Avoidance blocking
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Q . A set of 10 jobs is given below with their temporal
parameters ( r,e,d) andprecedence relation among the jobs.
J
1
(0,2,12) ; J
2
(11,2,25); J
3
(5,2,20); J
4
(0,2,7); J
5
(6,2,15);
J
6
(0,4,20) ; J
7
(6,4,25); J
8
(10,4,20); J
9
(8,4,30); J
10
(0,2,25)
J
1
J
2
; J
1
J
4
; J
2
J
3
; J
4
J
5
; J
3
J
10
;
J
6
J
7
; J
6
J
8
; J
7
J
9
; J
8
J
9
; J
9
J
10
;
a) Draw the precedence graph.
b) Draw an EDF schedule on a single processor
c) Now determine their effective release times and
effective deadlines and draw a feasible EDF schedule
on a single processor with these parameters
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Question on Clock-Driven Scheduling
Three tasks (15,5,14); (20,2,26) ; (22,3)
Aperiodic jobs (16,3); (40,4); (46,3)
How much maximum percentage reduction in average
response time is possible?
April 1, 2014
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Question on schedulability
Use time demand analysis to show that the set of
periodic tasks (1,5,1); (1,8,2) and (14,4) is
schedulable according to the RMA.
If we make first 2 units of T
3
nonpreemptible, find
whether the system is schedulable or not.
Assume that the three tasks are in phase, find out
the maximum value of context switch CS, such that
the system remain schedulable.
April 1, 2014
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 11)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems : Scheduling
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
April 1, 2014
Swati Keskar
1-401
Scheduling Aperiodic Jobs
Scheduling Sporadic Jobs
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling Aperiodic and
Sporadic Jobs
We assume that the operating system maintains the priority
queue.
The ready periodic tasks are placed in the periodic task queue
according to their priority assigned by any one of the
algorithms
Each accepted sporadic job is assigned a priority and is placed
in priority queue
Each newly arrived aperiodic job is placed in the aperiodic job
queue
April 1, 2014 402 Swati Keskar
April 1, 2014 403 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Alternative approaches
Background execution
Polled execution
Interrupt driven execution
April 1, 2014 404 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Background Execution
Aperiodic jobs are scheduled and executed only at times
when there is no periodic or sporadic job ready for execution
Always produces correct schedules
Simple to implement
Drawback is that the execution of aperiodic jobs is delayed
and response time is prolonged
April 1, 2014 405 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Interrupt Driven Execution
Whenever an aperiodic job arrives, the execution of periodic
tasks are interrupted and the aperiodic job is executed.
In this case, aperiodic job may have the shortest possible
response time
But it has main disadvantage that if aperiodic job always
execute as soon as possible ,periodic task may miss some
deadlines
April 1, 2014 406 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Polling Server
A poller or polling server is a periodic task whose polling
period is p
s
and e
s
is its execution time
The poller is ready for execution periodically and is scheduled
together with the periodic tasks in the system
When it executes, it examines the aperiodic job queue
If the queue is nonempty, the poller executes the job at the
head of the queue
Server suspends its execution when either budget is
exhausted or when the queue becomes empty
April 1, 2014 407 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Polling Server
The main disadvantage of poling server is that if at the
beginning of a polling period the poller finds the aperiodic job
queue empty , it suspends immediately
It will not be ready for execution and able to examine the
queue again until the next polling period
April 1, 2014 408 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Periodic Server
The periodic server is nothing but a periodic task created for
the purpose of executing aperiodic jobs
It has period p
s
and execution time e
s
which is called as
execution budget or simply budget
The ratio u
s
= e
s
/p
s
is the size of the server
At the beginning of each period, the budget of the poller is set
to e
s
i.e. its budget is replenished
April 1, 2014 409 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Periodic Server
The periodic server is backlogged whenever the aperiodic job
queue is nonempty and there is at least an aperiodic job to be
executed by the server
The server is idle when the queue is empty
The server is eligible for execution only when it is backlogged
and budget
When the server is scheduled and executes aperiodic jobs, it
consumes its budget at the rate of one per unit time
The server budget becomes exhausted when the budget
becomes zero
April 1, 2014 410 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Bandwidth-preserving Servers
If we can preserve the execution budget of the poller when it
finds an empty queue and allow it to execute later in the
period if any aperiodic job arrives, we can improve the
response time of aperiodic job
Algorithms that improve the polling approach in ths manner
are called bandwidth preserving server algorithm
These are periodic servers, each type of server is defined by a
set of consumption and replenishment rules
April 1, 2014 411 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Types of bandwidth-preserving servers
Deferrable servers
Sporadic servers
Constant utilization/total bandwidth servers and weighted
fair-queuing servers
Bandwidth-preserving Servers
April 1, 2014 412 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Deferrable servers
Consumption rule: The execution budget of the server is
consumed at the rate of one per unit time whenever the
server executes
Replenishment rule : The execution budget of the server is set
to e
s
at time instants kp
k
for k = 0,1,2
April 1, 2014 413 Swati Keskar
April 1, 2014 414 Swati Keskar
April 1, 2014 415 Swati Keskar
April 1, 2014 416 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulability with deferrable Server
Time demand analysis can be used to determine whether all
the periodic tasks remain schedulable in the presence of a
deferrable server (highest priority)
The time demand function of the task T
i
in presence of
deferrable server is given by
April 1, 2014 417 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulable Utilization
Schedulability of a fixed-priority system in which a deferrable
server is scheduled at an arbitrary priority cannot be assured
Only exception is when the deferrable server has shortest
period in a system of n tasks and the system is scheduled rate-
monotonically
April 1, 2014 418 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Theorem for Schedulable Utilization
Consider a system of n independent, preemptible periodic
tasks whose periods satisfy the inequalities
p
s
< p
1
< p
2
< < p
n
< 2p
s
and p
n
> p
s
+ e
s
and whose relative
deadlines are equal to their respective periods.
This system is schedulable rate-monotonically with a
deferrable server (p
s
, e
s
) if their total utilization is less than or
equal to
April 1, 2014 419 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
When the servers period is arbitrary, we can use U
RM
(n) to
determine whether each periodic task T
i
is schedulable if the
periodic tasks and the server are scheduled rate-
monotonically
We can treat additional e
s
units of time as additional blocking
time of the task T
i
. T
i
is surely schedulable if
Theorem for Schedulable Utilization
April 1, 2014 420 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Schedulability with deadline-driven systems
A periodic task T
i
in a system of n independent, preemptive
periodic tasks is schedulable with a deferrable server with
period ps, execution budget es and utilization us, according to
the EDF algorithm if
April 1, 2014 421 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sporadic Servers
Improved version of deferrable servers
The consumption and replenishment rules of this server
ensure that each sporadic server with period p
s
and budget e
s
never demands more processor time than the periodic task
(p
s
,e
s
) in any time interval
We can treat the sporadic server exactly like the periodic task
when we check for the schedulability of the system
A system of periodic tasks containing a sporadic server may be
schedulable while the same system containing a deferrable
server with same parameters is not
April 1, 2014 422 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Simple Sporadic Server
Consumption rules : at any time t after t
r
ie replenishment
time, the servers budget is consumed at the rate of 1 unit per
time until the budget is exhausted when either one of the
following conditions are not true
C1 : The server is executing
C2: The server has executed since t
r
and END <t where END
is the end of the latest busy interval
April 1, 2014 423 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Replenishment Rules
Replenishment rules of Simple Fixed-Priority-Sporadic server
are
R1 : Initially when the system begins execution and each time
when the budget is replenished, the execution budget = e
s
and t
r
= the current time
R2: At the time t
f
(first instant after t
r
when server begins
execution), if END = t
f
, t
e
= max( t
r
, BEGIN). If END < t
f,
t
e
=t
f
. The next replenishment time is set at t
e
+p
s
April 1, 2014 424 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Replenishment Rules
R3 : The next replenishment occurs at the next replenishment
time, except under the following conditions
If the next replenishment time t
e
+ p
s
is earlier than t
f
, the
budget is replenished as soon as it is exhausted
If the system T becomes idle before the next replenishment
time t
e
+ p
s
, and becomes busy again at tb, the budget is
replenished at min( t
e
+p
s
, t
b
).
April 1, 2014 425 Swati Keskar
26/04/2012 Swati Keskar 426
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling of Sporadic Jobs
The scheduler performs an acceptance test on each sporadic
job upon its arrival
The acceptance tests are performed on sporadic jobs in the
EDF order
Once accepted, sporadic jobs are ordered among themselves
in the EDF order
April 1, 2014 427 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Acceptance Test
For deadline-driven system
For first sporadic job S (t,d,e), the scheduler accepts S if its
density e/(d-t) < 1-
For new sporadic jobs , the scheduler accepts the job S if
e / (d t) +
s,k
1- for all k = 1,2
April 1, 2014 428 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
For fixed-priority systems
For first sporadic job, find slack time

s,1
(t) = (d
s,1
-t)/p
s
e
s
e
s,1
0
For next sporadic jobs, the scheduler computes the slack

s,I
according to

s,i
(t) = (d
s,i
-t)/p
s
e
s
e
s,I
(e
s,k
-
s,k
) 0
Acceptance Test
April 1, 2014 429 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 12)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Real Time OS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
4/1/2014
Swati Keskar
1-432
Scheduling sporadic jobs
Real-Time Operating Systems
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sporadic Servers
Improved version of deferrable servers
The consumption and replenishment rules of this server
ensure that each sporadic server with period p
s
and budget e
s
never demands more processor time than the periodic task
(p
s
,e
s
) in any time interval
We can treat the sporadic server exactly like the periodic task
when we check for the schedulability of the system
A system of periodic tasks containing a sporadic server may be
schedulable while the same system containing a deferrable
server with same parameters is not
April 1, 2014 433 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Simple Sporadic Server
Consumption rules : at any time t after t
r
ie replenishment
time, the servers budget is consumed at the rate of 1 unit per
time until the budget is exhausted when either one of the
following conditions are not true
C1 : The server is executing
C2: The server has executed since t
r
and END <t where END
is the end of the latest busy interval
26/04/2012 434 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Replenishment Rules
Replenishment rules of Simple Fixed-Priority-Sporadic server
are
R1 : Initially when the system begins execution and each time
when the budget is replenished, the execution budget = e
s
and t
r
= the current time
R2: At the time t
f
(first instant after t
r
when server begins
execution), if END = t
f
, t
e
= max( t
r
, BEGIN). If END < t
f,
t
e
=t
f
. The next replenishment time is set at t
e
+p
s
26/04/2012 435 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Replenishment Rules
R3 : The next replenishment occurs at the next replenishment
time, except under the following conditions
If the next replenishment time t
e
+ p
s
is earlier than t
f
, the
budget is replenished as soon as it is exhausted
If the system T becomes idle before the next replenishment
time t
e
+ p
s
, and becomes busy again at tb, the budget is
replenished at min( t
e
+p
s
, t
b
).
26/04/2012 436 Swati Keskar
26/04/2012 Swati Keskar 437
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling of Sporadic Jobs
The scheduler performs an acceptance test on each sporadic
job upon its arrival
The acceptance tests are performed on sporadic jobs in the
EDF order
Once accepted, sporadic jobs are ordered among themselves
in the EDF order
April 1, 2014 438 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Acceptance Test
For deadline-driven system
For first sporadic job S (t,d,e), the scheduler accepts S if its
density e/(d-t) < 1-
For new sporadic jobs , the scheduler accepts the job S if
e / (d t) +
s,k
1- for all k = 1,2
April 1, 2014 439 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
For fixed-priority systems
For first sporadic job, find slack time

s,1
(t) = (d
s,1
-t)/p
s
e
s
e
s,1
0
For next sporadic jobs, the scheduler computes the slack

s,I
according to

s,i
(t) = (d
s,i
-t)/p
s
e
s
e
s,I
(e
s,k
-
s,k
) 0
Acceptance Test
April 1, 2014 440 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 441
Computer Software
Computer software has two main categories
Application software: Consists of the programs for performing
tasks particular to the machines utilization
System software:
More transparent, less noticed
Provides a general programming environment in which
programmers can create specific applications to suit their
needs
This environment provides new functions that are not
available at the hardware level
Performs tasks related to executing the application program
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 442
Operating system (OS)
An operating system is a collection of programs that acts as an
interface between a user of a computer and the computer
hardware
Purpose of an OS is to provide an environment in which a user
may execute the programs
OS is resource manager: main resources are computer
hardware such as processor, storage, I/O devices,
communication devices and data
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 443
Functions of OS
Some of the functions of OS are:
Implementing the user interfaces
Sharing hardware among users
Allowing users to share data among themselves
Preventing users from interfering with one another
Scheduling resources among users
Facilitating input/output
Recovering from errors etc
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 444
Types of OSs
Batch processing operating system
Time sharing operating system
Real-Time operating system
Multiprogramming operating system
Multiprocessing systems
Networking operating system
Distributed operating system
Operating systems for embedded devices
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 445
Some examples
DOS
UNIX
WINDOWS
MACINTOSH
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 446
Comparison of GPOS and RPOS
Functional similarities between GPOS and RTOS are
Some level of multitasking
Software and hardware resource management
Provision of underlying OS services to applications
Abstracting the hardware from the software application
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 447
Comparison contd
Key functional differences are
Better reliability in embedded application contexts
The ability to scale up and 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
Better portability to different hardware platforms
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 448
Real-Time Operating Systems
These are designed to service those applications where the
response time is important to prevent error,
misrepresentation or even disaster
A very important part of an RTOS is managing the resources of
the computer so that a particular operation executes in
precisely the same amount of time every time it occurs
An RTOS typically has very little user-interface capability and
no end-user utilities
Used to control machinery, scientific instruments and
industrial systems
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 449
Characteristics of RTOS
Reliability
Predictability
Performance
Compactness
scalability
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 450
Examples of RTOS
RTLinux
WinCE
VxWorks
QNX/Neutrino
LynxOS
pSOSystem
VRTX
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 451
RTOS Kernel
In some applications, RTOS comprises only a kernel, which is
core supervisory software that provides minimal logic,
scheduling and resource management algorithms
In other applications, RTOS can be a combination of various
modules such as kernel, a file system, networking protocol
stacks and other components required for a particular
application
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Requirements
4/1/2014 Swati Keskar 452
Thread priorities can be set by the client
Threads always run according to priority
Kernel must be preemptible or bounded
Interrupts must be bounded
No virtual memory
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 453
Kernel contd
Most RTS contain the following components
Scheduler
Objects
Services
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 454
Kernel
Scheduler
Objects
Services
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 455
Scheduler
Scheduler is at the heart of every kernel
It provides the algorithms needed to determine which task
executes when
It consists of
Schedulable entities
Multitasking
Context Switching
Dispatcher
Scheduling Algorithms
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 456
Schedulable Entities
It is a kernel object that can compete for execution time on a
system, based on a predefined scheduling algorithm
Examples are tasks and processes
Task is an independent thread of execution that contains a
sequence of independently schedulable instructions
Processes are similar to tasks in the sense that they can
independently compete for CPU time
Difference is that processes provide better memory
protection features at the expense of overheads
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 457
Multitasking
Multitasking is the ability of the operating system to handle
multiple activities within set deadlines
A real-time kernel may have multiple tasks that it has to
schedule to run
Tasks follow the kernels scheduling algorithms
As the number of tasks to schedule increases, so do CPU
performance requirements
This is due to increased switching between the contexts of the
different threads of execution
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 458
The context Switch
Each task has its own context
A context switch occurs when the scheduler switches from
one task to another
Every time a new task is created , kernel also creates and
maintains an associated task control block (TCB).
TCBs are system data structures that the kernel uses to
maintain the task-specific information.
TCBs contain everything a kernel needs to know about a
particular task
When a task is running, its contexts are highly dynamic which
is stored in TCB also context switch
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 459
Dispatcher
The part of the scheduler that performs context switching and
changes the flow of execution
Any time an RTOS is running, the flow of execution, also flow
of control passes through task, kernel or an ISR
When a task or ISR makes a system call, the flow of control
passes to the kernel to execute one of the system routines
provided by the kernel
Then dispatcher is responsible for passing control to one of
the users application
Scheduling algorithm of the scheduler determines which task
executes next, dispatcher does the actual work
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 460
Scheduling Algorithm
Determines which task runs when
Two commonly used algorithms are
-Preemptive priority based algorithm
-Round-robin algorithm
RT kernel generally support 256 priority levels
Each task is assigned some priority depending on algorithm
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 461
Scheduling Algorithm contd
Although tasks are assigned a priority when they are created,
a tasks priority can be changed dynamically
This allows an embedded application the flexibility to adjust
to external events as they occur, creating a true real-time
responsive system
Misuse of this capability lead to priority inversion, deadlock
and sometimes system failure
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 462
Objects and Services
Objects are special constructs that are the building blocks for
application development for real-time systems
Examples are tasks, semaphores, message queues etc
Kernels provide services that help developers create
application
These services are sets of API calls that can be used to
perform operations on kernel objects
Also can be used in general to facilitate timer management,
interrupt handling, device I/O and memory management
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 463
Tasks
Real-rime applications must be designed for concurrency
which generally handle multiple inputs and outputs within
time constraints
Concurrent design requires developers to decompose an
application into small, schedulable and sequential program
units
Most RT kernels provide task objects and task management
services to achieve concurrency
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 464
Task Definition
A task is an independent thread of execution that can
compete with other concurrent tasks for processor execution
time
A task is schedulable if it is able to complete execution on
time as per the defined algorithm
A task is defined by its distinct set of parameters and
supporting data structures
On creation, each task has an associated name, unique ID, a
priority, a task control block, a stack and task routine
4/1/2014 Swati Keskar 465
A typical TCB
Program counter
Task status
Task ID
Content of register 0
Pointer to next TCB
.
.
.
Contents of register n
Other context
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 466
System Tasks
When kernel starts, it creates its own tasks and allocates the
appropriate priority to each from a set of reserved priority
levels
Initialization or startup tasks
Idle tasks: Uses processor idle cycles when no other activity is
present
Logging tasks: logs system messages
Debug agent tasks: allows debugging with a host debugger
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 467
Task states
At any time each task exists in one of a smaller number of
states
Dormant
Ready
Running or executing
Blocked or suspended
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 468
Task Scheduling
Operations for task scheduling include
Suspend
Resume
Delay
Restart
Get priority
Set priority
Preemption lock
Preemption unlock
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 469
Task Information
Task information is useful for debugging and monitoring
Important are Get ID ,Get TCB
In blocking condition
A semaphore token for which a task is waiting
A message, on which the task is waiting
A time delay imposed on the task expires
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 470
Typical Task Operations
Creating and deleting tasks
Controlling task scheduling
Obtaining task information
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 471
Intertask communication
The communication of data between processes and
synchronization of the tasks
Multiple concurrent threads of execution within an
application must be able to synchronize their execution and
coordinate mutually exclusive access to shared resources
For example semaphores are effective for protecting critical
sections
Mailboxes can be used to implement efficient semaphores
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 472
Data buffers
Specially useful when one task is creating data at higher speed
but other task is not consuming it at the same speed
To cope up this difference , the processor fills a storage area
called buffer with such data
Buffer can be a stack or other data structure
Selection of the appropriate size of buffer is critical
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 473
Time-relative Buffering
Common use of global variables is in double-buffering or ping-
pong buffering
This technique is used when time-relative data need to be
transferred between cycles of different rates
Also when a full set of data is needed by one process but can
be supplied slowly by another process
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 474
Ring Buffers
A special data structure, also called circular queue
Works on first-in-first-out basis
Easy to manage
Simultaneous input and output to the list are achieved by
keeping head and tail pointers
Data are loaded at the tail and read from the head
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 475
Mailboxes
Also called message exchanges are an intertask
communication device
Can also be used like semaphores
A mailbox is a mutually agreed upon memory location that
two or more tasks can use to pass data
Scheduler allows task to write to the location via a post
operation or read via pend operation
Pend operation is different from polling by the fact that
pending task is suspended while waiting for data to appear
Busy waiting is eliminated
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 476
Message Queues
Message queues are buffer-like kernel objects used for data
communication and synchronization between two tasks or
between an ISR and a task
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 and one or more
task-waiting lists
The beginning and end of message queues are called head
and tail respectively
Each buffer contain one message called message queue
element
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 477
Message Queue contd
Message queues are empty when created, full when all
message queue elements contain messages and nonempty
when some elements are available
Sending message to full message queue can cause the sending
task to block, similarly reading an empty queue also cause
blocking
Task waiting list associated with it can release task in either
FIFO basis or priority basis
The data itself can either be sent as the message or as a
pointer to the data
Common message operations include creating and deleting
queue, obtaining information and sending, receiving
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 478
Semaphores
This is a kernel object that one or more threads of execution
can acquire or release for the purpose of synchronization or
mutual execution
When created, kernel assigns SCB, a unique ID, a value and a
task-waiting list
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 479
Semaphore contd
Semaphore is like a key that allows a task to carry out some
operation or to access a resource
If a task can acquire semaphore, it can carry out the intended
operation or access the resource
A single semaphore can be acquired a finite number of times
When a semaphores limit is reached, it can no longer be
acquired until some task releases the semaphore
The kernel tracks the number of times a semaphore has been
acquired or released such as token
As a task acquires the semaphore, the token count is
decremented and vice-a-versa
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 480
Types of Semaphores
Some types of semaphores are
Binary semaphore
Counting semaphores
Mutual-exclusion semaphores or mutex
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 481
Binary Semaphores
A binary semaphore can have a value of either 0 or 1
When 0,the semaphore is unavailable (or empty)
When 1, the semaphore is available (or full)
Binary semaphores are treated as global resource
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 482
State diagram
available
unavailable
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 483
Counting Semaphores
A counting semaphore uses a count to allow it to be acquired
or released multiple times
When creating a semaphore, a count is assigned as a
semaphore token
One or more tasks continue to acquire a token from the
counting semaphore until no tokens are left
These are also treated as global resources that can be shared
by any task
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 484
State Diagram
available unavailable
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 485
Mutex Semaphore
A mutual exclusion semaphore is special binary semaphore that supports
--Ownership
--Recursive locking
--Task deletion safety
--priority inversion avoidance
--One or more protocols for avoiding problems inherent
to mutual exclusion
The states of a mutex are locked or unlocked
Initially it is created in unlocked state and can be acquired by a task
After being acquired, mutex moves into lock state and vice-a-versa
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 486
Mutex contd
Ownership of a mutex is gained when a task first locks the
mutex by acquiring it
When a task owns the mutex, it is not possible for any other
task to lock or unlock
Recursive locking allows the task that owns the mutex to
acquire it multiple times in the locked state and is called
recursive mutex
Recursive mutex is most useful when a task requiring
exclusive access to a shared resource calls one or more
routines that also require access to same resource
A lock count track is required to keep by kernel
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 487
Mutex contd
Some mutex implementations also have built-in task deletion
safety
Enabling this capability within a mutex ensures that while a
task owns the mutex, the task cannot be deleted
Enabling certain protocols that are typically built into mutexes
can help avoid priority inversion
Two commonly used protocols are
--priority inheritance protocol
--ceiling priority protocol
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 488
Typical Semaphore Operations
Typical operations that a developer wants to perform are
Creating and deleting semaphores
Acquiring and releasing semaphores
Clearing a semaphores task-waiting list
Getting semaphore information
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 489
Acquiring a semaphore
The operations for acquiring and releasing may have different
names such as take/give, pend/post and lock/unlock
A task typically make a request to acquire a semaphore in one of
the following way
Wait forever: task remains blocked until it is able to acquire
Wait with a timeout: task remains blocked until it acquire
semaphore or until a set interval of time passes
Do not wait: If semaphore is not available on request, task
does not block
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 490
Event Flags and Signals
Event flags allow for the specification of an event that causes
the setting of some flag
A second process is designed to react to this flag
Raising the flag transfers flow-of-control to the operating
system which can then invoke the appropriate handler
Tasks waiting for occurrence of an event are blocked
A signal is a type of software interrupt handler that is used to
react to an exception indicated by the raise operation
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 13)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Real Time OS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
4/1/2014
Swati Keskar
1-493
Real-Time Operating Systems
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 494
Characteristics of RTOS
Reliability
Predictability
Performance
Compactness
scalability
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 495
Examples of RTOS
RTLinux
WinCE
VxWorks
QNX/Neutrino
LynxOS
pSOSystem
VRTX
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 496
RTOS Kernel
In some applications, RTOS comprises only a kernel, which is
core supervisory software that provides minimal logic,
scheduling and resource management algorithms
In other applications, RTOS can be a combination of various
modules such as kernel, a file system, networking protocol
stacks and other components required for a particular
application
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Requirements
4/1/2014 Swati Keskar 497
Thread priorities can be set by the client
Threads always run according to priority
Kernel must be preemptible or bounded
Interrupts must be bounded
No virtual memory
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 498
Layers of OS Functionality
A nanokernel provides simple thread management
A micokernel provides in addition, task scheduling
A kernel provides intertask communication and
synchrinization
A real-time executive is a kernel that includes memory blocks,
I/O services and complex functions
Operating System provides generalized user interface,
security, file management
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Layers of OS Functionality
User Interface Shell
File and Disk Support
Intertask communication & synchronization
Task Scheduling
Thread Management
Hardware
Users
Nanokernel
Microkernel
Kernel
Executive
Operating System
4/1/2014 499 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Essential Features of a RT-Kernel
Timer Management
Task Management
Message Management
Memory Management
4/1/2014 500 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer Management
Pause
One-shot Timers
Periodic Timers
Differential Timer Management
4/1/2014 501 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Task Management
Task Creation
Task Scheduling
Task Priorities
Task Deletion (optional)
4/1/2014 502 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Message Management
Message Queuing
Variable Size Messages
Wait on a Message
Time wait on a message
Peeking
Message priorities, identify, throttling
4/1/2014 503 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Memory Management
High speed deterministic memory management
Fixed block memory management is preferred
4/1/2014 504 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Kernel
Most RTS contain the following components
Scheduler
Objects
Services
4/1/2014 505 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 506
Kernel
Scheduler
Objects
Services
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 507
Scheduler
Scheduler is at the heart of every kernel
It provides the algorithms needed to determine which task
executes when
It consists of
Schedulable entities
Multitasking
Context Switching
Dispatcher
Scheduling Algorithms
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 508
Schedulable Entities
It is a kernel object that can compete for execution time on a
system, based on a predefined scheduling algorithm
Examples are tasks and processes
Task is an independent thread of execution that contains a
sequence of independently schedulable instructions
Processes are similar to tasks in the sense that they can
independently compete for CPU time
Difference is that processes provide better memory
protection features at the expense of overheads
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 509
Multitasking
Multitasking is the ability of the operating system to handle
multiple activities within set deadlines
A real-time kernel may have multiple tasks that it has to
schedule to run
Tasks follow the kernels scheduling algorithms
As the number of tasks to schedule increases, so do CPU
performance requirements
This is due to increased switching between the contexts of the
different threads of execution
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 510
The context Switch
Each task has its own context
A context switch occurs when the scheduler switches from
one task to another
Every time a new task is created , kernel also creates and
maintains an associated task control block (TCB).
TCBs are system data structures that the kernel uses to
maintain the task-specific information.
TCBs contain everything a kernel needs to know about a
particular task
When a task is running, its contexts are highly dynamic which
is stored in TCB also context switch
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Context Switch
Lists of
Tasks
Time
Task 1
Context switch time
Task 2
4/1/2014 511 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Contexts of a Task
Contents of registers
Contents of program counter
Contents of coprocessor registers (if any)
Memory page registers
Memory mapped I/O
Special Variables
4/1/2014 512 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 513
Dispatcher
The part of the scheduler that performs context switching and
changes the flow of execution
Any time an RTOS is running, the flow of execution, also flow
of control passes through task, kernel or an ISR
When a task or ISR makes a system call, the flow of control
passes to the kernel to execute one of the system routines
provided by the kernel
Then dispatcher is responsible for passing control to one of
the users application
Scheduling algorithm of the scheduler determines which task
executes next, dispatcher does the actual work
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 514
Scheduling Algorithm
Determines which task runs when
Two commonly used algorithms are
-Preemptive priority based algorithm
-Round-robin algorithm
RT kernel generally support 256 priority levels
Each task is assigned some priority depending on algorithm
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 515
Scheduling Algorithm contd
Although tasks are assigned a priority when they are created,
a tasks priority can be changed dynamically
This allows an embedded application the flexibility to adjust
to external events as they occur, creating a true real-time
responsive system
Misuse of this capability lead to priority inversion, deadlock
and sometimes system failure
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 516
Objects and Services
Objects are special constructs that are the building blocks for
application development for real-time systems
Examples are tasks, semaphores, message queues etc
Kernels provide services that help developers create
application
These services are sets of API calls that can be used to
perform operations on kernel objects
Also can be used in general to facilitate timer management,
interrupt handling, device I/O and memory management
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Objects and Services
Objects are special constructs that are the building blocks for
application development for real-time systems
Examples are tasks, semaphores, message queues etc
Kernels provide services that help developers create
application
These services are sets of API calls that can be used to
perform operations on kernel objects
Also can be used in general to facilitate timer management,
interrupt handling, device I/O and memory management
4/1/2014 517 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Kernel strategies
Poller loop systems
Interrupt driven system
Preemptive-Priority Systems: Multitasking
Hybrid Systems
Foreground/Background Systems
Full featured RTOS
4/1/2014 518 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Polled Loop Systems
Simplest and faster real-time kernel
A single and repetitive instruction to test a flag that indicates
whether or not some event has occurred
If event has not occurred, then the polling continues
No intertask communication or scheduling needed, only a task
exists
4/1/2014 519 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Excellent for handling high-speed data channels, especially when
Events occur at widely spaced intervals
Processor is dedicated to handling the data channel
Often used inside other real-time schemes to poll a suite of
sensor data or user input
Polled Loop Systems
4/1/2014 520 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pros
Simple to write and debug
Response time easy to determine
Cons
Can fail due to burst of events
Not sufficient to handle complete systems
Waste of CPU time, especially when event being polled occurs
infrequently
Polled Loop Systems
4/1/2014 521 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Interrupt Driven Systems
Interrupt is a software or hardware signal to processor
indicates something urgent such as
-Current task wants to sleep or get I/O
-Scheduler wants to run a different task
-Sensors detect inbound hostile weapon
Real-time system can handle several interrupts in priority
fashion
Processors must check frequently , if any, stops and runs ISR
4/1/2014 522 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Interrupt Service Routine ISR
A program runs in response to an interrupt
-disable all interrupts
-runs code to service the event
-clears the interrupt flag that got it called
-reenables interrupts
-exits so processor can go back to its
current task
Should be as fast as possible
4/1/2014 523 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Foreground/Background Systems
Most common hybrid solution for embedded applications
Involve interrupt driven (foreground) and non-interrupt driven
(polled loop at background) processes
Anything not time-critical should be in background
Background is process with lowest priority
4/1/2014 524 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Foreground/Background Systems
Initialization
While TRUE do
background process
Main Program
Process 3
Process 2
Process 1
Interrupts
4/1/2014 525 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Full-featured RTOS
Expand foreground/background solution
Add, network interfaces, device drivers, complex debugging
tools
Most common choice for complex systems
Many commercial operating systems available
4/1/2014 526 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Choosing an RTOS Approach
Look at what is driving your system ie arrival pattern of data
Irregular : known but varying sequence of intervals between
events
Bursty: arbitrary sequence with bound on number of events
Bounded: minimum interarrival interval
Bounded with average rate
Unbounded: statistical prediction only
4/1/2014 527 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 528
Tasks
Real-rime applications must be designed for concurrency
which generally handle multiple inputs and outputs within
time constraints
Concurrent design requires developers to decompose an
application into small, schedulable and sequential program
units
Most RT kernels provide task objects and task management
services to achieve concurrency
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 529
Task Definition
A task is an independent thread of execution that can
compete with other concurrent tasks for processor execution
time
A task is schedulable if it is able to complete execution on
time as per the defined algorithm
A task is defined by its distinct set of parameters and
supporting data structures
On creation, each task has an associated name, unique ID, a
priority, a task control block, a stack and task routine
4/1/2014 Swati Keskar 530
A typical TCB
Program counter
Task status
Task ID
Content of register 0
Pointer to next TCB
.
.
.
Contents of register n
Other context
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 531
System Tasks
When kernel starts, it creates its own tasks and allocates the
appropriate priority to each from a set of reserved priority
levels
Initialization or startup tasks
Idle tasks: Uses processor idle cycles when no other activity is
present
Logging tasks: logs system messages
Debug agent tasks: allows debugging with a host debugger
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 532
Task states
At any time each task exists in one of a smaller number of
states
Dormant
Ready
Running or executing
Blocked or suspended
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 533
Task Scheduling
Operations for task scheduling include
Suspend
Resume
Delay
Restart
Get priority
Set priority
Preemption lock
Preemption unlock
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 534
Task Information
Task information is useful for debugging and monitoring
Important are Get ID ,Get TCB
In blocking condition
A semaphore token for which a task is waiting
A message, on which the task is waiting
A time delay imposed on the task expires
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 535
Typical Task Operations
Creating and deleting tasks
Controlling task scheduling
Obtaining task information
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 536
Intertask communication
The communication of data between processes and
synchronization of the tasks
Multiple concurrent threads of execution within an
application must be able to synchronize their execution and
coordinate mutually exclusive access to shared resources
For example semaphores are effective for protecting critical
sections
Mailboxes can be used to implement efficient semaphores
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 537
Data buffers
Specially useful when one task is creating data at higher speed
but other task is not consuming it at the same speed
To cope up this difference , the processor fills a storage area
called buffer with such data
Buffer can be a stack or other data structure
Selection of the appropriate size of buffer is critical
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 538
Time-relative Buffering
Common use of global variables is in double-buffering or ping-
pong buffering
This technique is used when time-relative data need to be
transferred between cycles of different rates
Also when a full set of data is needed by one process but can
be supplied slowly by another process
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Double-Buffering
Fill here
Empty here
Swap buffers with
Interrupts off
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 540
Ring Buffers
A special data structure, also called circular queue
Works on first-in-first-out basis
Easy to manage
Simultaneous input and output to the list are achieved by
keeping head and tail pointers
Data are loaded at the tail and read from the head
Ring Buffers
Head, empty here
Tail, fill here
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 542
Mailboxes
Also called message exchanges are an intertask
communication device
Can also be used like semaphores
A mailbox is a mutually agreed upon memory location that
two or more tasks can use to pass data
Scheduler allows task to write to the location via a post
operation or read via pend operation
Pend operation is different from polling by the fact that
pending task is suspended while waiting for data to appear
Busy waiting is eliminated
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 543
Message Queues
Message queues are buffer-like kernel objects used for data
communication and synchronization between two tasks or
between an ISR and a task
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 and one or more
task-waiting lists
The beginning and end of message queues are called head
and tail respectively
Each buffer contain one message called message queue
element
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 544
Message Queue contd
Message queues are empty when created, full when all
message queue elements contain messages and nonempty
when some elements are available
Sending message to full message queue can cause the sending
task to block, similarly reading an empty queue also cause
blocking
Task waiting list associated with it can release task in either
FIFO basis or priority basis
The data itself can either be sent as the message or as a
pointer to the data
Common message operations include creating and deleting
queue, obtaining information and sending, receiving
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 545
Semaphores
This is a kernel object that one or more threads of execution
can acquire or release for the purpose of synchronization or
mutual execution
When created, kernel assigns SCB, a unique ID, a value and a
task-waiting list
Semaphore
1
2
Task list
SCB
Value
Binary/Count
Name or ID
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 547
Semaphore contd
Semaphore is like a key that allows a task to carry out some
operation or to access a resource
If a task can acquire semaphore, it can carry out the intended
operation or access the resource
A single semaphore can be acquired a finite number of times
When a semaphores limit is reached, it can no longer be
acquired until some task releases the semaphore
The kernel tracks the number of times a semaphore has been
acquired or released such as token
As a task acquires the semaphore, the token count is
decremented and vice-a-versa
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 548
Types of Semaphores
Some types of semaphores are
Binary semaphore
Counting semaphores
Mutual-exclusion semaphores or mutex
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 549
Binary Semaphores
A binary semaphore can have a value of either 0 or 1
When 0,the semaphore is unavailable (or empty)
When 1, the semaphore is available (or full)
Binary semaphores are treated as global resource
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 550
State diagram
available
unavailable
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 551
Counting Semaphores
A counting semaphore uses a count to allow it to be acquired
or released multiple times
When creating a semaphore, a count is assigned as a
semaphore token
One or more tasks continue to acquire a token from the
counting semaphore until no tokens are left
These are also treated as global resources that can be shared
by any task
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 552
State Diagram
available unavailable
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 553
Mutex Semaphore
A mutual exclusion semaphore is special binary semaphore that supports
--Ownership
--Recursive locking
--Task deletion safety
--priority inversion avoidance
--One or more protocols for avoiding problems inherent
to mutual exclusion
The states of a mutex are locked or unlocked
Initially it is created in unlocked state and can be acquired by a task
After being acquired, mutex moves into lock state and vice-a-versa
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 554
Mutex contd
Ownership of a mutex is gained when a task first locks the
mutex by acquiring it
When a task owns the mutex, it is not possible for any other
task to lock or unlock
Recursive locking allows the task that owns the mutex to
acquire it multiple times in the locked state and is called
recursive mutex
Recursive mutex is most useful when a task requiring
exclusive access to a shared resource calls one or more
routines that also require access to same resource
A lock count track is required to keep by kernel
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 555
Mutex contd
Some mutex implementations also have built-in task deletion
safety
Enabling this capability within a mutex ensures that while a
task owns the mutex, the task cannot be deleted
Enabling certain protocols that are typically built into mutexes
can help avoid priority inversion
Two commonly used protocols are
--priority inheritance protocol
--ceiling priority protocol
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 556
Typical Semaphore Operations
Typical operations that a developer wants to perform are
Creating and deleting semaphores
Acquiring and releasing semaphores
Clearing a semaphores task-waiting list
Getting semaphore information
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 557
Acquiring a semaphore
The operations for acquiring and releasing may have different
names such as take/give, pend/post and lock/unlock
A task typically make a request to acquire a semaphore in one of
the following way
Wait forever: task remains blocked until it is able to acquire
Wait with a timeout: task remains blocked until it acquire
semaphore or until a set interval of time passes
Do not wait: If semaphore is not available on request, task
does not block
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 558
Event Flags and Signals
Event flags allow for the specification of an event that causes
the setting of some flag
A second process is designed to react to this flag
Raising the flag transfers flow-of-control to the operating
system which can then invoke the appropriate handler
Tasks waiting for occurrence of an event are blocked
A signal is a type of software interrupt handler that is used to
react to an exception indicated by the raise operation
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG 553 (Lecture 14)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Real Time OS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
4/1/2014
Swati Keskar
1-561
Intertask communication
Memory management
Timer management
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 562
Intertask communication
The communication of data between processes and
synchronization of the tasks
Multiple concurrent threads of execution within an
application must be able to synchronize their execution and
coordinate mutually exclusive access to shared resources
For example semaphores are effective for protecting critical
sections
Mailboxes can be used to implement efficient semaphores
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 563
Data buffers
Specially useful when one task is creating data at higher speed
but other task is not consuming it at the same speed
To cope up this difference , the processor fills a storage area
called buffer with such data
Buffer can be a stack or other data structure
Selection of the appropriate size of buffer is critical
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 564
Time-relative Buffering
Common use of global variables is in double-buffering or ping-
pong buffering
This technique is used when time-relative data need to be
transferred between cycles of different rates
Also when a full set of data is needed by one process but can
be supplied slowly by another process
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Double-Buffering
Fill here
Empty here
Swap buffers with
Interrupts off
4/1/2014 565 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 566
Ring Buffers
A special data structure, also called circular queue
Works on first-in-first-out basis
Easy to manage
Simultaneous input and output to the list are achieved by
keeping head and tail pointers
Data are loaded at the tail and read from the head
Ring Buffers
Head, empty here
Tail, fill here
4/1/2014 567 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 568
Mailboxes
Also called message exchanges are an intertask
communication device
Can also be used like semaphores
A mailbox is a mutually agreed upon memory location that
two or more tasks can use to pass data
Scheduler allows task to write to the location via a post
operation or read via pend operation
Pend operation is different from polling by the fact that
pending task is suspended while waiting for data to appear
Busy waiting is eliminated
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 569
Message Queues
Message queues are buffer-like kernel objects used for data
communication and synchronization between two tasks or
between an ISR and a task
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 and one or more
task-waiting lists
The beginning and end of message queues are called head
and tail respectively
Each buffer contain one message called message queue
element
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 570
Message Queue contd
Message queues are empty when created, full when all
message queue elements contain messages and nonempty
when some elements are available
Sending message to full message queue can cause the sending
task to block, similarly reading an empty queue also cause
blocking
Task waiting list associated with it can release task in either
FIFO basis or priority basis
The data itself can either be sent as the message or as a
pointer to the data
Common message operations include creating and deleting
queue, obtaining information and sending, receiving
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 571
Semaphores
This is a kernel object that one or more threads of execution
can acquire or release for the purpose of synchronization or
mutual execution
When created, kernel assigns SCB, a unique ID, a value and a
task-waiting list
Semaphore
1
2
Task list
SCB
Value
Binary/Count
Name or ID
4/1/2014 572 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 573
Semaphore contd
Semaphore is like a key that allows a task to carry out some
operation or to access a resource
If a task can acquire semaphore, it can carry out the intended
operation or access the resource
A single semaphore can be acquired a finite number of times
When a semaphores limit is reached, it can no longer be
acquired until some task releases the semaphore
The kernel tracks the number of times a semaphore has been
acquired or released such as token
As a task acquires the semaphore, the token count is
decremented and vice-a-versa
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 574
Types of Semaphores
Some types of semaphores are
Binary semaphore
Counting semaphores
Mutual-exclusion semaphores or mutex
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 575
Binary Semaphores
A binary semaphore can have a value of either 0 or 1
When 0,the semaphore is unavailable (or empty)
When 1, the semaphore is available (or full)
Binary semaphores are treated as global resource
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
State diagram
available
unavailable
Release (value=1)
Acquire (value=0)
Initial
Value=0
Initial
Value=1
4/1/2014 576 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 577
Counting Semaphores
A counting semaphore uses a count to allow it to be acquired
or released multiple times
When creating a semaphore, a count is assigned as a
semaphore token
One or more tasks continue to acquire a token from the
counting semaphore until no tokens are left
These are also treated as global resources that can be shared
by any task
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
State Diagram
available unavailable
Acquire
Count=count-1
Acquire
(count=0)
Release (count=count+1)
Release (count=1)
Initial count>0
Initial count=0
4/1/2014 578 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 579
Mutex Semaphore
A mutual exclusion semaphore is special binary semaphore that supports
--Ownership
--Recursive locking
--Task deletion safety
--priority inversion avoidance
--One or more protocols for avoiding problems inherent
to mutual exclusion
The states of a mutex are locked or unlocked
Initially it is created in unlocked state and can be acquired by a task
After being acquired, mutex moves into lock state and vice-a-versa
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 580
Mutex contd
Ownership of a mutex is gained when a task first locks the
mutex by acquiring it
When a task owns the mutex, it is not possible for any other
task to lock or unlock
Recursive locking allows the task that owns the mutex to
acquire it multiple times in the locked state and is called
recursive mutex
Recursive mutex is most useful when a task requiring
exclusive access to a shared resource calls one or more
routines that also require access to same resource
A lock count track is required to keep by kernel
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 581
Mutex contd
Some mutex implementations also have built-in task deletion
safety
Enabling this capability within a mutex ensures that while a
task owns the mutex, the task cannot be deleted
Enabling certain protocols that are typically built into mutexes
can help avoid priority inversion
Two commonly used protocols are
--priority inheritance protocol
--ceiling priority protocol
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 582
Typical Semaphore Operations
Typical operations that a developer wants to perform are
Creating and deleting semaphores
Acquiring and releasing semaphores
Clearing a semaphores task-waiting list
Getting semaphore information
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 583
Acquiring a semaphore
The operations for acquiring and releasing may have different
names such as take/give, pend/post and lock/unlock
A task typically make a request to acquire a semaphore in one of
the following way
Wait forever: task remains blocked until it is able to acquire
Wait with a timeout: task remains blocked until it acquire
semaphore or until a set interval of time passes
Do not wait: If semaphore is not available on request, task
does not block
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
RT Memory Management
Dynamic memory allocation is main concern
Important in terms of both the use of on-demand memory by
application tasks and the requirements of the OS
It is necessary but leads to nondeterminism
Stacks are used in systems
Task-control block is used in commercial executive
4/1/2014 584 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dangerous Allocation
Leads to nondeterminism
It can destroy event determinism for exa:
--stack overflowing
It can destroy temporal determinism by entering a deadlock
situation
Need to avoid it and reduce the overheads due to memory
allocation
4/1/2014 585 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Stack Management
In a multitasking system, context for each task is to be saved
and restored in order to switch processes
This is done by run-time stacks or the task control block
Run-time stack works best for interrupt-driven systems
TCB model works best with full-featured RTOS
4/1/2014 586 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Task-Control Block Model
A list of task-control blocks is kept
This list can be either fixed or dynamic
4/1/2014 587 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fixed Case
Number of tasks n is fixed so n task-control blocks are
allocated at system generation time, all in dormant
state
As the task is created, the TCB enters into the read
state
After deciding priority or after slicing , the task is
moved to the execution state
If a task is to be deleted, that tcb is simply put to the
dormant state
No real-time memory management is necessary
4/1/2014 588 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dynamic Case
The task-control blocks are added to a dynamic data structure
such as linked list when task is created
The tasks are in suspended state upon creation and enter the
ready state via OS
Execute state start depending on priority or time-slicing
When a task is to deleted, its TCB is removed from linked list
Its heap memory allocation is now at available state
Here RT management consists of managing the heap needed
to supply the TCB
4/1/2014 589 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Run-Time Stack management
To handle the run-time saving and restoring of context, two
simple routines are used save and restore
Save is called by an interrupt handler to save the current
context of the machine
Restore routine is to be called just before interrupts are
enabled and before returning from the interrupt handler
Some machines allow block save and block restore
instructions for n general registers
4/1/2014 590 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Stack management
Run-time stack is not suitable for round-robin systems
In such cases ring buffers can be used to save the context
Context is saved from tail and restored from head
The maximum size of the run-time stack needs to be known a
priory
If not a catastrophic memory allocation can happen and the
system will fail to satisfy event determinism
4/1/2014 591 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Multiple stacks
Single run-time stack is not sufficient to accommodate several
processes
A multiple stack scheme uses a single run-time stack and
several application tasks
Its advantages are
It permits tasks to interrupt themselves
The system can be written in a language that supports
reentrancy and recursion
4/1/2014 592 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Multiple Stack
TCB1
Pointer to run-time stack
Context Stack
Process 1 Process 2 Process 3
stack
stack stack
4/1/2014 593 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dynamic Allocation
Used to satisfy individual task requirements for
memory
Accomplished by using a data structure such as heap
In C memory allocation calls are implemented through
library calls to the operating systems
Compiler dependent
Main interest is dynamic memory allocation for
process code in memory and that w.r.t. real-time
systems
We consider when there are two or more programs
reside in main memory
4/1/2014 594 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Swapping
Simplest scheme
The OS is always memory resident and one process can co-
reside in the user space which is not required by OS
When a second process needs to run, the first process is
suspended and swapped along with its context, to a
secondary storage device
The second process is then loaded in the user space and
initiated by dispatcher
Context switch overhead and secondary memory access time
are main concerns
4/1/2014 595 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Overlays
This technique allows a single program to be larger
than the allowable user space
Program is broken up into dependent code and data
sections called overlays, which can fit into available
memory
Special program code is needed that permits new
overlays to be swapped into memory
Not suitable for RTS because the overlays must be
swapped in secondary memory
Swap or overlay manager is required
4/1/2014 596 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
MFT
MFT:- Multiprogramming with a fixed number of fixed number
of tasks
This allows more than one process to be memory resident at
one time
This is achieved by dividing the space into a number of fixed-
size partitions
Useful when the number of tasks to be executed is known and
fixed
Partition swapping to disk can occur when a task is preempted
4/1/2014 597 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Problems with MFT
Memory space is to be externally fragmented when
memory requests can not be satisfied because a
contiguous block of requested size does not exist
Internal fragmentation occurs when size of the
partition is more and request is for smaller size,
memory remain unused
Solution is to have partitions of several sizes
Overhead associated with their correction are more
4/1/2014 598 Swati Keskar
MFT
1 MB
4/1/2014 599 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Context
Not desired for Real-Time system operating because
It uses memory inefficiently
Overheads associated with fitting a process to
available memory and disk swapping are more
Can be efficiently used if memory can be divided into
regions in which each region contains a collection of
different-sized, fixed size partitions
4/1/2014 600 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
MVT
MVT:- Multiprogramming with a variable number of tasks
Memory allocated in amount is not fixed but is determined by
the requirements of the process to be loaded in the memory
This technique is useful when number of tasks is unknown or
varies
Little or no internal fragmentation can occur
External fragmentation still occur because of the dynamic
nature and memory is allocated to a process in contiguously
4/1/2014 601 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Compaction Technique
External fragmentation can be minimized by compressing
fragmented memory so that it is no longer fragmented, this
technique is called compaction
Compaction is CPU-intensive process and can not be used in
hard real-time systems
Also interrupts are disabled while memory is being reshuffled
Context switch overhead is much higher than in simpler
schemes
4/1/2014 602 Swati Keskar
Compaction Technique
4/1/2014 603 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Demand Paging
Program segments are permitted to be loaded in
memory as they are requested in fixed size called
pages or page frames
This eliminates external fragmentation
Program code that is not held in main memory is
swapped to secondary storage
Paging is advantageous because it allows
nonconsecutive references via a page table
Also can be used in conjunction with bank switching
hardware to extend the virtual address space
4/1/2014 604 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Demand Paging
Pointers are used to access the desired page
These pointers represent memory-mapped locations to map
the desired memory bank
Address needs to be calculated
Paging can leads to very high paging activity called thrashing,
internal fragmentation and deadlock
4/1/2014 605 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Paging summary
Most efficient when supported by appropriate
hardware
Allows multitasking and extension of address space
A page fault occurs if the requested page is not in main
memory and causes interrupt
Hardware registers used to page frame translation add
additional overhead when doing context switching
If hardware mapping page is not used, additional
overheads for address calculation
In time critical real-time systems we cannot afford the
overheads by these methods
4/1/2014 606 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Working Sets
Working sets are based on the model of locality-of-reference
Most of the instructions in a recently executed program are
localized to a small number of instructions
However the locality-of-reference is altered when interrupts,
procedure calls etc
Idea is that a set of local code windows is maintained in cache
then one of the windows is replaced by another
Performance is based on the size of the working set window
and number of windows in working set
4/1/2014 607 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Garbage Collection
Garbage is that memory that has been allocated but is no
longer being used by a task
Garbage can accumulate when tasks terminate abnormally
without releasing memory resource
Garbage collection algorithms have unpredictable
performance
Tag all memory from the heap which is pointed by a variable
and then reclaim all nontagged memory for the heap
Loss of determinism due to unknown amount of garbage and
tagging time of data structure
4/1/2014 608 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Garbage collection
Loss of determinism due to unknown amount of garbage
Tagging time of data structure
Another technique to build a heap or table of memory blocks
along an associated process ID for the owner of the block
This data structure periodically checks whether memory is
allocated to a process that no longer exists
Overheads are more
4/1/2014 609 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Stack vs Heap Allocation
When a program is loaded into the memory, it is organized into
three areas of memory called segments
Text (Code) segment
Stack segment
Heap segment
The text segment is where the compiled code of the program
resides
It is machine language representation of the program steps to
be carried out
4/1/2014 610 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Stack vs Heap
Other two areas are those where storage may be allocated by
the compiler for data storage
In stack, new storage is allocated and deallocated at only one
end called the top of the stack
Memory allocation in this area contain garbage values left
over from previous usage
Heap segment provides more stable storage of data for a
program
Memory allocated in the heap remain existed for the duration
of a program, so need not contain garbage
4/1/2014 611 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
I/O Subsystems
Port-mapped I/O
Memory-mapped I/O
DMA
I/O Device hardware
Device Drivers
Interrupt handlers
I/O Subsystem
Application Software
4/1/2014 612 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
4/1/2014 Swati Keskar 613
Event Flags and Signals
Event flags allow for the specification of an event that causes
the setting of some flag
A second process is designed to react to this flag
Raising the flag transfers flow-of-control to the operating
system which can then invoke the appropriate handler
Tasks waiting for occurrence of an event are blocked
A signal is a type of software interrupt handler that is used to
react to an exception indicated by the raise operation
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer Services
Timer services are often required to :
Schedule system tasks and user tasks
To perform context switch of a preset time interval
periodically
To ensure execution fairness in round-robin method
To refresh dynamic memory
And so on..
4/1/2014 614 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timers
Two different forms of timers: hard times and soft
timers
Hard timers are derived from physical timer chips that
directly interrupt the processor when they expire,
precise!
Soft timers are software events that are scheduled
through a software facility
4/1/2014 615 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-time Clocks and
System Clock
Real-time clocks exist in many embedded systems and track
time, date, month and year
They are integrated with battery-powered DRAM
It becomes independent of CPU and the programmable
interval timer, making the maintenance of real-time between
system power cycles possible
4/1/2014 616 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The job of the system clock is identical to that of the real-time
The initial value is retrieved from the real-time clock at power
up or is set by the user
The programmable interval Timer drives the system clock ie
value increments per timer interrupt
Real-time Clocks and
System Clock
4/1/2014 617 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A Real-Time Clock
+
--
Real-time clock
11:30 AM
23/10/2008
Battery
4/1/2014 618 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Programmable Interval Timer
The programmable interval timer (PIT) or Timer chip, is a
device designed mainly to function as
--an event counter
--elapsed time indicator
--rate-controllable periodic event generator
4/1/2014 619 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer chip features an input clock source with a fixed
frequency
A set of programmable timer control registers
The timer interrupt rate is the number of timer interrupts
generated per second
Timer countdown value determines when the next interrupt
occurs
It is loaded in one of the timer control registers and is
decremented by one every input clock cycle
Programmable Interval Timer
4/1/2014 620 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer Chip Initialization
Resetting and bringing the timer chip into a known hardware
state
Calculating the proper value to obtain the desired timer
interrupt frequency
Programming other timer control registers that are related to
earlier interrupt frequency
Programming the timer chip with proper mode of operation
Installing the timer interrupt service routine into the system
4/1/2014 621 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer Interrupt Service Routines
Part of timer chip initialization involves installing Timer ISR which
performs following duties
Updating the system clock: bith absolute and elapsed time
Calling a registered kernel function to notify the passage of a
preprogrammed period
Acknowledging the interrupt, reinitializing the necessary
timer control registers and returning
4/1/2014 622 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Soft-Timer Handling Facility
The functions performed by this facility are
Allowing applications to start a timer
Allowing applications to stop or cancel a previously installed
timer
Internally maintaining the application timers
Two components : one lives within the timer tick ISR and other
lives in the context of a task
4/1/2014 623 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Model for Soft-Timer Handling Facility
Do real work
ISR Context
Task context
ISR_timeout_fn
Count down=10
invokes
ISR
Worker
Task
Worker
Task
Readies task
If count_down=10
gives semaphore
decrements
4/1/2014 624 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timing Wheel
A timing wheel is a construct with a fixed size array in which
each slot represents a unit of time w.r.t. the precision of the
soft timer facility
Advantage of the sorted timer list for updating the timers
efficiently
Efficient operation for timer installation and cancellation
4/1/2014 625 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timing Wheel
Time slot
Time slot
Time slot
Time slot
..
Clock Dial
Time line
past
future
Each time slot
Contains a list of
Timer to expire
At this point
4/1/2014 626 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Periodic Timeout
Soft-timer facility installs a periodic timeout (a clock tick)
using the underlying timer hardware
Drives all the soft-timers installed within the facility
The frequency determines the precision, smallest is 50ms
A doubly linked list of timeout event handlers is sorted within
each slot
4/1/2014 627 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timeout Event Handlers
Time slot
Event handler
&
Handler context
Event handler
&
Handler context
Event handler
&
Handler context
4/1/2014 628 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG 553 (Lecture 15)
Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Real Time OS
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
4/1/2014
Swati Keskar
1-631
Timer management
Design Issues
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Paging summary
Most efficient when supported by appropriate
hardware
Allows multitasking and extension of address space
A page fault occurs if the requested page is not in main
memory and causes interrupt
Hardware registers used to page frame translation add
additional overhead when doing context switching
If hardware mapping page is not used, additional
overheads for address calculation
In time critical real-time systems we cannot afford the
overheads by these methods
4/1/2014 632 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Working Sets
Working sets are based on the model of locality-of-reference
Most of the instructions in a recently executed program are
localized to a small number of instructions
However the locality-of-reference is altered when interrupts,
procedure calls etc
Idea is that a set of local code windows is maintained in cache
then one of the windows is replaced by another
Performance is based on the size of the working set window
and number of windows in working set
4/1/2014 633 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Garbage Collection
Garbage is that memory that has been allocated but is no
longer being used by a task
Garbage can accumulate when tasks terminate abnormally
without releasing memory resource
Garbage collection algorithms have unpredictable
performance
Tag all memory from the heap which is pointed by a variable
and then reclaim all nontagged memory for the heap
Loss of determinism due to unknown amount of garbage and
tagging time of data structure
4/1/2014 634 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Garbage collection
Loss of determinism due to unknown amount of garbage
Tagging time of data structure
Another technique to build a heap or table of memory blocks
along an associated process ID for the owner of the block
This data structure periodically checks whether memory is
allocated to a process that no longer exists
Overheads are more
4/1/2014 635 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Stack vs Heap Allocation
When a program is loaded into the memory, it is organized into
three areas of memory called segments
Text (Code) segment
Stack segment
Heap segment
The text segment is where the compiled code of the program
resides
It is machine language representation of the program steps to
be carried out
4/1/2014 636 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Stack vs Heap
Other two areas are those where storage may be allocated by
the compiler for data storage
In stack, new storage is allocated and deallocated at only one
end called the top of the stack
Memory allocation in this area contain garbage values left
over from previous usage
Heap segment provides more stable storage of data for a
program
Memory allocated in the heap remain existed for the duration
of a program, so need not contain garbage
4/1/2014 637 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
I/O Subsystems
Port-mapped I/O
Memory-mapped I/O
DMA
I/O Device hardware
Device Drivers
Interrupt handlers
I/O Subsystem
Application Software
4/1/2014 638 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer Services
Timer services are often required to :
Schedule system tasks and user tasks
To perform context switch of a preset time interval
periodically
To ensure execution fairness in round-robin method
To refresh dynamic memory
And so on..
4/1/2014 639 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timers
Two different forms of timers: hard timers and soft
timers
Hard timers are derived from physical timer chips that
directly interrupt the processor when they expire,
precise!
Soft timers are software events that are scheduled
through a software facility
4/1/2014 640 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-time Clocks and
System Clock
Real-time clocks exist in many embedded systems and track
time, date, month and year
They are integrated with battery-powered DRAM
It becomes independent of CPU and the programmable
interval timer, making the maintenance of real-time between
system power cycles possible
4/1/2014 641 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The job of the system clock is identical to that of the real-time
The initial value is retrieved from the real-time clock at power
up or is set by the user
The programmable interval Timer drives the system clock ie
value increments per timer interrupt
Real-time Clocks and
System Clock
4/1/2014 642 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A Real-Time Clock
+
--
Real-time clock
11:30 AM
23/10/2008
Battery
4/1/2014 643 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Programmable Interval Timer
The programmable interval timer (PIT) or Timer chip, is a
device designed mainly to function as
--an event counter
--elapsed time indicator
--rate-controllable periodic event generator
4/1/2014 644 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer chip features an input clock source with a fixed
frequency
A set of programmable timer control registers
The timer interrupt rate is the number of timer interrupts
generated per second
Timer countdown value determines when the next interrupt
occurs
It is loaded in one of the timer control registers and is
decremented by one every input clock cycle
Programmable Interval Timer
4/1/2014 645 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer Chip Initialization
Resetting and bringing the timer chip into a known hardware
state
Calculating the proper value to obtain the desired timer
interrupt frequency
Programming other timer control registers that are related to
earlier interrupt frequency
Programming the timer chip with proper mode of operation
Installing the timer interrupt service routine into the system
4/1/2014 646 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timer Interrupt Service Routines
Part of timer chip initialization involves installing Timer ISR which
performs following duties
Updating the system clock: bith absolute and elapsed time
Calling a registered kernel function to notify the passage of a
preprogrammed period
Acknowledging the interrupt, reinitializing the necessary
timer control registers and returning
4/1/2014 647 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Soft-Timer Handling Facility
The functions performed by this facility are
Allowing applications to start a timer
Allowing applications to stop or cancel a previously installed
timer
Internally maintaining the application timers
Two components : one lives within the timer tick ISR and other
lives in the context of a task
4/1/2014 648 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Model for Soft-Timer Handling Facility
Do real work
ISR Context
Task context
ISR_timeout_fn
Count down=10
invokes
ISR
Worker
Task
Worker
Task
Readies task
If count_down=10
gives semaphore
decrements
4/1/2014 649 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timing Wheel
A timing wheel is a construct with a fixed size array in which
each slot represents a unit of time w.r.t. the precision of the
soft timer facility
Advantage of the sorted timer list for updating the timers
efficiently
Efficient operation for timer installation and cancellation
4/1/2014 650 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timing Wheel
Time slot
Time slot
Time slot
Time slot
..
Clock Dial
Time line
past
future
Each time slot
Contains a list of
Timer to expire
At this point
4/1/2014 651 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Periodic Timeout
Soft-timer facility installs a periodic timeout (a clock tick)
using the underlying timer hardware
Drives all the soft-timers installed within the facility
The frequency determines the precision, smallest is 50ms
A doubly linked list of timeout event handlers is sorted within
each slot
4/1/2014 652 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timeout Event Handlers
Time slot
Event handler
&
Handler context
Event handler
&
Handler context
Event handler
&
Handler context
4/1/2014 653 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Hardware Issues
Architectural features such as the instruction set, addressing
modes
RISC versus CISC
Memory Access time
Modes of I/O to and from a computer
Coprocessors
4/1/2014 654 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Microcontrollers
Microcontroller is programmable via microinstructions
The complex macroinstruction decoding process is not
supported
Program execution is fast
4/1/2014 655 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CPU
Real-time Systems use
Microprocessor
Mainframe
Minicomputers
Microcontrollers
4/1/2014 656 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Architecture
Basic parts of a computer are CPU, memory and input/output
devices
Language : machine language
Binary instructions are fetched and executed continously
Von Neumann computers
Non von Neumann computers such as array and vector
processors, dataflow processors
4/1/2014 657 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Addressing Modes
Implied Mode
Immediate Mode
Register Direct
Register Indirect
Double Indirect
4/1/2014 658 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
n-Address Machine
0-address machine
1-address machine
2-address machine
3-address machine
4/1/2014 659 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
0-Address Machine
Also called stack architecture
Instructions are centered on an internal memory (stack) and
on an accumulator
No other registers are available
PUSH/POP or LOAD/STORE instructions are used for data
transfer
Not suitable for Real-Time Systems
4/1/2014 660 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
1-address Machine
In this type an implied accumulator is used
All instructions are allowed upto one memory or general
register reference
Immediate instructions are permitted
4/1/2014 661 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
2, 3-Address Machines
In the 2-address architecture, a maximum of two memory or
general register references are allowed in each instruction
No implied accumulator is used
In the 3-address architecture, a maximum of three memory or
general register references are allowed in each instruction
4/1/2014 662 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Special Instructions
In all above mentioned architectures, instructions are provided
to alter the flow-of-control
Test instructions
Conditional Jump instructions
Unconditional Jump instructions
Subroutine instructions
Interrupts
Floating point Instructions
4/1/2014 663 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pipelining
Von Neumann computer architectures suffer from one serious
flaw- the von Newmann bottleneck
This seriously limits CPU performance
To overcome this problem pipelining technique is used
The drawback of this pipelining is that if the flow-of-control
changes, other instructions back in the pipeline are of no use
The real-time programmer must realize that before an
interrupt can be handled, the oldest instruction in the
pipeline must be completed and the others either saved or
flushed
4/1/2014 664 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Coprocessors
Specialized CPU to perform certain operations
Used to extend the instruction set
Works with handshake signals
Coprocessors improve real-time performance because they
extend the instruction setto support faster, specialized
instructions
But they also present special problems to real-time systems
4/1/2014 665 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Memories
Semiconductor memories
Magnetic memories
Ferrite Core
The most important real-time characteristics are access time,
density and cost
4/1/2014 666 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Semiconductor memories
Volatile memory, RAM
RAM: SRAM and DRAM
DRAMs use a capacitive charge to store logic 1 and 0s
Must be refreshed
SRAMs are faster and require less power but more expensive
Nonvolatile memory ROM
UVROM, EPROM, EEPROM etc
4/1/2014 667 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Magnetic Memory
Compact Disc
Floppy Disc
Ferrite Core
Flash memory: type of ROM
Uses a single transistor per bit hence more cost effective and
dense
Access time is fast
4/1/2014 668 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Input and Output
Programmed I/O
Memory mapped I/O
DMA
Other devices such as MUX Transceivers, ADC, DAC, Interrupt
controllers
Important Device for CPU check is Watchdog timer
4/1/2014 669 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Language Features and Comparison
Main issue is compiler generated code
Mainly used languages Ada, Fortran, C, Assembly languages
Increased use of object oriented languages
RT languages seek to support expression and analysis of
temporal behaviour by
i- Elimination of constructs that have indeterminate
execution times, infinite loops
ii- Extension of existing language
iii- Construction of languages jointly with the operating
system
4/1/2014 670 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Language Issues
Parameter Passing
- Call-by-value: The value of the actual parameter is
copied into the called procedures formal parameter
- Call-by-reference/address: the address of the parameter is
passed by the calling routine to the called procedure.
Execution takes longer since indirect instructions are needed
for any calculation
Relative advantages and disadvantages are dependent on
language used, compiler implementation, coding style, target
hardware, size of parameter passed etc.
4/1/2014 671 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Parameter Passing
Relative advantages and disadvantages are dependent on
language used, compiler implementation, coding style, target
hardware, size of parameter passed etc
FORTRAN, Pascal, Ada
C supports using simulation by pointer types
Other calling methods are call-by-name, call-by-value result
4/1/2014 672 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Parameter Lists
Parameter lists and global parameters
Global variables are within the scope of all modules of the
software systems so references can be made in direct mode,
faster
Parameter lists is advantageous because the interfaces
between the modules are clearly defined
At the same time it can get long and often interrupts are
disabled during parameter passing
4/1/2014 673 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Recursion
Procedures are self-referential, it can call itself
Procedure calls require the allocation and deallocation of
storage, this time is unpredictable and cannot be afforded
It necessitates the use of a large number of costly memory
indirect and register indirect instructions
It becomes impossible to determine the size of run-time
memory requirement
Reentrant code includes critical regions protected by
semaphores
4/1/2014 674 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dynamic Allocation
The ability to dynamically allocate memory is important in the
construction and maintenance of stacks needed by RTOS
It is time consuming but necessary
Linked lists, trees, heaps or other dynamic data structures
used in RTS can be compensated at the expense of speed
4/1/2014 675 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Typing
Strongly typed languages force the programmer to be precise
about the way data are to handled
It can also prevent unwanted or unnoticed molestation of
data through truncation or rounding
Abstract data typing includes the ability to represent and
manipulate data types that are not a standard type supported
by the language
4/1/2014 676 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Exception Handling
Facility to deal with errors or other anomaly conditions that
arise during program execution
Certain code is invoked to handle exceptional conditions
4/1/2014 677 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Abstract Data Typing
The ability to represent abstract ideas
Such capabilities tend to make program design easier and
clearer
Drawback is only grouping of similar kinds of data
Ada, C, Pascal, Modula-2
Record types structure in C
4/1/2014 678 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Object oriented Programming
Provide constructs encouraging a high degree of information
hiding and data abstraction
Object oriented programming languages support
-- Abstraction of data type
-- Inheritance
-- Polymorphism
4/1/2014 679 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Advantages
The promise of OOP languages in real-time application lies in
clearer design and better maintainability
Disadvantage is that execution is slower by almost 50%
4/1/2014 680 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Modularity
Partitioning software systems into modules in a way clearly
defines intermodule communication and prevents unwanted
intermodule interference
But resultant overhead associated with procedure calls affects
performance adversly
4/1/2014 681 Swati Keskar
Feature Comparison
Language c-r c-v da st te eh et md rc
Ada y y y y y y y y y
BASIC na na n n n n n n n
C y y y n n y y y y
FORTRAN n y n n n n n n n
Modula-2 y y y y y n y y y
Pascal y y y y n n y y y
4/1/2014 682 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Programming
A Programming Style
1- Imperative (sequential) as in Ada, RT-Java
2- Functional (recursive) as in LISP
3- Declarative (logic) as in Prolog
4- Data flow machines
5- Finite state machine
B Static or dynamic
C Modular, Concurrent or Distributed
D Synchronous, continuous time
E Control oriented or data oriented
4/1/2014 683 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Suitable Language for RTS
Predictability- No operation which will lead to unforeseeable
timing behavior
Real-time Support for temporal scopes
Concurrency Support for tasking and threading
Reliability Detect errors at compile-time or the run-time
environment
Scalable, modular or object-oriented + separate compilation
4/1/2014 684 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Software
An engineering approach to
-specification
-design
-construction
-testing
-maintenance
is essential for maximizing the reliability and reducing the
life-cycle cost
4/1/2014 685 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Phases in S/W Cycle
Concept phase
Requirement phase
Design phase
Programming phase
Test phase
Maintenance phase
4/1/2014 686 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Concept Phase
Driven by
management directive,
customer input,
technology changes
marketing decisions
Identify product need and goals
Produce feasibility studies
4/1/2014 687 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Requirement Phase
Generally prepared by customer
Functional Nonfunctional requirements
requirements
4/1/2014 688 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Requirement contd
Functional requirements are those system features that can
be directly tested by executing the program
Nonfunctional requirements are such as the type of machine
that will run on, programming language to use it etc
4/1/2014 689 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Chief Goals in Phase
Chief goals are
Define all hardware and software interfaces
Write requirement document
Write test plan
Prepare project schedule
4/1/2014 690 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rules for R & D documents
The document must be complete
The document should be correct
The document should be consistent
Each requirement or design element should be testable
4/1/2014 691 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Design Phase
Partition software into modules
Prepare detailed design document
Develop test cases
4/1/2014 692 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Programming Phase
Responsibilities
Termination
Software Management
4/1/2014 693 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Programming Phase contd
Write software modules
Debug software
Develop automated test cases
Integrate modules
4/1/2014 694 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Test Phase
Acceptance or rejection of the software is based on how well it
fares against the test set
Perform software validation
Prepare test reports
4/1/2014 695 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Maintenance Phase
Product deployment
Customer report
Continuing program error correction
4/1/2014 696 Swati Keskar
Phase Activity
Output
Concept Define project goals White
paper
Requirem
ent
Decide what the product
must do
Requirem
document
Design Show how the product will
meet the requirements
Design
document
Code Build the system Program
code
Test Check if the system meets
the requirements
Test
reports
Maintena
nce
Maintain system Maint.
reports
4/1/2014 697 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Standards
There are many informal standards for the development of
software
DoD-STD-2167A
ISO 9000
IEEE 830
4/1/2014 698 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 16)
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Software Design Issues
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
4/1/2014
Swati Keskar
1-701
Software Issues
Software Life Cycle
Software Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Language Features and Comparison
Main issue is compiler generated code
Mainly used languages Ada, Fortran, C, Assembly languages
Increased use of object oriented languages
RT languages seek to support expression and analysis of
temporal behaviour by
i- Elimination of constructs that have indeterminate
execution times, infinite loops
ii- Extension of existing language
iii- Construction of languages jointly with the operating
system
4/1/2014 702 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Metrices
Economy of Execution
Economy of Compilation
Economy of Small-scale Development
Economy of Large-scale Development
Economy of Language Features
4/1/2014 Swati Keskar 703
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Typing
Strongly typed languages force the programmer to be precise
about the way data are to handled
It can also prevent unwanted or unnoticed molestation of
data through truncation or rounding
Abstract data typing includes the ability to represent and
manipulate data types that are not a standard type supported
by the language
4/1/2014 704 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Exception Handling
Facility to deal with errors or other anomaly conditions that
arise during program execution
Certain code is invoked to handle exceptional conditions
4/1/2014 705 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Abstract Data Typing
The ability to represent abstract ideas
Such capabilities tend to make program design easier and
clearer
Drawback is only grouping of similar kinds of data
Ada, C, Pascal, Modula-2
Record types structure in C
4/1/2014 706 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Object oriented Programming
Provide constructs encouraging a high degree of information
hiding and data abstraction
Object oriented programming languages support
-- Abstraction of data type
-- Inheritance
-- Polymorphism
4/1/2014 707 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Advantages
The promise of OOP languages in real-time application lies in
clearer design and better maintainability
Disadvantage is that execution is slower by almost 50%
4/1/2014 708 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Modularity
Partitioning software systems into modules in a way clearly
defines intermodule communication and prevents unwanted
intermodule interference
But resultant overhead associated with procedure calls affects
performance adversly
4/1/2014 709 Swati Keskar
Feature Comparison
Language c-r c-v da st te eh et md rc
Ada y y y y y y y y y
BASIC na na n n n n n n n
C y y y n n y y y y
FORTRAN n y n n n n n n n
Modula-2 y y y y y n y y y
Pascal y y y y n n y y y
4/1/2014 710 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Programming
A Programming Style
1- Imperative (sequential) as in Ada, RT-Java
2- Functional (recursive) as in LISP
3- Declarative (logic) as in Prolog
4- Data flow machines
5- Finite state machine
B Static or dynamic
C Modular, Concurrent or Distributed
D Synchronous, continuous time
E Control oriented or data oriented
4/1/2014 711 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Suitable Language for RTS
Predictability- No operation which will lead to unforeseeable
timing behavior
Real-time Support for temporal scopes
Concurrency Support for tasking and threading
Reliability Detect errors at compile-time or the run-time
environment
Scalable, modular or object-oriented + separate compilation
4/1/2014 712 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Software
An engineering approach to
-specification
-design
-construction
-testing
-maintenance
is essential for maximizing the reliability and reducing the
life-cycle cost
4/1/2014 713 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Phases in S/W Cycle
Concept phase
Requirement phase
Design phase
Programming phase
Test phase
Maintenance phase
4/1/2014 714 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Concept Phase
Driven by
management directive,
customer input,
technology changes
marketing decisions
Identify product need and goals
Produce feasibility studies
4/1/2014 715 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Requirement Phase
Generally prepared by customer
Functional Nonfunctional requirements
requirements
4/1/2014 716 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Requirement contd
Functional requirements are those system features that can
be directly tested by executing the program
Nonfunctional requirements are such as the type of machine
that will run on, programming language to use it etc
4/1/2014 717 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Chief Goals in Phase
Chief goals are
Define all hardware and software interfaces
Write requirement document
Write test plan
Prepare project schedule
4/1/2014 718 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rules for R & D documents
The document must be complete
The document should be correct
The document should be consistent
Each requirement or design element should be testable
4/1/2014 719 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Design Phase
Partition software into modules
Prepare detailed design document
Develop test cases
4/1/2014 720 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Programming Phase
Responsibilities
Termination
Software Management
4/1/2014 721 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Programming Phase contd
Write software modules
Debug software
Develop automated test cases
Integrate modules
4/1/2014 722 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Test Phase
Acceptance or rejection of the software is based on how well it
fares against the test set
Perform software validation
Prepare test reports
4/1/2014 723 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Maintenance Phase
Product deployment
Customer report
Continuing program error correction
4/1/2014 724 Swati Keskar
Phase Activity
Output
Concept Define project goals White
paper
Requirem
ent
Decide what the product
must do
Requirem
document
Design Show how the product will
meet the requirements
Design
document
Code Build the system Program
code
Test Check if the system meets
the requirements
Test
reports
Maintena
nce
Maintain system Maint.
reports
4/1/2014 725 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Standards
There are many informal standards for the development of
software
DoD-STD-2167A
ISO 9000
IEEE 830
POSIX
4/1/2014 726 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Specifications and Design Techniques
No technique is perfect, therefore a combination of
techniques should be used
The specification of temporal behavior is most difficult
Techniques for generating the software requirements
documents and the design document
4/1/2014 727 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Contd
Specifications:- Performed by the customer, tells us what the
software is to do
Design:- Performed by the system analyst or designer, tells us
how the software will do it
With the advent of CASE tools, a graphical specification can
immediately be converted into code
4/1/2014 728 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Specifications
The techniques used in specification of real-time systems are
a rich superset of those used for non-real time systems
Natural Languages:- Language such as English are required in
the specification of software systems
It should be used only to provide redundant descriptions of
features
Care should be taken so that description should not be
ambiguous and tedious
Used to describe simple systems only
4/1/2014 729 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Mathematical Specifications
When used, is precise, unambiguous and efficient
Optimization becomes simpler with mathematical model
using formal methods
Formal proof techniques can be applied to software in the
same manner as the underlying mathematics, during software
verification and testing process
4/1/2014 730 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Flow Charts
Standard flow charts are not encouraged for the use in the
specifications of systems as they promote the unwanted
GOTO statement
Oldest modeling tool and widely understood
Useful for systems of the order of 5,000 to 10,000
instructions, not beyond that size
Interaction between processes is not easily represented
Temporal behavior can not be described
4/1/2014 731 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Structure Charts
Also called calling trees
Useful for describing the modular decomposition of a system
Rectangles are used to represent processes
Left to right- increasing sequence in execution
Top to bottom- indicates increasing detail
No formal method for indicating conditional branches
Widely found in CS literature and in describing systems
Widely used for the design of www pages
4/1/2014 732 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Advantages of Structured charts
Useful for very simple systems
Clearly identify function execution sequence
Help to identify recursion and repeated modules
Encourage top-down design
4/1/2014 733 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Disadvantages of Structured charts
They are flat in nature
Cannot easily be used to depict conditional branching
Cannot describe concurrent systems
4/1/2014 734 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pseudocodes and PDLs
High order language, very abstract, detached from the
underlying architecture of the machine on which system will
run
PDLs can be input into a compiler and translated into high-
order languages
Pseudocode is a programming language with some simple set
of semantics for which no compiler is usually built
4/1/2014 735 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Advantages and Disadvantages
Advantages:-
More abstract than writing specifications directly in high order
language
Are closer, hence can often be translated into programs
Disadvantages:-
User must be fluent in the PL
Error prone
Significant additional cost and maintenance of these design
tools
4/1/2014 736 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Finite state Automata
Type of mathematical model used in the design of
Compilers
Hard-wired logic
Communication systems
FSA rely on the fact that many systems can be represented by
a fixed number of unique states
The system may change state depending on time or the
occurrence of specific event
Commonly used method is Moore FSA
Moore machine does not allow for outputs during transition
4/1/2014 737 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Disadvantage of FSA
Major disadvantage is that insideness of modules cannot be
depicted
There is no way to indicate how functions can be broken into
subfunctions
Intertask communication for multiple FSAs is difficult to
specify
Depending on the system and alphabet used, the number of
states can grow very large
4/1/2014 738 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dataflow Diagrams
Used as a structured analysis tool for modeling software
systems
Extensions to the original model, permit real-time systems to
be modeled
Through functional requirements, analyze dataflow through
the system and determine the major function
Concurrency can be identified by identifying all the functions
and dataflow between them
Governed by DeMarcos rules
4/1/2014 739 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dataflow contd
Dataflow conventions
Process sink or source
Data store Data flow
4/1/2014 740 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dataflow contd
Similar to dataflow diagrams, control flow diagrams can also
drawn to make it more suitable of real-time applications
It represents flow of control signals through the system
In the absence of concurrency, these are FSA
Structure charts can be derived from this to assist in the
design process
Can be used to partition a system into hardware and software
components
Flaw is that they make it difficult to depict synchronization in
flow
4/1/2014 741 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Petri Nets
Mathematical model used to specify the operations in
multiprocessing and multitasking environment
Graphical representation is possible
Circles are used as places to represent data stores or
processes
Rectangular boxes are used to represent transitions or
operations
The processes and transitions are labeled with a data count
and transition function
4/1/2014 742 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Petri Nets contd
Initial markings represent initial data count in the process
New markings are the result of firing of transitions
A transition fires if it has as many inputs as required for
output
Firing table gives details of the transitions
1 0
4/1/2014 743 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Petri Net contd
Can be used to model systems and to analyze timing
constraints and race conditions
Are excellent for representing multiprocessing and
multiprogramming systems
They are mathematical in nature, so the techniques for
optimization and formal programming can be employed
Can depict concurrency
If the system is complex, timing can be obscured
4/1/2014 744 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
4/1/2014 745 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
First Firing
4/1/2014 746 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Second Firing
4/1/2014 747 Swati Keskar
Firing Table
P
1
P
2
P
3
P
4
P
5
P
6
P
7
m
0
3 1 3 0 0 0 0
m
1
m
2
4/1/2014 748 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Statecharts
State Chart combine FSA with dataflow diagrams and
broadcast communication
Statecharts= FSA+ depth+ orthogonality+ broadcast
communication
Depth represents level of details
Orthogonality represents separate tasks
Broadcast communication allows different orthogonal
processes to react to the same event
4/1/2014 749 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Representation
4/1/2014 750 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Depth
Encouragement of top-down design of a module
A system may consists of several internal states
Each of these in turn can be decomposed into appropriate
states that represent program modules
Those states can also be decomposed and so on
The depth or insideness is similar to the nesting levels
Incourages the correct application of information hiding
principles
4/1/2014 751 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Orthogonality
It depicts concurrency in the system that run in isolation
Represented by dashed lines
If Y consists of AND components a and D, Y is called
orthogonal product of A and D
4/1/2014 752 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Broadcast communication
It is depicted by the transition of orthogonal states based on
same event
Chain reaction is possible i.e. events can trigger other events
Output events can be attached to the triggering event
Statecharts are excellent for representing real-time systems as
they depict concurrency while preserving modularity
Concept of broadcast communication allows easy intertask
communication representation
4/1/2014 753 Swati Keskar
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 17)
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Design Issues
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
4/1/2014
Swati Keskar
1-756
Software Design
Fault Tolerance
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Finite state Automata
Type of mathematical model used in the design of
Compilers
Hard-wired logic
Communication systems
FSA rely on the fact that many systems can be represented by
a fixed number of unique states
The system may change state depending on time or the
occurrence of specific event
Commonly used method is Moore FSA
Moore machine does not allow for outputs during transition
4/1/2014 757 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Disadvantage of FSA
Major disadvantage is that insideness of modules cannot be
depicted
There is no way to indicate how functions can be broken into
subfunctions
Intertask communication for multiple FSAs is difficult to
specify
Depending on the system and alphabet used, the number of
states can grow very large
4/1/2014 758 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dataflow Diagrams
Used as a structured analysis tool for modeling software
systems
Extensions to the original model, permit real-time systems to
be modeled
Through functional requirements, analyze dataflow through
the system and determine the major function
Concurrency can be identified by identifying all the functions
and dataflow between them
Governed by DeMarcos rules
4/1/2014 759 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dataflow contd
Dataflow conventions
Process sink or source
Data store Data flow
4/1/2014 760 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dataflow contd
Similar to dataflow diagrams, control flow diagrams can also
drawn to make it more suitable of real-time applications
It represents flow of control signals through the system
In the absence of concurrency, these are FSA
Structure charts can be derived from this to assist in the
design process
Can be used to partition a system into hardware and software
components
Flaw is that they make it difficult to depict synchronization in
flow
4/1/2014 761 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Petri Nets
Mathematical model used to specify the operations in
multiprocessing and multitasking environment
Graphical representation is possible
Circles are used as places to represent data stores or
processes
Rectangular boxes are used to represent transitions or
operations
The processes and transitions are labeled with a data count
and transition function
4/1/2014 762 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Petri Nets contd
Initial markings represent initial data count in the process
New markings are the result of firing of transitions
A transition fires if it has as many inputs as required for
output
Firing table gives details of the transitions
1 0
4/1/2014 763 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Petri Net contd
Can be used to model systems and to analyze timing
constraints and race conditions
Are excellent for representing multiprocessing and
multiprogramming systems
They are mathematical in nature, so the techniques for
optimization and formal programming can be employed
Can depict concurrency
If the system is complex, timing can be obscured
4/1/2014 764 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
4/1/2014 765 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
First Firing
4/1/2014 766 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Second Firing
4/1/2014 767 Swati Keskar
Firing Table
P
1
P
2
P
3
P
4
P
5
P
6
P
7
m
0
3 1 3 0 0 0 0
m
1
m
2
4/1/2014 768 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Statecharts
State Chart combine FSA with dataflow diagrams and
broadcast communication
Statecharts= FSA+ depth+ orthogonality+ broadcast
communication
Depth represents level of details
Orthogonality represents separate tasks
Broadcast communication allows different orthogonal
processes to react to the same event
4/1/2014 769 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Representation
4/1/2014 770 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Depth
Encouragement of top-down design of a module
A system may consists of several internal states
Each of these in turn can be decomposed into appropriate
states that represent program modules
Those states can also be decomposed and so on
The depth or insideness is similar to the nesting levels
Incourages the correct application of information hiding
principles
4/1/2014 771 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Orthogonality
It depicts concurrency in the system that run in isolation
Represented by dashed lines
If Y consists of AND components a and D, Y is called
orthogonal product of A and D
4/1/2014 772 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Broadcast communication
It is depicted by the transition of orthogonal states based on
same event
Chain reaction is possible i.e. events can trigger other events
Output events can be attached to the triggering event
Statecharts are excellent for representing real-time systems as
they depict concurrency while preserving modularity
Concept of broadcast communication allows easy intertask
communication representation
4/1/2014 773 Swati Keskar
Fault Tolerant Task scheduling
Fault tolerance is defined as how to provide, by redundancy, service
complying with the specification in spite of faults having occurred or
occurring.
Important in critical applications
RTS may fail to perform because of h/w, s/w errors or because it fails
the timing constraints
RTS must perform in at timely manner even in presence of faults
Classification of RTS according to their Fault tolerance:
Fail-safe systems
Fail-operational systems
4/1/2014 774 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Expressing Fault Tolerance
Dependability
Reliability 0.999999 for 10-hour mission 10
-6
Availability.- 0.999999- 1 hr in 1 million hours
Available system may fail
But fault recovery time less availability is good
4/1/2014 Swati Keskar 775
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Basic Steps in Fault Handling
Fault Detection
Fault Masking
Retry
Diagnosis
Reconfiguration
Recovery
Restart
Fault Confinement
Repair
Reintegration
4/1/2014 Swati Keskar 776
Job Retry
Process Retry
Procedure Retry
Instruction Retry
Bus Cycle Retry
Hardware
Microcode
Macrocode
OS
Application
4/1/2014 777 Swati Keskar
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fault Tolerant Task scheduling
Fault Hypothesis:
Load Hypothesis
Fault Hypothesis
In a known fault scenario fault tolerant system must provide a QoS
If fault increase- degrade gracefully
Load and fault hypothesis must capture the behavior of the
environment
Assumption coverage
4/1/2014 Swati Keskar 778
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fault Tolerant Task scheduling
Fault Classification
Faults can occur during any stage of system evolution
Specification, design, development, manufacturing or installation,
operational life
Classification done :Duration of fault, o/p behavior of fault
,correlation with other faults
Fault causes an incorrect system state error
Causes of failures: Errors in the specification or design
Defects in the components
Environmental defects
4/1/2014 Swati Keskar 779
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fault Tolerant Task scheduling
Fault Classification
A hardware fault: some physical defect that can cause a component
malfunction
A software fault: a bug that can cause the program to fail for given
set of inputs
An error : manifestation of a fault
Fault latency : the duration between the onset of a fault and its
manifestation as an error
Error latency : the duration between when an error is produced and
when it is recognized as an error or causes the failure
4/1/2014 Swati Keskar 780
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fault Tolerant Task scheduling
Classification of fault duration
Permanent
Intermittent
Transient
Classification by output behavior
Malicious/ Byzantine
Non Malicious/ Stuck -at
Fail-stop system
Fail-safe
independent and correlated faults
Fault-Avoidance, Fault-tolerant
4/1/2014 Swati Keskar 781
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fault Tolerant Task scheduling
Redundancy
H/w Permanent Faults
-Active
-Passive
S/w
Exception handling
Temporal/time Transient Faults
Information
Redundancy and fault-tolerance trade-off Time & Space
Quality of computation can be changed
4/1/2014 Swati Keskar 782
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fault Tolerant Techniques
N-Modular redundancy
Forward error correction scheme
N-multiple identical processors running the same program concurrently
Tolerate m- processor failure N = (2m+1)
N-version Programming
Forward error correction scheme
Design Diversity multiple versions of the same program
Version1
Version 2
Version 3
Voter
Majority
N-version with triple Modular redundancy
4/1/2014 Swati Keskar 783
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Fault Tolerant Techniques
Recovery Blocks
One module (task) is primary- rest secondary
Version 1 Acceptance Test
Version 2 Acceptance Test
Version 3 Acceptance Test
Imprecise Computational model
To avoid timing faults during transient overloads
4/1/2014 Swati Keskar 784
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Safety critical tasks have hard deadlines even if aperiodic
Guarantee deadlines with fault tolerance requirements
Fault Tolerant Scheduling Approaches
Dynamic Planning Based approach
Static over allocation of resources- Minimum number of
processors reqd depends on system load and characteristics of
arriving task
Fault Tolerance based on resource availability
Fault Tolerant Scheduling
4/1/2014 Swati Keskar 785
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real Time Scheduling with Recovery Block
fault tolerance
n identical processors
Centralized scheduling model
Error detection method already available
Fail-signal processors
Alarms/watchdogs
Signatures
4/1/2014 Swati Keskar 786
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real Time Scheduling with Recovery Block
fault tolerance
Task Model T
i
= <a
i
,r
i
,d
i
,c
i
>
Window of task is twice as large as its computation time
w
i
= d
i
r
i
Both primary and backup has to be scheduled.
No precedence constraints
Both primary(PR
i
), and backup(BK
i
) copies of the task have to be
scheduled
Primary and secondary copies are scheduled on two different
processors
Algo evaluated- Acceptance ratio, rejection ratio, resiliency
4/1/2014 Swati Keskar 787
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real Time Scheduling with Recovery Block
fault tolerance
Scheduling scheme
In RTS, tasks must be memory resident
Processor functioning as a spare will be idle throughout the lifetime
of a system if no error occurs
For hard RTS- resource reservation must be done for primary as
well as secondary - different scheduling schemes can be used
Dedicated spare- processor not used if no fault
Backup overloading only one processor can breakdown at a time
Backup de-allocation
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real Time Scheduling with Recovery Block
fault tolerance
The necessary conditions for tolerating faults in a single fault real-
time system
Both PR
i
,BK
i
must be scheduled within the tasks r
i
and d
i
The slot for BK
i
should be later than slot for PR
i
PR
i
and BK
i
must be scheduled on different processors
PR
i
and PR
j
are scheduled on the same processor then BK
i
and BK
j
cannot overlap on same processor p
j
to tolerate permanent faults
Resilience of a system is the time it takes to tolerate a second fault
after the first fault has occurred on p
i
(TTSF)
PR1
PR2
PR3
BK1
BK3
BK2
PR4
BK4
BITSPilani
Pilani|Dubai|Goa|Hyderabad
BITS ZG553 (Lecture 18)
BITSPilani
Pilani|Dubai|Goa|Hyderabad
Real-Time Systems :
Tutorial II
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plan of The Lecture
4/1/2014
Swati Keskar
1-793
tutorial
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Q 1
A system contains three periodic tasks T
1
(10,2), T
2
(15,4) and
T
3
(21,3) and one deferrable server whose period is 18. (Use
RMA)
a) What maximum budget the server may have, so that the
system is schedulable?
b) If the server period is 12, compare the budgets in both
cases. Comment on the result.
4/1/2014 Swati Keskar 794
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Q 2
4/1/2014 Swati Keskar 795
A Given set of tasks T
1
(3,1); T
2
(4,1); T
3
(7,2.2) is to be
scheduled by using clock-
driven scheduling algorithm.
a) What are the hyper period and possible frame
size(s)?
b) Choosing the largest frame size, draw Network
Flow Graph and Timing Diagram.
c) Find the minimum average response time of
two aperiodic jobs A
1
(5,2) and A
2
(13,1.5)
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A system contains three periodic tasks T
1
(100,30), T
2
(150,40)
and T
3
(190,35).
The tasks are scheduled by using Rate Monotonic
Algorithm.
i. Determine whether the system is schedulable or not. Also
find worst case response time of T
3
.
ii. If a new task T
x
is of period 50 to be added without
disturbing schedulability, then what should be the maximum
execution time of the new task?
4/1/2014 Swati Keskar 796
Q 3
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Consider a robot that is facing down a hallway and has ability
to detect doorways using a sensor that is mounted on it. In
addition, the robot is able to detect when it runs into a
wall. Assuming an ability to make perfect movements, design
a finite state machine that will take the robot to the third door
on the left side of the hallway, turn, enter it and stop
(assume that the robot knows, it has moved through the door
when it can no longer see the door in front of it).
In addition if there is a collision, the robot should stop and signal
an error condition. Clearly define various states, events,
actions used to draw finite state automaton. Give transition
table also.
4/1/2014 Swati Keskar 797
Q 4

You might also like