Top Banner
Wei Gao ECE 1175 Embedded System Design Real-Time Scheduling - II 1
26

Real-Time Scheduling - II

Feb 02, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Real-Time Scheduling - II

Wei Gao

ECE 1175 Embedded System Design

Real-Time Scheduling - II

1

Page 2: Real-Time Scheduling - II

Comparison Schedulability RMS may not guarantee schedulability even when CPU is

not fully utilized EDF can guarantee schedulability as long as CPU is not fully

utilized Overhead RMS: low overhead, priorities are never changed EDF: higher overhead, task priorities may need to be

changed online Optimality RMS: optimal static priority scheduling algorithm EDF: optimal dynamic priority scheduling algorithm

2

Page 3: Real-Time Scheduling - II

Relaxing Assumptions Single processor. All tasks are periodic. Zero context switch time. Relative deadline = period. No priority inversion.

What if priority inversion exists?

3

Page 4: Real-Time Scheduling - II

Priority Inversion A lower-priority task blocks a higher-priority task

from running. Sources of priority inversion Access shared resources guarded by semaphores

• Lower-priority task gets the resource first

Access non-preemptive subsystems• Communication subsystems• Storage

4

Page 5: Real-Time Scheduling - II

Priority Inversion

5

1

44 4

0 2 4 6 8 10 12 14 16 18 20 22

1 1

4

critical section

T1 blocked!

T4 starts to runT4 acquires a semaphore

T4 preempted by T1T1 tries to get the same semaphore

Page 6: Real-Time Scheduling - II

Unbounded Priority Inversion

6

1

44 4

0 2 4 6 8 10 12 14 16 18 20 22

1 1

critical sectionT1 blocked by 4,2,3!

3

2

4 4

T1 tries to get the semaphore

Page 7: Real-Time Scheduling - II

Solution: Priority Inheritance Let the low-priority task inherit the priority of the

blocked high-priority task.

7

1

44 4

0 2 4 6 8 10 12 14 16 18 20 22

1 1

critical sectionT1 only blocked by 4

2

3

4

T1 tries to get semaphore so T4 inherits T1’s priority

T4 returns to priority 4 after the critical section

Page 8: Real-Time Scheduling - II

Real Incident Mars Pathfinder Priority inversion on Mars

http://www.cse.chalmers.se/~risat/Report_MarsPathFinder.pdf https://www.youtube.com/watch?v=lyx7kARrGeM

8

Page 9: Real-Time Scheduling - II

Relaxing Assumptions Single processor. All tasks are periodic. Zero context switch time. Relative deadline = period. No priority inversion. (relaxed)

What if we have multiple processors?

9

Page 10: Real-Time Scheduling - II

End-to-End Task Model An (end-to-end) task is composed of

multiple subtasks running on multiple processors Message/event Remote method invocation

Subtasks are subject to precedence constraints Task = a chain/tree/graph of subtasks E.g. ship navigation

10

Sonar Signal processing

Obstacle detection Navigation

Page 11: Real-Time Scheduling - II

Notation Ti = {Ti,1, Ti,2, … , Ti,n(i)} n(i): the number of subtasks of Ti

Precedence constraint: Job Ji,j cannot be released until Ji,j-1 is completed.

11

Sonar Signal processing

Obstacle detection Navigation

Task Ti

Subtasks: Ti,1 Ti,2 Ti,3Ti,4

Page 12: Real-Time Scheduling - II

End-to-End Scheduling Framework1. Task allocation2. Synchronization protocol3. Subdeadline assignment4. Schedulability analysis

12

Page 13: Real-Time Scheduling - II

Task Allocation Load code (e.g., objects) to processors Strategies Offline, static allocation subject to resource availability Allocate a task when it arrives dynamically Re-allocate (migrate) a task after it starts

Optimal solutions for maximum schedulability How to meet all deadlines in an optimal way?

• E.g., minimize the number of needed processors

NP-hard: heuristics needed

13

Page 14: Real-Time Scheduling - II

Bin Packing for Task Allocation Pack subtasks to bins (processors) with

limited capacity Size of a subtask

• Utilization: Ci,j/Pi

Capacity of each bin is its utilization bound

Goal: minimize the number of bins subject to the capacity constraints

14

…………

T1

T2

T3

T2T1

Page 15: Real-Time Scheduling - II

End-to-End Scheduling Framework1. Task allocation2. Synchronization protocol3. Subdeadline assignment4. Schedulability analysis

15

Sonar Signal processing

Obstacle detection Navigation

After a subtask is finished, should the next subtask start immediately or wait for a while?

Page 16: Real-Time Scheduling - II

Greedy Protocol After a subtask is finished, the next subtask starts

immediately Release job Ji,j;k as soon as Ji,j-1;k is completed Subsequent subtasks may not be periodic under a

greedy protocol Difficult for schedulability analysis High-priority tasks arrive early high worst-case response

time for lower-priority tasks

16

Sonar Signal processing

Obstacle detection Navigation

Page 17: Real-Time Scheduling - II

Greedy Protocol Illustrated Task: (C,P)

17

On P1On P2

T1

T2,1

T2,2

T3

2 4 6 8 10 12

2 4 6 8 10 12

2 4 6 8 10 12

2 4 6 8 10 12T3 starts here

P2

T3’s deadline

T3misses

deadline

P1 P2

(2,4)T1

(2,6)T2,1

(2,6)T2,2

(4,7)T3

P1

Page 18: Real-Time Scheduling - II

Properties of Greedy Protocol Low overhead Low average response time Difficult schedulability analysis Subsequent subtasks are no longer periodic

High worst-case response time

18

Page 19: Real-Time Scheduling - II

Release Guard After a subtask is finished, the next subtask may wait for a

while before release Every subtask (if not a first subtask) has a release guard, which waits for the preceding subtask for a result/event then releases the job

• at the point of exact one period from the last release time (Rule1)OR• whenever the processor becomes idle (Rule 2)

Release guard strategy improves worst response time without affecting schedulability

19

Page 20: Real-Time Scheduling - II

Release Guard Illustrated Task: (C,P)

20

On P1On P2

T1

T2,1

T2,2

T3

2 4 6 8 10 12

2 4 6 8 10 12

2 4 6 8 10 12

2 4 6 8 10 12

Next release = 4+6=10 Release guard releases the job

T3 meets deadline

T3’s deadlineT3 starts here

P1 P2

(2,4)T1

(2,6)T2,1

(2,6)T2,2

(4,7)T3

P1P2

Page 21: Real-Time Scheduling - II

End-to-End Scheduling Framework1. Task allocation2. Synchronization protocol3. Subdeadline assignment4. Schedulability analysis

21

Page 22: Real-Time Scheduling - II

Subdeadline Assignment Algorithms

Notation (Relative) deadline Di of task Ti

(Relative) subdeadline Dij of subtask Tij (1 ≤ j ≤ n(i))

Ultimate Deadline (UD): Dij = Di Example

• An end-to-end task T1, with deadline as 12, has 4 subtasks: T11, T12, T13 and T14 with execution times as: 3, 1, 1, 1.

• D11 = D12 = D13 = D14 = D1 = 12

But T11, T12, T13 must finish earlier than the end-to-end deadline such that T14 can have time to run.

22

Page 23: Real-Time Scheduling - II

Common Assignment Algorithms Proportional Deadline (PD): Assign deadline proportionally to execution time

Example• An end-to-end Task T1, with deadline as 12, has 4 subtasks T11,

T12, T13 and T14 with execution time as: 3, 1, 1, 1.• D11 = 12 * 3/(3+1+1+1) = 6• D12 = 12 * 1/(3+1+1+1) = 2• D13 = 12 * 1/(3+1+1+1) = 2• D13 = 12 * 1/(3+1+1+1) = 2

23

( )

1

ijij i n i

ikk

CD D

C=

=∑

Page 24: Real-Time Scheduling - II

End-to-End Scheduling Framework1. Task allocation2. Synchronization protocol3. Subdeadline assignment4. Schedulability analysis Decide an appropriate scheduling algorithm

• RMS, EDF, etc

For each processor, conduct uniprocessor schedulabilityanalysis• Then synchronize among multiple processors

24

Page 25: Real-Time Scheduling - II

Summary End-to-end scheduling framework

Task allocation• Bin packing

Synchronization protocol• Greedy protocol, release guard

Subdeadline assignment• Ultimate deadline, proportional deadline

Schedulability analysis

25

Page 26: Real-Time Scheduling - II

Reading Priority inversion on Mars http://www.cse.chalmers.se/~risat/Report_MarsPathFinde

r.pdf

https://www.youtube.com/watch?v=lyx7kARrGeM

26