• No results found

Rajib Mall Chapters 1,2,3

N/A
N/A
Protected

Academic year: 2021

Share "Rajib Mall Chapters 1,2,3"

Copied!
343
0
0

Loading.... (view fulltext now)

Full text

(1)

03/08/10 1 1

Characteristics of

Real-Time Systems

(Lecture 2)

Dr. RAJIB MALL Professor

Department Of Computer Science & Engineering

(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.

(3)

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 airbag’s motion sensors detect a collision, the system needs to respond by deploying the airbag within 10ms or less.

(4)

Embedded Systems = Hardware + RTOS +Application Program

SENSORS CONVERSIOND/A

DIAGNOSTIC PORT

SOFTWARE

A/D

CONVERSION CPU ACTUATORS

MEMORY HUMAN INTERFACE AUXILLARY SYSTEMS (POWER, COOLING) ELECTROMECHANICAL BACKUP & SAFETY

External

(5)

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.

(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,

(7)

03/08/10 7 7

Characteristics of an

Embedded System c

ont…

• 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.

(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).

(9)

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.

(10)

Characteristics of

Embedded Systems

(11)

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.

(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.

(13)

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

(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.

(15)

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

(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.

(17)

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.

(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.

(19)

03/08/10 19 19

How to Design a Highly

Reliable System?

–Error Avoidance

–Error Detection and

Removing

(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.

(21)

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

(22)

Triple Modular Redundancy

(23)

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.

(24)

Recovery Blocks

(25)

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

(26)

Block Diagram of An

Embedded System

Processor control panel Real-time OS controller processes UI processes ASIC Programmable DSP ProgrammableDSP DSP Assembly Code DSP Assembly Code Dual-ported RAM CODEC

(27)

03/08/10 27 27

Some Basic Issues

(Lecture 3)

Dr. RAJIB MALL

Professor

Department Of Computer Science & Engineering

(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

(29)

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?

(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:

(31)

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

(32)

Processor Architectures Widely

Used in New Embedded Designs

• ARM

• X86

• PowerPC

• MIPS

• Xscale (ARM)

• Renesas SuperH

(33)

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

(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

(35)

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

(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

(37)

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.

(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:

(39)

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.

(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

(41)

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.

(42)

Modelling Timing

Constraints

(Lecture 4)

Dr. RAJIB MALL

Professor

Department Of Computer Science & Engineering

(43)

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

(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

(45)

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

(46)

Firm Real-Time Systems

• Examples:

A video conferencing application

A telemetry application

Satellite-based surveillance

applications

(47)

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

(48)

Soft Real-Time Systems

• Examples of soft real-time

systems:

Railway reservation system

Web browsing

(49)

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.

(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

(51)

03/08/10 51 51

Events in a Real-Time

System

• Events in a real-time system

can be classified into:

Stimulus Events

(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

(53)

03/08/10 53 53

Stimulus Event

cont

• Periodic stimulus event example :

 Periodic sensing of temperature in a

(54)

Response Event

• Produced by the system:

 In response to some stimulus events

• Example:

 In a chemical plant as soon as the temperature exceeds 100°C,

 The system responds by switching off the heater.

(55)

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.

(56)

Classification of Timing

Constraints

• Different timing constraints

can broadly be classified into:

Performance constraints

(57)

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.

(58)

Types of Timing

Constraints

• Both performance and

behaviorial constraints can

be classified into:

Delay Constraints

Deadline Constraints

(59)

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)

(60)

Deadline Constraint

• Expresses the maximum

permissible separation:

Between any two arbitrary

events.

(61)

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

(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)

t(e1) t(e2) Min

(63)

03/08/10 63 63

Timing Constraints in

an Example System

(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.

(65)

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

(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.

(67)

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.

(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.

(69)

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.

(70)

Timing Constraints

Behaviorial Constraints Performance Constraints

Delay Deadline Duration

RR SR RR SR

Delay Deadline Duration

(71)

03/08/10 71 71

Modelling Timing

Constraints

(cont…)

(Lecture 5)

Dr. RAJIB MALL Professor

Department Of Computer Science & Engineering

(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.

(73)

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.

(74)

FSM

• Transition is annotated with:

 Enabling event

 Action that takes place during transition

S1

S2

(75)

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

(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

(77)

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

(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

(79)

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

(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.

(81)

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?

(82)

Model of Duration

Constraint Example

Await event1 Local operator Internl operator Await event2 Await Button release Dial tone

(83)

03/08/10 83 83

Exercise 1

• When the temperature of a

chemical reactor rises above

T°C:

The heater needs to be

shut-off within 10mSec

Otherwise, the entire plant is

shut-off.

(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.

(85)

03/08/10 85 85

Basics of Real-Time

Task Scheduling

(Lecture 6) Dr. RAJIB MALL Professor

Department Of Computer Science & Engineering

(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:

(87)

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

(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.

(89)

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

(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

(91)

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.

(92)

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.

(93)

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 e2 e3 time

(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 e2 e3 time

(95)

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.

(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.

(97)

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.

(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.

(99)

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.

(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

(101)

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.

(102)

Clock-Driven Scheduling

• Popular examples:

Table-driven scheduler

Cyclic scheduler

• Round robin scheduling is

also an example of

clock-driven scheduling.

(103)

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.

(104)

Table-Driven

Scheduling

TaskStart timeStop time

T1

0

100

T2

101

150

(105)

03/08/10 105 105

Cyclic Schedulers

(Lecture 7)

Dr. RAJIB MALL

Professor

Department Of Computer Science & Engineering

(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

(107)

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?

(108)

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.

(109)

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.

(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.

(111)

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:

(112)

Major Cycle

• In each major cycle:

The different tasks recur at

identical time points.

Major cycle Major cycle

(113)

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.

(114)

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.

(115)

03/08/10 115

A Typical Schedule

T2 F3 T3 F2 T2 F1

Task

Frame

(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

(117)

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.

(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.

(119)

03/08/10 119

Minimum Context Switch

•To avoid unnecessary context switches:

• Selected frame size should be larger

than execution time of each task.

(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

(121)

03/08/10 121

Major cycle Major cycle

(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

(123)

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

(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

(125)

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:

(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

(127)

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

(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).

(129)

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.

(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:

(131)

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

(132)

Event-Driven

Scheduling

(Lecture 8)

Dr. RAJIB MALL

Professor

Department Of Computer Science & Engineering

(133)

03/08/10 133

Event-Driven Schedulers

• Unlike clock-driven

schedulers:

These can handle sporadic

and aperiodic tasks.

Used in more complex

(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:

(135)

03/08/10 135 135

Scheduling Points for

Event-Driven Schedulers

• Scheduling decisions are

made when certain events

occur:

•A task becoming ready

(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.

(137)

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.

(138)

Preemptive Scheduling

• Independent tasks execute

on a uniprocessor.

Two algorithms pretty much

summarise the important

results in this case:

• EDF

• RMA

(139)

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:

(140)

Background Task Completion Time

•Let T

B

be the only background task

• Its processing time be eB

• The time for it to complete would be:

i i B

p

e

e

ct

B

1

(141)

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.

(142)

Example 2

•On account of every context

switch :

•Assume an overhead of 1 msec.

•Compute the completion time of

(143)

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.

(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

(145)

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

(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.

(147)

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.

(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

p

u

i

e

n i i i

(149)

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

(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.

(151)

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

(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.

(153)

03/08/10 153

Disadvantages of EDF

•Main disadvantages of EDF:

•Poor transient overload

handling

•Runtime inefficiency

•Poor support for resource sharing

among tasks.

(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.

(155)

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:

(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.

(157)

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

n i i i i

d

p

e

(158)

Implementation of EDF

• Simple FIFO queue:

A freshly arriving task is

inserted at the end of the

queue.

• Sorted queue:

(159)

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

(160)

Efficient EDF Implementation

Task Queue Deadline Levels 1 2 3 4 5 6

(161)

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:

(162)

Rate Monotonic

Scheduling

(Lecture 9)

Dr. RAJIB MALL

Professor

Department Of Computer Science & Engineering

(163)

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

(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:

(165)

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

p

u

i

e

n i i i

(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

)

1

2

(

1

u

n

n i

(167)

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

u

i

(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

(169)

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



p ui 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         

ui nn

(170)

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).

(171)

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

(172)

Some More Issues in

RMA Scheduling

(Lecture 10)

Dr. RAJIB MALL

Professor

Department Of Computer Science & Engineering

(173)

03/08/10 173

RMA Schedulability

• Utilization bound 1:

• Utilization bound 2:

(Liu-Layland)

• Schedulability check 3: Liu and Lehoczky’s Completion

Time Theorem

1

1

p

u

i

e

n i i i

)

1

2

(

1

u

n

n i U1 U2

(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

(175)

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:

(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. T1=10,30 Φ=0

T2=60,120 Φ=0

T1=10,30 Φ=20 T2=60,120 Φ=0 (a) T1 is in phase with T2

T2 T1 T2 20 30 50 60 T2 T1 Time in milliseconds 80 T1 T2 T1 T2 T1 T2 10 30 40 60 70 90

(177)

03/08/10 177 177

Testing Liu and

(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.

(179)

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



pui e n i i i

(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.

(181)

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



pui e n i i i

(182)

Checking for Lehoczky’s

Criterion

T1

20 100

Deadline for T1

(a) T meets its first deadline

50

T2

(b) T meets its first deadline

Deadline for T2 150 T3 T1 T2 Deadline for T3 T3 120 190

(c) T meets its first deadline

T1: e1=20mSec, p1=100mSec T2: e2=30mSec, p2=150mSec T3: e3=90mSec, p3=200mSec

References

Related documents

The JMA physicians’ liability insurance covered the liability of individual Class-A members, but payments for the liability of non-member physi- cians were cut, and there was a rush

This section outlines the method to find the best allocation of n distinguishable processors to m dis- tinguishable blocks so as to minimize the execution time.. Therefore,

Most companies recruit for full-time and internship positions, but some indicate Co-Op as a recruiting priority, while not attending Professional Practice

wire mesh panel galvanized after manufacture, that can be used as a plaster support or as reinforcing mesh for insulation mortars. Armanet ® Iso is especially

• Storage node - node that runs Account, Container, and Object services • ring - a set of mappings of OpenStack Object Storage data to physical devices To increase reliability, you

The Department of Health, Physical Education, Recreation and Dance offers a Master of Science in Education in Health and Physical Education and a Master of Science in

We are now using the second part of our test database (see Figure 4 ) ; the boxpoints table which contains 3000 customer points, and the box table with 51 dierent sized bounding

The casualty rate for secondary schools (4.5 casualties per 1000 pupils) is significantly higher than that for primary schools (1.7), and our analysis found that a factor strongly