periodic task scheduling - university of british columbiacourses.ece.ubc.ca/494/files/5-edf.pdf ·...

42
Periodic task scheduling Optimality of rate monotonic scheduling (among static priority policies) Utilization bound for EDF Optimality of EDF (among dynamic priority policies) Tick-driven scheduling (OS issues)

Upload: others

Post on 31-May-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

Periodic task scheduling

Optimality of rate monotonic scheduling (among static priority policies) Utilization bound for EDF Optimality of EDF (among dynamic priority policies) Tick-driven scheduling (OS issues)

Page 2: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

2

Lecture outline

Periodic task scheduling

Rate monotonic EDF

Bound Optimality Bound Optimality

Page 3: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

3

Lecture outline

Periodic task scheduling

Rate monotonic EDF

Bound Optimality Bound Optimality

Page 4: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

4

Lecture outline

Periodic task scheduling

Rate monotonic EDF

Bound Optimality Bound Optimality

Page 5: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

5

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority (or static-priority) scheduling policy for periodic tasks.

• Optimality (Trial #1):

Page 6: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

6

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority scheduling policy for periodic tasks.

• Optimality (Trial #1): If any other fixed-priority scheduling policy can meet deadlines, so can RM.

Page 7: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

7

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority scheduling policy for periodic tasks.

• Optimality (Trial #1): If any other fixed-priority scheduling policy can meet deadlines, so can RM

Page 8: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

8

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority scheduling policy for periodic tasks.

• Optimality (Trial #1): If any other fixed-priority scheduling policy can meet deadlines, so can RM

Page 9: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

9

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority scheduling policy for periodic tasks.

• Optimality (Trial #1): If any other fixed-priority scheduling policy can meet deadlines, so can RM

Page 10: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

10

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority scheduling policy for periodic tasks.

• Optimality (Trial #1): If any other fixed-priority scheduling policy can meet deadlines, so can RM

Page 11: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

11

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority scheduling policy for periodic tasks.

• Optimality (Trial #2): If any other fixed-priority scheduling policy can meet deadlines in the worst case scenario, so can RM.

• How do we prove it?

Page 12: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

12

Rate monotonic scheduling

• Rate monotonic scheduling is the optimal fixed-priority scheduling policy for periodic tasks.

• Optimality (Trial #2): If any other fixed-priority scheduling policy can meet deadlines in the worst case scenario, so can RM.

• How do we prove it?

• Consider the worst case scenario

• Show that if someone else can schedule then RM can

Page 13: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

13

The worst-case scenario

• Q: When does a periodic task, T, experience the maximum delay?

• A: When it arrives together with all the higher-priority tasks (critical instance)

•  Idea for the proof

•  If some higher-priority task does not arrive together with T, aligning the arrival times can only increase the completion time of T.

Critical instant theorem

Page 14: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

14

Proof (Case 1)

Task 1

Task 2

Case 1: Higher priority task 1 is running when task 2 arrives.

Page 15: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

15

Proof

Task 1

Task 2

Case 1: higher priority task 1 is running when task 2 arrives shifting task 1 right will increase completion time of 2

Page 16: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

16

Proof

Task 1

Task 2

Case 1: higher priority task 1 is running when task 2 arrives shifting task 1 right will increase completion time of 2

Task 1

Task 2

Page 17: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

17

Proof (Case 2)

Task 1

Task 2

Case 2: processor is idle when task 2 arrives

Page 18: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

18

Proof (Case 2)

Task 1

Task 2

Case 2: processor is idle when task 2 arrives shifting task 1 left cannot decrease completion time of 2

Page 19: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

19

Proof (Case 2)

Task 1

Task 2

Task 1

Task 2

Case 2: processor is idle when task 2 arrives shifting task 1 left cannot decrease completion time of task 2

Page 20: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

20

Optimality of the RM policy

•  If any other fixed-priority policy can meet deadlines so can RM

Policy X meets deadlines?

Page 21: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

21

Optimality of the RM policy

•  If any other policy can meet deadlines so can RM

Policy X meets deadlines? RM meets deadlines

YES

Page 22: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

22

Lecture outline

Periodic task scheduling

Rate monotonic EDF

Bound Optimality Bound Optimality

Page 23: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

23

Lecture outline

Periodic task scheduling

Rate monotonic EDF

Bound Optimality Bound Optimality

Page 24: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

24

Utilization bound for EDF

• Why is it 100%?

• Consider a task set where:

•  Imagine a policy that reserves for each task i a fraction fi of each clock

tick, where fi = C

i /P

i

Clock tick

Page 25: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

25

•  Imagine a policy that reserves for each task i a fraction fi of each time

unit, where fi = C

i /P

i

•  This policy meets all deadlines, because within each period Pi it reserves

for task i a total time

•  Time = fi Pi = (Ci / Pi) Pi = Ci (i.e., enough to finish)

Clock tick

Utilization bound for EDF

Page 26: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

26

• Pick any two execution chunks that are not in EDF order and swap them

Utilization bound for EDF

Page 27: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

27

• Pick any two execution chunks that are not in EDF order and swap them

• Still meets deadlines!

Utilization bound for EDF

Page 28: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

28

• Pick any two execution chunks that are not in EDF order and swap them

• Still meets deadlines!

• Repeat swap until all in EDF order

•  EDF meets deadlines

Utilization bound for EDF

Page 29: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

29

Lecture outline

Periodic task scheduling

Rate monotonic EDF

Bound Optimality Bound Optimality

Page 30: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

30

Lecture outline

Periodic task scheduling

Rate monotonic EDF

Bound Optimality Bound Optimality

Page 31: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

31

Tick-based scheduling within an OS

•  A real-time library for periodic tasks on Linux or Windows

•  There is need to provide approximate real-time guarantees on common operating systems (as opposed to specialized real-time OSes)

•  A high-priority “real-time” thread pool is created and maintained

•  A higher-priority scheduler is invoked periodically by timer-ticks to check for periodic invocation times of real-time threads. The scheduler resumes threads whose arrival times have come.

•  Resumed threads execute one invocation then block.

•  Scheduling is preemptive

•  The scheduler can implement arbitrary scheduling policies including EDF, RM, etc.

•  An admission controller is responsible for spawning new periodic threads if the new task set can meet its deadlines.

OS Kernel

Time-driven Scheduler

Clock

Real-time threads Admission Controller

Resume

Done

Page 32: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

32

•  A real-time library for periodic tasks on Linux or Windows

•  There is need to provide approximate real-time guarantees on common operating systems (as opposed to specialized real-time OSes)

•  A high-priority “real-time” thread pool is created and maintained

•  A higher-priority scheduler is invoked periodically by timer-ticks to check for periodic invocation times of real-time threads. The scheduler resumes threads whose arrival times have come.

•  Resumed threads execute one invocation then block.

•  Scheduling is preemptive

•  The scheduler can implement arbitrary scheduling policies including EDF, RM, etc.

•  An admission controller is responsible for spawning new periodic threads if the new task set can meet its deadlines.

•  Scheduler implements wrappers for blocking primitives

OS Kernel

Time-driven Scheduler

Clock

Real-time threads Admission Controller

Lock Lib

Resume

Done

Block

Tick-based scheduling within an OS

Page 33: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

33

The time-driven scheduler

•  /* N is the number of periodic tasks */

•  For i=1 to N

•  if (current_time = next_arrival_time of task i)

•  put task i in ready_queue

•  /* ready_queue is a priority queue that implements

•  the desired scheduling policy. */

•  Inspect top task from ready queue, call it j

•  If (a task is running and its priority is higher than priority of j) return

•  Else resume task j (and put the running task into the ready queue if applicable); return

OS Kernel

Time-driven Scheduler

Clock

Real-time threads Admission Controller

Lock Lib

Resume

Done

Block

Page 34: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

34

An example schedule

Time ticks

Scheduler

Task 1 - Invocation times - Actual Execution

Task 2 - Invocation times - Actual Execution

Page 35: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

35

An example schedule

Time ticks

Scheduler

Task 1 - Invocation times - Actual Execution

Task 2 - Invocation times - Actual Execution

Page 36: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

36

An example schedule

Time ticks

Scheduler

Task 1 - Invocation times - Actual Execution

Task 2 - Invocation times - Actual Execution

Page 37: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

37

An example schedule

Time ticks

Scheduler

Task 1 - Invocation times - Actual Execution

Task 2 - Invocation times - Actual Execution

Page 38: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

38

An example schedule

Time ticks

Scheduler

Task 1 - Invocation times - Actual Execution

Task 2 - Invocation times - Actual Execution

Page 39: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

39

An example schedule

Time ticks

Scheduler

Task 1 - Invocation times - Actual Execution

Task 2 - Invocation times - Actual Execution

Page 40: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

40

An example schedule

Time ticks

Scheduler

Task 1 - Invocation times - Actual Execution

Task 2 - Invocation times - Actual Execution

Page 41: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

41

Admission controller

• Implements schedulability analysis

•  If U+Cnew/Pnew < Ubound admit task

• Must account for various practical overheads. How?

• Examples of overhead:

•  How to account for the overhead of running the time-driven scheduler on every time-tick?

•  How to account for the overhead of running the scheduler after task termination?

• If new task admitted

• U = U + Cnew/Pnew

• Create a new thread

• Register it with the scheduler

OS Kernel

Time-driven Scheduler

Clock

Real-time threads Admission Controller

Lock Lib

Resume

Done

Block

Page 42: Periodic task scheduling - University of British Columbiacourses.ece.ubc.ca/494/files/5-EDF.pdf · 2012-02-02 · Periodic task scheduling Optimality of rate monotonic scheduling

42

Library with lock primitives

•  Lock (S) {

•  Check if semaphore S = locked

•  If locked

•  enqueue running tasks in semaphore queue

•  Else

•  let semaphore = locked

•  }

•  Unlock (S) {

•  If semaphore queue empty then

•  semaphore = unlocked

•  Else

•  Resume highest-priority waiting task

•  }

OS Kernel

Time-driven Scheduler

Clock

Real-time threads Admission Controller

Lock Lib

Resume

Done

Block

Problem: some threads may execute blocking OS calls (e.g., disk or network read/write and block without calling your lock/unlock!)