introduction to real-time systems · “any information processing system which has to responde to...

53
Introduction to Real-Time Systems Real-Time Systems, Lecture 1 Martina Maggio and Karl-Erik ˚ Arz´ en 21 January 2020 Lund University, Department of Automatic Control

Upload: others

Post on 20-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Introduction to Real-Time Systems

Real-Time Systems, Lecture 1

Martina Maggio and Karl-Erik Arzen

21 January 2020

Lund University, Department of Automatic Control

Page 2: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Content

[Real-Time Control System: Chapter 1, 2]

1. Real-Time Systems: Definitions

2. Real-Time Systems: Characteristics

3. Real-Time Systems: Paradigms

1

Page 3: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Systems: Definitions

Page 4: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Systems

“Any information processing system which has to responde to externally

generated input stimuli within a finite and specified period”

“Real-Time systems are those in which the correctness of the system

depends not only on the logical results of the computation but also on

the time at which results are produced”

2

Page 5: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Definitions

A hard real-time system is a system where it is absolutely imperative that

the responses occur within the required deadline (for example because in

safety-critical applications in aerospace, automotive and so on).

A soft real-time system is a system where deadlines are important, but

where the system still functions if the deadlines are occasionally missed

(for example in multimedia systems, user interfaces and so on).

3

Page 6: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time and Control

Control-Engineering Computer Engineering

Real-Time Systems

• All control systems are real-time systems.

• Many hard real-time systems are control systems.

4

Page 7: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

• Control engineers need real-time systems to implement their systems.

• Computer engineers need control theory to build ‘controllable

systems’.

• Interesting research problems in the interface.

5

Page 8: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Hard Real-Time Systems

• The focus of this course.

• Many (most?) hard real-time systems are real-time control systems.

• Most real-time control systems are not hard real-time systems.

• Many hard real-time systems are safely-critical.

• Common misconception: Real time equals high-speed computations.

This is not true. Real-time systems execute at a speed that makes it

possible to fulfill the timing requirements.

6

Page 9: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Control Systems

Computer Control System

Controller Controlled System

Industrial

Process

Operator

Interface

Communi-

cation

ActuatorsD/A

SensorsA/D

7

Page 10: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Control Systems

Two types of real-time control systems:

• Embedded systems:

– dedicated control system

– the computer is an embedded part of some equipment

– microprocessors, real-time kernels, RTOS

– aerospace, industrial robots, vehicular systems

• Industrial control systems:

– distributed control systems (DCS)

– programmable logic controllers (PLC)

– hierarchically organized

– process industry, manufacturng industry

8

Page 11: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Example

9

Page 12: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Some more

10

Page 13: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Example

In a modern car

• Embedded control systems: brakes, transmission, engine, safety,

climate, emissions: 40-100 ECUs in a new car, 2-5 milion lines of

code;

• Networked systems: VOLVO XC 90 has 3 CAN-buses and other

buses.

11

Page 14: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Networked Control

12

Page 15: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Networked Control

13

Page 16: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Cyber-Physical Systems

• Name coined in the US around 2008.

• Denotes systems with a very tight connection between computing,

communication, control and the physical world.

CPS

Computing

Communication

Physical worldControl

14

Page 17: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

CPS Examples

• Smart/Green/Low-energy buildings: require interaction between

architects, mechanical engineers and control engineers; require

interaction between a number of subsystems (cooling, lightning,

security);

• Green cars;

• Smart Power Grids;

• Server Farms/Data Centers: require interaction between load

balancing and energy consumption;

• Battery-driven computing and communication devices (like smart

phones, laptops and sensor networks);

• Cross-layer design and optimization in networks: in embedded

systems resource-aware design.

15

Page 18: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

Page 19: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

flight control

Page 20: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

flight control

robot controlengine control

inverted pendulum

Page 21: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

flight control

robot controlengine control

inverted pendulum

light

control

Page 22: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

flight control

robot controlengine control

inverted pendulum

light

control

TV remote

control

USB

stick

Page 23: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

flight control

robot controlengine control

inverted pendulum

light

control

TV remote

control

USB

stick

digital TV

Page 24: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

flight control

robot controlengine control

inverted pendulum

light

control

TV remote

control

USB

stick

digital TV

optimizing car shape

Page 25: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Systems: Embedded, Cyber-Physical, Real-Time

CPS

ES

RTS

flight control

robot controlengine control

inverted pendulum

light

control

TV remote

control

USB

stick

digital TV

optimizing car shape

RTOS

16

Page 26: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Systems: Characteristics

Page 27: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Embedded Control Characteristics

• Limited computing and communication resources:

– often mass-market products, like cars

– CPU time, communication bandwidth, energy, memory

• Autonomous operation:

– No human operator in the loop

– Several use-cases and complex functionality, often large amount of

software

– need for formal guarantees

17

Page 28: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Embedded Control Characteristics

Limited Resources =⇒ Efficiency

• Code-size efficiency

• Run-time efficiency

• Energy efficiency

• Weight and size efficiency

• Cost efficiency

Autonomous operations =⇒ Dependability

• Reliability

• Availability

• Safety

• Security

• Maintainability

18

Page 29: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Example: The Buffer Tanks

T

Q

L1

L0

V

Raw Material and Heating

Goals:

• Level control: open V when level below L0, keep the valve open

until level above L1,

• Temperature control: PI-controller.

19

Page 30: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Typical Characteristics

• Parallel activities.

• Timing requirements: more or less hard.

• Discrete and analog signals.

• Continuous (time-driven) control and

Discrete (event-driven) sequential control.

20

Page 31: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Continuous Time-Driven Control

Controller on continuous (analog form)

• PI controller

u(t) = K ((yref (t)− y(t)) +1

Ti

∫t

(yref (τ) − y(τ))dτ)

Can be implemented in several ways, e.g., using analog electronics

Here, we will assume that it is implemented using a computer.

How, should this be done?

21

Page 32: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Sampling - Control - Actuation

Frequently:

• Sampling of measured signal y(t),

• Calculation of control signal (software algorithm),

• Actuation of calculated control signal u(k).

In most cases periodically, i.e. driven by a clock (time).

22

Page 33: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Sampled-Data Control Systems

Process

u t( )

)

uk

y t(u t( )

yk

SamplerHold

Computer

uk

yk

tt

t

y t( )

t

D-A A-D

23

Page 34: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Networked Control Systems

uk

uk

ky

ky

Communication network

Computer

Process

y(t). . . . .u(t)

t

.

andD−A

Hold

Sampler

A−Dand

y(t)u(t)

. . . .t

. .. .

.. . .t

t

24

Page 35: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Design Approaches

Sampled control-design:

• Discrete-time design,

• Use a model of the plant that only describes the behaviour at the

sampling instants – sampling the system.

Approximation of a continuous-time design:

• Design the controller assuming a continuous-time implementation,

• Approximate this controller by a discrete-time controller.

25

Page 36: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Ideal Controller Timing

y

y(tk−1)

y(tk )

y(tk+1)

Time

u

t k−1 t k tk+1

u(tk− 1)

u(t k)

Time

Con

trol

Va

ria

ble

Mea

sure

d V

ari

ab

le

Computa-tionallag τ

• Output y(t) sampled periodically at time instants tk = kh,

• Control u(t) generated after short and constant time delay τ .

26

Page 37: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real Controller Timing

y(t)

u(t)

rk−1 rk rk+1

Lk−1s Lk−1

ioLks

Lkio

Lk+1s

Lk+1io

sk−1 fk−1 sk fk sk+1fk+1

Rk−1 Rk Rk+1

τ

t

t

• Control task τ released periodically at time instances rk = kh,

• Output y(t) sampled after time-varying sampling latency Ls ,

• Control u(t) generated after time-varying input-output latency Lio .

27

Page 38: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Non-Deterministic Timing

Caused by sharing of computing resources:

• multiple tasks sharing the CPU,

• preemptions, blocking, priority inversion, varying computation times,

and so on.

Caused by sharing of network bandwidth:

• control loops closed over communication networks,

• network interface delay, queuing delay, transmission delay,

propagation delay, re-sending delay, ACK delay,

• lost packets.

How can we minimize the non-determinism?

How does the non-determinism effect control performance?

28

Page 39: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Discrete Event-Driven Control

Event-driven:

• wait for a condition to become true or an event to occur,

• perform some actions,

• wait for some new conditions.

The event can be a clock-tick.

Often modeled using state machine/automata-based formalism.

In many cases implemented using periodic sampling.

29

Page 40: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Events

Real-Time systems must respond to events.

• Periodic events,

• Non-periodic events,

• Aperiodic events: unbounded arrival frequency,

• Sporadic events: bounded arrival frequency.

Events can be external or internal.

Each event requires a certain amount of processing and has a certain

deadline.

30

Page 41: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Parallelism

The real world is parallel.

Events may occur at the same time.

The work that has to be done to service an event is called the task

associated with the event.

It is often natural to handle the different tasks independently during

design.

31

Page 42: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Systems: Paradigms

Page 43: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Parallel Multi-Core Programming

DesignLevel

ExecutionLevel

Concurrent Tasks

CPU

CPU

CPU

Program

Program

Program

32

Page 44: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Sequential Programming

DesignLevel

ExecutionLevel

Manual interleaving

CPU

Cyclic Executive

Sequential Program

33

Page 45: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Interleaved Code

Interleaved temperature and level loops

while (true) { while (level above L0) { Measure temperature; Calculate temperature error; Calculate the heater signal with PI-control; Output the heater signal; Wait for h seconds; } Open inlet valve; while (level below L1) { Measure temperature; Calculate temperature error; Calculate the heater signal with PI-control; Output the heater signal; Wait for h seconds; } Close inlet valve;}

Complex and non user-friendly code – Can often be automated.

Sequential program = static schedule (cyclic executive).

34

Page 46: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Static Sequential Approaches

Advantages:

• determinism,

• a lot of different constraints can be ensured,

• simple real-time computing platforms may be used.

Disadvantages:

• inflexible,

• generation of the sequential process can be a difficult optimization

problem.

35

Page 47: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Concurrent Programming

DesignLevel

ExecutionLevel

Concurrent Tasks

Concurrent Processes

CPU

The CPU is shared between the processes (switches).

36

Page 48: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Operating Systems

• Switches between processes (real-time kernel),

• Timing primitives and interrupts,

• Process communication,

• CPU free to service other tasks.

Temperature Loop with Sleep

while (true) { Measure temperature; Calculate temperature error; Calculate the heater signal with PI-control; Output the heater signal; Sleep(h); }

37

Page 49: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Non-Real-Time Operating Systems

• Polling (inefficient).

Polled Temperature Loop

Polling

while (true) { Measure temperature; Calculate temperature error; Calculate the heater signal with PI-control; Output the heater signal; counter = 0; while (counter < hcount) { INC(counter); }}

38

Page 50: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Systems Characteristics

• Timing requirements,

• Must be deterministic and predictable,

• Worst-case response times of interest rather than average-case,

• Large and complex,

• Distributed,

• Tight interaction with hardware,

• Safety critical,

• Execution is time dependent,

• Testing is difficult,

• Operating over long time periods.

39

Page 51: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Real-Time Systems Course

In this course, as in most of industry, we will follow the concurrent

programming paradigm.

Two different environments will be used during the lectures:

• Java

• concurrency through Java threads,

• language used in projects.

• STORK

• real-time kernel implemented in Modula-2,

• close in nature to commercial real-time kernels and real-time

operating systems (OS),

• makes it possible to teach how a real-time kernel is implemented.

40

Page 52: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Java in real-time – NO

• Java was not developed for real-time applications.

• The just-in-time compilation in Java and the dynamic method

dispatching makes Java non-deterministic and slow.

• The automatic garbage collection makes Java execution

non-deterministic.

• Java lacks many important real-time primitives.

41

Page 53: Introduction to Real-Time Systems · “Any information processing system which has to responde to externally ... It is often natural to handle the different tasks independently

Java in real-time – YES

• A nice concurrent programming language.

• A nice object-oriented language.

• A nice teaching language.

• Strong trends towards Real-Time Java.

• Many of the shortcomings of Java can be handled, e.g., the garbage

collection problem.

• Microsoft’s .NET and C# (a Java clone) + Google’s Android has

strongly increased the industrial use of Java.

42