csci1600: embedded and real time software lecture 23: real time scheduling i steven reiss, fall 2015

33
CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015

Upload: mariah-hamilton

Post on 19-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

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

CSCI1600: Embedded and Real Time SoftwareLecture 23: Real Time Scheduling I

Steven Reiss, Fall 2015

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

Scheduling Problem

Arduino Main Loop Round-robin scheduler (with interrupts)

No preemption

Assuming not that much is time critical

Possibly one interrupt routine

What happens in a more complex system We first must understand the components

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

Periodic Tasks Execution time (e units) : max execution time

Release time (t – when it becomes available to run) Period p: the time between releases

Deadline (d – relative to release time) How quickly it needs to be processed

Default = period

P(p,e,d) : representation of a job P(p,e) = P(p,e,p)

Goal: ensure all deadlines are met

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

Aperiodic Tasks

Background tasks that run occassionally Arise at random (possibly with a distribution)

Soft deadlines

Can have priorities

Again have release time, deadline, execution time

GOAL: Execute these jobs as fast as possible Average or worst case time

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

Sporadic Tasks

Response to interrupts or unusual events Arise randomly (possibly with a distribution)

Hard deadlines

Again have release time, deadline, execution time

GOAL: ensure these can be serviced correctly Accept or reject the job

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

Simplifying Assumptions All jobs are preemptible at any time

Relaxations:

Not preemptible until non-runnable

Preempt at “safe” times (calling OS, acquiring synchronization)

Switching overhead is 0

No resource contention between jobs (no blocking)

Jobs don’t suspend voluntarily

Job execution time (max) is known

Simple processor

All of these can be taken into account, but things are more complex

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

Scheduling Problem

Given a set of periodic tasks, can they be scheduled

Can aperiodic tasks at a given rate be handled

Can all sporadic tasks be handled Can we accept/reject a sporadic task when it arises

We first need to decide what type of solution we want

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

Solution Models: Fixed Schedule

Also call clock-based

Single schedule Schedule is precomputed, stored in a table

Time allocated for aperiodic and sporadic tasks

Can be fully static (all decisions made in advance)

Can be static order Order precomputed

When to run decided at run time

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

Solution Models: Fixed Priority

Assign priority to jobs as they arise Priorities don’t change once they are assigned

Low numbers are higher priority

Highest priority job runs

Schedule reexamined as new jobs come in

Aperiodic and sporadic jobs are accommodated Either directly by priority

Or by creating a periodic job for them

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

Solution Models: Dynamic Priority

Jobs are assigned priorities as they arise But job priorities can be changed over time

Highest priority job runs

Schedule reexamined periodically & as new jobs arise

Accommodate aperiodic and sporadic jobs

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

Solution Models: Advanced

Multiple threads/cores/processors

Handling aperiodic and sporadic tasks

Relaxing assumptions

Resource scheduling

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

Example

Consider three jobs P1(4,2), P2(6,2), P3(12,2)

Can we schedule these

How many time units do we have to consider

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

Schedule Representations P1(4,2), P2(6,2), P3(12,2)

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

Schedule Representations P1(4,2), P2(6,2), P3(12,2)

P1

P2

P3

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

Scheduling Example

P1(4,1), P2(6,2), P3(12,3)

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

Schedule Representations P1(4,1), P2(6,2), P3(12,3)

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

Scheduling Example

P1(4,2), P2(6,3), P3(12,1)

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

Clock-Based Scheduling Set up fixed schedule in advance

Problem is NP-complete but can be solved

Done once off-line

Still need to handle aperiodic and sporadic tasks Need to leave slack in schedule

We’ll get back to this

Pros and Cons Simple to implement

Can use an optimal schedule

Assumes release times are fixed (no jitter)

Everything must be known in advance

Changing anything can be messy

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

Fixed Priority Scheduling Basic Idea

Assign a priority to a job as it arrives

Not necessarily based on its a priori priority

Based on scheduling requirements

Job with highest priority is run

If a new job gets higher priority, it preempts running job

Implementaiton Maintain a priority queue of jobs

New jobs are inserted into the queue

And may cause preemption

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

Fixed Priority Assignment

Problem: how to assign priorities

Rate Monotonic (RM) priority assignment Priority is the period

Shortest task gets the highest priority

Deadline Monotonic (DM) priority assignment Priority is the deadline

Jobs with shortest relative deadline gets highest priority

If deadline = period, these are the same

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

Rate Monotonic Example

P1(4,1), P2(5,2), P3(20,5)

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

Feasibility Analysis How good is a RM/DM schedule?

What do you want to measure?

Utilization of the CPU

Does the algorithm produce a feasible schedule

If the jobs are schedulable

Under what circumstances

Necessary and Sufficient Schedule All cycles are needed to service jobs and there are enough cycles

to service jobs

Achieving this is NP-hard. Settle for sufficient (enough cycles)

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

Critical Instant Theorem

The critical instant for a job is the worst time to start it The release time for which response is maximized

Theorem: The critical instant occurs (for periodic tasks with fixed priorities) when all higher priority jobs share the release time with the job in question This is fairly robust : stays true even if we remove

simplifying assumptions

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

Checking a Schedule

Notation

τi – the ith task or the ith execution of task τ

Di – the relative deadline for the ith task

Pi – the period of the ith task

ei – the execution time of the ith task

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

Checking a Schedule

Simple necessary and sufficient test of feasibility Assuming synchronous release

Release jobs from all tasks at time t

Simulate until lowest priority job completes or misses

Only on deadline and release points

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

RM Priority Assigment If a task set can be scheduled at all by a fixed priority

schedule It can be scheduled with a RM policy

Hence RM (or DM) is optimal in some sense

Define the utility of a task ui = ei/Pi

The utility of a set of tasks is their sum If Sum > 1 then the jobs can’t be scheduled

If Sum = 1 and tasks can be scheduled, algorithm is optimal

What can be done using RM/DM scheduling?

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

RM Scheduling

A RM policy scheduling n tasks is feasible if:

A pair of tasks is schedulable if they consume < 82.84%

As n approaches infinity, RHS approaches ln(2) =~ 69.31%

This is sufficient, not necessary

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

RM and DM Can Be Optimal

Simply Periodic For every pair of tasks A and B with Pa < Pb, Pb is an

integral multiple of Pa

Then we can schedule the jobs if Utilization <= 1

Can we do better in the general case?

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

Rate (Deadline) Monotonic

Jobs come in, are assigned a priority, highest runs

Consider (8,3), (9,3), (15,3) Is this guaranteed to be schedulable?

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

Rate Monotonic Scheduling

Consider (10,2) , (12,5) , (15,4) Utilization = 0.2 + 0.417 + 0.27 = 0.887

But RM fails: (WHY)

Page 31: CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I 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 32: CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I 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 33: CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015

Homework

Read 12.3-12.4