ee5900 advanced embedded system for smart infrastructure

35
1 EE5900 Advanced Embedded System For Smart Infrastructure RMS and EDF Scheduling

Upload: zody

Post on 04-Feb-2016

35 views

Category:

Documents


0 download

DESCRIPTION

EE5900 Advanced Embedded System For Smart Infrastructure. RMS and EDF Scheduling. C’ i. t. d i. Laxity. Priority-driven Preemptive Scheduling. Assumptions & Definitions Tasks are periodic No aperiodic or sporadic tasks Job (instance) deadline = end of period No resource constraints - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: EE5900 Advanced Embedded System For Smart Infrastructure

1

EE5900 Advanced Embedded System For Smart Infrastructure

RMS and EDF Scheduling

Page 2: EE5900 Advanced Embedded System For Smart Infrastructure

2

Priority-driven Preemptive Scheduling

Assumptions & Definitions• Tasks are periodic • No aperiodic or sporadic tasks• Job (instance) deadline = end of period• No resource constraints• Tasks are preemptable

• Laxity (Slack) of a Task • Ti = di – (t + ci’) where di: deadline;

t : current time;ci’ : remaining computation time.

t

C’i

Laxity

di

Page 3: EE5900 Advanced Embedded System For Smart Infrastructure

3

Rate Monotonic Scheduling (RMS)

• Schedulability check (off-line) - A set of n tasks is schedulable on a uniprocessor by the RMS algorithm if the processor utilization (utilization test)

ci is the execution time and pi is the period,The term n(21/n -1) approaches ln 2, (0.69 as n ).

- This condition is sufficient, but not necessary.

Page 4: EE5900 Advanced Embedded System For Smart Infrastructure

4

RMS (cont.)

• Schedule construction (online)

- Task with the smallest period is assigned the highest priority (static priority).

- At any time, the highest priority task is

executed.

Page 5: EE5900 Advanced Embedded System For Smart Infrastructure

5

RMS Scheduler - Example 1

Task set: Ti = (ci, pi) [computation time, period]

T1 = (2,4) and T2 = (1,8)

Schedulability check:

2/4 + 1/8 = 0.5 + 0.125 = 0.625 ≤ 2(√2 -1) = 0. 82

T11 T2

1 T12

0 2 3 4 6 8

Active Tasks :

{T1, T2}

Active Tasks :{T2}

Active Tasks :{T1}

Page 6: EE5900 Advanced Embedded System For Smart Infrastructure

6

RMS scheduler – Example 2

Task set: Ti = (ci, pi)

T1 = (2,4) and T2 = (4,8)

Schedulability check:

2/4 + 4/8 = 0.5 + 0.5 = 1.0 > 2(√2 -1) = 0. 82

T11 T2

1 T12

0 2 3 4 6 8

Active Tasks :

{T1, T2}

Active Tasks :{T2}

Active Tasks :

{T2, T1}

T21

Active Tasks :{T2}

Some task sets that FAIL the utilization-based schedulability test are also schedulable under RMS

Page 7: EE5900 Advanced Embedded System For Smart Infrastructure

RMS is not optimal

• T1=(1,2) and T2=(2.5,5)

7

Page 8: EE5900 Advanced Embedded System For Smart Infrastructure

8

Earliest Deadline First (EDF)

• Schedulability check (off-line)

- A set of n tasks is schedulable on a uniprocessor by the EDF algorithm if the processor utilization.

• This condition is both necessary and sufficient.

- Least Laxity First (LLF) algorithm has the same schedulability check.

Page 9: EE5900 Advanced Embedded System For Smart Infrastructure

9

EDF/LLF (cont.)

• Schedule construction (online) – EDF/LLF: Task with the smallest deadline/laxity is

assigned the highest priority (dynamic priority).– At any time, the highest priority task is executed.

• It is optimal (i.e., whenever there is a feasible schedule, EDF can always compute it) when preemption is allowed and no resource constraint is considered. – Given any two tasks in a feasible schedule, if

they are not scheduled in the order of earliest deadline, you can always swap them and still generate a feasible schedule.

Page 10: EE5900 Advanced Embedded System For Smart Infrastructure

10

EDF scheduler - Example

Task set: Ti = (ci, pi, di)

T1 = (1,3,3) and T2 = (4,6,6)

Schedulability check:

1/3 + 4/6 = 0.33 + 0.67 = 1.0

T11 T2

1 T12

0 1 5 6

Active Tasks :

{T1, T2}

Active Tasks :{T2}

Active Tasks :

{T2, T1}

Active Tasks :{T1}

Unlike RMS, Only those task sets which pass the schedulability test are schedulable under EDF

3

T21

Page 11: EE5900 Advanced Embedded System For Smart Infrastructure

11

Comparison of RMS and EDF

0 5 10 15 20 25 30 35

0 7 14 21 28 35

T1

T2

RMS schedule

0 5 10 15 20 25 30 35

0 7 14 21 28 35

T1

T2

EDF schedule

Deadline miss

Process Period, T WCET, C T1 5 2 T2 7 4

Page 12: EE5900 Advanced Embedded System For Smart Infrastructure

12

Resource sharing

• Periodic tasks

• Task can have resource access

• Semaphore is used for mutual exclusion

• RMS scheduling

Page 13: EE5900 Advanced Embedded System For Smart Infrastructure

13

Background – Task State diagram

• Ready State: waiting in ready queue

• Running State: CPU executing the task

• Blocked: waiting in the semaphore queue until the shared resource is free

• Semaphore types – mutex (binary semaphore), counting semaphore

Page 14: EE5900 Advanced Embedded System For Smart Infrastructure

14

Task State Diagram

READY RUN

WAITING

Activate

scheduling

Preemption

Termination

Wait on busy

resource

Signal free

resource

Process/Task state diagram with resource constraints

Page 15: EE5900 Advanced Embedded System For Smart Infrastructure

15

Priority Inversion Problem

Priority inversion is an undesirable situation in which a higher priority task gets blocked (waits for CPU) for more time than that it is supposed to, by lower priority tasks.

Example:

• Let T1 , T2 , and T3 be the three periodic tasks with decreasing order of priorities.

• Let T1 and T3 share a resource S.

Page 16: EE5900 Advanced Embedded System For Smart Infrastructure

16

Priority Inversion - Example

• T3 obtains a lock on the semaphore S and enters its critical section to use a shared resource.

• T1 becomes ready to run and preempts T3. Then, T1 tries to enter its critical section by first trying to lock S. But, S is already locked by T3 and hence T1 is blocked.

• T2 becomes ready to run. Since only T2 and T3 are ready to run, T2 preempts T3 while T3 is in its critical section.

Ideally, one would prefer that the highest priority task (T1) be blocked no longer than the time for T3 to complete its critical section. However, the duration of blocking is, in fact, unpredictable because task T2 got executed in between.

Page 17: EE5900 Advanced Embedded System For Smart Infrastructure

17

Priority Inversion example

T1

T2

T3T3

0

T3 is the only

active task

Preempted by higher priority

task T1

T1

Makes a request for resource S and gets blocked

T3

Preempted by higher priority

task T2

T2

T3

T3 completes

T1

Resource S is available and

T1 is scheduled

here

K1 K2K3

T2 completes

L1

Total blocking time for task T1 = (K2+K3) + (L1)

Highest priority

Least priority

Medium priority

T1 and T3 share resource

S

A higher priority task waits for a

lower priority task

Page 18: EE5900 Advanced Embedded System For Smart Infrastructure

18

Priority Inheritance ProtocolPriority inheritance protocol solves the problem of priority inversion.

Under this protocol, if a higher priority task TH is blocked by a lower priority task TL, because TL is currently executing critical section needed by TH, TL temporarily inherits the priority of TH.

When blocking ceases (i.e., TL exits the critical section), TL resumes its original priority.

Unfortunately, priority inheritance may lead to deadlock.

Page 19: EE5900 Advanced Embedded System For Smart Infrastructure

19

Resource access control - example

Task Ti ci pi cix ci

y ciz

T1 2 8 2 0 0

T2 4 12 0 4 0

T3 2 6 1 1 0

T2 and T3 have access to a shared resource R

cix : Task duration before entering the critical section

ciy : Critical section duration

ciz : Task duration after the critical section

ci = cix + ci

y + ciz

By RMS, T3 > T1 > T2

Page 20: EE5900 Advanced Embedded System For Smart Infrastructure

20

Schedules

Locks R

Preempted by T3

T3 T1 T2 T3 T2 T1 T2 T3 T3 T2

T3 T1 T2 T3 T2 T3 T1 T3 T2

Direct blocking of T3 by T2

Priority inversion of T3 by T1

0 2 4 6 7 8 10 11 12 14 16

RMS Schedule

RMS Schedule with Priority Inheritance Protocol

0

Direct blocking of T3 by T2

Inheritance blocking of T1 by T2

Release R

Task Ti ci pi cix ci

y ciz

T1 2 8 2 0 0

T2 4 12 0 4 0

T3 2 6 1 1 0

Page 21: EE5900 Advanced Embedded System For Smart Infrastructure

21

Priority Inheritance Protocol – Deadlock Assume T2 has higher priority than T1

Page 22: EE5900 Advanced Embedded System For Smart Infrastructure

22

Priority Ceiling Protocol• Priority ceiling protocol solves the priority inversion

problem without getting into deadlock.• For each semaphore, a priority ceiling is defined,

whose value is the highest priority of all the tasks that may lock it.

• When a task Ti attempts to execute one of its critical sections, it will be suspended unless its priority is higher than the priority ceiling of all semaphores currently locked by tasks other than Ti.

• If task Ti is unable to enter its critical section for this reason, the task that holds the lock on the semaphore with the highest priority ceiling is said to be blocking Ti and hence inherits the priority of Ti.

Page 23: EE5900 Advanced Embedded System For Smart Infrastructure

23

Priority Ceiling Protocol - properties

• This protocol is the same as the priority

inheritance protocol, except that a task Ti can also be blocked from entering a critical section if any other task is currently holding a semaphore whose priority ceiling is greater than or equal to the priority of task Ti.

Page 24: EE5900 Advanced Embedded System For Smart Infrastructure

24

Priority Celiling Protocol - Example

• For the previous example, the priority ceiling for both CS1 and CS2 is the priority of T2.

• From time t0 to t2, the operations are the same as before.

• At time t3, T2 attempts to lock CS1, but is blocked since CS2 (which has been locked by T1) has a priority ceiling equal to the priority of T2.

• Thus T1 inherits the priority of T2 and proceeds to completion, thereby preventing deadlock situation.

Page 25: EE5900 Advanced Embedded System For Smart Infrastructure

25

Scheduling tasks with precedence relations

Scheduler{T1, T2}

Conventional task set

T1 T2

Modify task parameters in order to respect

precedence constraintsScheduler

task set with precedence constraints

Page 26: EE5900 Advanced Embedded System For Smart Infrastructure

26

Modifying the task parameters for RMS

• While using the RMS scheduler the task parameters (ready time) need to be modified in order to respect the precedence constraints

• Rj* ≥ Max (Rj, Ri*) where Ri* is the modified ready time of the task Ti

• Priority Prioi ≥ Prioj

Ti Tj

Page 27: EE5900 Advanced Embedded System For Smart Infrastructure

27

Modifying ready times for RMS: example

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 5

T2 5 2 7

T3 0 2 5

T4 0 1 10

T5 0 3 12

Initial Task Parameters

Page 28: EE5900 Advanced Embedded System For Smart Infrastructure

28

Modifying the Ready times for RMS

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 5

T2 5 2 7

T3 0 2 5

T4 0 1 10

T5 0 3 12

Initial Task Parameters

R1 = 0 R2 = 5

R3 = 0R4 = 0

R5 = 0

R3’ = max(R1,

R3) R3’ = 0

R4’ = max(R1, R2,R4)

R4’ = 5

R5’ = max(R3’, R4’,R5)

R5’ = 5

Page 29: EE5900 Advanced Embedded System For Smart Infrastructure

29

Modified Ready times for RMS

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 5

T2 5 2 7

T3 0 2 5

T4 5 1 10

T5 5 3 12

Modified Task Parameters

R1 = 0 R2 = 5

R3’ = 0 R4’ =

5

R5’ = 5

Page 30: EE5900 Advanced Embedded System For Smart Infrastructure

30

Assigning task priorities for RMS

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 5

T2 5 2 7

T3 0 2 5

T4 5 1 10

T5 5 3 12

Modified Task Parameters

R1 = 0 R2 = 5

R3’ = 0 R4’ =

5

R5’ = 5

Assume all tasks of a connected component have the same period. Therefore, as per RMS all tasks will have a tie. We assign priorities to

break the ties.

Priority

3

4

2

1

0

Page 31: EE5900 Advanced Embedded System For Smart Infrastructure

31

Modifying task parameters for EDF

• While using the EDF scheduler the task parameters need to be modified in order to respect the precedence constraints

• Rj* ≥ Max (Rj, (Ri* + Ci))

• Di* ≥ Min (Di, (Dj* – Cj))

Ti Tj

Page 32: EE5900 Advanced Embedded System For Smart Infrastructure

32

Modifying the Ready times for EDF

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 5

T2 5 2 7

T3 0 2 5

T4 0 1 10

T5 0 3 12

Initial Task Parameters

R1 = 0 R2 = 5

R3 = 0R4 = 0

R5 = 0

R3’ = max(R1 + C1, R3)

R3’ = 1

R4’ = max(R1+C1, R2+C2,R4)

R4’ = 7

R5’ = max(R3’+C3, R4’+C4,R5)

R5’ = 8

Page 33: EE5900 Advanced Embedded System For Smart Infrastructure

33

Modifying the Ready times for EDF

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 5

T2 5 2 7

T3 1 2 5

T4 7 1 10

T5 8 3 12

Modified Task Parameters

R1 = 0 R2 = 5

R3’ = 1 R4’ =

7

R5’ = 8

Page 34: EE5900 Advanced Embedded System For Smart Infrastructure

34

Modifying the Deadlines for EDF

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 5

T2 5 2 7

T3 1 2 5

T4 7 1 10

T5 8 3 12

Modified Task Parameters

D1 = 5 D2 = 7

D3 = 5D4 =

10

D5 = 12

D3’ = Min( (D5 – C5), D3)

D4’ = Min( (D5 – C5), D4)

D3’ = 5 D4’ =

9

D2’ = Min( (D4’ – C4), D2)

D2’ = Min( (D4’ – C4), (D3’ – C3), D1)

D2’ = 7

D1’ = 3

Page 35: EE5900 Advanced Embedded System For Smart Infrastructure

35

Modifying the Deadlines for EDF

T11

T22

T32

T41

T53

Task Ri Ci Di

T1 0 1 3

T2 5 2 7

T3 1 2 5

T4 7 1 9

T5 8 3 12

Modified Task Parameters

D5 = 12

D3’ = 5 D4’ =

9

D2’ = 7

D1’ = 3