IMC4-2RT Real-time scheduling Damien MASSON - - PowerPoint PPT Presentation

imc4 2rt
SMART_READER_LITE
LIVE PREVIEW

IMC4-2RT Real-time scheduling Damien MASSON - - PowerPoint PPT Presentation

IMC4-2RT Real-time scheduling Damien MASSON http://esiee.fr/~massond/Teaching/ last modification: December 1, 2014 References Hard real-time computing systems: predictable scheduling algorithms and applications, Giorgio C. Buttazzo, Springer,


slide-1
SLIDE 1

IMC4-2RT

Real-time scheduling Damien MASSON http://esiee.fr/~massond/Teaching/ last modification: December 1, 2014

slide-2
SLIDE 2

2/56

References

Hard real-time computing systems: predictable scheduling algorithms and applications, Giorgio C. Buttazzo, Springer, 2005 - 425 pages (http://books.google.com/books/about/Hard_real_ time_computing_systems.html?id=fpJAZM6FK2sC) Internet

slide-3
SLIDE 3

3/56

Concurrency

Operating systems are mutlitasks, even on monoprocessors

  • architectures. How is it possible ? with processes !
slide-4
SLIDE 4

4/56

Real-Time

Real-Time: different from quick, more synonymous to deterministic

slide-5
SLIDE 5

4/56

Real-Time

Several kind of real-time systems:

RTS with strict constraints (hard real-time systems): deadline miss equal human life lost / mission failure (avionic industry) RTS with relative constraints(soft real-time systems): deadline misses are tolerated (multimedia) RTS with mixed constraints

slide-6
SLIDE 6

4/56

Real-Time

Several kind of real-time systems:

RTS with strict constraints (hard real-time systems): deadline miss equal human life lost / mission failure (avionic industry) RTS with relative constraints(soft real-time systems): deadline misses are tolerated (multimedia) RTS with mixed constraints

Example

Standard DO-178B developed for the avionic industry in USA distinguish 5 criticality levels, e.g: Safety Critical: failure = human lost (e.g. engines control, automatic pilot) Mission Critical: navigation systems, ...

slide-7
SLIDE 7

5/56

Scheduling

Scheduling algorithm: the algorithm used to decide which task is executed when Schedule: the result of the scheduling algorithm (a sequence

  • f task)

Scheduler: the task responsible to apply the scheduling algorithm to produce the schedule two families: preemptive, non preemptive two methodologies: offline / online

slide-8
SLIDE 8

5/56

Scheduling

Scheduling algorithm: the algorithm used to decide which task is executed when Schedule: the result of the scheduling algorithm (a sequence

  • f task)

Scheduler: the task responsible to apply the scheduling algorithm to produce the schedule two families: preemptive, non preemptive two methodologies: offline / online In this class, we will study online preemptive algorithms

slide-9
SLIDE 9

6/56

Periodic Model

Real-Time: ensure constraints respect. Which constraints ? The most studied model (from the control command field): periodic task systems A periodic task τi is defined by: its first release time instant: ri its worst case execution time (WCET): Ci its period: Ti its relative deadline: Di from which we can deduce the absolute deadline of its instance k: di,k the logic is: upper cases for durations, lower cases for instants ... (extensible model !)

slide-10
SLIDE 10

7/56

Example

Ci Ti Di τ1 3 6 6 τ2 3 12 6 τ3 3 12 12 Round Robin

5 10 1 1 1 1 2 2 2 2 3 3 3 3

τ3 τ2 τ1

slide-11
SLIDE 11

7/56

Example

Ci Ti Di τ1 3 6 6 τ2 3 12 6 τ3 3 12 12 Round Robin

5 10 1 1 1 1 2 2 2 2 3 3 3 3

τ3 τ2 τ1

fixed priorities

5 10 1 1 1 1 2 2 2 2 3 3 3 3

τ3 τ2 τ1

slide-12
SLIDE 12

8/56

Online preemptive real-time scheduling

(Mono Processor)

Tasks instances (job) are sorted by priorities. At each time instant, the scheduler gives CPU to the task with the highest priority. fixed priority: tasks priority are fixed once and for all (according to a constant like period, deadline, importance...

  • r arbitrarily),

dynamic priority: priorities can change, they are given according to a variable like the next deadline proximity, the system laxity... Evaluating a scheduling algorithm ??

slide-13
SLIDE 13

8/56

Online preemptive real-time scheduling

(Mono Processor)

Tasks instances (job) are sorted by priorities. At each time instant, the scheduler gives CPU to the task with the highest priority. fixed priority: tasks priority are fixed once and for all (according to a constant like period, deadline, importance...

  • r arbitrarily),

dynamic priority: priorities can change, they are given according to a variable like the next deadline proximity, the system laxity... Evaluating a scheduling algorithm ??

  • ptimality

schedulability bound easy or not to implement ? execution overhead jitter, stability, average response times...

slide-14
SLIDE 14

9/56

Main algorithms

Rate Monotonic (RM): priority to the task with the smallest period Deadline Monotonic (DM) : priority to the task with the smallest relative deadline EDF : priority to the most urgent JOB (not task) LLF : priority to the task with the smallest laxity (variable function of time)

slide-15
SLIDE 15

9/56

Main algorithms

Rate Monotonic (RM): priority to the task with the smallest period Deadline Monotonic (DM) : priority to the task with the smallest relative deadline EDF : priority to the most urgent JOB (not task) LLF : priority to the task with the smallest laxity (variable function of time)

Laxity

4 4 4 5 6 6 6 7 8 9 11 10 Li(t) = Di(t) − C∗

i (t)

Li(t) Di(t)

slide-16
SLIDE 16

10/56

Exercises

Give the schedules obtain with these 4 algorithms between t = 0 et t = 30 for taskset: ri Ti Di Ci τ1 6 6 2 τ2 7 4 3 τ3 15 15 3

slide-17
SLIDE 17

11/56

RM

  • 10

15 20 25 30 5 τ1 τ2 τ3

slide-18
SLIDE 18

12/56

DM

  • 5

10 15 20 25 30 τ1 τ2 τ3

slide-19
SLIDE 19

13/56

EDF

  • τ1

τ2 τ3 5 10 15 20 25 30

slide-20
SLIDE 20

14/56

LLF

  • τ1

τ2 τ3 5 10 15 20 25 30

slide-21
SLIDE 21

15/56

Schedulability (validity)

= Feasibility

Feasibility: given a taskset, is it possible to propose a schedule that respect all timing constraints? Schedulability: given a taskset, is it possible to propose a deterministic algorithm that generates a valid schedule? Schedulability with A: given a taskset and an algorithm A, is A produces a valid schedule? Several approaches depending on the studied problem and the system criticality: sufficient condition for an admission control scheme, fault and/or overload detection, exact analysis with feasibility/schedulability analysis theory.

slide-22
SLIDE 22

16/56

System Load study

Processor load: U =

n

  • i=1

Ci Ti This can be enough to conclude under certain assumptions: U ≤ n(2

1 n − 1) is sufficient (but not necessary) condition for

the schedulability iff ∀iDi = Ti (implicit deadlines) with a fixed priority algorithm, U ≤ 1 is a necessary and sufficient condition for the schedulability under EDF iff ∀iDi = Ti, ... But if Di ≤ Ti (constrained deadlines), or when Di not related to Ti (general case) things are not so simple...

slide-23
SLIDE 23

17/56

Schedulability study when Di = Ti

(fixed priority)

U ≤ n(2

1 n − 1) is a sufficient condition and U ≤ 1 is a

necessary condition when 1 ≤ U > n(2

1 n − 1) ?

workload study: we are looking for a time instant before the deadline where all the cumulated demand is satisfied worst case response time computation

job j response time Rj

i : time between the request and the end

  • f the job

task worst case response time (WCRTi): maximum amongst the Rj

i for all j

slide-24
SLIDE 24

18/56

Demand study

If ∀i, Di ≤ Ti, the system is schedulable with a fixed priority algorithm iff it exists a time instant t in the interval (0, Di] such that t = wi(t) with wi(t) =

  • k≤i

t Tk

  • Ck

recursive algorithm: computation of t1 = wi(0), then t2 = wi(t1), ..., tn = wi(tn−1) the algorithms ends either when the deadline is reached or if a t with t = wi(t) is found.

slide-25
SLIDE 25

18/56

Demand study

If ∀i, Di ≤ Ti, the system is schedulable with a fixed priority algorithm iff it exists a time instant t in the interval (0, Di] such that t = wi(t) with wi(t) =

  • k≤i

t Tk

  • Ck

recursive algorithm: computation of t1 = wi(0), then t2 = wi(t1), ..., tn = wi(tn−1) the algorithms ends either when the deadline is reached or if a t with t = wi(t) is found.

Exercises

study the level 2 demand on the preceding example with RM study the level 2 demand on the preceding example with DM study the level 3 demand on the preceding example with RM is the level 3 demand with DM different ?

slide-26
SLIDE 26

19/56

DM

  • 5

10 15 20 25 30 τ1 τ2 τ3

slide-27
SLIDE 27

19/56

DM

  • 5

10 15 20 25 30 τ1 τ2 τ3

t 8 13 15 w3(t) 13 15 18

slide-28
SLIDE 28

20/56

Limitations

this test permits only to conclude on the schedulability, it does not provide any other informations. It can be of interest to compute the response times, allowing the system designer to have a better idea of the tasks behaviors (jitter, average response time...). it works only for tasks with implicit deadlines Di ≤ Ti to convince yourself, try to analyze this example: ri Ci Ti Di Priority Pi τ1 4 8 10 high τ2 3 6 8 low What is the value of w2(7) ? Is it relevant to compare this to D2 ? anyway this system is not schedulable, but one has to wait until time t = 21 to see that the second instance of task τ2 misses its deadline (the worst response time is no longer the

  • ne of the first job!)
slide-29
SLIDE 29

21/56

Computing response times

recursive computation very similar to the demand analysis a task may be delayed only by tasks with an higher priority we will compute the response time of task τi ’s job number j, job 1 being the one starting at ri. Its termination instant, denoted F j

i , is given by equation:

F j

i = min t>0{t = wi−1(t) + j ∗ Ci}

(1) its response time, Rj

i , is then the difference between its

termination instant and its release instant: Rj

i = F j i − (ri + (j − 1)Ti)

(2)

slide-30
SLIDE 30

22/56

Busy Period

processor continuous activity

a level i busy period is the time interval between two level-i idle time: the processor is idle or occupied with lower priorities Level-i idle times are solution of the equation wi(t) = t we want to compute the duration of the one starting at time t = 0, because the worst scenario for task τi must occur during it (assuming a synchronous activation scenario). The algorithm is the same as the one used for the demand analysis excepted that we do not stop when the deadline is reached. It is sufficient to study a task during the first busy period to encounter its worst case response time.

slide-31
SLIDE 31

22/56

Busy Period

processor continuous activity

a level i busy period is the time interval between two level-i idle time: the processor is idle or occupied with lower priorities Level-i idle times are solution of the equation wi(t) = t we want to compute the duration of the one starting at time t = 0, because the worst scenario for task τi must occur during it (assuming a synchronous activation scenario). The algorithm is the same as the one used for the demand analysis excepted that we do not stop when the deadline is reached. It is sufficient to study a task during the first busy period to encounter its worst case response time.

Exercise

compute the level 2 busy period (bp2) for the previous example compute Qi, the τ2 activations number during bp2 compute the Qi first response times of τ2

slide-32
SLIDE 32

23/56

Other Task Models

until now, we made the hypothesis that tasks were independants, but other constraints can exists:

precedence constraints between tasks resource sharing with mutual exclusion

non periodic task have to be handle:

by setting a bound on their interarrival time, and worst case study (sporadis model) encapsulate their handling inside a server with limited ressources handling in backgroud or with a slack stealing algorithm

slide-33
SLIDE 33

24/56

ressource sharing

when two concurrent task access ressources, we have to protect the resources accesses with lock (semaphore, mutex, ...) to access a ressource, a task have to obtain the associated lock

  • ne task at once ca have a given lock

when asking a lock, a task is blocked until the lock is available special attention must be given to the lock attribution algorithm

slide-34
SLIDE 34

25/56

Issues and solution with fixe priorities

Bounding the priority inversions Avoid deadlocks Prevent blocking chains

slide-35
SLIDE 35

25/56

Issues and solution with fixe priorities

Bounding the priority inversions when a task execute whereas another one with an higher priority is blocked Avoid deadlocks Prevent blocking chains

slide-36
SLIDE 36

25/56

Issues and solution with fixe priorities

Bounding the priority inversions Avoid deadlocks when a task has a first lock, and ask for another one previously given to a second task, which waits for the first lock Prevent blocking chains

slide-37
SLIDE 37

25/56

Issues and solution with fixe priorities

Bounding the priority inversions Avoid deadlocks Prevent blocking chains When a task instance is blocked several times

slide-38
SLIDE 38

25/56

Issues and solution with fixe priorities

Bounding the priority inversions Avoid deadlocks Prevent blocking chains

Three algorithms :

Priority Inheritance Protocol (PIP) Priority Ceiling Protocol (PCP) Priority Ceiling Emulation (PCE)

slide-39
SLIDE 39

25/56

Issues and solution with fixe priorities

Bounding the priority inversions Avoid deadlocks Prevent blocking chains

Three algorithms :

Priority Inheritance Protocol (PIP) Priority Ceiling Protocol (PCP) Priority Ceiling Emulation (PCE)

slide-40
SLIDE 40

25/56

Issues and solution with fixe priorities

Bounding the priority inversions Avoid deadlocks Prevent blocking chains

Three algorithms :

Priority Inheritance Protocol (PIP) Priority Ceiling Protocol (PCP) Priority Ceiling Emulation (PCE)

slide-41
SLIDE 41

25/56

Issues and solution with fixe priorities

Bounding the priority inversions Avoid deadlocks Prevent blocking chains

Three algorithms :

Priority Inheritance Protocol (PIP) Priority Ceiling Protocol (PCP) Priority Ceiling Emulation (PCE)

slide-42
SLIDE 42

26/56

Unbound Inversion

Execution normale Execution en section critique, ressource bleue Blocage D R R D τ1 τ2 τ3

slide-43
SLIDE 43

27/56

Unbound Inversion

Execution normale Execution en section critique, ressource bleue Blocage D D τ3 τ1 τa τb τc τd

slide-44
SLIDE 44

28/56

Priority Inheritance Protocol (PIP)

when τ1 asks for a ressource used by a lower priority task τ2, τ1 is blocked and τ2 inherits τ1 priority the inheritance is transitive, when τ3 blocks τ2 and τ2 blocks τ1, then τ3 inherits τ1 priority from τ2 (with P1 > P2 > P3) when τ2 free the ressource, it goes back to its initial priority when a ressource is free, it is allocated to the task with the highest priority (amongs ones waiting for it)

slide-45
SLIDE 45

29/56

Priority Inheritance Protocol (PIP)

Execution normale Execution en section critique, ressource bleue Blocage D R D R τ1 τ2 τ3

slide-46
SLIDE 46

30/56

Priority Ceiling Emulation (PCE)

a ceiling priority is statically computed for each ressources when a task enters a critical section, it takes the ceiling priority of the ressource

slide-47
SLIDE 47

31/56

Priority Ceiling Emulation (PCE)

Execution normale Execution en section critique, ressource bleue Blocage R D R D τ1 τ2 τ3

slide-48
SLIDE 48

32/56

Priority Ceiling Protocol (PCP)

a ceiling priority is statically computed for each ressources a task can enter into a critical section iff its priority is greater than all the ceiling priorities of currently used ressources as with PIP, there is priority inheritance when a task is already into a critical section, it can obtain

  • ther lock without verifying the preceeding condition
slide-49
SLIDE 49

33/56

Priority Ceiling Protocol (PCP)

Example 1

Execution normale Execution en section critique, ressource bleue Blocage D R D R τ1 τ2 τ3

slide-50
SLIDE 50

34/56

Priority Ceiling Protocol (PCP)

Example 2

DJ DJ DB DR RB RR DB RB RJ RJ Execution normale Blocage Execution en section critique, ressource bleue Execution en section critique, ressource rouge Execution en section critique, ressource jaune τ1 τ2 τ3

slide-51
SLIDE 51

35/56

Chaˆ ıne de blocage

PIP

Execution en section critique, ressource jaune Execution en section critique, ressource bleue Execution normale Blocage DB DJ RJ RJ DJ RB DB RB τ1 τ2 τ3

slide-52
SLIDE 52

36/56

(Pas de) Chaˆ ıne de blocage

PCE

Execution en section critique, ressource jaune Execution en section critique, ressource bleue Execution normale Blocage DB DJ RB RJ DB RB DJ RJ τ1 τ2 τ3

slide-53
SLIDE 53

37/56

(Pas de) Chaˆ ıne de blocage

PCP

Execution en section critique, ressource jaune Execution en section critique, ressource bleue Execution normale Blocage DB DJ RJ DB RB RJ DJ RB τ1 τ2 τ3

slide-54
SLIDE 54

38/56

Interblocage

PIP

Execution en section critique, ressource jaune Execution en section critique, ressource bleue Execution normale Blocage DJ DB DJ DB τ1 τ2

slide-55
SLIDE 55

39/56

(Pas d’)Interblocage

PCE

Execution en section critique, ressource jaune Execution en section critique, ressource bleue Execution normale Blocage DJ DB RB RJ DJ DB RJ RB τ1 τ2

slide-56
SLIDE 56

40/56

(Pas d’)Interblocage

PCP

Execution en section critique, ressource jaune Execution en section critique, ressource bleue Execution normale Blocage DJ DB DB RB RJ DJ RJ RB τ1 τ2

slide-57
SLIDE 57

41/56

PIP & PCP : H´ eritage transitif

PIP

DB DJ DB DJ RB RB RJ RJ Execution en section critique, ressource bleue Execution en section critique, ressource jaune Execution normale Blocage τ1 τ2 τ3

slide-58
SLIDE 58

42/56

Aperiodic Model

Mix Scheduling Periodic/aperiodic

1 ensure deadlines respect for the periodic traffic 2 minimize the response times for the aperiodic traffic

Impossible to offer temporal warranty for an aperiodic task:

it can arrive at any instant an unbounded number can arrive simultaneously at any instant

slide-59
SLIDE 59

43/56

Schedule in background (BS)

Background Scheduling

the lowest priorities are reserved for aperiodic tasks very simple to setup there is no interference with the periodic traffic (warning: no resource sharing between periodic and aperiodic is permitted) just solve the first point! nothing is done to minimizing the aperiodic response times

slide-60
SLIDE 60

44/56

BS

  • τ1

τ2 5 10 15 20 25 3

BS

4ut 6ut

slide-61
SLIDE 61

45/56

Aperiodic-task server

Task server

resource reservation bound the interference on other tasks The aperiodic traffic is delegated to an other specific task with: a budget a policy to replenish this budget Lot of algorithms available: PS, DS, SS, PE, EPE...

slide-62
SLIDE 62

46/56

Polling Server (PS)

Ou serveur ` a scrutation Il s’agit d’une tˆ ache p´ eriodique et il s’analyse comme telle. PS = {(rs, Cs, Ts)} ´ eventuellement : PS = {(rs, Cs, Ts, Ps)} les ap´ eriodiques sont ajout´ ees dans une file d’attente lors de leur activation, lorsque le serveur obtient le processeur, il ex´ ecute les tˆ aches de la file dans la limite de sa capacit´ e, la capacit´ e revient au maximum p´ eriodiquement, si la file est vide alors que le serveur a la main, la capacit´ e tombe ` a z´ ero.

slide-63
SLIDE 63

47/56

Polling Server (PS)

  • τ1

τ2 5 10 15 20 25 3

PS

4ut 6ut

slide-64
SLIDE 64

48/56

Deferrable Server (DS)

Ou serveur ajournable DS = {(rs, Cs, Ts)} ´ eventuellement : DS = {(rs, Cs, Ts, Ps)} identique au PS, mais conserve sa capacit´ e lorsque la file est vide, n’est plus une tˆ ache p´ eriodique, et ne s’analyse plus comme telle.

slide-65
SLIDE 65

49/56

Deferrable Server (DS)

  • τ1

τ2 5 10 15 20 25 3

DS

4ut 6ut

slide-66
SLIDE 66

50/56

Deferrable Server (DS)

  • verflow

Time

DS τ1

slide-67
SLIDE 67

51/56

DS: Schedulability analysis

Sufficient condition on the load with Rate Monotonic : U = Us +

n

  • i=1

Ci Ti ≤ Us + n × Us + 2 2Us + 1 1

n

− 1

  • (3)

with Us = Cs

Ts and n the number of periodic tasks (without the

server). when n tends to infinity: U ≤ Us + ln Us + 2 2Us + 1

  • (4)

For the response time analysis, the worst case now is:

for periodic task with lesser priorities than the server, synchronous activation at t = rs + Ts − Cs, for the server, synchronous activation with higher priority tasks, equivalent to feasibility analysis for tasks with activation jitters.

slide-68
SLIDE 68

52/56

Slack stealing

Slack Stealing

no reservation dynamic computation of the system laxity (additional load the system can handler at time t) better performances (average random case) but no more reservation (no more “warranty”)

slide-69
SLIDE 69

53/56

Laxity

Definitions

Si(t) : additional possible work at priority levels ≥ i until next τi deadline 2 4 6 8 10 12 14 16 18 1 2

  • 20

3ut

τ1

slide-70
SLIDE 70

53/56

Laxity

Definitions

Si(t) : additional possible work at priority levels ≥ i until next τi deadline St = min Si(t)

  • 2

4 6 8 10 12 14 16 18 20 3ut

τ2 τ1

slide-71
SLIDE 71

53/56

Laxity

Definitions

Si(t) : additional possible work at priority levels ≥ i until next τi deadline St = min Si(t)

  • 3ut

SS τ2 τ1

slide-72
SLIDE 72

54/56

Dynamic computation

Si(t) computation

polynomial time complexity principle: compute the duration of the next busy period, then the one of the following idle period, and so on until the next deadline. the complexity of the wall process is too high to be usable in practice solution: use a lower bound on the slack time

slide-73
SLIDE 73

55/56

Principle

Si(t) ≥  di(t) − t −

  • j≤i

I i

j (t, di(t))

  O(n) Si(t) increase only when τi complete an instance between two time instants, Si decrease by the time spent to execute higher priority tasks Si must so be recomputed at the end of each periodic tasks we need to know at each instant how much processor time each time has consumed (not so easy to implement)

slide-74
SLIDE 74

56/56

Going further

multiprocessor real-time scheduling, more complex arrival time patterns: activation jitter... more complex constraints model: (m,k)firm model... temporal fault tolerance, overload detection, ...