RTS Exercises & Solutions

23
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 11 1 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 Petri- net? (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

description

solution of liu

Transcript of RTS Exercises & Solutions

  • IL2212 Embedded SoftwareExercises

    Ingo Sander

    February 24, 2012

    Contents

    1 Modeling and Languages 1

    2 Clock-Driven and Round-Robin Scheduling 2

    3 Real-Time Scheduling onMultiprocessors 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 SystemDesign 9

    A Solution to selected exercises 11

    1 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 Petri-net?

    (b) Draw a Petri Net where a semaphore is used to protect a sharedresource that is accessed by two tasks.

    2. How can you express a watchdog timer in Esterel? The timer shall senda signal ALARM, if no signal ALIVE has been received for 60 emissions ofthe signal TICK.

    3. Given is the following synchronous data flow graph.

    1

  • 321 42

    1

    1

    1

    2D

    1

    2

    1 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 solutionsafter a sequence of firings of this Petri net. You do not have to drawthe 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.

    1b

    c

    a

    2

    y2

    x

    3

    zD

    (a) Give the smallest possible values for x, y and z, so that a periodicadmissible sequential schedule exists. Motivate your answer. Givethe schedule.

    (b) What are the required buffer sizes for this schedule?

    (c) How would you efficiently realize a system based on this SDF graphin software on a single processor? Keep the discussion on an ab-stract level.

    2 Clock-Driven and Round-Robin Scheduling

    1. (Taken from [Liu00]) A system uses the cyclic EDF algorithm to sched-ule 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 initialamount 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, sporadicjobs S2(16, 0.8) and S3(20, 0.5) arrives in frame 2. In which framesare the accepted sporadic jobs scheduled?

    (b) Suppose that, in addition to the sporadic jobs, an aperiodic jobwith execution time 3 arrives at time 1. When will it be completed,if the system does not do slack stealing?

    3 Real-Time Scheduling onMultiprocessors

    1. (Taken from [Liu00], who based it on [Gra69]) A system contains ninenonpreemptable jobs named Ji, for i = 1, 2, . . . , 9. Their executionstimes are 3, 2, 2, 2, 4, 4, 4, 4, and 9, respectively, their release times areequal to 0, and their deadlines are 12. J1 is the immediate predecessorof J9, and J4 is the immediate predecessor of J5, J6, J7, and J8. Thereare no other precedence constraints. For all the jobs, Ji has a higherpriority 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 threeprocessors?

    (c) Can the jobs meet their deadlines if we make them preemptableand schedule them preemptively?

    (d) Can the jobs meet their deadlines if they are scheduled nonpremp-tively on four processors?

    (e) Suppose that due to an improvement of the three processors, theexecution time of every job is reduced by 1. Can the jobs meet theirdeadlines?

    2. A multiprocessor system contains the following set of independent pe-riodic tasksT = {(3,1), (4,1), (9,3), (10,4), (27,9), (56,5)}.

    (a) How many processors are needed, if the task assignment is donewith the rate-monotonic small task (RMST) algorithm. Give theassignment of tasks to processors.

    (b) Can you find a better task assignment than the one produced bythe RMST algorithm? In this case give the assignment of tasks toprocessors and motivate, why the RMST algorithm was not able tofind it.

    3. A multiprocessor system contains the following set of preemptable in-dependent 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 taskson 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 bescheduled 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 theset of independent periodic tasks is schedulable using the rate-monotonic algorithm. Give the maximum possible response timesWi for each task!

    (b) Assume now that an additional task T4 = (8, 1) is introduced. Cal-culate the maximum possible response times for the task T4 by it-eration 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 followingpractical factors shall be taken into account for a time demand analysisin order to calculate the maximum possible response time of task T2. Inthe following subtasks you have only to take into account the practicalfactors that affect the response time for task T2.

    For each subtask motivate the additional terms for the time demandfunction in one or two sentences.

    (a) Give the time demand analysis function forw2(t) if no practical fac-tors are taken into account.

    (b) Take now the time for context switching is into account. Each con-text switch takes 0.05 units of time. Give the modified time demandanalysis function for w2(t).

    (c) The task T3 shall have a non-preemptable section that lasts for 0.5time units. Give the modified time demand analysis function forw2(t).

    (d) Assume now that the scheduler operates periodically. The periodp0 of clock interrupts is 1.0 and the scheduler takes 0.1 units of timeto complete, when there are no ready jobs to be moved to the readyqueue. The scheduler takes 0.1 time units of time to move a jobfrom the waiting queue to the ready queue. Give the modified timedemand analysis function for w2(t).

    3. Given is the following set of independent periodic tasks, which shall bescheduled rate-monotonically.

    T1 = (4,1); T2 = (8,3); T3 = (10,2)

    1The 4-tuple (i, pi, ei,Di) gives the phase i, period pi, execution time ei and relative dead-lineDi. In case of a 2-tuple (pi, ei) i is 0 andDi is pi.

    4

  • (a) Show with the graphical form of the time-demand analysis, if theset of independent periodic tasks is schedulable using the rate-monotonic algorithm. Give the maximum possible response timesWi 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 theresponse times by an iteration of the time demand analysis func-tion, in case they still meet their deadlines.

    4. Can you guarantee that a feasible schedule exists without a simulationof the schedule or time demand analysis, if

    (a) the set of tasks T = {(5, 2), (8, 3), (10, 1)} is scheduled by the rate-monotonic algorithm.

    (b) the set of tasks T = {(3, 1), (6, 1), (18, 6), (36, 4)} is scheduled by theleast-slack-time-first algorithm.

    (c) the set of tasks T = {(3, 1), (0, 6, 1, 4), (18, 6), (36, 4)} is scheduledby the earliest-deadline-first algorithm.

    (d) the set of tasks T = {(3, 1), (6, 1), (18, 6), (36, 4)} is scheduled by thedeadline-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 taskpractical factors shall be taken into account for a time demand analysisin order to calculate the maximum possible response time of task T2.You have only to take into account the practical factors that affect theresponse time for task T2.

    Give the time demand analysis function for w2. Motivate modified andadditional terms that arise due to practical factors in one or two sen-tences.

    (a) The task T3 shall have a non-preemptable section that lasts for 0.4time units.

    (b) Assume that the scheduler operates periodically. The period p0 ofclock interrupts is 1.0 and the scheduler takes 0.04 units of time tocomplete, when there are no ready jobs to be moved to the readyqueue. The scheduler takes 0.03 time units of time to move a jobfrom 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 fol-lowing table shows the job parameters and their execution pattern. Theexecution pattern describes how each job is executed. [R;t] is read as

    2The 4-tuple (i, pi, ei,Di) gives the phase i, period pi, execution time ei and relative dead-lineDi. In case of a 2-tuple (pi, ei) i is 0 andDi is pi.

    5

  • follows: the job requires the resource R for t time units. Here, job J1requires 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 sec-tion, which comprises the following resource requests: the recourse Xis requested for two time units, the resource Y is requested for one timeunit, and finally the resource X is requested for one time unit.

    Job ri ei pii Execution PatternJ1 7 3 1 [-;1][X;1][-;1]J2 5 3 2 [-;1][Y;1][-;1]J3 4 2 3J4 2 6 4 [-;1][[X;2][Y;1][X;1]][-;1]J5 0 6 5 [-;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 executingjob 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 ofthe tasks are given in the following figure.

    T1

    T2

    T3

    X

    Y

    T4

    Z

    0.3

    0.5

    0.4

    0.2

    0.6

    The tasks are scheduled by the rate-monotonic algorithm and the ba-sic priority-ceiling protocol. Calculate the maximum response time foreach task. Are the tasks schedulable for any combination of 1, 2, 3and 4?

    3. A system contains four jobs. There are two resources X and Y. The fol-lowing table shows the job parameters and their execution pattern. Theexecution pattern describes how each job is executed. [R;t] is read asfollows: the job requires the resource R for t time units. Here, job J3requires no resource for one time unit, the resource Y for two time unitsand no resource for one further time unit.

    Job ri ei pii Execution PatternJ1 6 3 1 [-;1][X;1][-;1]J2 4 3 2 [-;1][Y;1][-;1]J3 2 4 3 [-;1][Y;2][-;1]J4 0 6 4 [-;1][X;4][-;1]

    6

  • (a) Use the basic priority-inheritance protocol to schedule the systemof jobs. Give the schedule and show also the current priority of theexecuting job at all time instants.

    (b) Use the basic priority-ceiling protocol to schedule the system ofjobs. Give the schedule and show also the current priority ceilingand 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 thefollowing figure.

    T1

    T2

    T3

    X

    Y

    T4

    Z

    0.4

    0.6

    0.9T6

    T5

    0.2

    0.5

    W

    0.7

    The tasks are scheduled by the rate-monotonic algorithm.

    (a) Give the maximum blocking times for all tasks, if the nonpreemp-tive critical section protocol is used.

    (b) Give the maximum blocking times for all tasks, if the basic priority-ceiling protocol is used.

    6 Scheduling Aperiodic and Sporadic Jobs inPriority-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 addi-tion to these tasks a simple sporadic server with an execution budget ofes = 1 shall be integrated into the system.

    (a) What is the minimal period ps, where ps is an integer number, thatcan be chosen for the sporadic server, so that all periodic tasks arestill 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 9and has an execution time of 3, and A3 arrives at 23.5 and has anexecution time of 0.5. Give the schedule for all tasks and the budgetof the sporadic server at all time instances.

    7

  • (c) Assume that the system uses a deferrable server with the same val-ues of ps and es instead of the sporadic server. How can you findout, if the periodic tasks are still schedulable? Motivate your an-swer (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 thesetasks a periodic server with a period ps and an execution budget of esshall be integrated into the system.

    (a) Assume that the periodic server is a simple sporadic server with anexecution budget of es = 2.What is the minimal period ps, where psis an integer number, that can be chosen for the sporadic server, sothat 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 fol-lowing sporadic jobs Si = (ri, di, ei) can be accepted given the fol-lowing order? Assume that the accepted sporadic jobs are sched-uled 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 preemp-tive real-time operating system with fixed priorities such as MicroC/OS-II?

    2. Given are the following two periodic tasks: T1 = (300, 100), T2 =(400, 200). The task T1 executes periodically a single function f1, whichhas an execution time that is always less than 100 time units. The task T2executes a single function f2, which has an execution time that is alwaysless than 200 time units.

    Explain, how you can implement these periodic tasks using a hardwaretimer, and a preemptive real-time operating systems that provides softtimers and semaphores.

    Illustrate your solution with a diagram containing hardware timer, softtimer(s), semaphores and tasks, and give pseudocode for both tasks T1and T2.

    8

  • 8 Interprocess Communication

    1. The following algorithm using a weak binary semaphore S that was ini-tialized with S = {1, } solves the critical section problem for two pro-cesses.P1 P2loop 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 pro-cesses?

    2. A set ofn concurrent processes accesses a shared variable Shared of typeinteger. In order to provide consistency, mutual exclusive access to thevariable is to be ensured during a read operation ReadVariable and awrite operation WriteVariable.

    (a) Give the pseudo-code for a protected object with the opera-tions ReadVariable() and WriteVariable(X: Integer) that en-sures mutually-exclusive access to the variable Shared.

    (b) What property is required for the protected object, so that starva-tion does not occur?

    3. Describe the principle operation of a watch-dog timer. Illustrate it witha block diagram.

    9 Embedded SystemDesign

    1. One morning Peters boss comes to his office and tells him a splendididea. I have read a lot about these systems-on-chip. Now we can put ahuge amount of processors and memory on a single chip, which givesan extreme performance! Now, lets think of the whole PC-programmarket. 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! Ithink this is the way to go!

    Come on Peter, since you are our expert engineer, I want you within afew days to come up with the following:

    some strategy for a compiler that implements a sequential C-program efficiently on some system-on-a-chip;

    an idea of possible hardware platforms. But not only one, there areplenty of customers out in the world, and you know the customeris KING!

    9

  • So, come on, start working, well be rich very soon!

    While Peters enthusiastic boss leaves the office, Peter starts to thinkabout the implementation of the great idea of his boss. . .

    Within a year you can be at Peters place. Please help him to answer thefollowing questions.

    (a) What are the key problems and challenges, which have to besolved? Motivate!

    (b) Can all expectations of Peters boss be met or should Peter convincehim to modify his plans? What should be modified and why?

    (c) Are there some general principles that are important for the devel-opment of the compiler? Explain and motivate these principles!

    (d) Give an overview of the parts of the compiler. What are the tasksthat have to be done in order to get a running application,which ex-ploits the advanced SOC architectures, from a sequential program.

    This task has not an exact answer, but shall show your understanding ofthe system-on-chip design process! Thus it is very important that youmotivate your answers. Without motivations no points will be awarded.Focus on the most central points and try to keep your answers withinone or two pages.

    10

  • A Solution to selected exercises

    1-1(a) Acquire Lock (Wait/P(S)) and Release Lock (Signal/V(S))

    tWait

    pk+1

    pk S

    S

    tSignal

    pk

    pk+1

    P(S) - Wait V(S) - Signal

    (b) Protection of a Shared Resource

    t1

    t2

    t3

    t4

    T1 T2

    p1

    p2

    p3

    ps

    p4

    p5

    p6

    Critical

    Section

    Semaphore

    1-2Esterel Implementation of Watchdog

    WatchdogTimer

    TICK

    ALIVE

    System

    ALARM

    ...

    loop

    do % ALARM is emitted

    await 60 TICK; % if 60 TICKs are received

    emit ALARM % before a single occurence

    watching ALIVE % of ALIVE!

    11

  • end

    ||

    loop % System

    ...

    emit ALIVE

    ...

    end

    ...

    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 inp4 is generated. At this stage no transition is enabled and thePetri-net reaches a final state.

    2. If t2 fires, the tokens in p2 and p3 are consumed and a token inp5 is generated. At this stage no transition is enabled and thePetri-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 2 00 3 2y 0 x

    =

    3 0 40 3 2y 0 x

    (1)

    Since rank() needs to be s1 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 00 3 23 0 4

    q1q2q3

    =00

    0

    (2)A possible solution is

    Q =

    423

    (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 0a 6 2 0a 3 3 0a 0 4 0b 0 2 3b 0 0 6c 4 0 4c 8 0 2c 12 0 0

    Max Buffer 12 4 6However, there is a better solution that takes into account that afiring of node c generates tokens for node a. Here z = 8 and theschedule 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 0a 2 2 0b 2 0 3c 6 0 1a 3 1 1a 0 2 1b 0 0 4c 4 0 2c 8 0 0

    Max Buffer 8 2 4

    (b) The required buffer sizes are b = [bca, bab, bbc] = [8, 2, 4]

    (c) Since the schedule is static and periodic, we repetitively calls thefunctions (nodes). Each time a function is executed it reads datafrom the input buffer and writes it into an output buffer. A real-time operating system is not needed.

    2-1

    (a) S1(23, 1): Acceptance test at time 5. Sufficient slack in frames2, 3 and 4 (1.5 time units) Accepted!

    S2(16, 0.8): Acceptance test at time 10. Acceptance depends onusage 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 stillenough slack for S1 (in the beginning of frame 5).

    S3(20, 0.5): Acceptance test at time 10. Acceptance depends onusage of slack-stealing.

    13

  • (a) Slack-stealing is not used (onlyS1 has been accepted): S3 isaccepted. There is sufficient slack (0.5 time units in frame4).

    (b) Slack-stealing is used (S1 andS2 has been accepted). Thereis not sufficient slack S3 (only 0.2 in the beginning of frame4).

    The diagrams are shown below:

    (a) No Slack-Stealing (Figure includes aperiodic job):

    20 2525 30

    10 15 20

    0 5 10

    (b) Slack-Stealing:

    20 2525 30

    10 15 20

    0 5 10

    (b) As can be seen in the upper figure, the aperiodic job finishes at time30.

    3-1

    (a) Precedence Graph

    14

  • (b) Three processors - non-preemptable jobs (Priority: pi1 > pi2 > > pi9)

    0 2 4 6 8 10 12 14 16

    Deadline

    All jobs meet their deadline!

    (c) Three processors - preemptable jobs (Priority: pi1 > pi2 > > pi9)

    0 2 4 6 8 10 12 14 16

    Deadline

    Job J9 does not meet its deadline!

    (d) Four processors - non-preemptable jobs (Priority: pi1 > pi2 > >pi9)

    0 2 4 6 8 10 12 14 16

    Deadline

    J9 misses its deadline! Observe that all jobs meet their dead-line with only three processors. Such a phenomenon is called ascheduling anomaly.

    (c) Three processors - reduced execution time (Priority: pi1 > pi2 > > pi9)

    0 2 4 6 8 10 12 14 16

    Deadline

    Job J9 does not meet its deadline! Another scheduling anomaly.(Schedule is identical for preemptable and non-preemptable jobs)

    15

  • 3-3The set of tasks {(6, 1), (18, 9), (54, 18)} is simply periodic. The utiliza-tion of this set is U{(6,1),(18,9),(54,18)} = 1. Thus this set of tasks can bescheduled on a single processor.

    The other tasks have a total utilization of U{(4,1),(8,2),(20,4),(100,2)} =0.72 < URM (4) = 4(2

    14 1) = 0.757. They can be scheduled on a single

    processor.

    Two processors are required!

    4-3

    (a) Time Demand:

    0 1 2 3 4 5 6 7 8 9 10

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    w1(t)

    Time

    Time Demand

    11

    w2(t)

    w3(t)

    The maximum response times are derived from the diagram thatW1 = 1, W2 = 4 and W3 = 7.

    (b) The response times for T1 and T2 do not change, since the priorityof Tx is lower than T1 and T2, but higher than T3.Thus we calculate the response time for Tx. The time demand forTx is

    wx(t) = ex +

    i1k=1

    t

    pk

    ek (4)

    Here

    wx(t) = 1 +

    t

    4

    1 +

    t

    8

    3 (5)

    We start the iteration at time t(0) = W2 + ex = 5, and continue untilt(l) = t(l+1) (success) or t(l) > p2 (failure). In case of success, thedeadline is t(l).

    16

  • t(1) = 1 +54

    1 +

    58

    3

    = 6t(2) = 1 +

    64

    1 +

    68

    3

    = 6

    (6)

    Since t(1) = t(2), Wx = 6.

    The time demand for w3 is

    w3(t) = 2 +

    t

    4

    1 +

    t

    8

    3 +

    t

    9

    1 (7)

    We start our iteration with t(0) = Wx + e3 = 8.

    t(1) = 2 +84

    1 +

    88

    3 +

    89

    1

    = 8(8)

    Since t(0) = t(1), W3 = 8. Thus all tasks meet their deadlines.

    4-4

    (a) Since the utilization U = 25 +38 +

    110 = 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 feasibleschedule.

    (c) Since the relative deadline of the task (0, 6, 1, 4)} is smaller than theperiod, we have to calculate the density =

    4i=1

    eimin(pi,Di)

    of theset of tasks, which is = 1.027 > 1. Thus there is no guaranteethat there is a feasible schedule.

    (d) Since this is a set of simply periodic tasks and U = 0.944 1, thereexists a feasible schedule.

    4-5

    1. The process T2 can be blocked by process T3 for 0.4 time units. Thisis reflected by an additional term b2 = 2 = 0.4 in the time demandanalysis 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 releasedjob to the ready queue.

    an additional task T 0 = (p3,CS 0) = (10, 0.03), which reflectsthe time it takes to move a released job of task T3 to the readyqueue. Since the task is run by the scheduler, it gets a higherpriority than T1 and T2.

    17

  • modify the blocking time b2 due to the non-preemptibility ofT3 and tick scheduling to

    b2 = (2p0

    + 1)p0 = 2 (9)

    Thus the time demand analysis function that includes the practical fac-tors for task T2 is

    w2(t) = b2 + (e2 + CS 0) +

    tp0

    (e0) +

    tp1

    (e1 + CS 0) +

    tp3

    CS 0

    = 2 + 2.03 +t1

    0.04 +

    t4

    (1.03) +

    t10

    (0.03)

    (10)

    5-3

    (a) Priority-Inheritance Protocol

    X X X

    X

    J4

    J3

    J2

    J1

    X

    0 2 4 6 8 10 12 14 16

    4 4

    3

    2

    1

    1

    3

    4

    Y

    3

    Y

    2

    1 1

    11

    22

    Y

    (b) Priority-Ceiling Protocol

    X X X

    X

    0 2 4 6 8 10 12 14

    J4

    J3

    J2

    J1

    X

    Y

    Y

    0 2 4 6 8 10 12 14 16

    Y

    4 4

    3

    3

    2

    2

    1

    1

    1 1

    2 2

    33 3

    4

    4321

    (t)

    16

    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 re-maining size of the server is uS = 0.158. Thus the minimal periodfor the sporadic server is ps = d 10.158e = 7.

    (b) Priority-Order: pi(T1) > pi(T2) > pi(TS) > pi(T3)

    0 4 8 12 16 20 24 28

    1Budget

    0 4 8 12 16 20 24 28

    A1 A1A2 A2 A2 A2 A3

    C1 C1 C1 C1 C1C2C1C2

    A11

    1.5A2

    9

    3A3

    0.523.5

    tf BEGIN END tr te te + ps Rule

    2.0 0.0 2.0 0.0 0.0 8.0 R2, but also R3b. System is idleat t = 7 and becomes busyagain at tb = 8. Next replenish-ment time is at t+r = 8 (both ruleR2 and R3 give the same next re-plenishment time t+r = 8.0.

    9.0 8.0 9.0 8.0 8.0 16.0 R2, but also R3b. System is idleat t = 10 and becomes busyagain at tb = 11. Next replenish-ment time is moved to t+r = 11.

    11.0 8.0 9.0 11.0 11.0 19.0 R2, but also R3b. System is idleat t = 17 and becomes busyagain at tb = 18. Next replenish-ment time is moved to t+r = 18.

    19.0 18.0 19.0 18.0 18.0 26.0 R2, but also R3b. System is idleat t = 21 and becomes busyagain at tb = 22. Next replenish-ment time is moved to t+r = 22.

    22.0 20.0 21.0 22.0 22.0 30.0 R2, but also R3b. System is idleat t = 26.5 and becomes busyagain at tb = 28. Next replenish-ment time is moved to t+r = 28.

    19

  • 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 ex-ecute for 2es in an interval of length 2es. In order to determinewhether the system is still schedulable, time demand analysis canbe used, where

    wi(t) = ei + es + d t espsees +

    i1k=1

    d tpkeek (11)

    for the tasks, which have a lower priority than the deferrable server.

    6-21. 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 schedula-ble, if U{T1,T2} +

    esps URM (3) = 3(2 13 1) = 0.78.

    It follows that ps =

    2URM (3)U{T1,T2}

    = 5.

    2. The time demand for task T1 is w1(t) = e1 + es +tesps

    es. For an

    iterative solution, we start with t(0) = e1 + es = 3.

    t(1) = 3 +326

    2

    = 5t(2) = 3 +

    526

    2

    = 5

    (12)

    Since t(1) = t(2) the maximum response time is W1 = 5.

    3. The schedule below assumes that the polling server is always back-logged.

    T2

    0 5 10 15 20 25 30

    T1

    TS

    S3 = (17, 32, 6)S1 = (1, 10, 3) S2 = (5, 36, 5)

    The sporadic jobs S1 is not accepted, since the server has nobudget at time 1. Thus the job can not be earlier executed thanin 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-1An extra task with lower priority than the working task set can be usedto indirectly measure the CPU untilization. The extra task is running acounter.

    The measurement works as follows:

    In the initialisation phase, only the counter task is run for a definedtime period tm (for example 100 OS ticks). This value maxCountercorresponds 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, thecounter is reset to 0 every time period tm. At the end of the pe-riod, the current counter value curCounter is determined. Then theutilization can be calculated by

    U = 1 curCountermaxCounter

    (13)

    7-2

    B B

    Hardware

    Timer

    SoftTimer

    SoftTimer

    Interrupt every Time Unit

    Post every 400 time unitsPost every 300 time units

    Task 1 Task 2

    WaitWait

    Sem2Sem1

    void task1(...) {

    while(1) {

    OSSemPend(Sem1);

    f1();

    }

    }

    void task2(...) {

    while(1) {

    OSSemPend(Sem2);

    f2();

    }

    }

    8-1

    (a) All possible states of the program:

    21

  • Since there is no state with no outgoing edges, the algorithm isdeadlock-free for two tasks.Since there is no path on which a task has issued a wait on thesemaphore S, but does never acquire it, the algorithm does notstarve any of the two tasks. Or with other words: On all paths,where the semaphore S is requested by a task, the access iseventually granted to that task.

    (b)Process P1 Process P2 Process P3 S

    (0) NCS NCS NCS {1, }wait(S)

    (1) CS {0, }wait(S)

    (2) blocked {0, {P2}}wait(S)

    (3) blocked {0, {P2, P3}}signal(S)

    (4) NCS CS {0, {P2}}wait(S)

    (5) blocked {0, {P1, P2}}signal(S)

    (6) CS NCS {0, {P2}}wait(S)

    (7) blocked {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 star-vation in the sense that a process (likeP2) 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 theprotected object, need to be queued, so that they will eventually beserved.

    8-3

    WatchdogTimer

    Load Timer

    ResetCPU

    22

  • A watchdog timer watches the operation of the CPU. Initially it is loadedwith a value and counts downwards. In case it reaches zero, it shallreset the system into a safe state. In a working system the watchdogtimer shall never reach zero! Thus the CPU needs to reload the watch-dog timer before it reaches zero. Thus the system is configured in sucha way that the CPU reloads the timer perodically. In case the CPU isnot able to reload the timer, something unexpected has happened, andthen the watchdog timer will put the system into a safe state.

    References

    [Gra69] R. L. Graham. Bounds on multiprocessing timing anaomalies. SIAMJournal of Applied Mathematics, 17(2), March 1969.

    [Liu00] Jane W. S. Liu. Real-Time Systems. Prentice Hall, 2000.

    23