Documente Academic
Documente Profesional
Documente Cultură
IA
260
IA
Real-time programming
4.1
Problem definition
4.2
4.3
Tasks
4.4
Synchronization of tasks
4.5
4.6
Scheduling methods
261
IA
Real-time computing
262
IA
NON-REAL-TIME Computing:
Input data
Data
Processing
Output data
REAL-TIME Computing:
Time
Time
Input data
Time
Data
Processing
Output data
263
IA
Real-Time Programming
Creation of programs in such a way that the time requirements on the
compilation of input data, on the processing and on the delivery of output data
are fulfilled.
time requirements
Time requirements are dependent on the processes in the technical system
coordination with the technical process
Real-time:
264
IA
Time dependent
input data
process
Example:
Automation
system
Automation
system
Technical
process
265
IA
Information systems
Real-time systems
data-driven system
I/O-intensive
computation-intensive
machine-independent
machine-dependent
266
IA
Embedded systems
Integration of the automation system in the technical process physically and
logically.
Examples: electric razor, cellular phone, washing machine,
power drill
267
IA
Time
2009 IAS, Universitt Stuttgart
268
IA
269
IA
1
0
t1
t2
t3
t4
t2
270
IA
1
0
t1
1
0
t1
271
IA
Absolute time
requirements
Relative time
requirements
Execution of a function at
a fixed time
Analysis of substances
in chemistry
Execution of a function
within a tolerance time
range
Recording of controlled
variables
Measured value
supervision on sliding
boundaries
Execution of a function
within an interval up to a
latest time
Recording of data
telegrams
Recording of cargo
indicator labels
Sequence control in
batch processes
Recording of signals
of a light barrier
Execution of a function
within an interval starting
from an earliest time
272
IA
Examples:
273
IA
Realization of concurrency
Prerequisite:
Processes in the environment are slow in comparison to
the computation of the programs on the computer
274
IA
275
IA
276
IA
Dialog systems
Keyboard
Light pen
Mouse
Screen
Printer
Storekeeping systems
Timeliness in dialog systems
277
IA
278
IA
Answer
hard real-time
system
Newspaper printing device
car electrical window control
TV electron beam control
telephone switching control
CNC milling head control
aircraft turbine engine control
soft real-time
system
X
X
X
X
X
X
279
IA
Real-time programming
4.1
Problem definition
4.2
4.3
Tasks
4.4
Synchronization of tasks
4.5
4.6
Scheduling methods
280
IA
Different methods
Synchronous programming:
Planning of the time sequence in advance of the execution of
programs
planned economy
281
IA
Patient
Execution Dentist and dentists chair
place
Organisator Dentist's assistant
Automation Program
Processor, that executes the
programs
Operating system
Preplanning
Synchronous programming
Liveplanning
Asynchronous, parallel
programming
282
IA
283
IA
controlled system 1
"heating circuit flat"
u2 (t)
controlled system 2
"heating circuit office"
room temperature
flat
y1 (t)
room
temperature
office
y2 (t)
preheatingtemperature
u3 (t)
controlled system 3 y3 (t)
"boiler"
analog-output
analog-input
process-signal-in/output
real-time
clock
2009 IAS, Universitt Stuttgart
automation
computer
operating
terminal
284
IA
Planning
Ti
T1
T2
2T
T3
5T
285
IA
Subprogram
Identifier
(name)
Sampling time
(cycle time)
CONTROL 1
T1 = T
CONTROL 2
T2 = 2T
CONTROL 3
T3 = 5T
286
IA
invoke all T2 = 2T
CONTROL2
invoke all T3 = 5T
CONTROL3
Wait loop
287
IA
Z2 := 1
Z3 := 1
initialize Z2 and Z3
CONTROL1
no
Z2=2
?
yes
CONTROL2
Z2 := Z2 + 1
Z2 := 1
no
Z3=5
?
yes
CONTROL3
Z3 := Z3 + 1
Z3 := 1
Wait loop
288
IA
CONTROL2
CONTROL1
Control program
t/T
0
Assumption:
3
4
5
6
7
8
Interrupt signal of the real-time clock
10
289
IA
290
IA
PLC-programming
291
IA
292
IA
synchronous
(cyclic)
u2(t)
u3 (t)
Analog-Output
Controlled
system
1
y1 (t)
Controlled
system
2
asynchronous
(stochastic)
Warning
lamp
y2 (t)
Controlled
system
3
u1 (t)
y3 (t)
Analog-Input
Digital
Output
Digital
Input
Process unit
Realtime
clock
2009 IAS, Universitt Stuttgart
Automation
computer
system
Operating terminal
Printer
293
IA
Subprogram
Sampling
time
Priority
number
Priority
ALARM
Reaction
on burner failure
with alarm
message
highest
CONTROL 1
Temperature
control unit for
heating circuit 1
T1 = T
second
highest
CONTROL 2
Temperature
control unit for
heating circuit 2
T2 = 2T
third
highest
CONTROL 3
Temperature
control unit for
heating circuit 3
T3 = 5T
lowest
Identifier-Name
294
IA
D e s ir e d c o u r s e
CONTROL3
(P r io r ity 4 )
CONTROL2
(P r io r ity 3 )
CO NTRO L1
(P r io r ity 2 )
ALARM
(P r io r ity 1 )
T
b)
signals
failure
Burner
re a l-tim e c lo c k
A c tu a l c o u r s e
T 3 (1 )
CO NTRO L3
CO NTRO L2
T 1 (1 )
T 2 (3 )
T 2 (2 )
T 2 (1 )
T 1 (2 )
T 1 (3 )
T 2 (4 )
T 1 (4 )
CO NTRO L1
ALAR M
O p e r a tin g
s y s te m
t
0
2T
3T
4T
5T
6T
7T
295
IA
Time requirements are fulfilled the better the higher the priority of the
corresponding subprogram
Actual time sequence can shift away from the desired time sequence
Subprograms can over take each other mutually
296
Event-driven architectures
IA
Asynchronous programming
activation of tasks
transmission of messages
support through real-time operating systems
non-deterministic behavior
flexible regarding modifications
Time-driven architectures
Synchronous programming
easy to analyze
297
IA
Answer
f In real-time programming only the timeline of an event is in center.
f Real-time means as fast as possible.
f In soft real-time systems timelines do not have to be fulfilled.
298
IA
Real-time programming
4.1
Problem definition
4.2
4.3
Tasks
4.4
Synchronization of tasks
4.5
4.6
Scheduling methods
299
4.3 Tasks
IA
Distinction
Task
Invocation of subprograms
Invocation of a task
300
4.3 Tasks
IA
Task
A task is the procedure of execution of a sequential program controlled by a
real time operating system
Task starts with entry in a list of the real-time operating system and
ends with the deletion from that list
Task does not exist only during the execution of the commands,
but also during planned and forced waiting times
301
4.3 Tasks
IA
Thread
Owner of resources
Element of a task
302
4.3 Tasks
IA
4 basic states
State running
the task is processed
State runnable or ready
all time conditions for the process are fulfilled
what is missing is the start from the operating system
i.e. the execution
State suspended
task is waiting for the occurrence of an event
as soon as event occurs transition from state suspended to ready
State dormant
task is not ready because time conditions or other conditions are not
fulfilled
303
4.3 Tasks
IA
sk
f ta
o
n
etio
Del
lara
tion
of t
he
task
Planning of tasks
"dormant"
planning
"runnable"
"suspended"
"running"
304
4.3 Tasks
IA
The task
Control 3
is:
running
(active)
suspended
runnable
(ready)
dormant
0
2T
3T
4T
5T
6T
7T
305
4.3 Tasks
IA
Arrival time
R:
Request time
S:
Start time
C:
Completion time
D:
Deadline
E:
Execution time
P:
Period time
L:
Laxity
F(t):
Flow time
RF(t):
306
4.3 Tasks
IA
period time P
A: Arrival time
R: Request time
S: Start time
C: Completion time
D: Deadline
states of a task
laxity L
Enew(t)
suspended"
runnable"
"dormant"
A
C
time of viewing
D
t
307
4.3 Tasks
IA
Enew (t):
Laxity
for the execution of a task
L=D-S-E
308
IA
Answer
f A task in the state runnable is being processed.
The task state can directly move from running to dormant.
f A task in the state suspended can move directly to running.
In the state dormant a task is not ready because time conditions or other
conditions are not fulfilled.
309
IA
Real-time programming
4.1
Problem definition
4.2
4.3
Tasks
4.4
Synchronization of tasks
4.5
4.6
Scheduling methods
310
IA
Two actions of two different tasks are called concurrent if they can
run simultaneously (outer parallelism)
Two actions of one task are called simultaneous, if they can be run
at the same time
Actions = Threads
311
IA
312
IA
Example
the dependencies of tasks
due to shared resources
Shared resources:
report printer
analog-input
deadlock!
Task
MEASUREMENTS
Task
PROCESS SUPERVISION
Use analoginput
Use of driver
program
program for
for
report printer
Input and
conversion of
measurements
Output error
message on
report printer
Use of driver
program for
report printer
Use analoginput
Printmeasurements
and time
Input and
monitor process
variables
313
IA
Problems of dependency
Deadlock:
Two or more tasks block themselves mutually
Permanent blocking (livelock, starvation)
A conspiracy of tasks block a task
314
IA
Animation: Deadlock
2009 IAS, Universitt Stuttgart
315
IA
Animation: Livelock
2009 IAS, Universitt Stuttgart
316
IA
Synchronization means
Resource-oriented synchronization
317
IA
Synchronization methods
Semaphore
Critical regions
Rendezvous concept
318
IA
Semaphore concept
Synchronization of tasks through signals (Dijkstra)
Semaphore variable:
V(Si):
P(Si):
319
IA
in
tra
in
tra
track magnet
P(S1)
P(S1)
operation
variable
signal
S1
V(S1)
0
1
synchronization
position
V(S1)
track magnet
in
tra
tra
in
track magnet
operation
320
IA
AA
nn
aai i
TTrr
Track
Track magnet
magnet
TTrr
aai i
nn
BB
Direction
Directionof
ofthe
thetrains
trains
P(S1)
P(S1)
P(S2)
P(S2)
Signal
Signal
S1
S1
0
1
0
0
1
0
V(S1)
V(S1)
Track
Track magnet
magnet
Track
Track magnet
magnet
TTrr
aai i
nn
AA
V(S2)
V(S2)
Signal
Signal
S2
S2
BB
nn
aai i
TTrr
with
ordered sequence
ABAB
321
P (S1)
S1 = 0
V(S2)
S2 = 1
Task B
S1 = 1
Task A
Example:
IA
P (S2)
S2 = 0
V(S1)
S1 = 1
P (S2)
S2 = 0
logical synchronization
P (S1)
S1 = 0
V(S2)
S2 = 1
322
IA
323
IA
Real-time programming
4.1
Problem definition
4.2
4.3
Tasks
4.4
Synchronization of tasks
4.5
4.6
Scheduling methods
324
IA
Definition
Synchronization =
Fulfillment of time related and logical conditions in the parallel run of tasks
Communication =
Exchange of data between parallel running tasks
325
IA
common variable
Sending of messages
326
IA
Synchronous communication
Asynchronous communication
no waiting times
327
IA
328
IA
Real-time programming
4.1
Problem definition
4.2
4.3
Tasks
4.4
Synchronization of tasks
4.5
4.6
Scheduling methods
329
IA
Scheduling problem
Example:
330
IA
Scheduling:
Allocation of the processor to runnable tasks according to a predefined
algorithm (Scheduling-method)
Problem:
1.
2.
Example:
331
IA
Static scheduling
Deterministic behavior
Dynamic scheduling
332
IA
Preemptive scheduling
Non-preemptive scheduling
333
IA
Scheduling methods
Earliest-deadline-first method
334
IA
FIFO scheduling
Non-preemptive scheduling
The processor is allocated to the task with the longest delayed planning
Simple implementation
Task D runnable
t
The tasks are executed in the order in which they become runnable
D
t
335
IA
336
IA
10 20
2009 IAS, Universitt Stuttgart
A C
t/ms
337
IA
Simple implementation
338
IA
Priority
Highest
Priority
A*
E
t
339
IA
Rate-Monotonic Scheduling
Pre-emptive strategy
340
IA
Execution
time
Period
Priority
A
B
C
D
10 ms
20 ms
10 ms
20 ms
40 ms
50 ms
80 ms
100 ms
1
2
3
4
A1
0
B1
10
20
C1 A2
30
40
B2
50
60
D1a A3 C2
70
80
90
B3
A4 D1b
t / ms
341
IA
Earliest-Deadline-First-method
(Minimal-remaining-flow-time-method)
Preemptive method
342
IA
Example: Earliest-Deadline-First-Method
Task
Execution Time
Tmin
Tmax
10 ms
0 ms
40 ms
10 ms
0 ms
30 ms
30 ms
30 ms
100 ms
40 ms
50 ms
200 ms
finish
10 ms
70 ms
90 ms
= deadline
Execution sequence:
D*
D
t/ms
10
20
30
40
Deadline of B is earlier
than the one of A
50
60
70
80
90
100
110
120
IA
344
4.6 Scheduling-Methods
IA
Execution Time
Activation
TD
30 ms
0 ms
40 ms
10 ms
0 ms
30 ms
30 ms
30 ms
100 ms
40 ms
50 ms
200 ms
10 ms
70 ms
90 ms
TD: Deadline
Execution Sequence
Aa
10
B
20
Ab
30
C
40
50
E
60
70
D
80
90
100
t/ms
110
120
345
IA
Schedulability test
A schedulability test is a mechanism to proof whenever a set of tasks can be
scheduled in such a manner that the deadlines are not missed.
necessary condition
sufficient condition
346
IA
Ci
1
i =1 Ti
Where:
Ci : Execution time of task i
Ti : Period of task i
n: Number of tasks
347
IA
Ci
*
n
U n = n 2 1, n = 1, 2,...
i =1 Ti
Where:
U 1* = 1,0
n
U 2* = 0,828
U 3* = 0,779
U * = ln 2 = 0,693
and:
Ci
Ui =
Ti
Sufficient test
2009 IAS, Universitt Stuttgart
348
IA
349
IA
350
IA
Crosswords to Chapter 4
351
IA
Crosswords to Chapter 4
Across
1
4
6
7
9
10
11
12
Down
2
3
4
5
8
352