Documente Academic
Documente Profesional
Documente Cultură
Michal Sojka
November 8, 2017
Some slides are derived from lectures by Steve Goddard and James H. Anderson
1 / 48
Classification of scheduling algorithms
(used in real-time systems)
Scheduling algorithms
2 / 48
Table of contents
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
3 / 48
What Is Clock-Driven Scheduling
Outline
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
4 / 48
What Is Clock-Driven Scheduling
Motivation
5 / 48
What Is Clock-Driven Scheduling
Schedule table
8 / 48
What Is Clock-Driven Scheduling
Example
τ1 τ3 τ2 τ1 τ4 τ2 τ1 τ2 τ1 τ1 τ2 schedule repeats
0 2 4 6 8 10 12 14 16 18 20
The schedule table will look like this:
Time 0 1 2 3.8 4 5 6 8 9.8 10.8 ... 18
Task τ1 τ3 τ2 × τ1 × τ4 τ1 × τ2 ... τ2
9 / 48
What Is Clock-Driven Scheduling
10 / 48
What Is Clock-Driven Scheduling
11 / 48
Frame-based scheduling
Outline
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
12 / 48
Frame-based scheduling
Frame-based scheduling
Problems
Big number of tasks ⇒ big schedule table
Embedded systems have limited size of memory
Reprogramming the timer might be slow
Idea
Divide time to constant-size frames
Combine multiple jobs into a single frame
Scheduling decisions are made only at frame boundaries
Consequences:
There is no preemption within each frame.
Each job must fit into the frame
In addition to schedule calculation, we should check for various error
conditions such as task overrun.
Let f denote the frame size. How to select f?
13 / 48
Frame-based scheduling
1 We want big enough frames to fit every job without preempting it.
This gives us
f ≥ max (Ci ). (1)
i=1,...,n
14 / 48
Frame-based scheduling
t t+f t + 2f t + 3f
t′ t′ + Di t′ + Ti
(release time of job τi )
Thus:
2f − gcd(Ti , f) ≤ Di . (3)
See Liu 5.3.2 for explanation.
15 / 48
Frame-based scheduling
Example
Let’s have a system from the last example with four tasks:
τ1 = (4, 1), τ2 = (5, 1.8), τ3 = (20, 1), τ4 = (20, 2).
From the first constraint (1): f ≥ 2.
Hyperperiod is 20 so second constraint (2), tells us that f can be one
of 2, 4, 5, 10 a 20.
Third constraint (3) satisfies only f = 2.
Possible cyclic schedule:
τ1 τ3 τ2 τ1 τ4 τ2 τ1 τ2 τ1 τ1 τ2 schedule repeats
0 2 4 6 8 10 12 14 16 18 20
16 / 48
Frame-based scheduling
Split jobs
0 4 8 12 16 20
17 / 48
Frame-based scheduling
18 / 48
Schedule Construction with Network Flow Algorithm
Outline
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
19 / 48
Schedule Construction with Network Flow Algorithm
f ≥ max (Ci )
i=1,...,n
20 / 48
Schedule Construction with Network Flow Algorithm
Network-flow graph
21 / 48
Schedule Construction with Network Flow Algorithm
Jobs Frames
..
.
Ji f Fx
Ci f f
Fy
f
source sink
Ck f f
Jk f Fz f
..
.
FF
22 / 48
Schedule Construction with Network Flow Algorithm
∑
Clearly, maximal flow is at most equal to i=1,...,N Ci . This is the
duration of jobs that need to be scheduler during major cycle.
∑
If the flow found by the maximum-flow algorithm is i=1,...,N Ci , it
corresponds to feasible schedule.
If a job is “scheduled” in multiple frames, it has to be split to
sub-jobs.
23 / 48
Schedule Construction with Network Flow Algorithm
Ci /Ci h/f
(Ci − h)/f
Fy (C + Ck − h)/f
i
source sink
Ck /f 0/f
Ck /Ck Jk 0/f Fz 0/f
..
This flow tells us to split J1 into two subtasks.
.
One with execution time h, which is scheduled in FF
frame Fx and second with execution time (Ci −h),
which is scheduled in frame Fy . Jk stays as one
jobs as is scheduled in frame Fy .
24 / 48
Schedule Construction with Network Flow Algorithm
Example
Example: Consider τ = {(4, 1), (5, 2, 7), (20, 5)}. Constraints (2) and
(3) give us f = 2 a 4!
We select value 4 for the first max-flow algorithm iteration.
Maximum flow 18, which equals to the total execution time of all jobs
in the hyperperiod.
Flow of edges represent a schedule of the tasks:
schedule
τ1 τ2 τ31 τ1 τ32 τ1 τ2 τ1 τ2 τ1 τ2 τ33 repeats
0 4 8 12 16 20
25 / 48
Schedule Construction with Network Flow Algorithm
Example – graph
Jobs Frames
J11
1
J12 F1
(τ1 )
1
(τ1 ) J13
2
F2
(τ1 ) 1 4
J14
(τ1 ) 4
J15 1 F3
source (τ1 ) 3 sink
2
(τ2 ) 1 3
J21
(τ2 ) 4
1 2 F4
(τ2 ) J22 3
(τ2 ) 0
J23 2 F5
0
(τ3 )
J24 1
J31
26 / 48
Schedule Construction with Network Flow Algorithm
27 / 48
Cyclic Executive
Outline
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
28 / 48
Cyclic Executive
Cyclic Executive
Fancy name for a scheduler that executes the frame-based schedule.
29 / 48
Cyclic Executive
30 / 48
Cyclic Executive
31 / 48
Improving response times of non-periodic jobs
Outline
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
32 / 48
Improving response times of non-periodic jobs → Aperiodic jobs – slack stealing
33 / 48
Improving response times of non-periodic jobs → Aperiodic jobs – slack stealing
schedule
hard real- τ1 τ2 τ1 τ3 τ1 τ4 τ2 τ1 τ1 τ3 repeats
time jobs
0 4 8 12 16 20
1.5 0.5 2
aperiodic
jobs
0 4 8 12 16 20
without slack τ1 τ2 τ1 τ3 τ1 τ4 τ2 τ1 τ1 τ3
stealing
0 4 8 12 16 20
with slack τ1 τ2 τ1 τ3 τ1 τ4 τ2 τ1 τ1 τ3
stealing
0 4 8 12 16 20
34 / 48
Improving response times of non-periodic jobs → Aperiodic jobs – slack stealing
Slack stealing
(CZ: Kradení rezervy)
Let the total amount of time allocated to all the jobs scheduled in
frame k be xk .
Definition: slack available at the beginning of frame k is f − xk .
Scheduler change :
If aperiodic job queue is not empty, run aperiodic jobs in every frame
with non-zero slack.
35 / 48
Improving response times of non-periodic jobs → Aperiodic jobs – slack stealing
36 / 48
Improving response times of non-periodic jobs → Sporadic jobs
37 / 48
Improving response times of non-periodic jobs → Sporadic jobs
Example
38 / 48
Improving response times of non-periodic jobs → Sporadic jobs
Example (continued)
S1 is released in time 3.
Must be scheduled in frames 2, 3 and 4.
Acceptance test – at the beginning of frame 2:
Slack time is 4 which is less that execution time – job is rejected.
S2 is released in time 5.
Must be scheduled in frames 3 through 7.
Acceptance test – at the beginning of frame 3:
Slack time is 5.5 – job is accepted.
First part (2 units) executes in current frame.
S3 is released in time 11.
Must be scheduled in frames 4 and 5.
S3 runs ahead of S2 .
Acceptance test – at the beginning of frame 4:
Slack time is 2 (enough for S3 and the part of S2 ) – job is accepted.
First part (1 unit) S3 executes in current frame, followed by second part of S2 .
S4 is released in time 14.
Acceptance test – at beginning of frame 5:
Slack time is 4.5 (accounted for slack committed by S2 and S3 ) – job is rejected.
Remaining portion of S3 completes in current frame, followed by the part of S2 .
Remaining potions of S2 execute in the next two frames.
39 / 48
Improving response times of non-periodic jobs → Sporadic jobs
Admission test
Let σ(i, k) be initial slack in frames i through až k, where
1 ≤ i ≤ k ≤ F. This depends only on periodic tasks and their
parameters are known in advance.
Assume the admission test is executed at the beginning of frame t for
a just arrived sporadic task S with deadline D and execution time C.
Further assume that D happens in frame l + 1, i.e. S must be finished
before end of frame l.
The current total amount of slack time σc (t, l) in frames t through l
can be computed as
∑
σc (t, l) = σ(t, l) − Ck − ξ k
Dk ≤D
41 / 48
Improving response times of non-periodic jobs → Sporadic jobs
42 / 48
Miscellaneous
Outline
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
43 / 48
Miscellaneous
Practical considerations
44 / 48
Miscellaneous
45 / 48
Summary
Outline
2 Frame-based scheduling
4 Cyclic Executive
6 Miscellaneous
7 Summary
46 / 48
Summary
Main advantage: Cyclic executives are very simple – a single table is all
what is needed, no complex run queues etc.
For example, there is no need for concurrency control and task
synchronization (e.g. semaphores). In the simplest case, there are no
tasks and processes and everything is just a function call.
Can be validated, tested and certified with very high confidence.
Certain anomalies will not occur.
For these reasons, cyclic executives are predominant approach in
many safety critical applications (e.g in airplanes, trains, etc.)
47 / 48
Summary
48 / 48