IL2212 Embedded Software Exercises Ingo Sander February 24, 2012
Contents 1 Modeling and Languages
1
2 Clock-Driven and Round-Robin Scheduling
2
3 Real-Time Scheduling on Multiprocessors
3
4 Priority-Driven Scheduling
4
5 Resource Access Control
5
6 Scheduling Aperiodic and Sporadic Jobs in Priority-Driven Systems
7
7 Real-Time Operating Systems
8
8 Interprocess Communication
9
9 Embedded System Design
9
A Solution to selected exercises
1
11
Modeling and Languages 1. (a) How can you model the functions to acquire a semaphore lock (P(S)) and to release a semaphore lock (V(S)) by means of a Petrinet? (b) Draw a Petri Net where a semaphore is used to protect a shared resource that is accessed by two tasks. 2. How can you express a watchdog timer in Esterel? The timer shall send a signal ALARM, if no signal ALIVE has been received for 60 emissions of the signal TICK. 3. Given is the following synchronous data flow graph.
1
2
1
1
2
1
1
2
4
1 2D 1
3 2
(a) Give a periodic admissible sequential schedule in case it exists. (b) What are the maximum buffer sized for this schedule? 4. Consider the following marked Petri net. Give all possible final solutions after a sequence of firings of this Petri net. You do not have to draw the solutions, but have just to give the number of tokens in all places. Motivate your answer.
5. Given is the following synchronous data flow graph. 2
b
1
3
a 2
y zD
x
c
(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.
2
Clock-Driven and Round-Robin Scheduling 1. (Taken from [Liu00]) A system uses the cyclic EDF algorithm to schedule sporadic jobs. The cyclic schedule for a periodic task in the system 2
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?
3
Real-Time Scheduling on Multiprocessors 1. (Taken from [Liu00], who based it on [Gra69]) A system contains nine nonpreemptable jobs named Ji , for i = 1, 2, . . . , 9. Their executions times are 3, 2, 2, 2, 4, 4, 4, 4, and 9, respectively, their release times are equal to 0, and their deadlines are 12. J1 is the immediate predecessor of J9 , and J4 is the immediate predecessor of J5 , J6 , J7 , and J8 . There are no other precedence constraints. For all the jobs, Ji has a higher priority than Jk if i < k. (a) Draw the precedence graph of the jobs. (b) Can the jobs meet their deadlines if they are scheduled on three processors? (c) Can the jobs meet their deadlines if we make them preemptable and schedule them preemptively? (d) Can the jobs meet their deadlines if they are scheduled nonpremptively on four processors? (e) Suppose that due to an improvement of the three processors, the execution time of every job is reduced by 1. Can the jobs meet their deadlines? 2. A multiprocessor system contains the following set of independent periodic tasks T = {(3,1), (4,1), (9,3), (10,4), (27,9), (56,5)}. (a) How many processors are needed, if the task assignment is done with the rate-monotonic small task (RMST) algorithm. Give the assignment of tasks to processors. (b) Can you find a better task assignment than the one produced by the RMST algorithm? In this case give the assignment of tasks to processors and motivate, why the RMST algorithm was not able to find it. 3. A multiprocessor system contains the following set of preemptable independent periodic tasks T = {(4,1), (6,1), (8,2), (18,9), (20,4), (54,18), (100,2)}. What is the mininal number of processors needed, if the tasks on each processor are scheduled by the rate-monotonic algorithm?
3
4
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 .
4
(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.
5
Resource Access Control 1. A system contains three 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
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 .
5
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]
Use the basic priority-ceiling protocol to schedule the system of jobs. Give the schedule and show also the current priority of the executing job and the current priority ceiling at all time instants. 2. A system contains the following four periodic tasks: T1 = (φ1 ,4,1), T2 = (φ2 ,5,1.5), T3 = (φ3 ,6,1) and T4 = (φ4 ,8,1). The resource requirements of the tasks are given in the following figure.
0.5
T1
0.3 T2
X
0.2 Y
T3
0.6 0.4
Z
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]
(a) Use the basic priority-inheritance protocol to schedule the system of jobs. Give the schedule and show also the current priority of the executing job at all time instants. (b) Use the basic priority-ceiling protocol to schedule the system of jobs. Give the schedule and show also the current priority ceiling and the current priority of the executing job at all time instants. 4. A system contains the following six periodic tasks: T1 = (5,1), T2 = (6,1), T3 = (8,1), T4 = (10,1), T5 = (40,1) and T6 = (50,1) and four resources W , X, Y , and Z. The resource requirements of the tasks are given in the following figure.
W 0.2
T1
0.7 X
T3
T5
0.5
T2
Y
0.9 0.6
0.4
T6
Z
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.
6
Scheduling Aperiodic and Sporadic Jobs in Priority-Driven Systems 1. A system consists of three independent periodic tasks, T1 = (4,1), T2 = (6,1), T3 = (11,2). The system is scheduled rate-monotonically. In addition to these tasks a simple sporadic server with an execution budget of es = 1 shall be integrated into the system. (a) 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) For this task use a sporadic server with the parameters (ps , es ) = (8,1). What are the response times of the following aperiodic jobs: A1 arrives at 1 and has an execution time of 1.5, A2 arrives at 9 and has an execution time of 3, and A3 arrives at 23.5 and has an execution time of 0.5. Give the schedule for all tasks and the budget of the sporadic server at all time instances. 7
(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!
7
Real-Time Operating Systems 1. How can the CPU utilization be measured in a priority-driven preemptive real-time operating system with fixed priorities such as MicroC/OSII? 2. Given are the following two periodic tasks: T1 = (300, 100), T2 = (400, 200). The task T1 executes periodically a single function f1 , which has an execution time that is always less than 100 time units. The task T2 executes a single function f2 , which has an execution time that is always less than 200 time units. Explain, how you can implement these periodic tasks using a hardware timer, and a preemptive real-time operating systems that provides soft timers and semaphores. Illustrate your solution with a diagram containing hardware timer, soft timer(s), semaphores and tasks, and give pseudocode for both tasks T1 and T2 .
8
8
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.
9
Embedded System Design 1. One morning Peter’s boss comes to his office and tells him a splendid idea. “I have read a lot about these systems-on-chip. Now we can put a huge amount of processors and memory on a single chip, which gives an extreme performance! Now, let’s think of the whole PC-program market. Why not simply use a system-on-chip platform inside the PC, write an intelligent compiler and earn a lot of dollars, euro, or kronor! I think this is the way to go! Come on Peter, since you are our expert engineer, I want you within a few days to come up with the following: • some strategy for a compiler that implements a sequential Cprogram efficiently on some system-on-a-chip; • an idea of possible hardware platforms. But not only one, there are plenty of customers out in the world, and you know the customer is KING!
9
So, come on, start working, we’ll be rich very soon!” While Peter’s enthusiastic boss leaves the office, Peter starts to think about the implementation of the great idea of his boss. . . Within a year you can be at Peter’s place. Please help him to answer the following questions. (a) What are the key problems and challenges, which have to be solved? Motivate! (b) Can all expectations of Peter’s boss be met or should Peter convince him to modify his plans? What should be modified and why? (c) Are there some general principles that are important for the development of the “compiler”? Explain and motivate these principles! (d) Give an overview of the parts of the “compiler”. What are the tasks that have to be done in order to get a running application,which exploits the advanced SOC architectures, from a sequential program. This task has not an exact answer, but shall show your understanding of the system-on-chip design process! Thus it is very important that you motivate your answers. Without motivations no points will be awarded. Focus on the most central points and try to keep your answers within one or two pages.
10
A
Solution to selected exercises • 1-1 (a) Acquire Lock (Wait/P(S)) and Release Lock (Signal/V(S)) P(S) - Wait pk
V(S) - Signal S
pk
tWait
tSignal
pk+1
S
pk+1
(b) Protection of a Shared Resource T1
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)
Since rank(Γ) needs to be s−1 as necessary requirement for a PASS, x = 4 and y = 3. The number of firings can be calculated by finding a solution to 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)
A simple solution would use the following schedule with z = 12 is {a, a, a, a, b, b, c, c, c}.
12
Firing Node Arc (c → a) Arc 2 (a → b) Arc 3 (b → c) Initial 12 0 0 a 9 1 0 a 6 2 0 a 3 3 0 a 0 4 0 b 0 2 3 b 0 0 6 c 4 0 4 c 8 0 2 c 12 0 0 Max Buffer 12 4 6 However, there is a better solution that takes into account that a firing of node c generates tokens for node a. Here z = 8 and the schedule is {a, a, b, c, a, a, b, c, c}. Firing Node Arc (c → a) Arc 2 (a → b) Arc 3 (b → c) Initial 8 0 0 a 5 1 0 a 2 2 0 b 2 0 3 c 6 0 1 a 3 1 1 a 0 2 1 b 0 0 4 c 4 0 2 c 8 0 0 Max Buffer 8 2 4 (b) The required buffer sizes are b = [bc→a , ba→b , bb→c ] = [8, 2, 4] (c) Since the schedule is static and periodic, we repetitively calls the functions (nodes). Each time a function is executed it reads data from the input buffer and writes it into an output buffer. A realtime operating system is not needed. • 2-1 (a)
– S1 (23, 1): Acceptance test at time 5. Sufficient slack in frames 2, 3 and 4 (1.5 time units) ⇒ Accepted! – S2 (16, 0.8): Acceptance test at time 10. Acceptance depends on usage of slack-stealing. (a) Slack-stealing is not used: S2 is not accepted. There is not sufficient slack (0.5 time units in frame 3). (b) Slack-stealing is used: S2 is accepted. There is sufficient slack in the beginning of frame 3 and 4. There is still enough slack for S1 (in the beginning of frame 5). – S3 (20, 0.5): Acceptance test at time 10. Acceptance depends on usage of slack-stealing.
13
(a) Slack-stealing is not used (only S1 has been accepted): S3 is accepted. There is sufficient slack (0.5 time units in frame 4). (b) Slack-stealing is used (S1 and S2 has been accepted). There is not sufficient slack S3 (only 0.2 in the beginning of frame 4). The diagrams are shown below: (a) No Slack-Stealing (Figure includes aperiodic job):
0
5
10
10
15
20
20
25
30
0
5
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
(b) Three processors - non-preemptable jobs (Priority: π1 > π2 > · · · > π9 ) Deadline
0
2
4
6
8
10
12
14
16
All jobs meet their deadline! (c) Three processors - preemptable jobs (Priority: π1 > π2 > · · · > π9 ) Deadline
0
2
4
6
8
10
12
14
16
Job J9 does not meet its deadline! (d) Four processors - non-preemptable jobs (Priority: π1 > π2 > · · · > π9 ) Deadline
0
2
4
6
8
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
0
2
4
6
8
10
12
14
16
Job J9 does not meet its deadline! Another scheduling anomaly. (Schedule is identical for preemptable and non-preemptable jobs) 15
• 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)
1
Time
0 0
1
2
3
4
5
6
7
8
9
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 i−1 X t wx (t) = ex + ek (4) pk k=1
Here wx (t) = 1 +
t t 1+ 3 4 8
(5)
We start the iteration at time t(0) = W2 + ex = 5, and continue until t(l) = t(l+1) (success) or t(l) > p2 (failure). In case of success, the deadline is t(l) . 16
t(1) t(2)
= = = =
1 + 54 1 + 58 3 6 1 + 64 1 + 68 3 6
(6)
Since t(1) = t(2) , Wx = 6. The time demand for w3 is t t t 1+ 3+ 1 w3 (t) = 2 + 4 8 9
(7)
We start our iteration with t(0) = Wx + e3 = 8. t(1)
= 2+ = 8
8 4
1+
8 8
3+
8 9
1
(8)
Since t(0) = t(1) , W3 = 8. Thus all tasks meet their deadlines. • 4-4 1 (a) Since the utilization U = 25 + 38 + 10 = 0.875 > URM (3), there is no guarantee that there is a feasible schedule.
(b) Since the utilization U = 0.944 ≤ ULST = 1, there exists a feasible schedule. (c) Since the relative deadline of the task (0, 6, 1, 4)} is smaller than the P4 period, we have to calculate the density ∆ = i=1 min(peii ,Di ) of the set of tasks, which is ∆ = 1.027 > 1. Thus there is no guarantee that there is a feasible schedule. (d) Since this is a set of simply periodic tasks and U = 0.944 ≤ 1, there exists a feasible schedule. • 4-5 1. The process T2 can be blocked by process T3 for 0.4 time units. This is reflected by an additional term b2 = θ2 = 0.4 in the time demand analysis function. 2. The effects of tick scheduling are modelled by – an additional scheduler task T0 = (p0 , e0 ) = (1.0, 0.04) – an extended execution time CS 0 = 0.03 for all higher-priority tasks (including T2 ), which reflects the time to move a released job to the ready queue. – an additional task T00 = (p3 , CS 0 ) = (10, 0.03), which reflects the time it takes to move a released job of task T3 to the ready queue. Since the task is run by the scheduler, it gets a higher priority than T1 and T2 .
17
– modify the blocking time b2 due to the non-preemptibility of T3 and tick scheduling to θ2 b02 = ( + 1)p0 = 2 (9) p0 Thus the time demand analysis function that includes the practical factors for task T2 is l m l m l m w2 (t) = b02 + (e2 + CS 0 ) + pt0 (e0 ) + pt1 (e1 + CS 0 ) + pt3 CS 0 t = 2 + 2.03 + 1t 0.04 + 4t (1.03) + 10 (0.03) (10) • 5-3 (a) Priority-Inheritance Protocol 1
1 1 X
J1 2
2 2 Y
J2 3 3 Y
J3
2 Y
3
4 4 X
J4 0
1 1 1 X X X
2
4
6
8
4
10
12
14
16
(b) Priority-Ceiling Protocol 1
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
4
2
4
6
8
10
12
14
16
2
4
6
8
10
12
14
16
ˆ Π(t) 1 2 3 4 Ω 0
• 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
0
A1 A2 A2
4
8
A2
12
16
20
A3
A2
24
28
Budget 1
C1
0
C1
C1
4
8
C1
12
16
20
3 A2
1.5 A1 1
24
C1 C2
28
0.5 A3 23.5
9
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 i−1
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 + t−e ps iterative solution, we start with t(0) = e1 + es = 3. 2 = 3 + 3−2 6 = 5 = 3 + 5−2 2 6 = 5
t(1) t(2)
(12)
Since t(1) = t(2) the maximum response time is W1 = 5. 3. The schedule below assumes that the polling server is always backlogged. S1 = (1, 10, 3)
S2 = (5, 36, 5)
S3 = (17, 32, 6)
TS T1 T2 0
5
10
15
20
25
30
– The sporadic jobs S1 is not accepted, since the server has no budget at time 1. Thus the job can not be earlier executed than in cycle 6. Not sufficient slack. – The sporadic job S2 is accepted. – The sporadic jobs S3 is not accepted, since the server has not sufficient slack for both S2 and S3 . The completion time for S2 is 19.
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
B
Wait Task 1
B
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
Since there is no state with no outgoing edges, the algorithm is deadlock-free for two tasks. Since there is no path on which a task has issued a wait on the semaphore S, but does never acquire it, the algorithm does not starve any of the two tasks. Or with other words: On all paths, where the semaphore S is requested by a task, the access is eventually granted to that task. (b) (0) (1)
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
Load Timer Watchdog Timer Reset
22
A watchdog timer watches the operation of the CPU. Initially it is loaded with a value and counts downwards. In case it reaches zero, it shall reset the system into a safe state. In a working system the watchdog timer shall never reach zero! Thus the CPU needs to reload the watchdog timer before it reaches zero. Thus the system is configured in such a way that the CPU reloads the timer perodically. In case the CPU is not able to reload the timer, something unexpected has happened, and then the watchdog timer will put the system into a safe state.
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