50
Scheduling policies for real-time embedded systems

Scheduling policies for real-time embedded systems

  • Upload
    kaycee

  • View
    36

  • Download
    0

Embed Size (px)

DESCRIPTION

Scheduling policies for real-time embedded systems. Scheduling Policies in RT systems. Two general categories fixed or static scheduling policies dynamic scheduling policies Many commercial RTOSs today support fixed priority scheduling policies - PowerPoint PPT Presentation

Citation preview

Page 1: Scheduling policies for real-time embedded systems

Scheduling policies for real-time embedded systems

Page 2: Scheduling policies for real-time embedded systems

Scheduling Policies in RT systems

• Two general categories– fixed or static scheduling policies– dynamic scheduling policies

• Many commercial RTOSs today support fixed priority scheduling policies

• Fixed priority scheduling algorithms do not modify a job’s priority while the task is running

Page 3: Scheduling policies for real-time embedded systems

Scheduling Policies in RT systems

– The task itself is allowed to modify its own priority for reasons

– approach requires very little support code on the scheduler to implement this functionality

– scheduler is fast and predictable with this approach

– scheduling is mostly done off-line (before the system runs)

Page 4: Scheduling policies for real-time embedded systems

Scheduling Policies in RT systems

• Requires system designer to know the task set a-priori (ahead of time)– not suitable for tasks that are created

dynamically during run time

• The priority of the task set must be determined beforehand and cannot change when the system runs unless the task itself changes its own priority

Page 5: Scheduling policies for real-time embedded systems

Scheduling Policies in RT systems

• Dynamic scheduling algorithms allow a scheduler to modify a jobs priority based on one of several scheduling algorithms or policies–more complicated approach and

requires more code in the scheduler to implement

Page 6: Scheduling policies for real-time embedded systems

Scheduling Policies in RT systems

– leads to more overhead in managing a task set

– scheduler must spend more time dynamically sorting through the system task set and prioritize tasks for execution based on the scheduling policy

– leads to non-determinism which is not favorable, especially for hard real-time systems

Page 7: Scheduling policies for real-time embedded systems

Scheduling Policies in RT systems

• Dynamic scheduling algorithms are on-line scheduling algorithms– scheduling policy is applied to the task

set during the execution of the system– active task set changes dynamically as

the system runs– priority of the tasks can also change

dynamically

Page 8: Scheduling policies for real-time embedded systems

Examples

• Static scheduling policies– rate monotonic scheduling– deadline monotonic scheduling

• Dynamic scheduling policies– earliest deadline first– least slack scheduling

Page 9: Scheduling policies for real-time embedded systems

Rate Monotonic Scheduling

• Optimal fixed priority policy– the higher the frequency (1/period) of a task,

the higher is its priority

• Approach can be implemented in any OS supporting the fixed priority preemptive scheme

• Rate monotonic scheduling assumes the deadline of a periodic task is the same as its period

Page 10: Scheduling policies for real-time embedded systems

Deadline Monotonic Scheduling

• Generalization of the Rate-Monotonic scheduling policy

• Deadline of a task is a fixed (relative) point in time from the beginning of the period

• The shorter this (fixed) deadline, the higher the priority

Page 11: Scheduling policies for real-time embedded systems

Earliest Deadline First• Dynamic priority preemptive policy• Deadline of a task instance is the absolute

point in time by which the instance must complete

• Task deadline is computed when the instance is created

• OS scheduler picks the task with the earliest deadline to run

• A task with an earlier deadline preempts a task with a later deadline

Page 12: Scheduling policies for real-time embedded systems

Least Slack• Dynamic priority preemptive policy• Slack of a task instance is the absolute

deadline minus the remaining execution time for the instance to complete

• OS scheduler picks the task with the shortest slack to run first

• Task with a smaller slack preempts a task with a larger slack

• This approach maximizes the minimum lateness of tasks

Page 13: Scheduling policies for real-time embedded systems

More on dynamic policies

• Priority of a task can change from instance to instance or within the execution of an instance

• Higher priority task preempts a lower priority task

• Very few commercial RTOS support such policies– systems that are hard to analyze for real-time

and determinism properties

Page 14: Scheduling policies for real-time embedded systems

Periodic tasks

• Many systems are multi-rate systems– multiple tasks in the system running at

different periodic rates

• Muli-rate systems can be managed using non-preemptive as well as preemptive scheduling techniques

• Non-preemptive techniques include using state machines as well as cyclic executives

Page 15: Scheduling policies for real-time embedded systems

Examples of periodic tasks

Audio sampling in hardware Audio sample processing Video capture and processing Feedback control (sensing and

processing) Navigation Temperature and speed monitoring

Page 16: Scheduling policies for real-time embedded systems

Scheduling periodic tasks

• Preemptive scheduling is an effective approach for scheduling real-time DSP systems– modularity simplifies the overall design

• Application can be viewed as a collection of independent tasks or jobs– complexity is reduced as the functionality

becomes encapsulated into a set of well defined tasks

Page 17: Scheduling policies for real-time embedded systems

Scheduling periodic tasks

• Systems designed using preemptive scheduling are also more maintainable– issue of changes to one task in the

system affecting other jobs in the system is removed

– New functionality can easily be added by adding a new task

Page 18: Scheduling policies for real-time embedded systems

Scheduling periodic tasks

• Preemptive scheduling approach also makes the system more efficient– preemptive scheduling is more efficient

at utilizing time slots that may not be fully utilized

• Scheduling algorithms– rate monotonic scheduling– deadline monotonic scheduling

Page 19: Scheduling policies for real-time embedded systems

cost of handling event C = 4

periodic arrivals. period T = 10

---- 10 ----

4 4 4

System Utilization = C/T = .40

Periodic Arrivals with Fixed Cost of Processing

System will be able to meet all deadlines. It can finish processing arrivals before the next arrival occurs.

Page 20: Scheduling policies for real-time embedded systems

1. periodic arrival, period T = 10 and C=4

2. periodic arrival, T=10 and C=3 ??

---- 10 ----

4 4 4

Can a second periodic event be accommodated?

Page 21: Scheduling policies for real-time embedded systems

1. periodic arrival, period T = 10 and C=4

2. periodic arrival, T=10 and C=3 ??

---- 10 ----

4 4 4

System Utilization C/T = .70

Can a second periodic event be accommodated?

Page 22: Scheduling policies for real-time embedded systems

1. periodic arrival, period T = 10 and C=4

2. periodic arrival, T=6 and C=3 ??

---- 10 ----

4 4 4

How about 2nd periodic event with T=6 and C=3?

Page 23: Scheduling policies for real-time embedded systems

1. periodic arrival, period T = 10 and C=4

2. periodic arrival, T=6 and C=3 ??

---- 10 ----

4 4 4

System Utilization C/T = .90

How about 2nd periodic event with T=6 and C=3?

Page 24: Scheduling policies for real-time embedded systems

---- 10 ----

4 4 4

--6--

If we process Event #1 before Event #2 then,

2nd event processing will not complete before the next comparable event occurs

Can’t Meet Deadline!

Event #1

Event #2

Task #1

Task #2

Page 25: Scheduling policies for real-time embedded systems

---- 10 ----

4

--6--

Event #1

Event #2

Try Event #2 before Event #1-

We still cannot complete task 1 before the next task 2 event occurs at t=6

unless...

Task #1

Task #2

Page 26: Scheduling policies for real-time embedded systems

---- 10 ----

4

--6--

Event #1

Event #2

Try Event #2 before Event #1-

We still cannot complete task 1 before the next task 2 event occurs at t=6

unless…we Interrupt task 1

Task #1

Task #2

Page 27: Scheduling policies for real-time embedded systems

---- 10 ----

4

--6--

Event #1

Event #2

Try Event #2 before Event #1-

We still cannot complete task 1 before the next task 2 event occurs at t=6

unless…we Interrupt task 1

Giving event #2 priority means that we can meet our deadline IF we preempt the processing of event #1 when event #2 occurs

Task #1

Task #2

Page 28: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis

Page 29: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis

• Assume a set of “n” periodic tasks– period Ti– worst case execution time Ci

• Rate-monotonic priority assignment– task with a shorter period (higher rate)

assigned a fixed higher priority

Page 30: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis

• Rate Monotonic scheduling addresses how to determine whether a group of tasks, whose individual CPU utilization is known, will meet their deadlines– assumes a priority preemption

scheduling algorithm– assumes independent tasks (no

communication or synchronization)

Page 31: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis

– restriction of no communication or synchronization may appear to be unrealistic, but there are techniques for dealing with this

– Each task is a periodic task which has a period T, which is the frequency with which it executes

Page 32: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis

An execution time C, which is the CPU time required during the period

A utilization U, which is the ratio C/T• A task is schedulable if all its deadlines

are met (i.e., the task completes its execution before its period elapses.)– A group of tasks is considered to be

schedulable if each task can meet its deadlines

Page 33: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis

• RMA is a mathematical solution to the scheduling problem for periodic tasks with known cost– assumption is that the total utilization

must always be less than or equal to 100%• Any more and you are exceeding the

capacity of the CPU• Are you asking for more computing power

than you have? IF so, forget it!

Page 34: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis

• For a set of independent periodic tasks, the rate monotonic algorithm assigns each task a fixed priority based on its period, such that the shorter the period of a task, the higher the priority

Page 35: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis• For three tasks T1, T2, and T3 with periods

of 5, 15 and 40 msec respectively the highest priority is given to the task, T1, as it has the shortest period, the medium priority to task T2, and the lowest priority to task T3– priority assignment is independent of the

applications “priority” i.e. how important meeting this deadline is to the functioning of the system or user concerns

Page 36: Scheduling policies for real-time embedded systems

Rate Monotonic Analysis• A mathematical solution to the scheduling

problem for Periodic Tasks with known Cost

• Tasks will have:– Cost (Time to complete a task)– Period (Time between events)– Utilization ( Cost/Period)

• Assumption– Total Utilization must always be <= 100%

Page 37: Scheduling policies for real-time embedded systems

3 levels of analysis using RMA

• Utilization bound test

• Completion time test

• Response time test

Page 38: Scheduling policies for real-time embedded systems

Utilization bound test

• If this simple rule is followed, then all tasks are guaranteed to meet their requirements if the following holds true;

)()12(/..../ /111 nUnTCTC n

nn where and are the execution time andperiod of task , respectively.

iCiT

it

Page 39: Scheduling policies for real-time embedded systems

Utilization bound test

• In this rule, the bound is 1.0 for harmonic task sets

• A task set is said to be harmonic if the periods of all its tasks are either integral multiples or sub-multiples of one another– On the average, for random Cs and Ts,

this number will be about 0.88.

Page 40: Scheduling policies for real-time embedded systems

Utilization bound test

• Theory is a worst case approximation

• For a randomly chosen group of tasks, it has been shown that the likely upper bound is 88%– Harmonic periods can give even higher

upper bounds– The algorithm is stable in conditions

where there is a transient overload

Page 41: Scheduling policies for real-time embedded systems

Utilization bound test

• In this case, there is a subset of the total number of tasks, namely those with the highest priorities that will still meet their deadlines

Page 42: Scheduling policies for real-time embedded systems

Example of UB test

Task t1: C1=20; T1= 100; U1 = .2 Task t2: C2=30; T2= 150; U2 = .2 Task t3: C3=60; T3= 200; U3 = .3

– The total utilization for this task set is .2 + .2 + .3 = .7. Since this is less than the 0.779

– utilization bound for this task set, all deadlines will be met.

Page 43: Scheduling policies for real-time embedded systems

ExampleCan these 4 tasks be

scheduled?

– Can the system run and meet all hard deadlines?

Task Ci Ti Ui

1 3 10 .302 3 12 .253 4 16 .254 7 20 .35

Page 44: Scheduling policies for real-time embedded systems

ExampleExampleCan these 4 tasks be Can these 4 tasks be

scheduled?scheduled?

– Can the system run and meet all hard deadlines?

– NO! The Total Utilization = 115%

Task Ci Ti Ui

1 3 10 .302 3 12 .253 4 16 .254 7 20 .35

Page 45: Scheduling policies for real-time embedded systems

Example

Can these tasks always meet their deadlines?Total Utilization = 80%It MAY be possible - Rate Monotonic Scheduling applies!

Task Ci Ti Ui

1 6 20 .302 4 16 .253 3 12 .25

Page 46: Scheduling policies for real-time embedded systems

Rate Monotonic Theorem• For PERIODIC Tasks• Most frequent task gets highest

priority• THEOREM (Simple Version)– IF the utilization of all tasks is

less than or equal to 69%, then all tasks will ALWAYS meet their deadlines

Page 47: Scheduling policies for real-time embedded systems

Are These Tasks Schedulable?

Task Ci Ti Ui

1 2 20 .102 4 16 .253 3 12 .254 1 20 .05

Page 48: Scheduling policies for real-time embedded systems

Are These Tasks Are These Tasks Schedulable?Schedulable?

Task Ci Ti Ui

1 2 20 .102 4 16 .253 3 12 .254 1 20 .05

Yes. Total CPU Utilization is 65% < 69%

Page 49: Scheduling policies for real-time embedded systems

Are These Tasks Are These Tasks Schedulable?Schedulable?

Task Ci Ti Ui

1 2 20 .102 4 16 .253 3 12 .254 3 20 .15

Page 50: Scheduling policies for real-time embedded systems

Are These Tasks Are These Tasks Schedulable?Schedulable?

Task Ci Ti Ui

1 2 20 .102 4 16 .253 3 12 .254 1 20 .05

Total CPU Utilization is 65%

???