Professional Documents
Culture Documents
RTS Exercises & Solutions
RTS Exercises & Solutions
RTS Exercises & Solutions
Exercises
Ingo Sander
February 24, 2012
Contents
1 Modeling and Languages
4 Priority-Driven Scheduling
8 Interprocess Communication
11
1
2D
1
3 2
a
2
y
zD
(a) Give the smallest possible values for x, y and z, so that a periodic
admissible sequential schedule exists. Motivate your answer. Give
the schedule.
(b) What are the required buffer sizes for this schedule?
(c) How would you efficiently realize a system based on this SDF graph
in software on a single processor? Keep the discussion on an abstract level.
uses a frame size of 5, and a major cycle of 6 frames. Suppose the initial
amount of slack times in the frames is 1, 0.5, 0.5, 0.5, 1, and 1.
(a) Suppose that a sporadic job S1 (23, 1) arrives in frame 1, sporadic
jobs S2 (16, 0.8) and S3 (20, 0.5) arrives in frame 2. In which frames
are the accepted sporadic jobs scheduled?
(b) Suppose that, in addition to the sporadic jobs, an aperiodic job
with execution time 3 arrives at time 1. When will it be completed,
if the system does not do slack stealing?
Priority-Driven Scheduling
1. Given is the following set of independent periodic tasks, which shall be
scheduled rate-monotonically.
T1 = (2,1); T2 = (5,1); T3 = (4,10,1,10) 1
(a) Show with the graphical form of the time-demand analysis, if the
set of independent periodic tasks is schedulable using the ratemonotonic algorithm. Give the maximum possible response times
Wi for each task!
(b) Assume now that an additional task T4 = (8, 1) is introduced. Calculate the maximum possible response times for the task T4 by iteration of the time demand analysis function w4 (t).
(c) Do all tasks still meet their deadlines?
2. The following set of independent periodic tasks T1 = (3,1), T2 = (4,1), T3 =
(5,1) is scheduled using the rate-monotonic algorithm. In the following
practical factors shall be taken into account for a time demand analysis
in order to calculate the maximum possible response time of task T2 . In
the following subtasks you have only to take into account the practical
factors that affect the response time for task T2 .
For each subtask motivate the additional terms for the time demand
function in one or two sentences.
(a) Give the time demand analysis function for w2 (t) if no practical factors are taken into account.
(b) Take now the time for context switching is into account. Each context switch takes 0.05 units of time. Give the modified time demand
analysis function for w2 (t).
(c) The task T3 shall have a non-preemptable section that lasts for 0.5
time units. Give the modified time demand analysis function for
w2 (t).
(d) Assume now that the scheduler operates periodically. The period
p0 of clock interrupts is 1.0 and the scheduler takes 0.1 units of time
to complete, when there are no ready jobs to be moved to the ready
queue. The scheduler takes 0.1 time units of time to move a job
from the waiting queue to the ready queue. Give the modified time
demand analysis function for w2 (t).
3. Given is the following set of independent periodic tasks, which shall be
scheduled rate-monotonically.
T1 = (4,1); T2 = (8,3); T3 = (10,2)
1 The 4-tuple ( , p , e , D ) gives the phase , period p , execution time e and relative deadi i i
i
i
i
i
line Di . In case of a 2-tuple (pi , ei ) i is 0 and Di is pi .
(a) Show with the graphical form of the time-demand analysis, if the
set of independent periodic tasks is schedulable using the ratemonotonic algorithm. Give the maximum possible response times
Wi for each task, in case it meets its deadline.
(b) Assume now that an additional task Tx = (7, 9, 1, 9)2 is introduced.
Do all tasks including Tx still meet their deadlines? Calculate the
response times by an iteration of the time demand analysis function, in case they still meet their deadlines.
4. Can you guarantee that a feasible schedule exists without a simulation
of the schedule or time demand analysis, if
(a) the set of tasks T = {(5, 2), (8, 3), (10, 1)} is scheduled by the ratemonotonic algorithm.
(b) the set of tasks T = {(3, 1), (6, 1), (18, 6), (36, 4)} is scheduled by the
least-slack-time-first algorithm.
(c) the set of tasks T = {(3, 1), (0, 6, 1, 4), (18, 6), (36, 4)} is scheduled
by the earliest-deadline-first algorithm.
(d) the set of tasks T = {(3, 1), (6, 1), (18, 6), (36, 4)} is scheduled by the
deadline-monotonic algorithm.
Please give a short motivation for each subtask.
5. The following set of independent periodic tasks T1 = (4,1), T2 = (6,2), T3
= (10,1) is scheduled using the rate-monotonic algorithm. In this task
practical factors shall be taken into account for a time demand analysis
in order to calculate the maximum possible response time of task T2 .
You have only to take into account the practical factors that affect the
response time for task T2 .
Give the time demand analysis function for w2 . Motivate modified and
additional terms that arise due to practical factors in one or two sentences.
(a) The task T3 shall have a non-preemptable section that lasts for 0.4
time units.
(b) Assume that the scheduler operates periodically. The period p0 of
clock interrupts is 1.0 and the scheduler takes 0.04 units of time to
complete, when there are no ready jobs to be moved to the ready
queue. The scheduler takes 0.03 time units of time to move a job
from the waiting queue to the ready queue.
2 The 4-tuple ( , p , e , D ) gives the phase , period p , execution time e and relative deadi i i
i
i
i
i
line Di . In case of a 2-tuple (pi , ei ) i is 0 and Di is pi .
follows: the job requires the resource R for t time units. Here, job J1
requires no resource for one time unit, the resource X for 1 time units,
and no resource for one time unit. The job J4 has a nested critical section, which comprises the following resource requests: the recourse X
is requested for two time units, the resource Y is requested for one time
unit, and finally the resource X is requested for one time unit.
Job
J1
J2
J3
J4
J5
ri
7
5
4
2
0
ei
3
3
2
6
6
Execution Pattern
[-;1][X;1][-;1]
[-;1][Y;1][-;1]
i
1
2
3
4
5
[-;1][[X;2][Y;1][X;1]][-;1]
[-;1][Y;4];[-1]
0.5
T1
0.3
T2
0.2
Y
T3
0.6
0.4
T4
The tasks are scheduled by the rate-monotonic algorithm and the basic priority-ceiling protocol. Calculate the maximum response time for
each task. Are the tasks schedulable for any combination of 1 , 2 , 3
and 4 ?
3. A system contains four jobs. There are two resources X and Y. The following table shows the job parameters and their execution pattern. The
execution pattern describes how each job is executed. [R;t] is read as
follows: the job requires the resource R for t time units. Here, job J3
requires no resource for one time unit, the resource Y for two time units
and no resource for one further time unit.
Job
J1
J2
J3
J4
ri
6
4
2
0
ei
3
3
4
6
i
1
2
3
4
6
Execution Pattern
[-;1][X;1][-;1]
[-;1][Y;1][-;1]
[-;1][Y;2][-;1]
[-;1][X;4][-;1]
W
0.2
T1
0.7
X
T3
T5
0.5
T2
0.9
0.6
0.4
T6
T4
The tasks are scheduled by the rate-monotonic algorithm.
(a) Give the maximum blocking times for all tasks, if the nonpreemptive critical section protocol is used.
(b) Give the maximum blocking times for all tasks, if the basic priorityceiling protocol is used.
(c) Assume that the system uses a deferrable server with the same values of ps and es instead of the sporadic server. How can you find
out, if the periodic tasks are still schedulable? Motivate your answer (a new calculation is not necessary)!
2. A system consists of two independent periodic tasks T1 = (10,1), T2 =
(16,4). The system is scheduled rate-monotonically. In addition to these
tasks a periodic server with a period ps and an execution budget of es
shall be integrated into the system.
(a) Assume that the periodic server is a simple sporadic server with an
execution budget of es = 2.What is the minimal period ps , where ps
is an integer number, that can be chosen for the sporadic server, so
that all periodic tasks are still schedulable.
(b) Assume that the periodic server is a deferrable server with (ps , es )
= (6,2). Give the maximum response time of the task T1 .
(c) Assume now that the periodic server is a polling server with (ps , es )
= (6,2), which is used to schedule sporadic jobs. Which of the following sporadic jobs Si = (ri , di , ei ) can be accepted given the following order? Assume that the accepted sporadic jobs are scheduled according to the earliest-deadline-first paradigm.
i. S1 = (1, 10, 3)
ii. S2 = (5, 36, 5)
iii. S3 = (17, 32, 6)
Give the completion times for the accepted sporadic tasks!
Interprocess Communication
1. The following algorithm using a weak binary semaphore S that was initialized with S = {1, } solves the critical section problem for two processes.
P1
P2
loop forever
loop forever
non-critical section
non-critical section
wait(S)
wait(S)
critical section
critical section
signal(S)
signal(S)
(a) Show why it solves the problem for two processes.
(b) Does it also solve the critical section problem for three or more processes?
2. A set of n concurrent processes accesses a shared variable Shared of type
integer. In order to provide consistency, mutual exclusive access to the
variable is to be ensured during a read operation ReadVariable and a
write operation WriteVariable.
(a) Give the pseudo-code for a protected object with the operations ReadVariable() and WriteVariable(X: Integer) that ensures mutually-exclusive access to the variable Shared.
(b) What property is required for the protected object, so that starvation does not occur?
3. Describe the principle operation of a watch-dog timer. Illustrate it with
a block diagram.
10
V(S) - Signal
S
pk
tWait
tSignal
pk+1
pk+1
T2
p1
p4
t1
t3
Critical Section
Semaphore
p2
ps
p5
t2
t4
p3
p6
1-2
Esterel Implementation of Watchdog
TICK
Watchdog
Timer
ALARM
ALIVE
System
...
loop
do
await 60 TICK;
emit ALARM
watching ALIVE
%
%
%
%
ALARM is emitted
if 60 TICKs are received
before a single occurence
of ALIVE!
11
end
||
loop
...
emit ALIVE
...
end
...
% System
1-4
Both transitions t1 and t2 are enabled, but only one can fire!
Firing is nondeterministic. Either t1 or t2 fires, but not both.
1. If t1 fires, the tokens in p1 and p2 are consumed and a token in
p4 is generated. At this stage no transition is enabled and the
Petri-net reaches a final state.
2. If t2 fires, the tokens in p2 and p3 are consumed and a token in
p5 is generated. At this stage no transition is enabled and the
Petri-net reaches a final state.
Thus the following final states can be reached: {p1 , p2 , p3 , p4 , p5 , p6 } =
{0, 0, 1, 1, 0, 0} or {p1 , p2 , p3 , p4 , p5 , p6 } = {1, 0, 0, 0, 1, 0}.
1-5
(a)
1
= 0
y
3
= 0
y
2 0
3 2
0
x
0 4
3 2
0 x
(1)
1 2 0
q1
0
0
3 2 q2 = 0
(2)
3 0
4
q3
0
A possible solution is
4
Q = 2
3
(3)
12
13
10
10
15
20
20
25
30
10
10
15
20
20
25
30
(b) Slack-Stealing:
(b) As can be seen in the upper figure, the aperiodic job finishes at time
30.
3-1
(a) Precedence Graph
14
10
12
14
16
10
12
14
16
10
12
14
16
J9 misses its deadline! Observe that all jobs meet their deadline with only three processors. Such a phenomenon is called a
scheduling anomaly.
(c) Three processors - reduced execution time (Priority: 1 > 2 >
> 9 )
Deadline
10
12
14
16
3-3
The set of tasks {(6, 1), (18, 9), (54, 18)} is simply periodic. The utilization of this set is U{(6,1),(18,9),(54,18)} = 1. Thus this set of tasks can be
scheduled on a single processor.
The other tasks have a total utilization of U{(4,1),(8,2),(20,4),(100,2)} =
1
0.72 < URM (4) = 4(2 4 1) = 0.757. They can be scheduled on a single
processor.
Two processors are required!
4-3
(a) Time Demand:
Time Demand
w3 (t)
11
10
9
8
7
6
w2 (t)
5
4
3
2
w1 (t)
Time
0
0
10
The maximum response times are derived from the diagram that
W1 = 1, W2 = 4 and W3 = 7.
(b) The response times for T1 and T2 do not change, since the priority
of Tx is lower than T1 and T2 , but higher than T3 .
Thus we calculate the response time for Tx . The time demand for
Tx is
i1
X
t
wx (t) = ex +
ek
(4)
pk
k=1
Here
wx (t) = 1 +
t
t
1+
3
4
8
(5)
t(1)
t(2)
=
=
=
=
1 + 54 1 + 58 3
6
1 + 64 1 + 68 3
6
(6)
(7)
= 2+
= 8
8
4
1+
8
8
3+
8
9
(8)
17
1 1
X
J1
2
2 2
Y
J2
3 3
Y
J3
2
Y
4 4
X
J4
0
1 1 1
X X X
10
12
14
16
1 1
X
J1
2
2 2
Y
J2
3
3 3 3
Y Y
J3
4 4
X
J4
0
3
X
2
X
1
X
10
12
14
16
10
12
14
16
(t)
1
2
3
4
5-4
(a) Nonpreemptive critical section protocol: b1 = b2 = b3 = 0.9, b4 =
0.7, b5 = 0.4, b6 = 0
(b) Priority-ceiling protocol: b1 = b2 = 0.5, b3 = b4 = b5 = 0.4, b6 = 0
18
6-1
(a) The total utilization of the three tasks is T1 , T2 and T3 is 0.598. The
schedulable utilization for four tasks for RMS is URM (4) = 0.756.
Since the sporadic server can be treated as a periodic task, the remaining size of the server is uS = 0.158. Thus the minimal period
1
e = 7.
for the sporadic server is ps = d 0.158
(b) Priority-Order: (T1 ) > (T2 ) > (TS ) > (T3 )
A1
A1 A2 A2
A2
12
16
20
A3
A2
24
28
Budget
1
C1
C1
C1
C1
12
16
20
3
A2
1.5
A1
1
24
C1
C2
28
0.5
A3
23.5
tf
2.0
BEGIN
0.0
END
2.0
tr
0.0
te
0.0
te + p s
8.0
9.0
8.0
9.0
8.0
8.0
16.0
11.0
8.0
9.0
11.0
11.0
19.0
19.0
18.0
19.0
18.0
18.0
26.0
22.0
20.0
21.0
22.0
22.0
30.0
19
C1
C2
Rule
R2, but also R3b. System is idle
at t = 7 and becomes busy
again at tb = 8. Next replenishment time is at t+
r = 8 (both rule
R2 and R3 give the same next replenishment time t+
r = 8.0.
R2, but also R3b. System is idle
at t = 10 and becomes busy
again at tb = 11. Next replenishment time is moved to t+
r = 11.
R2, but also R3b. System is idle
at t = 17 and becomes busy
again at tb = 18. Next replenishment time is moved to t+
r = 18.
R2, but also R3b. System is idle
at t = 21 and becomes busy
again at tb = 22. Next replenishment time is moved to t+
r = 22.
R2, but also R3b. System is idle
at t = 26.5 and becomes busy
again at tb = 28. Next replenishment time is moved to t+
r = 28.
The response times are W (A1 ) = 8.5, W (A2 ) = 13.5, and W (A3 ) =
6.
(c) A deferrable server does not behave as a periodic task. It can execute for 2es in an interval of length 2es . In order to determine
whether the system is still schedulable, time demand analysis can
be used, where
i1
wi (t) = ei + es + d
X t
t es
ees +
d eek
ps
pk
(11)
k=1
for the tasks, which have a lower priority than the deferrable server.
6-2
1. Simple sporadic server behaves like a periodic task. The utilization
of the rest of the system is U{T1 ,T2 } = 0.35. The system is schedula1
ble, if U{T1 ,T2 } + pess URM (3) = 3(2 3 1) = 0.78.
l
m
2
It follows that ps = URM (3)U
= 5.
{T1 ,T2 }
m
l
s
es . For an
2. The time demand for task T1 is w1 (t) = e1 + es + te
ps
iterative solution, we start with t(0) = e1 + es = 3.
2
= 3 + 32
6
= 5
= 3 + 52
2
6
= 5
t(1)
t(2)
(12)
S2 = (5, 36, 5)
S3 = (17, 32, 6)
TS
T1
T2
0
10
15
20
25
30
20
7-1
An extra task with lower priority than the working task set can be used
to indirectly measure the CPU untilization. The extra task is running a
counter.
The measurement works as follows:
In the initialisation phase, only the counter task is run for a defined
time period tm (for example 100 OS ticks). This value maxCounter
corresponds to 0% CPU utilization.
Then the other tasks are also started. Whenever the system is idle,
the counter task is run. In order to determine the utilization, the
counter is reset to 0 every time period tm . At the end of the period, the current counter value curCounter is determined. Then the
utilization can be calculated by
U =1
curCounter
maxCounter
(13)
7-2
Hardware
Timer
Interrupt every Time Unit
Soft
Timer
Post every 300 time units
Sem1
Soft
Timer
Post every 400 time units
Wait
Task 1
Sem2
Wait
Task 2
void task2(...) {
while(1) {
OSSemPend(Sem2);
f2();
}
}
void task1(...) {
while(1) {
OSSemPend(Sem1);
f1();
}
}
8-1
(a) All possible states of the program:
21
Process P1
NCS
wait(S)
CS
Process P2
NCS
(3)
(5)
(6)
S
{1, }
{0, }
wait(S)
blocked
(2)
(4)
Process P3
NCS
signal(S)
NCS
wait(S)
blocked
{0, {P2 }}
wait(S)
blocked
{0, {P2 , P3 }}
CS
{0, {P2 }}
{0, {P1 , P2 }}
signal(S)
NCS
wait(S)
blocked
CS
(7)
{0, {P2 }}
{0, {P2 , P3 }}
State (3) and (7) are identical and the schedule can repeat infinitely.
Thus an implementation with a weak semaphore can lead to starvation in the sense that a process (like P2 ) that has issued a request,
may never be served.
8-2
protected object SharedVariable
Shared : Integer 0
operation ReadVariable()
return Shared
operation WriteVariable(X: Integer)
Shared X
Tasks that are blocked, while they execute an operation to access the
protected object, need to be queued, so that they will eventually be
served.
8-3
CPU
22
References
[Gra69] R. L. Graham. Bounds on multiprocessing timing anaomalies. SIAM
Journal of Applied Mathematics, 17(2), March 1969.
[Liu00] Jane W. S. Liu. Real-Time Systems. Prentice Hall, 2000.
23