scheduling & schedulersbeaulieu.segfaults.net/courses/17w/eee499/lecture/07 - scheduling...

24
Real Time Operating Systems Scheduling & Schedulers

Upload: others

Post on 17-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Real Time Operating Systems

Scheduling & Schedulers

Page 2: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Real Time Operating Systems

Subtitled …Specifying Timing

Constraints

Modeling Timing Constraints and

Resources

Page 3: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Outline

• Scheduling & Resource Management

• Approaches to Scheduling (RTS)

– Clock-Driven Scheduling

– Round-Robin Scheduling

– Priority Scheduling

– Static versus Dynamic Systems & Scheduling

• Periodic task Model

• RTOS Schedulers

Page 4: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Scheduling and Resource Management

• Scheduling algorithms - Policy – the rules under which jobs are assigned to

processors are defined by the system scheduling algorithm

• Resource management (access-control) – the allocation and coordination of the system

(passive) resources to jobs is defined by the resource access-control protocols

• The scheduler - Mechanism – the module which implements these

algorithms and protocols

Page 5: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Scheduling and Resource Management

• Schedules – a schedule is the assignment by the scheduler of

all jobs in the system to the available processors

– we assume that the scheduler is correct in that ->

• It only produces valid schedules 1. at any time one processor is assigned at most one job

2. at any time each job is assigned at most one processor*

3. no job is scheduled before its release time

4. the total amount of processor time allocated is equal to each job’s maximum execution time (or actual)**

5. all precedence and resource constraints are met

* implies no parallel processing at job level ** depends on algorithm

Page 6: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Scheduling and Resource Management

• Feasible schedules – a feasible schedule is one in which all jobs meet

their timing constraints (usually deadlines)

– to say that a set of jobs is schedulable by an algorithm implies that scheduling under this algorithm always produces a feasible schedule

• Optimal algorithms – finding feasible schedules is not always easy

– an algorithm which always produces a feasible schedule, if one exists, is said to be optimal

What does this say about a set of jobs which cannot be scheduled by an optimal algorithm?

Page 7: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Scheduling and Resource Management

• Hierarchical scheduling – rarely is there ever just one scheduler in a RTS, and

frequently these multiple schedulers exist within some type of hierarchical structure

– may have schedulers of logical / physical devices which exist separate from the application scheduler • monitors, database servers, disk drives ...

– may have jobs scheduled by the application scheduler which are themselves schedulers • message handlers

• Example - a queued aperiodic poller

Page 8: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Approaches to Scheduling

• There are generally three broad classes, or approaches to processor scheduling: – Clock-driven scheduling – Weighted Round-robin scheduling – Priority scheduling

• greedy scheduling

• One can also classify scheduling schemes according to: – Off-line versus On-line scheduling – Static versus Dynamic scheduling

Page 9: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Clock-Driven Scheduling

• At pre-specified time instants, a job or sequence of jobs are scheduled onto the processor(s)

– job/task scheduling is designed off-line

– all system job parameters are known a priori and are fixed

– scheduling overhead is minimal

– may be implemented using a hardware timer mechanism

Page 10: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Timer-Driven Scheduling

• Observe the schedule below for this system:

{T1= (4,1) , T2= (5,1.5), T3 = (20,1) , T4 = (20,2)}

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

...

hyperperiod, H = 20

slack time (space for asynchronous jobs)

T1 T1 T1 T1 T1 T2 T2 T2 T2 T3 T4

How do we choose this design? How do we implement this design?

T1

Page 11: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Timer-Driven Scheduling

• Rather than making scheduling decisions at arbitrary times, limit decision making to specific points in the hyperperiod, at frame boundaries

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

...

hyperperiod, H = 20

frame size, f = 4

T1 T1 T1 T1 T1 T2 T2 T2 T2 T3 T4

scheduling decision points

major cycle

No preemption within frames minor cycle on T1

Page 12: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Round-Robin Scheduling

• In straight round robin scheduling, – ready jobs are inserted in a FIFO queue and when

they reach the front of the queue they are given an equal slice of processor time

– jobs are preempted at the end of their slice regardless of completion status

– therefore in an n job system, each job gets 1/n th of the processor

– typically processor time slices are quite short with respect to execution times

Page 13: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Weighted Round-Robin Scheduling

• In weighted round robin scheduling,

– each job gets wt slices of the processor time depending upon the weight of the job

– therefore in an n job system, job Ji gets wti/(wt) of the processing time

• Example: Job Wt e % CPU

J1 2 3 ___

J2 5 7 ___

J3 2 4 ___

J4 1 3 ___

What would 1 round of time slice scheduling look like?

Page 14: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Priority-Driven Scheduling

• In a priority-driven system, ready jobs are assigned to processors according to their relative priorities – also called greedy scheduling or list scheduling

– priorities may be static or dynamic

– jobs may be preemptable or nonpreemptable • in general preemptive scheduling feels intuitively better than

nonpreemptive

• but there are exceptions

• Most commonly supported approach in RTOS

Page 15: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Dynamic versus Static Systems

• A dynamic system has a common job priority queue such that when a processor becomes available the next ready job is executed; a static system configures jobs statically on a predefined processor

• Intuition says that a dynamic system will have better performance than a static one – again there are exceptions

• Within a dynamic system jobs may be able to migrate or not – jobs which can not migrate start on the first available

processor, and must finish there

Page 16: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Dynamic versus Static Priority Scheduling

• A dynamic priority scheduling algorithm allows for task / job priorities to change at run-time

• With static priority scheduling the tasks / jobs have a fixed (generally) a priori priority assignment

– do not confuse this with dynamic & static systems

• We will only study fixed (static) priority scheduling algorithms

Page 17: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Validating the Timing Constraints of a System

• Step 1 – specification correctness – Check for consistency/correctness of constraints

• Step 2 – task feasibility – Validate that each task can meet its constraints if

it were to execute standalone on the processor

• Step 3 – system validation* – Validate that all tasks together under the given

scheduling & resource management strategy meet their respective constraints

* The difficult part!

Page 18: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

The Periodic Task Model

• The periodic task model is a classical workload model of real-time systems; one which we will study further in this course – the underlying assumption is that each regular or

semi-regular function of the system be modeled as a periodic task

– each periodic task (Ti) is defined by its period (pi) and its worst-case execution time (ei)

– a task’s period is defined as the minimum length of all time intervals between release times of consecutive jobs

Page 19: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

The Periodic Task Model

• The accuracy of the model is dictated by how closely it resembles the system under study

– it is quite accurate when the release time jitter is small (best when all tasks are truly periodic) and when the execution times of tasks are well known and have small deviations

– conversely the accuracy of the model degrades if the release time jitters are high and/or the execution times have high variance

Page 20: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

The Periodic Task Model

• k jobs in a task Ti -> Ji,1 , Ji,2 , … Ji,k (k is usually infinite)

• release time ri,1 of Ji,1 defines the phase of Ti – given J1,1 of (2,7]; {read this as r1,1=2, d1,1=7}

• the phase of T1, 1 = 2

• the hyperperiod (H) of a set of periodic tasks is defined by their least common multiple – given tasks with periods of 3, 8 & 12

– H = 24 and the maximum # of jobs N = 8 +3 +2 = 13

• the amount of time a task keeps the processor busy is known as utilization – ui = ei / pi

Page 21: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

The Periodic Task Model

• Often we assume that within each task a job releases at the beginning of the period and that it need only complete by the end of the period

– -> default deadline is equal to the period (Di = pi )

• More generally, Di can be any value

– we can model job precedence in terms of release times and deadlines

– example: r1,1= 0, d1,1= 3, r1,2= 3, d1,2= 7 -> J1,1 < J1,2

How can we use deadline to minimize response jitter?

Page 22: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

The Periodic Task Model

• Aperiodic and sporadic tasks model events which arrive (release) unpredictably – the inter-arrival times of these tasks are identically distributed random

variables

– the execution times of these tasks are also i.d. random variables

• Aperiodic tasks have jobs with soft or no deadlines – example: Automobile Collision Avoidance System – update situational

awareness display

• Sporadic tasks have jobs with hard deadlines – example: ACAS – disengage auto-steering

Page 23: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

Question

• What about system overhead times such as context switching?

Page 24: Scheduling & Schedulersbeaulieu.segfaults.net/courses/17w/EEE499/lecture/07 - Scheduling and... · Scheduling and Resource Management •Schedules –a schedule is the assignment

References

[1] Liu, J.W.S., “Real-Time Systems”, Prentice-Hall, 2000.

[2] Labrosse, J.J., “MicroC/OS-II” 1st and 2nd Editions (1999, 2002)