Real-Time Embedded Systems

45
1 Real-Time Embedded Systems Krithi Ramamritham

description

Real-Time Embedded Systems. Krithi Ramamritham. Outline. Special Characteristics of Real-Time Systems Scheduling Paradigms for Real-time systems Operating System Paradigms Real-Time Linux Real-Time NT. What is “real” about real-time?. computer world real world - PowerPoint PPT Presentation

Transcript of Real-Time Embedded Systems

Page 1: Real-Time Embedded Systems

1

Real-Time Embedded Systems

Krithi Ramamritham

Page 2: Real-Time Embedded Systems

2

Outline

• Special Characteristics of Real-Time Systems

• Scheduling Paradigms for Real-time systems

• Operating System Paradigms

• Real-Time Linux

• Real-Time NT

Page 3: Real-Time Embedded Systems

3

computer world real worlde.g., PC industrial system, airplane

average response events occur in environment at

for user, interactive own speed

occasionally longer reaction too slow: deadline miss

reaction: reaction:

user annoyed damage, pot. loss of human life

computer controls speed computer has to follow real speedof user of environment

“computer time” “real-time”

What is “real” about real-time?

Page 4: Real-Time Embedded Systems

4

Why real-time, why not simply fast?

“Fast enough”: dependent on system and its environment and

• turtle: fast enough to eat salad

• mouse: fast to enough steal cheese

• fly: fast enough to escape

Page 5: Real-Time Embedded Systems

5

what if environment is changed?“systems” not fast enough

• mouse trap

• fly-swatter

time scale depends on - or dictated by - environment

cannot slow down environment

…is the real world

Page 6: Real-Time Embedded Systems

6

Average vs. Worst Case

Standard computing is concerned with average behavior of systeme.g., if it responds fast enough on average, it is acceptableword processing, etc.

Real-time computing requires timely behavior in all given situationse.g., a single value delivered too late can cause the system to fail, even when the average timing is keptair planes, power plants, etc.

“There was a man who drowned crossing a river with an average depth of 20cm.”

Page 7: Real-Time Embedded Systems

7

A real-time system is a system that reacts to events in the environment by performing predefined actions

I/O - data

I/O - data

Real-Time Systems

Real-timecomputing system

event

action

within specified time intervals.

time

Page 8: Real-Time Embedded Systems

8

Real-Time Systems: Properties of Interest

• Safety: Nothing bad will happen.

• Liveness: Something good will happen.

• Timeliness: Things will happen on time -- by their deadlines, periodically, ....

Page 9: Real-Time Embedded Systems

9

In a Real-Time System….

correct value delivered too late is incorrect

e.g., traffic light: light must be green when crossing, not enough before

Real-time:

(Timely) reactions to events as they occur, at their pace:(real-time) system (internal) time same time scale as environment (external) time

Correctness of results depends on valueand its time of delivery

Page 10: Real-Time Embedded Systems

10

Types of RT Systems

Dimensions along which real-time activities can be categorized:• how tight are the deadlines? --deadlines are tight when the

laxity (deadline -- computation time) is small.• how strict are the deadlines? what is the value of executing an

activity after its deadline?• what are the characteristics of the environment? how static or

dynamic must the system be?

Designers want their real-time system to be fast, predictable, reliable, flexible.

Page 11: Real-Time Embedded Systems

11

deadline (dl)

+

Hard, soft, firm

• Hardresult useless or dangerousif deadline exceeded

value

time

-

hardsoft

• Softresult of some - lower -value if deadline exceeded

• Firm

If value drops to zero at deadline

Deadline intervals:result required not laterand not before

Page 12: Real-Time Embedded Systems

12

Examples

• Hard real time systems

– Aircraft

– Airport landing services

– Nuclear Power Stations

– Chemical Plants

– Life support systems

• Soft real time systems

– Mutlimedia

– Interactive video games

Page 13: Real-Time Embedded Systems

13

Example of Real time systems

Temperature sensor

CPU

Memory

Input port

Output portHeater

Page 14: Real-Time Embedded Systems

14

Code for example

While true do

{

read temperature sensor

if temperature too high

then turn off heater

else if temperature too low

then turn on heater

else nothing

}

Page 15: Real-Time Embedded Systems

15

Comment on code

• Code is by Polling device (temperature sensor)• Code is in form of infinite loop• No other tasks can be executed• Suitable for dedicated system or sub-system only

Page 16: Real-Time Embedded Systems

16

Extended polling example

Computer

Temperature Sensor 1

Temperature Sensor 2

Temperature Sensor 3

Temperature Sensor 4

Heater 1

Heater 2

Heater 3

Heater 4

Task 1

Task 2

Task 3

Task 4

Conceptual link

Page 17: Real-Time Embedded Systems

17

Polling

• Problems– Arranging task priorities– Round robin is usual– Urgent tasks are delayed

Page 18: Real-Time Embedded Systems

18

Other methods

• Use interrupt driven system• Use general purpose operating system plus tasks• Use task handling language (e.g ADA)• Use special purpose operating system

Page 19: Real-Time Embedded Systems

19

Interrupt driven systems

• Advantages– Fast– Little delay for high priority tasks

• Disadvantages– Programming– Code difficult to debug– Code difficult to maintain

Page 20: Real-Time Embedded Systems

20

How can we monitor a sensor every 100 ms

Initiate a task T1 to handle the sensor

T1:

Loop

{Do sensor task T2

Schedule T2 for +100 ms

}

Note that the time could be relative (as here) or could be an actual time - there would be slight differences between the methods, due to the additional time to execute the code.

Page 21: Real-Time Embedded Systems

21

An alternative…

Initiate a task to handle the sensor T1

T1:

Do sensor task T2

Repeat

{Schedule T2 for n * 100 ms

n:=n+1}

There are some subtleties here...

Page 22: Real-Time Embedded Systems

22

Clock, interrupts, tasks

Clock ProcessorInterrupts

Task 1 Task 2 Task 3 Task 4

Job/Task queue

Examines

Tasks schedule events using the clock...

Page 23: Real-Time Embedded Systems

23

Real-Time: Items and Terms

Task– program, perform service, functionality– requires resources, e.g., execution time

Deadline– specified time for completion of, e.g., task– time interval or absolute point in time– value of result may depend on completion time

Page 24: Real-Time Embedded Systems

24

• Periodic

– activity occurs repeatedly

– number of instances

– e.g., to monitor environment values, temperature, etc.

time

period

periodic

Page 25: Real-Time Embedded Systems

25

• Aperiodic– can occur any time– no arrival pattern given

time

aperiodicaperiodic

Page 26: Real-Time Embedded Systems

26

• Sporadic– can occur any time, but– minimum time between arrivals

time

mint

sporadic

Page 27: Real-Time Embedded Systems

27

Who initiates (triggers) actions?

Example: Chemical process – controlled so that temperature stays below danger level– warning system: distance level to danger point, so that

cooling can still occur

Two possibilities:– action whenever temp raises above warn;

event triggered– look every int time intervals; action when temp if measures

above warn time triggered

Page 28: Real-Time Embedded Systems

28

TT

ET

time

t

Page 29: Real-Time Embedded Systems

29

TT

ET

time

t

Page 30: Real-Time Embedded Systems

30

ET vs TT

• Time triggered– Stable number of invocations

• Event triggered– Only invoked when needed– High number of invocation and computation demands if

value changes frequently

Page 31: Real-Time Embedded Systems

31

Michael Collins (astronaut Apollo 11)

“At five minutes into the burn (6000 feet above the surface)

... "Program alarm", barks Neil, "Its a 1202", what the hell is that?I don't have the alarm numbers memorized for my own computer, much less for the LM's I jerk out my checklist and start thumbing through it, but before I can find 1202 Houston say, "Roger, we're GO on that alarm" no problem in other words. My checklist says 1202 is an "executive overflow" meaning simply that the computer has been called upon to do too many things at once and is forced to postpone some of them. A little farther, at just 3000 feet above the surface the computer flashes 1201, another overflow condition, and again the ground is superquick to respond with assurances.

Excerpt from Apollo, Expeditions to the Moon,Scientific and Technical Information Office, NASA, Washington D.C.,

1975

Apollo 11, 1969, first lunar landing

Page 32: Real-Time Embedded Systems

32

interrupt handlerra

dar

Page 33: Real-Time Embedded Systems

33

interrupt handlerra

dar

Page 34: Real-Time Embedded Systems

34

interrupt handler

error 1201

rada

r

Page 35: Real-Time Embedded Systems

35

Slow down the environment?

• Importance– which parts of the system are important?– importance can change over time

e.g., fuel efficiency during emergency landing• Flow control

who has control over speed of processing, who can slow partner down?– environment– computer system

RT: environment cannot be slowed down

Page 36: Real-Time Embedded Systems

36

Performance Metrics in Real-Time Systems

• Beyond minimizing response times and increasing the throughput:

– achieve timeliness.

• More precisely, how well can we predict that deadlines will be met?

Page 37: Real-Time Embedded Systems

37

What is Predictability

A simplified definition:

The ability to reliably determine whether an activity will meet its deadline.

A complete definition can be quite complex and -- subject to assumptions about failure, etc.

Page 38: Real-Time Embedded Systems

38

Achieving Predictability

• Layer by layer: Predictability requirement of an activity percolates down/up the layers.

• Top-layer: Do your best to meet the deadline of an activity. If deadline cannot be met, handle the exception predictably.

Page 39: Real-Time Embedded Systems

39

Layer-by-layer Predictability

Applications: Activities having deadlines.

Processes: Processes with deadlines. one or more processes make up an activity.

Tasks: Tasks with deadlines multiple (precedence-related) tasks make up a process.

Operating System: Bounded code execution time. Bounded Operating System primitives. Bounded synchronization costs. Bounded scheduling costs.

Architecture: Bounded memory access times. Bounded instruction execution times. Bounded inter-node communication costs.

Page 40: Real-Time Embedded Systems

40

Top-layer Predictability

An activity has

• a component executed in the usual case with deadline (d -- r) executed using best-effort approaches

• a component executed in the exception case -- typically simple execution (if needed) is guaranteed.

Page 41: Real-Time Embedded Systems

41

Issues to worry about

• Meet requirements -- some activities may run only:– after others have completed - precedence constraints– while others are not running - mutual exclusion– within certain times - temporal constraints

• Scheduling– planning of activities, such that required timing is kept– models– methods

Page 42: Real-Time Embedded Systems

42

Issue: Running time of programs

• Depends on hardware, memory wait cycles, clock etc.

• Depends on virtual memory and caching• Depends on data• Depends on program control• Depends on pipelining• Depends on memory management

Page 43: Real-Time Embedded Systems

43

More Issues…

• Operating Systems– Off-the shelf (COTS)– Application-specific

• Dataflow– data are read from environment - sensors– data are processed by tasks– results are processed by other tasks…– data are transferred to environment

– actuators

Page 44: Real-Time Embedded Systems

44

Further Issues

• Programming languages– Maximum execution times– Difficult with recursions, unbounded loops, etc

• Networks– Bounded transmission times– e.g., ethernet, CSMA/CD large number of collisions

• Synchronization of clocks – Clock drift apart– Faulty clocks can cause wrong synchronization, e.g., for

average

Page 45: Real-Time Embedded Systems

45

Even more issues…

• Fault tolerance– Deadlines cannot be kept if computer or network has

hardware errors– Tolerate certain faults within timing

• Real-Time Databases– maintain data consistent and fresh

• Design– derive and specify timing