37
CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Embed Size (px)

Citation preview

Page 1: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

CSCI1600: Embedded and Real Time SoftwareLecture 24: Real Time Scheduling II

Steven Reiss, Fall 2015

Page 2: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Rate Monotonic Scheduling

Consider (8,4) , (10,2) , (12,3) Utilization = 0.5 + 0.2 + 0.25 = 0.95

RM fails: (WHY)

Page 3: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Dynamic Priority Scheduling

Priorities are changed dynamically for different tasks Otherwise same simplifying assumptions

Approaches to assigning priorities Basic idea: give priority to the job that needs it the most

Least laxity (least slack) first

Earliest deadline first

Page 4: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Least Laxity First

Laxity = time until deadline – compute time remaining This is a measure of how stressed we are to finish the job

Small laxity implies high priority

Page 5: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Least Laxity Scheduling (8,4) , (10,2) , (12,3)

0 :Laxity = 4, 8, 9

1 : Laxity = 4, 7, 8

2 : Laxity = 4, 6, 7

3 : Laxity = 4, 5, 6

4 : Laxity = X, 4, 5

5 : Laxity = X, 4, 4

6 : Laxity = X, X, 3

7 : Laxity = X, X, 3

8 : Laxity = 4, X, 3

9 : Laxity = 4, X, X

10 : Laxity = 4, 8, X

11 : Laxity = 4, 7, X

12 : Laxity = X, 7, 9 …

Page 6: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Least Laxity First Is optimal

Can schedule as long as utility is <= 1

Is complex

When do priorities change The laxity of a task changes dynamically

If it is not currently executing

How would you implement this

Generally not used Too much context switching, bookkeeping

Can we approximate it?

Page 7: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Earliest Deadline First

EDF: Put tasks in priority queue based on actual deadline (time when job needs to be done)

Priorities change only when a job is added

EDF is also optimal If the utility is <= 1 then EDF will create a schedule

Can transform any feasible schedule into an EDF one

But this is based on assumptions Perfect periodic tasks, zero overhead, independence

Page 8: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Earliest Deadline First Scheduling

(8,4) , (10,2) , (12,3) 0 : [8,10,12]

8 : [ 10, 12, 16]

10 : [ 12, 16, 20 ]

Page 9: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

EDF Scheduling

P1(4,1), P2(6,3), P3(10,3)

Why is this sufficient?

Page 10: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

EDF and LLF Seem Ideal Easy to implement, optimal, …

But only in an ideal world

If the workload is briefly unschedulable

Then both fail dramatically and unpredictably

Choices are based on deadlines, not importance

Work hard to display MPG rather than firing airbag

Work only with idealized situations

We need to relax the simplifying conditions

Sporadic and aperiodic tasks

Page 11: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Handling Overloads

Why bother Tasks might take longer than expected

Sporadic tasks (interrupts, etc)

Might be unavoidable

In EDF if one job is late and the system is loaded Then ALL future jobs might be late

Techniques What might you want to do?

Page 12: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Techniques for Handling Overload

Techniques Schedule late jobs at lower priority than on-time jobs

Change non-critical jobs to optional when late jobs occur

Discard jobs that cannot complete

Tradeoffs What are the effects of each of these

What might you use in practice

Depends on application

Page 13: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Relaxing Constraints

Nonpreemptability Compute maximum time a task might be nonpreemptible

Compute maximum time a task might be delayed by a nonpreemptible task

Only need to consider tasks of lower priority

Add this to its execution time when deriving schedule

Page 14: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Resource Contention

Recall what can happen with locks and priorities

Page 15: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Priority Protocols

τ2

τ3

t0 t+3 t+253

RL L L R

R L τ1

t+254

L L L

...L L

Blocked!

t+2

Page 16: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Fixing Priority Inversions

Make critical sections non-preemptible

Page 17: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Priority Ceiling Protocol Immediate Priority Ceiling Protocol

Assign priorities based on resources

Associate a priority ceiling p with each resource r

The highest priority task that can lock it

No task with priority >= p is allowed to lock r

Task acquiring r runs at priority p

Original Priority Ceiling Protocol

Task’s priority is raised when a higher-priority task tries to acquire the lock

Raised to priority ceiling of the resource

Task can acquire a lock r only if the task’s priority is strictly higher than the priority ceilings of all locks currently held by other tasks

Page 18: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Priority Inheritance Protocol

Priority inheritance protocol If Ti blocks Tk, execute Tk with priority min(j,k)

Which should you use?

Page 19: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Priority Protocols

τ2

τ3

t0 t+3 t+253

RL L L R

R L τ1

t+254

L L L

...L L

Blocked!

t+2

Page 20: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Handling Self-Suspension

Wait for I/O operations, etc

Split into two tasks Second task might have a shorter deadline

Take the suspension time into account when computing schedule

Page 21: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Handling Context Switching Time

Compute the max # of context switches for a task From its period and higher priority tasks

Worst case

Add the context switching time * max To the execution time of the task

Page 22: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Sporadic Tasks

Sporadic tasks Arise occassionally

Hard deadlines

Question: how to schedule these How to accommodate in RM/DM or EDF schedules

Goal Tell accept/reject when job is submitted

Page 23: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Sporadic Jobs and EDF Schedules

EDF will find a schedule as long as U <= 1 Keep track of U for the current system

Utilization of the periodic tasks

Plus the U for all accepted sporadic tasks

Compute U’ as current U plus U of the sporadic task If this is <= 1 then accept

Otherwise reject

Page 24: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Sporadic Jobs and RM Schedules

What guarantees can we make here? U <= x where x depends on the number of tasks

This would allow us to use the same approach

Page 25: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Aperiodic Job Scheduling

Aperiodic Tasks Arise occassionally

Soft deadlines

Might be prioritized

Goal: minimize worst/average case performance

Page 26: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Simple Aperiodic Scheduling

Run aperiodic tasks in open slots

How to schedule them Round robin

Prioritized round robin

Run tasks with higher priorities first

Allocate CPU time according to priority

This gives no guarantees of performance And complicates the scheduler

Page 27: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Total Bandwidth Server

Make an aperiodic job look like a sporadic one Add to schedule using standard algorithm (e.g. EDF)

Can reject the sporadic job if necessary

Key: set the parameters for the job so that The result is schedulable (total U <= 1)

Recall U = e/D e is known and fixed for the job

This lets us vary D to accommodate the jobs

Page 28: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Total Bandwidth Server Determine desired aperiodic load Us

To still allow sporadic jobs and periodic jobs

Total U <= 1

TBS is configured with budget Qs and period Ts

Qs/Ts = Us

Terminology

es : budget for the server (its execution time)

eq : execution time of job at the head of the queue

us : size of the server (max utilization)

Page 29: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Total Bandwidth Server Initially es = 0 and d = 0

When a new job with execution time e comes into an empty queue

Set d = max(d,t) + e/us

Set es = e

When the server completes the current job, remove the job from the queue If there are more jobs,

Set the server deadline to d+eq/us and es= eq

Page 30: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Example

Periodic: P1(4,1), P2(6,3)

Aperiodic: A3: e=2 at time 1, A4: e= 1 at time 2

First determine Us

Up = ¼ + 3/6 = 0.75

Us = 0.25 (could be less)

Page 31: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Example

At Start P1(4,1), P2(6,3), es= 0, d = 0

At time 1: d = max(0,1) + 2 / 0.25 = 9, es = 2

P1

P2

P3

Page 32: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Example

P1(4,1), P2(6,3), Ps(9,2)

At time 3: new aperiodic job Pt, but Ps not done

At time 7: Ps finishes, P2 has deadline 12

P1

P2

P3

Page 33: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Example

At time 7: d = d + eq/Us = 9 + 1/0.25 = 13, es = 1

Ps(13,1)

P1

P2

P3

Page 34: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Example

At time 7: d = d + eq/Us = 9 + 1/0.25 = 13, es = 1

Ps(13,1)

P1 and P2 have deadlines of 12

P1

P2

P3

Page 35: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Total Bandwidth Server

Guarantees Can always complete the job at the top of the queue

A given budget of time that is replenished each cycle

TBS is “work-conserving” TBS will run in any slack from periodic tasks

In any interval L, a TBS will not take more the UsL CPU time from the “real” task requests

TBS will use idle run time

Page 36: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Alternatives to TBS

Constant bandwidth server

Page 37: CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015

Homework

Read 12.5