You are on page 1of 343

03/08/10 1

1
Characteristics of
Real-Time Systems
(Lecture 2)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 2
2
What is a Real-Time
System?
A system is called real-time:
Whenever we need to quantitatively
express time to describe its
behaviour.
Recall how to describe the
behaviour of a system?
List inputs to the system and the
corresponding system response.
03/08/10 3
3
Important Characteristics
An embedded system responds to
events.
Process
New Data
External
Input Event
External
Output Event
Example: An Automobile airbag system.
When the airbags motion sensors detect a
collision, the system needs to respond by
deploying the airbag within 10ms or less.
or the system fails!
03/08/10 4
4
Embedded Systems = Hardware + RTOS
+Application Program
SENSORS
D/A
CONVERSION
DIAGNOSTIC
PORT
SOFTWARE
A/D
CONVERSION CPU
ACTUATORS
MEMORY
HUMAN
INTERFACE
AUXILLARY
SYSTEMS
(POWER,
COOLING)
ELECTROMECHANICAL
BACKUP & SAFETY
External
Environment
03/08/10 5
5
An embedded system responds to
external inputs:
If response time to an event is too
long, the system fails.
General purpose Operating
Systems:
Not designed for real-time use
Real-time Operating Systems:
Help tasks meet their deadline.
What is a Real-Time OS?
03/08/10 6
6
Characteristics of An
Embedded System
Real-time:
Every real-time task is
associated with some time
constraints, e.g. a Deadline.
Correctness Criterion:
Results should be logically
correct,
And within the stipulated time.
03/08/10 7
7
Characteristics of an
Embedded System cont
Safety and Task Criticality:
A critical task is one whose failure
causes system failure (example:
obstacle avoidance).
A safe system does not cause damage.
A safety-critical real-time system is
one where any failure causes severe
damage.
03/08/10 8
8
Characteristics of an
Embedded System cont
Concurrency:
A RT system needs to respond to
several independent events.
Typically separate tasks process
each independent event.
For the same inputs, the result can
be different (Non-determinism).
03/08/10 9
9
Characteristics of
Embedded Systems cont
Distributed and Feedback
Structure
Custom Hardware:
An embedded system is often
implemented on custom H/W that
is specially designed and developed
for the purpose.
03/08/10 10
10
Characteristics of
Embedded Systems
Feedback structure of real-time systems
03/08/10 11
11
Characteristics of Embedded
Systems cont
Reactive:
On-going interaction between
computer and environment.
Stability:
Under overload conditions, work
acceptably for at least important
tasks.
Exception Handling:
03/08/10 12
12
Safety and Reliability
Independent concepts in
traditional systems.
A safe system does not cause
damage even when it fails.
A reliable system operates for
long time without any failure.
03/08/10 13
13
Safety and Reliability
In traditional systems, safety and
reliability are independent
concerns:
A system can be safe and unreliable
and vice versa.
Give examples of:
A safe and unreliable system
A reliable and unsafe system
03/08/10 14
14
Safety and Reliability
cont
Interrelated in safety-critical
system.
A safety critical system is one
for which any failure of the
system would result in severe
damage.
Safety can be ensured only
through increased reliability.
03/08/10 15
15
Safety and Reliability
An unreliable system can be made
safe upon a failure:
By reverting to a fail-safe state.
A fail-safe state:
No damage can result if a system
fails in this state.
Example: For a traffic light, all
lights orange and blinking.
03/08/10 16
16
Fail-Safe State
The fail-safe state of a word
processing program:
The document being processed has
been saved onto the disk.
Fail-safe states help separate the
issues of safety and reliability.
Even if a system is unreliable, it
can always be made to fail in a fail-
safe state.
03/08/10 17
17
Safety and Reliability
For a safety-critical system
No fail-safe state exists.
Consider the navigation system on an
aircraft:
When the navigation system fails:
Shutting down the engine can be of
little help!
As a result, for a safety-critical
system:
The only way to achieve safety is by
making it reliable.
03/08/10 18
18
Safety-Critical
Systems
A safety-critical system is one
for which a failure can cause
severe damages.
A safety-critical system does
not have any fail-safe states:
Safety can only be ensured
through increased reliability.
03/08/10 19
19
How to Design a Highly
Reliable System?
Error Avoidance
Error Detection and
Removing
Fault Tolerance
03/08/10 20
20
Fault Tolerance in RT
System
The essential idea:
Provide redundancy
Hardware Fault-Tolerance:
Masks the effects of a hardware
fault.
Software Fault-Tolerance:
Masks the effects of a program
fault.
03/08/10 21
21
Fault Tolerance in RT
System
Hardware FT:
Built in self test (BIST)
Triple modular redundancy
Software FT:
N-Version programming
Recovery Blocks
03/08/10 22
22
Triple Modular Redundancy
C1, C2 and C3 are redundant copies of same component
03/08/10 23
23
N-version Programming
Software fault tolerance technique
inspired by TMR of hardware:
Different teams are employed to
develop the same software.
Unsatisfactory performance in
practice.
Reason: Faults are correlated in the
different versions.
All versions fail for similar reasons.
03/08/10 24
24
Recovery Blocks
Software Fault Tolerance using recovery blocks
03/08/10 25
25
Modern Embedded Systems
Embedded systems incorporate:
Application-specific hardware (ASICs, FPGAs
etc.)
performance, low power
Programmable processors: DSPs, controllers etc.
Mechanical transducers and actuators
Application
Specific HW
Processor
Cores
Analog
I/O
Memory
03/08/10 26
26
Block Diagram of An
Embedded System
Processor
control panel
Real-time
OS
controller
processes
UI
processes
ASIC
Programmable
DSP
Programmable
DSP
DSP
Assembly
Code
DSP
Assembly
Code
Dual-ported
RAM
CODEC
03/08/10 27
27
Some Basic Issues
(Lecture 3)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 28
28
Why Have an OS in an
Embedded Device?
Support for:
Multitasking, scheduling, and synchronization
Timing aspects.
Memory management
File systems
Networking
Graphics displays
Interfacing wide range of I/O devices
Scheduling and buffering of I/O operations
Security and power Management
03/08/10 29
29
Example: A recent cell phone operating system
contained over five million lines of code!
Few, if any projects will have the time and
funding:
To develop all of this code on their own!
Typical Embedded OS license fees are a few
dollars per device -- less than a desktop OS
Some very simple low-end devices might not need
an OS:
But new devices are getting more complex.
Why Have an OS in an
Embedded Device?
03/08/10 30
30
What is Actually Being Used?
What Types of Processors are used?
What Operating Systems are used?
What Programming Languages are
used?
Will examine data from a 2006 Market
Survey of design engineers:
Embedded Systems Design Magazine.
03/08/10 31
31
Processor Bit Size Used in
New Embedded Designs
Data was derived from EETimes and Embedded Systems Design Magazine 2006 Embedded Market Survey
0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00%
4-bit
8-bit
16-bit
32-bit
64-bit
03/08/10 32
32
Processor Architectures Widely
Used in New Embedded Designs
ARM
X86
PowerPC
MIPS
Xscale (ARM)
Renesas SuperH
03/08/10 33
33
32-64 bit Annual
Processor Sales
0.00% 5.00% 10.00% 15.00% 20.00% 25.00% 30.00% 35.00% 40.00%
PowerPC
SuperH
MIPS
X86
ARM
Processor Sales Volume
Based on 2002 sales data
03/08/10 34
34
Number of Processors Used
in New Embedded Designs
Data was derived from EETimes and Embedded Systems Design Magazine 2006 Embedded Market Survey
0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00%
More Than 5
3-5 Processors
2 Processors
1 Processor
03/08/10 35
35
Processor Selection Issues
Software Support
OS, Compilers, Debug Tools, Applications
Price
Performance
Power
Battery Life (MIPS/Watt), Cooling
(Fan?)
Desktop PC 100 W vs. Battery power 200 mw
Availability
Long term availability, Multiple Vendors?
03/08/10 36
36
Use of Real-Time OS Kernels
in New Embedded Designs
0.00% 10.00% 20.00% 30.00% 40.00% 50.00%
Open Source
Internally Developed
None
Commercial OS
Data was derived from EETimes and Embedded Systems Design Magazine 2006 Embedded Market Survey
03/08/10 37
37
Pros and Cons of Open
Source OS
Embedded devices are
extremely cost sensitive:
Even a $1 license fee per device
can make a product
uncompetitive.
For satisfactory performance:
The source code often needs to
be fine tuned.
03/08/10 38
38
Open Source OS: Cons
Free OS can increase product development
cost:
More time to develop device drivers, increased
labor cost.
More than offset the commercial OS license
fees saved.
Some other licenses may still required:
Encoders & decoders, encryption, media player
Open source license model may require:
That you publish your devices source code
03/08/10 39
39
Commercial Operating Systems
used in New Embedded Designs
0.00% 5.00% 10.00% 15.00% 20.00% 25.00% 30.00%
Others
Palm
Green Hills
Symbian
Wind River
Microsoft Emb.
Data was derived from EETimes and Embedded Systems Design Magazine 2006 Embedded Market Survey
03/08/10 40
40
Programming Languages Used
in New Embedded Designs
0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 70.00%
Others
Assembly
Java
C#
C++
C
Data was derived from EETimes and Embedded Systems Design Magazine 2006 Embedded Market Survey
03/08/10 41
41
Future of Embedded
Systems
Use of multi-core processors:
Present operating systems and
tools do not make satisfactory
utilization of the multiple cores.
Support of wireless and mobile
Internet.
Power minimization.
03/08/10 42
42
Modelling Timing
Constraints
(Lecture 4)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 43
43
Types of Real-Time Systems
Real-time systems are different from
the traditional systems:
Tasks have deadlines associated with
them.
A classified based on the consequence
of a failure:
Hard real-time systems
Soft real-time systems
Firm real-time systems
03/08/10 44
44
Hard Real-Time Systems
If a deadline is not met:
The system is said to have failed.
The task deadlines are of the order of
micro or milliseconds.
Many hard real-time systems are safety-
critical.
Examples:
Industrial control applications
On-board computers
Robots
03/08/10 45
45
Firm Real-Time Systems
If a deadline is missed occasionally,
the system does not fail:
The results produced by a task after
the deadline are rejected.
Utility
D
Time
03/08/10 46
46
Firm Real-Time Systems
Examples:
A video conferencing application
A telemetry application
Satellite-based surveillance
applications
03/08/10 47
47
Soft Real-Time Systems
If a deadline is missed, the system
does not fail:
Only the performance of the system is
said to have degraded.
The utility of a result decreases with
time after the deadline.
Utility
D Time
03/08/10 48
48
Soft Real-Time Systems
Examples of soft real-time
systems:
Railway reservation system
Web browsing
In fact, all interactive applications
03/08/10 49
49
Types of Real-Time Tasks
Periodic:
Periodic tasks repeats after a certain
fixed time interval.
Sporadic:
Sporadic tasks recurs at random instants.
Aperiodic:
Same as sporadic except that minimum
separation between two instances can be
0.
03/08/10 50
50
Timing Constraints
A timing constraint:
Defined with respect to some
event.
An event:
Can occur at an instant of time
May also have duration
Generated either by the system
or its environment
03/08/10 51
51
Events in a Real-Time
System
Events in a real-time system
can be classified into:
Stimulus Events
Response Events
03/08/10 52
52
Stimulus Event
Generated by the environment:
Act on the system.
Typically asynchronous in nature:
Aperiodic
Can also be periodic
Example:
A user pressing a button on a
telephone set
Stimulus event acts on the telephone
system.
Telephone
System
03/08/10 53
53
Stimulus Event
cont
Periodic stimulus event example :
Periodic sensing of temperature in a
chemical plant.
03/08/10 54
54
Response Event
Produced by the system:
In response to some stimulus events
Example:
In a chemical plant as soon as the
temperature exceeds 100C,
The system responds by switching
off the heater.
03/08/10 55
55
Classification of Timing
Constraints
Classification of the timing
constraints in a system:
Can help us to quickly identify
these from a problem
description.
03/08/10 56
56
Classification of Timing
Constraints
Different timing constraints
can broadly be classified into:
Performance constraints
Behavioral constraints
03/08/10 57
57
Types of Timing
Constraints
Performance constraints:
Imposed on the response of
the system.
Behavioral constraints:
Imposed on the stimuli
generated by the
environment.
03/08/10 58
58
Types of Timing
Constraints
Both performance and
behaviorial constraints can
be classified into:
Delay Constraints
Deadline Constraints
Duration Constraints
03/08/10 59
59
Delay Constraint
Expresses minimum time delay:
Allowed between the occurrence
of two arbitrary events e1 and e2
t(e2) - t(e1) d
if e2 occurs earlier than d then a
delay violation would occur.
t(e1) t(e2)
d
03/08/10 60
60
Deadline Constraint
Expresses the maximum
permissible separation:
Between any two arbitrary
events.
t(e2) - t(e1) d
03/08/10 61
61
Duration Constraint
A duration constraint on an
event:
Specifies the time period over
which the event acts.
A duration constraint can be:
minimum type
maximum type.
03/08/10 62
62
Duration Constraints
Minumum:
Once a duration event starts:
It must not end before a certain
minimum time.
Maximum:
Once a duration event starts:
It must end before a certain maximum
time.
t(e1) t(e2)
Max
t(e1)
t(e2)
Min
03/08/10 63
63
Timing Constraints in
an Example System
PSTN
03/08/10 64
64
SS Deadline Example
Deadline is defined between two
stimuli.
A behavioral constraint.
Imposed on stimulus.
Once a user completes dialling a digit,
He must dial the next digit within the
next 5 seconds.
Otherwise an idle tone is produced.
PSTN
03/08/10 65
65
RS Deadline Example
Deadline is defined on the stimulus
from the respective response event.
A behaviorial constraint.
Imposed on stimulus.
Once the dial tone appears:
The first digit must be dialed within 30
seconds,
Otherwise the system enters
an idle state and an idle tone is produced
PSTN
03/08/10 66
66
RR Deadline Example
Deadline is defined on the
response from another response.
A performance constraint.
Imposed on response.
Once ring tone is given to the callee,
Ring back tone must be given to the
caller within two seconds,
Otherwise the call is terminated.
PSTN
03/08/10 67
67
SR Deadline Example
Deadline is defined on the response
from the respective stimulus.
A performance constraint.
Imposed on response.
Once the receiver of the hand set is
lifted:
The dial tone must be produced by the
system within 2 seconds,
otherwise a beeping sound is produced
until the handset is replaced.
PSTN
03/08/10 68
68
SS Type Delay
Constraint
A behaviorial constraint.
Imposed on the environment.
Once a digit is dialled,
The next digit should be dialled
after at least 1 second.
Otherwise, a beeping sound is
produced until the call initiator
replaces the handset.
PSTN
03/08/10 69
69
Duration Constraint
Specifies the time interval over which the
event acts.
If you press the button of the handset for
less than 15 seconds,
It connects to the local operator.
If you press the button for any duration
lasting between 15 to 30 seconds,
It connects to the international operator.
If you keep the button pressed for more
than 30 seconds,
Then on releasing it would produce the dial
tone.
03/08/10 70
70
Timing Constraints
Behaviorial Constraints Performance Constraints
Delay Deadline Duration
RR SR RR SR
Delay Deadline Duration
RS SS RS SS
03/08/10 71
71
Modelling Timing
Constraints (cont)
(Lecture 5)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 72
72
Why Model Timing
Constraints?
Modelling time constraints in a
system:
Can serve as a formal specification
of the system.
May be used to automatically
generate code.
Can help to understand real-time
behavior.
03/08/10 73
73
Modelling Time
Constraints
Several approaches can be used.
We discuss an approach based on FSM
proposed by Dasarathy (IEEE TSE, 1985).
A state is defined in terms of the
values assumed by some attributes.
The states of an elevator may be denoted
in terms of its directions of motion.
Values of the attribute direction define
the states up, down, and stationery.
03/08/10 74
74
FSM
Transition is annotated with:
Enabling event
Action that takes place during
transition
S1 S2
e1/set-timer(20 msec)
03/08/10 75
75
Model of SS Deadline
Constraint
Once a user completes dialling a digit,
He must dial the next digit within the next
5 seconds.
Otherwise an idle tone is produced.
Await
second
digit
Await
Next
digit
Await
Caller
Onhook
03/08/10 76
76
Model of RS Deadline
Constraint
Once the dial tone appears:
The first digit must be dialed within 30 seconds,
Otherwise the system enters
an idle state and an idle tone is produced
Await
first digit
Await
Next
digit
Await
Caller
Onhook
03/08/10 77
77
Model of SR Deadline
Constraint
Once the receiver is lifted from the hand set:
The dial tone must be produced by the system
within 2 seconds,
Otherwise a beeping sound is produced until the
handset is replaced.
Await
Dial
tone
Await
first
digit
Await
Receiver
Onhook
03/08/10 78
78
Model of RR Deadline
Constraint
Once ring tone is given to the callee,
Ring back tone must be given to the caller within
two seconds,
Otherwise the call is terminated.
Await
Ringback
tone
Await
first
digit
Await
Receiver
Onhook
03/08/10 79
79
Model of Delay
Constraint
Once a digit is dialled,
The next digit should be dialled after at least 1
second.
Otherwise, a beeping sound is produced until the
call initiator replaces the handset.
Await
next
event
Await
next
digit
Await
Receiver
Onhook
03/08/10 80
80
Duration Constraint
Example
If you press the button of the handset
for less than 15 seconds,
It connects to the local operator.
If you press the button for any duration
lasting between 15 to 30 seconds,
It connects to the international operator.
If you keep the button pressed for more
than 30 seconds,
Then on releasing it would produce the
dial tone.
03/08/10 81
81
Model Construction for
Duration Example
To construct the model:
First identify the deadline and
delay constraints.
The constraints are for which
events?
03/08/10 82
82
Model of Duration
Constraint Example
Await
event1
Local
operator
Internl
operator
Await
event2
Await
Button
release
Dial
tone
03/08/10 83
83
Exercise 1
When the temperature of a
chemical reactor rises above
TC:
The heater needs to be shut-
off within 10mSec
Otherwise, the entire plant is
shut-off.
03/08/10 84
84
Exercise 2
Identify and model time
constraints:
Once the start switch of a
wash machine is pressed,
Stirring commences:
Continues until a preset timer
expires or the stop button is
pressed by the user.
03/08/10 85
85
Basics of Real-Time
Task Scheduling
(Lecture 6)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 86
86
Introduction
Real-time tasks are generated due
to certain event occurrences:
Either internal or external events.
Example:
A task may get generated due to a
temperature sensor sensing high-
level.
When a task gets generated:
It is said to be released or arrived .
03/08/10 87
87
Real-Time Task Scheduling
Task Scheduling:
Essentially refers to the order in
which the various tasks are to be
executed.
Primary means adopted by an
operating system to meet task
deadlines.
So, scheduling is an important
problem in RTOS.
03/08/10 88
88
Task Instance
A task typically recurs a large
number of times:
Each time triggerred by an event
Each time a task recurs, an
instance of the task is said to have
been generated.
The ith time a task T recurs:
Task instance Ti is said to have
arrived.
03/08/10 89
89
Relative and Absolute
Deadlines
Absolute deadline:
Counted from time 0.
Relative deadline:
Counted from time of occurrence of
task.
abs
deadline
relative
0
t
d
03/08/10 90
90
Response Time
The time from the occurrence of the
event generating the task:
To the time results are produced by the
task.
Response time
0
e
t
03/08/10 91
91
Response Time
For soft real-time tasks:
The response time needs to be
minimized.
For hard real-time tasks:
As long as the task completes
within its deadline,
No advantage of completing it any
early.
03/08/10 92
92
Types of Real-Time Tasks
Periodic:
Periodic tasks repeats after a certain
fixed time interval.
A vast majority of real-time tasks are
periodic.
Sporadic:
Sporadic tasks recurs at random instants.
Aperiodic:
Same as sporadic except that minimum
separation between two instances can be
0.
03/08/10 93
93
Phase of a Periodic
Task
Phase for a periodic task:
The time from 0 till the occurrence of
the first instance of the task.
Denoted by .

0
e1
time
e2 e3
P P
03/08/10 94
94
Phase Example
The track correction task starts
2000 mSecs after the launch of
the rocket:
Periodically recurs every 50 milli
Seconds then on.
Each instance of the task requires
a processing time of 8 mSecs and
its relative deadline is 50 mSecs.

0
e1
time e2
e3
P P
03/08/10 95
95
Important Scheduling
Terminologies
Valid Schedule:
At most one task is assigned to a
processor at a time.
No task is scheduled before it is ready.
Precedence and resource constraints of
all tasks are satisfied.
Feasible Schedule:
Valid schedule is one in which all tasks
meet their respective time constraints.
03/08/10 96
96
Important Scheduling
Terminologies
Proficient Scheduler:
A scheduler S1 is as proficient as another
Scheduler S2:
If whichever tasks that S2 can feasibly
schedule so can S1, but not vice versa.
Equally proficient schedulers:
If a task set scheduled by one can also be
scheduled by the other and vice versa.
03/08/10 97
97
Important Scheduling
Terminologies
Optimal Scheduler:
An optimal scheduler can
feasibly schedule any task set
that can be scheduled by any
other scheduler.
03/08/10 98
98
Scheduling Points
At these points on time line:
Scheduler makes decision regarding
which task to be run next.
Clock-driven:
Scheduling points are defined by
interrupts from a periodic timer.
Event-driven:
Scheduling points defined by task
completion and generation events.
03/08/10 99
99
Real-Time Task
Scheduling cont
Significant amount of research
has been carried out to develop
schedulers for real-time tasks:
Schedulers for uniprocessors
Schedulers for multiprocessors
and distributed systems.
03/08/10 100
100
Task Scheduling on
Uniprocessors
Focus of much research
during the 1970s and 80s.
Real-time task schedulers can
be broadly classified into:
Clock-driven
Event-driven
03/08/10 101
101
Clock-Driven Scheduling:
Basics
Decision regarding which job to
run next is made only at clock
interrupt instants:
Timers are used to determine the
scheduling points.
Which task to be run when and
for how long is stored in a table.
03/08/10 102
102
Clock-Driven Scheduling
Popular examples:
Table-driven scheduler
Cyclic scheduler
Round robin scheduling is
also an example of clock-
driven scheduling.
03/08/10 103
103
Clock-Driven Schedulers
Also called offline schedulers
and also static schedulers:
Used extensively in embedded
applications.
Pro: Very space and time
efficient.
Con: Cannot handle sporadic or
aperiodic tasks.
03/08/10 104
104
Table-Driven
Scheduling
TaskStart timeStop time
T1 0 100
T2 101 150
T3 151 225
03/08/10 105
105
Cyclic Schedulers
(Lecture 7)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 106
106
Task Scheduling on
Uniprocessors
Focus of much research
during the 1970s and 80s.
Real-time task schedulers can
be broadly classified into:
Clock-driven
Event-driven
03/08/10 107
107
Clock-Driven Scheduling
For scheduling n periodic
tasks:
The schedule is stored in a
table.
Repeated forever.
The designer needs to develop a
schedule for what period?
LCM(P1,P2,...,Pn).
03/08/10 108
108
Clock-Driven Scheduling
Used in low cost applications:
Pro:
Compact: Require very little storage
space
Efficient: Incur very little runtime
overhead.
Con:
Inflexible: Very difficult to accommodate
dynamic tasks.
The simplest is table-driven scheduler.
03/08/10 109
109
Disadvantage of Table-
Driven Schedulers
When the number of tasks are
large:
Requires setting a timer large
number of times.
The overhead is significant:
Remember that task instance runs
only for a few milli or microseconds.
03/08/10 110
110
Cyclic Schedulers
Cyclic schedulers are very
popular:
Extensively being used in the
industry.
A large majority of small
embedded applications being
manufactured at present use
cyclic schedulers.
03/08/10 111
Cyclic Schedulers
The schedule is stored for one
major cycle:
Precomputed schedule is repeated.
A major cycle is divided into:
One or more minor cycles (frames).
Scheduling points for a cyclic
scheduler:
Occur at the beginning of frames.
03/08/10 112
Major Cycle
In each major cycle:
The different tasks recur at
identical time points.
Major cycle Major cycle
Frame (minor
cycle)
03/08/10 113
Major Cycle
The major cycle of a set of tasks
ST={T1,T2,...,Tn} is at least:
LCM(p1,p2,...,pn)
Holds even when tasks have
arbitrary phasings.
Can be greater than LCM when F
does not divide major cycle.
03/08/10 114
114
Minor Cycle (Frame)
Each major cycle:
Usually contains an integral
number of minor cycles
(frames).
Frame boundaries are
marked:
Through interrupts from a
periodic timer.
03/08/10 115
A Typical Schedule
T2 F3
T3 F2
T2 F1
Task Frame
03/08/10 116
116
Minor Cycle (Frame)
Each task is assigned to run in
one or more frames.
Frame size (F) is an important
design parameter while using
cyclic scheduler.
A selected frame size has to
satisfy a few constraints.
03/08/10 117
117
Selecting an Appropriate Frame Size (F)
Minimum context switch:
F should be larger than each task size.
Sets a lower bound.
Minimization of table size:
F should squarely divide major cycle.
Allows only a few discrete frame
size.
Satisfaction of task deadline:
Between the arrival of a task and its
deadline:
At least one full frame must exist.
Sets an upper bound
03/08/10 118
118
Minimum Context Switch
A task instance must complete
running within its assigned
frame:
A task might otherwise have to be
suspended and restarted in a later
frame.
The scheduler would get invoked
many times.
03/08/10 119
Minimum Context Switch
To avoid unnecessary context switches:
Selected frame size should be larger
than execution time of each task.
Sets a lower bound for frame size.
03/08/10 120
120
Minimization of Table Size
Unless the minor cycle squarely
divides the major cycle:
Storing schedule for one major
cycle would not be sufficient.
Schedules in the major cycle would
not repeat:
This would
make the
size of the
table large.
Major cycle Major cycle
Frame
03/08/10 121
Major cycle Major cycle
Frame
03/08/10 122
122
Satisfaction of Task Deadline
Between the arrival of a task and
its deadline:
At least one full frame must exist.
If there is not even a single frame:
The task would miss its deadline,
By the time it could be taken up for
scheduling, the deadline could be
imminent.
ti di
F F
03/08/10 123
123
Satisfaction of Task
Deadline
The worst case for a task occurs
when the task arrives just after a
frame has started.
ti di
ti
di
ti would miss deadline
ti deadline can be met
03/08/10 124
124
Satisfaction of Task
Deadline
The minimum separation of an
arrival time for ti from a frame
start:
GCD(F,pi)
Thus, for all ti
2F-GCD(F,pi) di must be satisfied
ti di
F F
03/08/10 125
Selection of a Suitable Frame Size
Several frame sizes may satisfy the constraints:
Plausible frames.
A plausible frame size has been found:
Does not mean that the task set is schedulable.
The smallest plausible frame size needs to be chosen:
The chances of successful scheduling is higher.
03/08/10 126
126
Example 1
Compute a suitable frame
size for the following task
set:
e1 = 1, p1=4, d1=4
e2 = 1, p2=5, d2=5
e3 = 1.5, p3=20, d3=20
03/08/10 127
127
Example 2
Compute a suitable frame
size for the following task
set:
e1 = 1, p1=4, d1=4
e2 = 2, p2=6, d2=6
e3 = 3, p3=20, d3=20
03/08/10 128
What If None of the Frame
Sizes is Suitable?
Possible culprit is a task with large
execution time e.g. (20,100,100):
Prevents a smaller frame from being chosen.
Try splitting task with large execution time into two or three sub-
tasks.
Example: T1=(20,100,100) can be split into
(10,100,100) and (10,100,100).
03/08/10 129
129
Pros and Cons of Cyclic
Schedulers
As number of tasks increases:
It becomes very difficult to
select a suitable frame size.
Results in suboptimal schedules.
CPU times in many frames are
wasted.
Results in poor schedulability.
03/08/10 130
A Generalized Task Scheduler
Many practical systems:
Consist of a mixture of periodic, aperiodic, and sporadic tasks.
How can sporadic and aperiodic tasks be scheduled using a
cyclic scheduler?
Use the slack time and the unused frames:
As and when the spordic and aperiodic tasks arise.
03/08/10 131
cyclic-scheduler() {
current-task T = SchedTab[k];
k = k + 1;
k = k mod N;
dispatch-current-Task(T);
schedule-sporadic-tasks();
schedule-aperiodic-tasks();
idle(),
}
Cyclic Scheduler:
Pseudocode
03/08/10 132
132
Event-Driven
Scheduling
(Lecture 8)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 133
Event-Driven Schedulers
Unlike clock-driven
schedulers:
These can handle sporadic
and aperiodic tasks.
Used in more complex
applications.
03/08/10 134
134
Event-Driven Scheduling
Scheduling points:
Defined by task completion and arrival
events.
Preemptive schedulers:
On arrival of a higher priority task, the
running task may be preempted.
Simplest event-driven scheduler:
Foreground-Background Scheduler
03/08/10 135
135
Scheduling Points for
Event-Driven Schedulers
Scheduling decisions are
made when certain events
occur:
A task becoming ready
A task completing execution
03/08/10 136
Time-Sliced Round Robin Scheduling: A
Hybrid Scheduler
Time-sliced round robin schedulers:
Commonly used in the traditional operating
systems.
We shall not discuss much about it.
Scheduling points:
Tasks completing or suspending
Clock interrupts
Less proficient than cyclic and table-driven
schedulers:
Foreground task priorities not taken into
account.
03/08/10 137
137
Event-Driven Schedulers
These are called preemptive
schedulers:
When a higher priority task
becomes ready any executing
lower priority task is preempted.
These are greedy schedulers:
Never keep the processor idle if a
task is ready.
03/08/10 138
138
Preemptive Scheduling
Independent tasks execute
on a uniprocessor.
Two algorithms pretty much
summarise the important
results in this case:
EDF
RMA
03/08/10 139
139
Foreground-Background Scheduler
Real-time tasks are run as foreground tasks.
Sporadic, aperiodic, and non-real-time tasks
are run as background tasks.
Among the foreground tasks, at every
scheduling point:
The highest priority foreground task is
scheduled.
A background task can run:
When no foreground task is ready.
03/08/10 140
Background Task Completion Time
Let T
B
be the only background task
Its processing time be e
B
The time for it to complete would be:

=
i
i
B
p
e
e
ctB
1
03/08/10 141
Example 1
Consider a real-time system:
Tasks are scheduled using foreground-background scheduling.
There is only one periodic foreground task:
P1=50 msec, e1=100 msec, d1=100 msec
Background task TB, eB=1020msec.
Compute the completion time for the background task.
03/08/10 142
Example 2
On account of every context
switch :
Assume an overhead of 1 msec.
Compute the completion time of
TB.
03/08/10 143
143
Event-Driven Static
Priority Schedulers
The task priorities once
assigned by the programmer:
Do not change during runtime.
RMA (Rate Monotonic Algorithm)
is the optimal static priority
scheduling algorithm.
03/08/10 144
144
Event-Driven Dynamic
Schedulers
The task priorities can change
during runtime:
Based on the relative urgency
of completion of tasks.
EDF (Earliest Deadline First) is
the optimal uniprocessor
scheduling algorithm.
03/08/10 145
145
Event-Driven Schedulers
First let us consider the
simplest scenario:
Uniprocessor
Independent tasks:
Tasks do not share resources
There is no precedence ordering
among the tasks
03/08/10 146
146
EDF
EDF is the optimal uniprocessor
scheduling algorithm:
If EDF cannot feasibly schedule
a set of tasks:
Then, there can exist no other
scheduling algorithm to do that.
Can schedule both periodic and
aperiodic tasks.
03/08/10 147
EDF
At any scheduling point:
The scheduler dispatches the task
having the shortest deadline among
all ready tasks.
Preempts any task (with longer
deadline) that might be running.
03/08/10 148
EDF Schedulability Check
Sum of utilizations due to all tasks is less
than one:
Both the necessary and sufficient
condition for schedulability.
1
1
s =

=
i u
p
e n
i
i
i
03/08/10 149
149
Example 1
Compute a suitable frame
size for the following task
set:
e1 = 1, p1=4, d1=4
e2 = 1, p2=5, d2=5
e3 = 5, p3=20, d3=20
03/08/10 150
Is EDF Really a Dynamic Priority
Scheduling Algorithm?
If EDF were a dynamic priority
algorithm:
At any point of time, the priority value
of a task can be determined.
Also we should be able to show how it
changes with time.
03/08/10 151
Dynamic Priority
The longer a task waits in ready queue:
The higher the chance (probability) of
its being taken up for scheduling.
We can imagine a virtual priority value
associated with a task:
Keeps increasing with time until the task is
taken up for scheduling
03/08/10 152
152
EDF: An Evaluation
EDF is:
Simple
Optimal
But, is rarely used:
No commercial operating system
directly supports EDF scheduling.
Why?
Let us examine the disadvantages of
EDF.
03/08/10 153
Disadvantages of EDF
Main disadvantages of EDF:
Poor transient overload handling
Runtime inefficiency
Poor support for resource sharing
among tasks.
03/08/10 154
154
Poor Transient Overload Handling
Why does transient overload occur?
A task might take more time than
estimated.
Too many tasks might arise on some
event.
When an executing task takes more
time:
It is extremely difficult to predict
which task would miss its deadline.
03/08/10 155
155
Runtime Inefficiency
EDF is not very efficient:
In an implementation of EDF:
The tasks need to be maintained
sorted.
A priority queue based on task
deadlines is required.
The complexity of maintaining a
priority queue is:
log(n), n is the number of tasks.
03/08/10 156
156
Poor Resource Sharing Support
Support for tasks to share non-
premptable resources (critical
sections):
Extremely inefficient.
Tasks often miss their deadlines.
We shall elaborate this problem
later in our discussions.
03/08/10 157
157
General EDF Schedulability
When task deadlines differ from task
periods:
The schedulability criterion needs to be
generalized:
If pi<di, it becomes sufficient:
But not a necessary condition
1
) , min(
1
s

=
n
i
i i
i
d p
e
03/08/10 158
158
Implementation of EDF
Simple FIFO queue:
A freshly arriving task is
inserted at the end of the
queue.
Sorted queue:
Priority queue
03/08/10 159
159
An Efficient
Implementation of EDF
Maximum number of distinct
deadlines is fixed.
A queue is maintained for each
distinct deadline.
When a task arrives:
Its absolute deadline is
computed and inserted in Q.
03/08/10 160
Efficient EDF Implementation
160
Task Queue
Deadline
Levels
1
2
3
4
5
6
03/08/10 161
MLF: Variation of EDF
Minimum Laxity First:
Laxity= relative deadline time required to complete task
execution
The task that is most likely to fail first is assigned highest
priority.
EDF=MLF when tasks have equal execution times and
deadlines.
Bonus problem:
Analyze performance of MLF wrt EDF.
03/08/10 162
162
Rate Monotonic
Scheduling
(Lecture 9)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 163
163
RMA
The priority of a task is
proportional to its frequency.
The higher the frequency (or lower
the period) of a task, the higher is
its priority.
Frequency
Priority
03/08/10 164
164
RMA
The optimal uniprocessor static
priority scheduling algorithm:
If RMA cannot schedule a set of
periodic tasks:
No other static priority scheduling
algorithm can.
Schedulability test:
1. Utilization Bound
03/08/10 165
Utilization Bound 1
Sum of utilization due to tasks is less than
one:
Necessary condition for schedulability:
But not the sufficient condition.
1
1
s =

=
i u
p
e n
i
i
i
03/08/10 166
166
Sufficient Condition for RMA
Schedulability
Utilization bound II (Liu and Layland
1971):
ui is the processor utilization due to task Ti
n is the number of tasks
Utilization
bound
Number of tasks
) 1 2 (
1
s

n
n ui
03/08/10 167
Liu and Layland Bound
The maximum utilization for a schedulable
task set:
Falls as the number of tasks increases.
For a very large number of tasks:
What is the maximum utilization permitted?
692 . 0 2 ln ) 1 2 (
1
= = s

i u
03/08/10 168
168
Example 1
Check whether the following
task set is schedulable using
RMA:
T1: e1 = 1, p1=4, d1=4
T2: e2 = 2, p2=6, d2=6
T3: e3 = 3, p3=20, d3=20
03/08/10 169
Solution to Example 1
Therefore the task set is schedulable.
1
15
11
60
44
20
3
3
1
4
1
1
s = = + + = =

=
i u
p
e n
i
i
i
778 . 0 733 . 0
15
11
778 . 0 ) 1 259 . 1 ( 3 ) 1 2 ( 3 ) 1 2 (
3
1 1
s = =
= = =

i u
n
n
03/08/10 170
170
Liu and Layland Condition
The upper bound on utilization converges
to 69% (ln2):
As the number of tasks approaches
infinity
Liu and Layland's condition is conservative:
If a set of tasks passes Liu and Layland
test, then it is definitely RMA schedulable.
But, even if a task set fails Liu-Layland
test:
Still it may be RMA schedulable (completion
time theorem).
03/08/10 171
171
Example 2
Check RMA schedulability of three
periodic tasks:
T1: e1=20mSec, p1= d1= 100mSec
T2: e2=40msec, p2= d2= 150mSec
T3: e3=100mSec, p3= d3= 350mSec
The utilization for these 3 tasks are
0.2+0.267+0.286=0.753
Liu-Layland bound=3((2)
1/3
-1) =0.779
Therefore, the tasks are schedulable.
03/08/10 172
172
Some More Issues in
RMA Scheduling
(Lecture 10)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 173
RMA Schedulability
Utilization bound 1:
Utilization bound 2:
(Liu-Layland)
Schedulability check 3: Liu and Lehoczkys Completion
Time Theorem
1
1
s =

=
i u
p
e n
i
i
i
) 1 2 (
1
s

n
n ui
U1
U2
03/08/10 174
174
RMA Schedulability Test- III
Completion time theorem (Liu
and Lehoczky 1989):
If each of a set of tasks
individually meets its first
deadline under zero phasing:
Then the task set is RMA
schedulable for all task phasings.
03/08/10 175
175
Completion Time Theorem
(Liu and Lehoczky)
How to check schedulability of a
task set?
Consider zero phasing for all tasks.
Draw up the schedules till the first
deadline of each task.
Observe if each task is schedulable.
Then the task set is schedulable.
Drawing the schedule is cumbersome:
When the number of tasks is large.
03/08/10 176
Time in milliseconds
Completion Time Theorem: Basic Premise
Worst case completion time for a task:
Occurs when it is in phase with its higher
priority tasks.
176
T1=10,30 =0
T2=60,120 =0
T1=10,30 =20
T2=60,120 =0
(a) T
1
is in phase with T
2
T
2
T
2
T
1
20 30 50 60
T
2
T
1
Time in milliseconds 80
(b) T
1
has a 20 ms phase lag with T
2
T
1
T
1
T
1
T
2
T
2
T
2
10 30 40 60 70 90
03/08/10 177
177
Testing Liu and
Lehoczky's Criterion
03/08/10 178
178
Example 3
Consider three periodic tasks
T1: e1=20mSec, p1=100mSec
T2: e2=30mSec, p2=150mSec
T3: e3=60mSec, p3=200mSec
Check whether they are RMA
schedulable.
03/08/10 179
Answer 3
Checking for Liu-Layland criterion:
The criterion satisfied:
Therefore, the task set is schedulable.
78 . 0 7 . 0
600
420
200
60
150
30
100
20
1
< = = + + = =

=
i u
p
e n
i
i
i
03/08/10 180
180
Example 4
Consider three periodic tasks
T1: e1=20mSec, p1=100mSec
T2: e2=30mSec, p2=150mSec
T3: e3=90mSec, p3=200mSec
Check whether the tasks are
RMA schedulable.
03/08/10 181
Answer 4
Checking for Liu-Layland test:
Fails Liu-Layland test:
Before concluding about schedulability, let us
check Liu-Lehoczky criterion.
78 . 0 85 . 0
600
510
200
90
150
30
100
20
1
> = = + + = =

=
i u
p
e n
i
i
i
03/08/10 182
Checking for Lehoczkys
Criterion
182
T
1
20 100
Deadline for T
1
(a) T
1
meets its first deadline
50
T
2
(b) T
2
meets its first deadline
Deadline for T
2
150
T
3
T
1
T
2
Deadline for T
3
T
3
120 190
(c) T
3
meets its first deadline
T1: e1=20mSec, p1=100mSec
T2: e2=30mSec, p2=150mSec
T3: e3=90mSec, p3=200mSec
03/08/10 183
Checking for Lehoczkys
Criterion
For T1: 20< 100
Satisfied
For T2: 30+20*2 =70<150
Satisfied
For T3: 90 + 20*2+30*2=190<200
Satisfied
The task set is schedulable.
T1: e1=20mSec, p1=100mSec
T2: e2=30mSec, p2=150mSec
T3: e3=90mSec, p3=200mSec
03/08/10 184
Practice Problem
Test whether the following task set
is RMA schedulable.
T1: e1=10, p1=d1=50, 1=100
T2: e2=20,p2=d2=60, 2=0
T3: e3=30, p3=d3=80, 3=50
03/08/10 185
Further Tests?
What if a task set fails Liu-Lehoczkys criterion?
Can we conclude task set is unschedulable?
Or is it necessary to check further?
Liu-Lehoczky test checks the worst case scenario (zero
phasings).
It is possible that the worst case may not occur for a task set and
the task set may actually be schedulable.
03/08/10 186
A Basic Question
Construct an example for which EDF
and RMA produce different schedules.
Possibly simplest answer is:
Consider a task set unschedulable in RMA
but schedulable in EDF.
A nontrivial example would be:
Consider a task set in which a task is
preempted before completion.
03/08/10 187
Example
T1: e1=3,p1=8
T2: e2=6, p2=12
3 8 11
T1
T2
T1
RMA
3
9
T1 T2 T1
EDF
12 3 8 11
T1
T2
T1
RMA
12
03/08/10 188
188
RMA Under Transient
Overload
RMA is stable under transient
overload conditions:
When a task gets late:
It can be guaranteed that it will not
affect higher priority tasks.
Reason: Even when a task gets late
It must yield the CPU to a higher
priority task --- unlike EDF.
03/08/10 189
Implementation of RMA
A nave RMA implementation:
Maintain tasks in a FIFO Queue.
Insertion O(1)
Searching O(n)
A better implementation:
Maintain tasks in a priority Q
Insertion O(log(n))
Searching O(1)
Efficient implementation:
Multilevel feedback Q
03/08/10 190
Multi-Level Feedback Queue
190
Task Queue
Priority
Levels
1
2
3
4
5
6
Bonus Problem:
Analyze time
and space
complexity, etc.
and compare
with other
implementations
03/08/10 191
191
Deadline Monotonic
Scheduling and Other
Issues
(Lecture 11)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 192
192
RMA Schedulability of
Harmonically Related Tasks
A set of periodic tasks is
harmonically related, iff:
For every pair of tasks Ti and Tk:
If Pi>Pk, then Pi=n*Pk, where n is an
integer. (Example p1=10,p2=20,p3=60)
A set of harmonically related tasks is
RMA schedulable:
If the sum total of the utilization due
to the tasks is less than 1.
03/08/10 193
Schedulability of a Harmonic Task Set
By completion time theorem:
For harmonically related tasks:
Ceiling can be removed since the periods
are integral multiples.
So,
i k
k
i i
k
i p e
p
p
e s
(
(
(

=
*
1
1
1 ,
1
1
1
1
s
s +

=
i
k
p
e
or
p
e
p
e
i n
i
k i
k
i
i
03/08/10 194
Deadline Monotonic
Algorithm (DMA)
When task deadline and periods
are different, i.e., d
i
p
i
:
RMA is not an optimal scheduling
algorithm.
DMA is optimal for such task
sets
Essence of DMA:
Assign priorities based on task
deadlines.
194
03/08/10 195
Deadline Monotonic Algorithm
(DMA)
When do RMA and DMA produce
identical schedules?
Relative deadline of every task in a
task set is the same as its period.
For arbitrary relative deadlines:
DMA may produce a feasible
schedule even when RMA fails.
On the other hand, RMA will always
fail if DMA fails.
195
03/08/10 196
Exercise
Check for schedulability of following
tasks under RMA and DMA.
T
1
=(e
1
= 10 ms, p
1
= 50 ms, d
1
= 35 ms)
T
2
=(e
2
= 15 ms, p
2
=100 ms, d
2
= 20ms)
T
3
=(e
3
=20 ms, p
3
=200 ms,d
3
=200ms)
196
03/08/10 197
Answer
RMA: Checking Liu-Layland criterion
The task set is unschedulable
DMA completion time check:
T2 meets its first deadline: 15 < 20
T1 meets its first deadline: 15+20=35 <=35
T3 meets its first deadline: 15*2+10*4+20=90<200
The task set is schedulable.
1
1400
1590
200
20
20
15
35
10
1
> = + + = =

=
i u
p
e n
i
i
i
03/08/10 198
Overhead Due to Context
Switching
Context switching of tasks consumes
some time:
So far we neglected the overhead due to
context switching.
When a task arrives:
It preempts the currently running lower
priority task.
There may be no preemption if the CPU
was idle or a higher priority task was
running.
198
03/08/10 199
Overhead Due to Context
Switching
In the worst case, each task incurs at
most two context switches:
1. When it runs possibly preempting the
currently running task.
2. When it completes.
Let the context switching time be
constant and equal c ms.
Effectively, the execution time of
each task increases to (e
i
+ 2*c)
199
T1 T1 T1 T2 T2 T2
10 30 40 60 70 90
03/08/10 200
Example
Assume 3 periodic tasks:
T1: e1=10mSec, p1= d1= 50mSec
T2: e2=25msec, p2= d2= 150mSec
T3: e3=50mSec, p3= d3= 200mSec
Assume context switching time = 1msec
Determine whether the task set is
schedulable.
03/08/10 201
Answer
Effect of context switch:
Execution time of each task increases
at most by 2 msec.
Task T1: 12msec <50 mSec >>Schedulable
Task T2: 27+ 12*3=63<150 msec
>>Schedulable
Task T3: 52+ 12*4 + 27*2 =154<200msec
>>Schedulable
T1: e1=10mSec,
p1= d1= 50mS
T2: e2=25msec,
p2=d2= 150msec
T3: e3=50mSec,
p3= d3= 200mSec
03/08/10 202
Practice Problem
Check for schedulability of following
tasks under RMA.
T
1
=(e
1
= 10 ms, d
1
= p
1
= 50 ms)
T
2
=(e
2
= 5 ms, d
2
= p
2
=20 ms)
T
3
=(e
3
=9 ms, d
3
= p
3
=30 ms)
Assume that context switch overhead
is 1 ms.
202
03/08/10 203
Self Suspension
When does a task suspend execution?
It performs input/output operations
It is waiting for some event to occur
Self-suspension introduces an additional
scheduling point:
The OS removes the self-suspended task
from the ready queue and places it in the
blocked queue.
The OS then dispatches the next eligible
task.
203
03/08/10 204
Scheduling Points
Scheduling points need to be
redefined:
Task completion,
Task arrival,
Self-suspension events.
For simplicity let us assume :
A task undergoes at most a single
self suspension.
204
03/08/10 205
Self Suspension
bt
i
:
Delay that task T
i
incurs due its own self
suspension and that of all higher priority
tasks.
b
i
:
Worst case self suspension time of task T
i
205

=
+ =
1
1
) , min(
i
k
k k i i b e b bt
03/08/10 206
Revised RMA Condition
Lehoczkys criterion needs to be
modified to consider self suspension:
If a task undergoes multiple self
suspensions:
Then expression needs to be
changed.
206
i k
k
i i
k
i i p e
p
p
bt e s
(
(
(

+ +

=
*
1
1
03/08/10 207
Exercise
Consider the following set of
periodic real-time tasks:
T
1
= (e
1
=10 ms, p
1
=50 ms)
T2 = (e2=25 ms, p2=150 ms)
T
3
= (e3=50 ms, p3=200 ms)
self-suspension times: b1= 3 ms,
b2=3 ms and b3= 5 ms.
Determine whether the tasks are
schedulable using RMA.
207
03/08/10 208
Answer
The tasks are already ordered
according to their priorities.
Applying the revised RMA condition,
For T
1
:
T
1
will meet its deadline
For T2:
T2 will meet its deadline
208
ms 50 0 3 10 s + +
ms 150
50
150
* 10 ) 3 3 ( 25 s + + +
03/08/10 209
Answer
For task T
3
,
T
3
also would meet its first deadline
209
ms 200
150
200
* 25
50
200
* 10 ) 6 3 3 ( 50 s
(
(
(

+
(
(
(

+ + + +
03/08/10 210
Self Suspension with
Context Switch
In a fixed priority preemptable system:
Each task suffers at most two context
switches.
Self suspension introduces:
At most two other context switches.
With context switch overhead and single
self suspension:
Execution time of a task T
i
increases at
most to (e
i
+ 4*c)
210
03/08/10 211
Handling Critical Tasks With
Long Periods
What if task criticalities turn out to be
different from task priorities?
Simply raising the priority of a critical
task:
Will make the RMA schedulability check
results inapplicable.
A solution proposed by Sha and Raj
Kumars period transformation (1989).
03/08/10 212
Period Transformation Technique
A critical task is logically divided into many small
subtasks.
Let Ti be a critical task that is split into k subtasks:
Each one has execution time ei/k and deadline di/k.
This is done virtually at a conceptual level:
Rather than making any changes physically to the task itself.
03/08/10 213
Period Transformation: Example
Consider 2 tasks:
T1: e1=5, p1=d1=20 msec
T2: e2=8, p1=d1=30 msec
Assume that T2 is a critical task:
Should not miss deadline even under transient
underload.
T2a: e2a=4, p2=d2=15msec
Period transformation can also be used to improve
the schedulability of a task set.
Bonus problem:
What is the
impact on
schedulability?
03/08/10 214
214
Few Other Issues in
Using RMA
(Lecture 12)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 215
Handling Aperiodic and Sporadic
Tasks
It is difficult to assign high priority values
to sporadic tasks:
A burst of sporadic task arrivals could
overload the system:
Cause many tasks to miss deadlines.
Low priorities can be accorded:
But some sporadic tasks might be critical.
The aperiodic server technique may be
used.
03/08/10 216
Sporadic Tasks
Two kinds of sporadic tasks:
High priority: Emergency events
Non-critical: Background jobs (logging)
Background jobs can be deferred during
transient overload:
Tolerate long response time anyway.
High priority tasks:
Handled by converting them to periodic
tasks.
03/08/10 217
Aperiodic Server
Selects aperiodic and sporadic tasks at
appropriate times after they arise:
Passes them to RMA scheduler.
Server deposits a ticket at start:
Replenished at the expiration of a certain
replenishment period.
If a ticket is available, the task is transferred
to RMA scheduler.
03/08/10 218
Differable and Sporadic Servers
Based on ticket creation policy -- there are two kinds of
aperiodic servers:
Differable
Sporadic
Sporadic server results in higher schedulable utilization:
Lends itself more easily to analysis.
However, it is more complex to implement.
03/08/10 219
Differable Server
Tickets are replenished at regular
intervals:
Independent of actual usage.
When no task is sent over a duration:
Tickets are accumulated.
Deviates from RMA strict periodic
execution model:
Leads to conservative system design
and low processor utilization.
03/08/10 220
Sporadic Server
Ticket replenishment time:
Depends on exact ticket usage time.
As soon as a ticket is used:
The system sets a timer
When timer goes off, any used
tickets is replaced.
03/08/10 221
Sporadic Server
cont
Guarantees a minimum separation
between two instances of a task.
Helps to consider a sporadic task as a
periodic task for:
Schedulability analysis
Priority assignment
03/08/10 222
222
Insufficient Number
of Priorities
All RTOS have a restricted
number of priority levels
(why?).
When the number of tasks is
more than the number of
available priority values, the
schedulability of the system
decreases.
03/08/10 223
223
Priority Grid
Assigning priorities using
a priority grid:
Uniform scheme
Arithmetic scheme
Geometric scheme
Logarithmic scheme
03/08/10 224
Uniform Scheme
If there are N tasks and n priority
levels, then:
n/N number of task are assigned to
each level.
Rest of the tasks are distributed among
the lower priority levels.
03/08/10 225
Example
Consider 6 tasks and 4 priority levels.
T1=(5,10), T2=(10,20), T3=(20,40),
T4=(30,60), T5=(40,80); T6=(50,100)
Priority 1: T1
Priority 2: T2
Priority 3: T3,T4
Priority 4: T5,T6
03/08/10 226
Arithmetic Scheme
Consider N tasks:
N=r+2r+3r+4r+....nr
r tasks having the shortest
periods are assigned to the
highest priority level,
2r tasks are assigned the next
highest priority level, and so on.
03/08/10 227
Geometric Scheme
Consider N tasks:
N=r+r
2
+r
3
+r
4
+.... r
n
r tasks having the shortest periods
are assigned to the highest priority
level,
r
2
tasks are assigned the next
highest priority level, and so on.
03/08/10 228
Logarithmic Scheme
Experiments show that the logarithmic
grid works the best.
Basic idea:
Shorter period tasks should be allotted
distinct priority levels as much as
possible.
Assume: r = (pmax/pmin)
1/n
03/08/10 229
Logarithmic Scheme
Consider N number of tasks:
N=r+r
2
+r
3
+r
4
+.... r
n
r tasks having the shortest periods
are assigned to the highest priority
level,
r
2
tasks are assigned the next
highest priority level, and so on.
03/08/10 230
230
Insufficient Number
of Priorities: Example
r=(Pmax/Pmin)
1/nprio
Pmin=1msec, Pmax=100,000
and nprio=32
R=1.43
The gridlines become 1.00,
1.43, 2.04, ...
03/08/10 231
Dealing With Task Jitter
Task jitter:
Magnitude of variation in arrival or
completion times of a task.
Certain applications require jitter be
minimized as much as possible.
Arrival time jitter:
Latest arrival - Earliest arrival
03/08/10 232
Approach 1: To Deal With Task
Jitter
Applicable in situations where:
Set of tasks is highly schedulable
One or two tasks have high jitter
requirements.
Assign these tasks high priorities
03/08/10 233
Approach 2: To Deal With Task
Jitter
Assume a task set is barely schedulable.
Each task with jitter constraints is split into two:
One which computes the output,
One which passes the output on.
Set the second task's priority to very high values:
Its period is the same as that of the first task.
03/08/10 234
Quiz
Which of the following is an /(are)
important concern(s) of real-time
operating systems:
1. Average response time
2. Average throughput
3. Worst case execution time
4. Best case execution time
03/08/10 235
Identify True or False
Cyclic scheduler is more proficient compared table-driven
schedulers.
Unlike table-driven schedulers,
cyclic schedulers do not require to store a precomputed
schedule.
In a non-preemptive event-driven
task scheduler, scheduling decisions are made only at the
arrival and completion of tasks.
03/08/10 236
Identify True or False
For scheduling a set of soft real-time tasks on a
uniprocessor:
RMA is a better scheduling algorithm compared
to time-sliced round-robin
algorithm.
A set of periodic real-time tasks are being
scheduled on a uniprocessor using RMA
scheduling:
Assume they have similar arrival time jitter .
All tasks would show similar completion time
jitter.
03/08/10 237
Practice Problem
Identify a constraint on the task set
which will make RMA as proficient as
EDF.
In any implementation of EDF:
The scheduler needs to frequently
examine the ready queue of the tasks at
regular intervals to determine which task
should start running next.
03/08/10 238
238
Resource Sharing
Among Real-Time
Tasks
(Lecture 13)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 239
239
Introduction
So far, the only resource that
we considered is CPU.
CPU is serially reusable
Can be used by one task at a
time
The task can be preempted at
any time without affecting
correctness.
03/08/10 240
Critical Section
Tasks in reality need to share many
types of resources:
Files, data structures, devices.
These are nonpreemptable resources
A piece of code in which a shared
nonpreemptable resource is accessed:
Called a critical section in the operating
systems literature.
03/08/10 241
241
Critical Section Execution
Traditional operating system
solution to execute critical sections:
Semaphores.
However, in real-time systems this
solution does not work well ---
results in:
Priority inversion
Unbounded priority inversion
03/08/10 242
242
Priority Inversion
A task instance executing a
critical section:
Cannot be preempted.
Consqeuence: A higher priority
task keeps waiting:
While the lower priority task
progresses with its computations.
03/08/10 243
243
Priority Inversion
When a resource needs to be
shared in the exclusive mode.
A task may be blocked by a
lower priority task which is
already holding the resource.
03/08/10 244
244
Unbounded Priority
Inversion
Consider the following situation:
A low priority task is holding a
resource.
A high priority task is waiting
An intermediate priority task
which does not need resource
preempts the low priority task.
T1
T2 T3
T1
03/08/10 245
Unbounded Priority Inversion
Example
T6
T5
T4
T3
T2
T1
CPU Usage Time
Lock
CR
Lock
CR
Unlock
CR
03/08/10 246
246
Unbounded Priority
Inversion
Number of priority inversions
suffered by a high priority task :
Can be too many causing it to miss
its deadline.
Most celebrated example:
Mars path finder
03/08/10 247
Mars Pathfinder
Landed on the Mars surface on July 4th,
1997.
Bounced onto the Martian surface
surrounded by airbags.
Deployed the Sojourner rover.
Gathered and transmitted voluminous data
back to Earth:
Included the panoramic pictures now available
on the Web.
03/08/10 249
Mars Pathfinder
03/08/10 250
03/08/10 251
Mars Pathfinder Bug
Pathfinder began experiencing total
system resets:
Each resulting in loss of data.
The newspapers reported these
failures using terms such as:
Software glitches
The computer was trying to do too
many things at once, etc.
03/08/10 252
Debugging Mars Pathfinder
The real-time kernel used was VxWorks
(Wind River Systems Ltd.)
RMA scheduling of threads was used
Pathfinder contained:
A information bus -- a shared memory
Used for passing information between
different spacecraft components.
03/08/10 253
Debugging Mars Pathfinder
VxWorks can be run in trace mode:
Interesting system events: context switches,
uses of synchronization objects, and
interrupts are recorded.
JPL engineers spent hours running exact
spacecraft replica in lab:
Replicated the precise conditions under
which the reset occurred.
03/08/10 254
Debugging Mars Pathfinder
VxWorks mutex object:
Accepts a boolean parameter indicating whether priority
inheritance should be performed.
It was clear to the JPL engineers:
Turning ON priority inheritance would prevent the resets.
Initialization parameters were stored in global variables.
A short C program was uploaded to the spacecraft.
03/08/10 255
Solution for Simple
Priority Inversion
Longest duration for which a
simple priority inversion can
occur:
Bounded by the duration for
which a lower priority task
needs the resource in
exclusive mode.
.255
03/08/10 256
Solution to Simple Priority
Inversion
A simple priority inversion can be
tolerated:
Limit the time for which a task
executes its critical section.
A simple priority inversion can be
limited to tolerable levels by careful
programming.
03/08/10 257
257 257
Unbounded Priority Inversion
Consider the following situation:
A low priority task is holding a
resource:
A high priority task is waiting.
An intermediate priority task which
does not need resource:
Preempts the low priority task.
There can be an unlimited number of
such intermediate tasks.
T1
T2 T3
T1
03/08/10 258
Unbounded Priority
Inversion
258
T
H
T
I1
T
I2
T
I3
T
L
R
03/08/10 259
259 259
Unbounded Priority Inversion
Number of priority inversions
suffered by a high priority task
can be unbounded:
Can cause the task to miss its
deadline.
In the worst case:
The high priority task might have to
wait indefinitely.
03/08/10 260
260
Priority Inheritance Protocol
Sha and Rajkumar
The main idea behind this
scheme:
A task in critical section
cannot be preempted:
It should be allowed to
complete as early as possible.
03/08/10 261
Priority Inheritance Protocol
How do you make a task complete as early
as possible?
Raise its priority, so that low priority tasks
are not able to preempt it.
By how much should its priority be raised?
Make its priority as much as that of the task
it is blocking.
03/08/10 262
262
Priority Inheritance Protocol
Sha and Rajkumar
When a resource is busy:
Requests to lock the resource
are queued in FIFO order.
Then apply the inheritance
clause after a higher priority
task blocks.
T
H
T
L
R
03/08/10 263
263
Inheritance Clause
The priority of the task in the
critical section:
Raised to equal the highest
priority task in the queue.
T
H
T
L
R
03/08/10 264
Priority Inheritance Protocol (PIP)
Sha and Rajkumar
As soon as the task releases the
resource,
It gets back its original priority value
if it is holding no other critical
resource.
In case it is holding other critical
resources:
It inherits priority of the highest
priority task waiting for resource.264
03/08/10 265
PIP: Pseudocode
if the required resource is free,
then grant it
if the required resource is being held by a higher
priority task,
then wait for the resource
if the required resource is held by a lower
priority task, then
{
Wait for the resource
The low priority task holding the resource
acquires the priority of highest priority task
waiting for the resource.
}
265
03/08/10 266
Understanding PIP
How does PIP prevent unbounded
priority inversions?
The priority of low priority task holding
resource is raised to that of the waiting
high priority task:
Intermediate priority tasks can not
preempt it.
03/08/10 267
Working of PIP
267
pri(T
i
)=5 pri(T
i
)=5 pri(T
i
)=10 pri(T
i
)=5
pri(T
j
)=10 pri(T
j
)=10
T
i
CR
T
i
T
i
CR
T
i
CR
T
j
T
j
T
j
CR
pri(T
j
)=10
Instance 1 Instance 2 Instance 3 Instance 4
03/08/10 268
268 268
Shortcomings of the Basic
Priority Inheritance Scheme
PIP suffers from two
important drawbacks:
Deadlocks
Chain blocking
PIP is susceptible to chain blocking:
Also does nothing to prevent
deadlocks
03/08/10 269
269 269
Deadlocks
Consider two tasks T
1
and T
2
accessing
critical resources CR
1
and CR
2
.
Assume:
T1 has a higher priority than T2
T2 starts running first
T
1
: Lock R
1
, Lock R
2
, Unlock R
2
, Unlock R
1
T
2
: Lock R
2
, Lock R
1
, Unlock R
1
, Unlock R
2
03/08/10 270
Chain Blocking
A task needing to use a set of
resources is said to undergo
chain blocking:
If each time it needs a resource,
it undergoes priority inversion.
Example:
Assume a high-priority task T
1
needs several resources
270
03/08/10 271
Chain Blocking Example
271
T
2
CR
1
CR
2
T
1
Waiting for CR
1
T
1
T
2
CR
2
Waiting for CR
2
CR
1
T
2
CR
2
T
1 CR
1
T
2
executing T
1
executing T
2
executing
T
1
blocked T
2
blocked T
1
blocked
Snapshot 1 Snapshot 2 Snapshot 3
03/08/10 272
Practice Questions
What do you understand by priority
inversion?
(T/F) When several tasks share a set of
critical resources,
Is it possible to avoid priority inversion
altogether by using a suitable task
scheduling algorithm?
03/08/10 273
Practice Question
When priority inheritance is used:
What do you understand by inheritance-
related inversion?
When a set of real-time tasks share certain
critical resources using the priority
inheritance protocol:
The highest priority task does not suffer any
inversions. (T/F)
03/08/10 274
Practice Question
When priority inheritance scheme is used,
a task needing a resource undergoes
priority inversions due to:
A higher priority task holding the resource
A lower priority task holding the resource
An equal priority task holding the resource
Either a higher or a lower priority task
holding the resource
03/08/10 275
Practice Question
Using semaphores of traditional operating systems,
what is the maximum duration for which a task may
undergo priority inversion:
1. Longest duration for which a higher priority task uses a
shared resource.
2. Longest duration for which a lower priority task uses a
shared resource.
3. Sum of the durations for which different lower priority
tasks may use the shared resource.
4. Greater than the longest duration for which a lower
priority task uses a shared resource
03/08/10 276
276
Highest Locker and
Priority Ceiling Protocols
(Lecture 14)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 277
277
Highest Locker
Protocol
During the design of a system
A ceiling priority value is assigned to all
resources.
The ceiling priority is equal to the
highest priority of all tasks needing to
use that resource.
When a task acquires a resource:
Its priority value is raised to the
ceiling priority of that resource.
03/08/10 278
278 278
Highest Locker Protocol (HLP)
Addresses the shortcomings of PIP:
However, introduces new complications.
Addressed by Priority Ceiling Protocol
(PCP).
Easier to first understand working of HLP
and then PCP.
During the design of a system:
A ceiling priority value is assigned to all
critical resources.
The ceiling priority is equal to the highest
priority of all tasks using that resource.
03/08/10 279
Ceiling Priority of a Resource
When a task acquires a resource:
Its priority value is raised to the ceiling
priority of that resource.
T
1
T
2
T
3
R
Ceil(R) =
max-prio(T1,T2,T3)
03/08/10 280
Example
T
1
T
2
T
3
R
Ceil(R) =
max-prio(T1,T2,T3)
=2
prio(T1)=5
prio(T2)=2
prio(T3)=8
03/08/10 281
Highest Locker Protocol (HLP)
If higher priority values indicate
higher priority (e.g., Windows):
If higher priority values indicate
lower priority (e.g., Unix):
281
}) | ) ( max({ ) ( i j j i R needs T T pri R Ceil =
}) | ) ( min({ ) ( i j j i R needs T T pri R Ceil =
03/08/10 282
Highest Locker Protocol (HLP)
As soon as a task acquires a
resource R:
Its priority is raised to Ceil(R)
Helps eliminate the problems of:
Unbounded priority inversions,
Deadlock, and
Chain blocking.
However, introduces inheritance
blocking.
282
03/08/10 283
Example
T
1
T
2
T
3
R
Ceil(R) =
max-prio(T1,T2,T3)
=2
T
1
R
T
5
T
4
T
2
03/08/10 284
Highest Locker Protocol (HLP)
Theorem:
When HLP is used for resource sharing:
Once a task gets any one of the resource
required by it, it is not blocked any further.
Corollary 1:
Under HLP, before a task is granted one
resource:
All the resources required by it must be free.
Corollary 2:
A task can not undergo chain blocking in
HLP. 284
03/08/10 285
285 285
Highest Locker Protocol
Avoids unbounded priority inversion
Prevents deadlock (Corollary 1)
T1: lock R1, Lock R2, Unlock R2,
Unlock R1
T2: lock R2, Lock R1, Unlock R1,
Unlock R2
Prevents unbounded priority
inversion.
03/08/10 286
286 286
Shortcomings of HLP
Inheritance blocking occurs:
When the priority value of a low
priority task holding a resource is
raised to a high value.
Intermediate priority tasks not
needing the resource:
Cannot execute and undergo priority
inversion.
03/08/10 287
Inheritance Inversion Example
T
1
T
2
T
3
R
Ceil(R) =
max-prio(T1,T2,T3)
=2
T
1
R
T
5
T
3
03/08/10 288
Shortcomings of HLP
Due to the problem of inheritance-
related priority inversion.:
HLP is rarely used in real applications.
This may lead to several intermediate
priority tasks to miss their deadlines.
Priority Ceiling Protocol:
Extension of PIP and HLP to
overcome their drawbacks.
Can you list the drawbacks?
288
03/08/10 289
289
Priority Ceiling Protocol
Each resource is assigned a ceiling
priority:
Like in HLP
An operating system variable
denoting highest ceiling of all
locked semaphores is maintained.
We will call it Current System
Ceiling (CSC).
03/08/10 290
Priority Ceiling Protocol (PCP)
Difference between PIP and PCP:
PIP is a greedy approach
Whenever a request for a resource
is made, the resource is promptly
allocated if it is free.
PCP is not a greedy approach
A resource may not be allocated to a
requesting task even if it is free.
290
03/08/10 291
PCP: CSC
At any instant of time,
CSC = max({Ceil(CR
i
)|CR
i
is
currently in use})
At system start,
CSC is initialized to zero.
Resource sharing among tasks in
PCP is regulated by two rules:
Resource Grant Rule.
Resource Request Rule.
291
03/08/10 292
PCP: Resource Grant Rule
Resource grant rule has two
clauses:
Resource request clause
Applied when a task request a
resource.
Inheritance clause
Applied when a task is made to
wait for a resource.
292
03/08/10 293
293
PCP: Resource Request
Clause
Unless a task holds a
resource that set the
current system ceiling:
It can lock a resource only if
its priority is greater than
CSC.
03/08/10 294
294 294
PCP: Resource Request Clause
If a task T
i
is holding a resource
CR
j
whose ceiling priority equals
CSC, Then:
The task is granted access to the
resource.
Otherwise, T
i
is not granted CR
j
,
unless pri(T
i
) > CSC.
03/08/10 295
295 295
PCP: Resource Request Clause
In both (a) and (b):
If T
i
is granted access to
the resource CR
j
, and if
CSC < Ceil(CR
j
):
Then CSC is set to Ceil(CR
j
).
03/08/10 296
296 296
PCP: Inheritance Clause
If a task is prevented from
locking a resource:
The task holding the resource
inherits the priority of the
blocked task:
If the priority of the task holding
the resource is lower than that of
the blocked task.
03/08/10 297
Features of PCP
In PCP, a task when granted a
resource:
It does not immediately acquire the
ceiling priority of the resource.
On acquiring a resource, the priority
of the task does not change.
The priority of a task changes:
Only when the inheritance clause is
applied.
297
03/08/10 298
298 298
PCP: Analysis
Prevents deadlocks.
Prevents chain blocking.
Prevents unbounded priority
inversion.
Limits inheritance-related
inversion.
03/08/10 299
PCP: Resource Release Rule
If a task T
i
releases a critical
resource CR
j
that it was holding and
if Ceil(CR
j
) is equal to CSC,
Then, CSC = max({Ceil(CR
k
)|CR
k
is any
resource remaining in use}).
Else, CSC remains unchanged.
The priority of T
i
is also updated:
Reverts to its original priority, or
Reverts to the highest priority of all
tasks waiting for any resource which T
i
is still holding
299
03/08/10 300
Example
Ceil(R) =
max-prio(T1,T2,T3)
=10
T
1
T
2
T
3
R
T
4
CR1
03/08/10 301
Working of PCP
301
pri(T
2
)=2 pri(T
2
)=2 pri(T
2
)=5 pri(T
2
)=5
pri(T
j
)=5 pri(T
3
)=3
T
2
CR
T
1
T
1
CR
T
1
CR
T
3
T
3
T
3
CR
pri(T
j
)=5
Instance 1 Instance 2 Instance 3 Instance 4
CSC=10
CSC=10
T
4
CR1
CSC=10
03/08/10 302
302 302
Types of Priority
Inversions in PCP
Direct inversion
Inheritance-related inversion
Avoidance-related inversion
03/08/10 303
303 303
Direct Inversion
A lower priority task is
holding the resource CR:
Higher priority task waits for
the resource.
T
H
T
L
CR
03/08/10 304
Identify The Direct Inversions
T
1
T
2
T
3
R1
T
4
T
5
T
6
R3
R2
Assume tasks
have been
sorted in order
of priority
03/08/10 305
305
Inheritance-related
Inversion
When a low priority task is holding a
resource and a high priority task is
waiting for it:
The priority of the low priority task is
raised.
An intermediate priority task not
needing that resource:
Undergoes inheritance-related inversion.
03/08/10 306
Inheritance-Related
Inversion
306
T
L
CR
T
H
T
I
03/08/10 307
Identify The Inheritance-Related
Inversions
T
1
T
2
T
3
R1
T
4
T
5
T
6
R3
R2
Assume tasks
have been
sorted in order
of priority
03/08/10 308
308
Analysis of PCP
(Lecture 15)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 309
309 309
Avoidance-Related Inversion
Consider that a low priority task is
holding a resource:
CSC is made equal to the ceiling of the
resource being held.
A higher priority task, whose priority is
lower than the CSC, needs a resource
currently not in use:
Undergoes avoidance-related inversion
Due to the resource grant rule
Also called priority ceiling-related or
deadlock-avoidance inversion.
03/08/10 310
Avoidance-Related
Inversion
310
T
L
CR
1
T
H
Ceil(CR
1
) = 10
CSC=10
pri(T
H
) = 8
CR
2
03/08/10 311
Identify The Avoidance-Related
Inversions
T
1
T
2
T
3
R1
T
4
T
5
T
6
R3
R2
Assume tasks
have been
sorted in order
of priority
03/08/10 312
Avoidance-Related
Inversion
Theorem:
Tasks are single-blocking under
PCP.
Once a task acquires a resource, it
cannot undergo any inversion.
Corollary 1:
Under PCP a task can undergo at
most one inversion during its
execution.
312
03/08/10 313
Why is PCP Deadlock Free?
Deadlocks occur only when
Different tasks hold parts of each other's
required resources.
They request for the resources being held
by each other.
But under PCP, when one task is
executing with some resource,
Any other can not hold a required
resource.
03/08/10 314
How is Unbounded Priority
Inversion Avoided?
A task suffers unbounded priority
inversion, when
It is waiting for a lower priority task to
release a resources required by it.
In the mean while intermediate priority
tasks preempt the low priority task from
CPU usage.
03/08/10 315
How is Unbounded Priority
Inversion Avoided?
Whenever a high priority task waits
for a resource held by a low priority
task,
The lower priority task inherits the
priority of high priority task.
Intermediate priority tasks can not
preempt the low priority task from CPU
usage.
03/08/10 316
How is Chain Blocking Avoided?
Already we have proved:
Resource sharing among tasks
under PCP is single blocking.
This would give the clue how
chain blocking is avoided.
03/08/10 317
Inversion Analysis
T
1
T
2
T
3
R1
T
4
T
5
T
6
R3
R2
Direct Blocking
T5
T6
8 T4
1 T3
8 T2
8 2 T1
T6 T5 T4 T3 T2 T1
03/08/10 318
8 T5
T6
T4
T3
8 T2
T1
T6 T5 T4 T3 T2 T1
Inheritance Inversion
T5
T6
8 T4
1 T3
T2
T1
T6 T5 T4 T3 T2 T1
Avoidance Inversion
03/08/10 319
Analysis of Inversions
Each inversion table is an upper
triangular matrix:
Why?
A task does not suffer any
inversions due to higher priority
task.
03/08/10 320
Maximum Inversion for a Task
A task can suffer at best one of direct,
inheritance, or avoidance-related
inversion.
Therefore the maximum inversion that a
task can suffer is:
The maximum of the entry of the
corresponding row of the inversion table.
03/08/10 321
321
Handling Task
Dependencies
(Lecture 16)
Dr. RAJIB MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
03/08/10 322
Plan of This Lecture
We shall first complete:
Our incomplete discussions on
resource sharing.
We shall then discuss how
scheduling algorithms can be
extended:
To handle task dependencies.
03/08/10 323
Priority Inversions Under PCP
PCP reduces priority inversions:
As compared to HLP.
Higher priority tasks may still suffer
from three main types of inversions:
Direct inversions
Inheritance-related inversions
Avoidance-related inversions
Recall
03/08/10 324
Inversion Analysis Exercise 1
T
1
T
2
T
3
R1
T
4
T
5
T
6
R3
R2
Assume tasks have
been sorted in
increasing order
of priority.
03/08/10 325
Inversion Analysis Exercise 2
T
1
T
2
T
3
R1
T
4
T
5
T
6
R3
R2
Assume tasks
have been sorted
in increasing
order of priority
03/08/10 326
326
Liu and Lehoczky Condition
Under Resource Sharing
Let b
i
denote:
The longest time for which a task T
i
can undergo
priority inversions due to resource sharing.
T
i
will meet its first deadline if,
where p
i
is the period of task T
i
and
i j
i
j
j
i
i i p e
p
p
e b s
(
(
(

+ +

=
) * (
1
1
n p p p p ... 3 2 1 s s s
03/08/10 327
327
PCP for Dynamic Priority
Systems
The priority ceiling values:
Need to change dynamically with time.
A solution: Each time the priority of a
task changes:
Update the priority ceiling of each
resource and the current system ceiling.
However, this would incur unacceptably
high processing overhead.
03/08/10 328
Comparison of Resource
Sharing Protocols
PIP:
Simplest --- requires minimal
support from the OS.
Effectively overcomes the
unbounded priority inversion
problem.
However, tasks may suffer from
chain blockings and deadlocks.
328
03/08/10 329
Comparison of Resource
Sharing Protocols
HLP:
Requires moderate support from
the OS.
Solves the chain blocking and
deadlock problems.
Intermediate priority tasks:
May suffer from inheritance-
related inversions.
329
03/08/10 330
Comparison of Resource
Sharing Protocols
PCP:
Overcomes shortcomings of PIP.
Free from deadlocks and chain blocking.
Low chances of inheritance-
related inversions:
Priority of a task on acquiring a
resource does not change :
Until a higher priority task requests
the resource.
330
03/08/10 331
Quiz
When a set of real-time tasks share
certain critical resources using priority
ceiling protocol (PCP):
The highest priority task does not suffer any
inversions.
Under PCP, a task not requiring any
resource:
May still undergo priority inversion for some
duration.
03/08/10 332
Quiz
Construct an example to justify:
Why PCP is not a greedy algorithm?
Why PIP is a greedy algorithm?
Why under dynamic priority protocols:
Supporting resource sharing among real-
time tasks is difficult.
03/08/10 333
Handling Task Dependencies
So far, our discussions
assumed no dependencies
exist among tasks:
However, in practical
situations this is far from the
truth.
Existing scheduling techniques
need to be suitably modified.
333
03/08/10 334
334 334
Table-Driven Algorithm
Arrange the tasks in increasing order of
their deadlines
Do
Scan the list from the rightmost end
Find a yet to be scheduled tasks whose all
successors have been scheduled.
Schedule it as late as possible.
While there are tasks yet to be scheduled
Move all the tasks forward as much as
possible
03/08/10 335
Example
Determine a feasible schedule for
real-time a task set {T
1
, T
2
, T
5
}
T
1
= (2, 8)
T
2
= (5 , 25)
T3= (6 , 24)
T4= (10, 50)
T
5
=(7, 48)
335
03/08/10 336
Precedence Relationships
336
T
1
T
2
T
5
T
3
T
4
03/08/10 337
Solution
Step 1:
Arrangement of tasks in ascending order
of task deadlines:
T
1
T
3
T
2
T
5
T
4
Step 2:
Schedule tasks as late as possible
without violating precedence constraints:
0 6 8 14 20 25 33 40 50
Step 3:
Move tasks as early as possible
without altering the schedule
0 2 8 13 20 30
T
1
T
3
T
2
T
5
T
4
T
1
T
3
T
2
T
5
T
4
03/08/10 338
Extending EDF and RMA-
based Schedulers
Precedence constraints can be handled
with the following modifications to the
basic algorithm:
Do not enable a task until all its
predecessors complete their execution.
Check the tasks waiting to be enabled (on
account of its predecessors completing
their executions) after every task
completes.
338
03/08/10 339
RMA Scheduling of Tasks with
Precedence Relations
Scheduler
{T1, T2}
Conventional
task set
T1 T2
Modify task parameters
Scheduler
Task set with
precedence
constraints
03/08/10 340
Modifying Task Parameters for RMA
R
j*
Max (R
j
, R
i*
) where R
i*
is the
modified ready time of the task T
i
Priority Prio
i
Prio
j
03/08/10 341
Modifying Ready Times for RMA:
Example
T1
1
T2
2
T3
3
T4
1
T5
5
200 65 5 0 T5
70
40
25
15
10
d
i
200 5 5 T6
200 1 0 T4
200 3 0 T3
200 2 6 T2
200 1 0 T1
p
i
e
i

i
Task
Task Set
T6
5
03/08/10 342
Modifying the Ready times for
RMA
T1
1
T2
2
T3
2
T4
1
T5
3
R1 = 0 R2 = 6
R3 = 0
R4 = 0
R5 = 0
R3 =
max(R1, R3)
R3 = 0
R4 = max(R1,
R2,R4)
R4 = 6
R5 = max(R3, R4,R5)
R5 = 6
200 65 5 6 T5
70
40
25
15
10
d
i
200 5 5 T6
200 1 6 T4
200 3 0 T3
200 2 6 T2
200 1 0 T1
p
i
e
i

i
Task
Initial Task Parameters
T6
4
R6 = 5
03/08/10 343
Modifying Ready Times for RMA:
Example
T1
1
T2
2
T3
3
T4
1
T5
3
200
200
200
200
200
200
p
i
5 65 5 6 T5
70
40
25
15
10
d
i
6 5 5 T6
4 1 6 T4
3 3 0 T3
2 2 6 T2
1 1 0 T1
Prio
rity
e
i

i
Task
Initial Task Parameters
T6
4

You might also like