Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process →...

85
Real Time Operating Systems and Middleware Real-Time Scheduling Luca Abeni [email protected] Credits: Luigi Palopoli, Giuseppe Lipari, and Marco Di Natale Scuola Superiore Sant’Anna Pisa -Italy Real Time Operating Systems and Middleware – p. 1

Transcript of Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process →...

Page 1: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Real Time Operating Systems andMiddleware

Real-Time Scheduling

Luca Abeni

[email protected]

Credits: Luigi Palopoli, Giuseppe Lipari, and Marco Di Natale

Scuola Superiore Sant’Anna

Pisa -Italy

Real Time Operating Systems and Middleware – p. 1

Page 2: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Definitions

Algorithm → logical procedure used to solve a problem

Program → formal description of an algorithm, using aprogramming language

Process → instance of a program (program inexecution)

Program: static entityProcess: dynamic entity

The term task is used to indicate a schedulable entity(either a process or a thread)

Thread → flow of executionProcess → flow of execution + private resources(address space, file table, etc...)

Real Time Operating Systems and Middleware – p. 2

Page 3: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Scheduling

Tasks do not run on bare hardware...The OS kernel creates the illusion of virtual CPUOne virtual CPU per taskTasks have the illusion of executing concurrently

Concurrency is implemented by multiplexing tasks onthe same CPU...

Tasks are alternated on a real CPU......And the task scheduler decides which taskexecutes at a given instant in time

Tasks are associated temporal constraints (deadlines)The scheduler must allocate the CPU to tasks sothat their deadlines are respected

Real Time Operating Systems and Middleware – p. 3

Page 4: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Scheduler - 1

The scheduler is responsible for generating a schedulestarting from a set of tasks ready to execute

Mathematical modelLet’s start considering an UP system

A schedule σ(t) is a function mapping time t intoan executing task

σ : t → T ∪ τidle

where T is the set of tasks running in the systemτidle is the idle task: when it is scheduled, the CPUbecomes idle

For an SMP system (m CPUs), σ(t) can be extendedto map t in vectors τ ∈ (T ∪ τidle)

m

Real Time Operating Systems and Middleware – p. 4

Page 5: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Scheduler - 2

The scheduler is responsible for selecting the task toexecute

From an algorithmic point of viewScheduling algorithm → Algorithm used to select foreach time instant t a task to be executed on a CPUamong the ready taskGiven a task set T , a scheduling algorithm Agenerates the schedule σA(t)

A task set is schedulable by an algorithm A if σA doesnot contain missed deadlines

Schedulability test → check if T is schedulable by A

Real Time Operating Systems and Middleware – p. 5

Page 6: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

RT Scheduling: Why?

The task set T = {(1, 3), (4, 8)} is not schedulable byFCFS

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

τ1

τ2

T = {(1, 3), (4, 8)} is schedulable with other algorithms

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

τ1

τ2

Real Time Operating Systems and Middleware – p. 6

Page 7: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

RT Scheduling Anomalies

Consider jobs J1,1 and J1,2 using a semaphore...r1,1 = 2, c1,1 = 6, d1,1 = 9

r2,1 = 0, c2,1 = 12, d2,1 = 24

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

τ1

τ2L(S)

S

U(S)

L(S)

S

U(S)

Faster processor (c1,1 = 4.5, c2,1 = 9)

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

τ1

τ2L(S)

S S

U(S)

L(S)

S

U(S)

Real Time Operating Systems and Middleware – p. 7

Page 8: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Cyclic Executive Scheduling

Very popular in military and avionics systems

Also called timeline scheduling or cyclic scheduling

Originally used for periodic tasks

Examples:Air traffic controlSpace ShuttleBoeing 777

Real Time Operating Systems and Middleware – p. 8

Page 9: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

The idea

Static scheduling algorithm

Jobs are not preemptableA scheduled job executes until termination

The time axis is divided in time slots

Slots are statically allocated to the tasks (schedulingtable)

A periodic timer activates execution (allocation of a slot)Major Cycle: least common multiple (lcm) of all thetasks’ periods (also called hyperperiod)Minor Cycle: greatest common divisor (gcd) of all thetasks’ periodsA timer fires every Minor Cycle ∆

Real Time Operating Systems and Middleware – p. 9

Page 10: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Real Time Operating Systems and Middleware – p. 10

Page 11: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Implementation

Real Time Operating Systems and Middleware – p. 11

Page 12: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Advantages

Simple implementation (no real-time operating systemis required)

No real task exist: just function callsOne single stack for all the “tasks”

Non-preemptable scheduling ⇒ no need to protect dataNo need for semaphores, pipes, mutexes, mailboxes,etc.

Low run-time overhead

Jitter can be explicitly controlled

Real Time Operating Systems and Middleware – p. 12

Page 13: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Drawbacks

Not robust during overloads

Difficult to expand the schedule (static schedule)New task ⇒ the whole schedule must berecomputed

Not easy to handle aperiodic/sporadic tasks

All task periods must be a multiple of the minor cycletime

Difficult to incorporate processes with long periods (bigtables)

Variable computation time ⇒ it might be necessary tosplit tasks into a fixed number of fixed size procedures

Real Time Operating Systems and Middleware – p. 13

Page 14: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Overload Management

What do we do during task overruns?

Let the task continue? . . .

Possible domino effect on all the other tasks(timeline break)

Abort the task?The system can remain in inconsistent states

⇒ not well suited for soft tasks...

Real Time Operating Systems and Middleware – p. 14

Page 15: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Extensibility

If one or more tasks need to be upgraded, we may haveto re-design the whole schedule again

Example: B is updated but CA + CB > ∆

Real Time Operating Systems and Middleware – p. 15

Page 16: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Extensibility

We have to split B into two subtasks (B1, B2) andrecompute the schedule.

Real Time Operating Systems and Middleware – p. 16

Page 17: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Fixed Priority Scheduling

Very simple preemptive scheduling algorithmEvery task τi is assigned a fixed priority pi

The active task with the highest priority is scheduled

Priorities are integer numbers: the higher the number,the higher the priority

In the research literature, sometimes authors use theopposite convention: the lowest the number, thehighest the priority

In the following we show some examples, consideringperiodic tasks, constant execution times, and deadlinesequal to the period

Real Time Operating Systems and Middleware – p. 17

Page 18: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 19: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 20: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 21: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 22: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 23: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 24: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 25: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 26: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 27: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 28: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 29: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 30: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 31: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 32: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Schedule

Consider the following task set: τ1 = (2, 6, 6),τ2 = (2, 9, 9), τ3 = (3, 12, 12). Task τ1 has priority p1 = 3(highest), task τ2 has priority p2 = 2, task τ3 has priorityp3 = 1 (lowest)

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 18

Page 33: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Another Example (non-schedulable)

Consider the following task set: τ1 = (3, 6, 6), p1 = 3,τ2 = (2, 4, 8), p2 = 2, τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

In this case, task τ2 misses its deadline!

Real Time Operating Systems and Middleware – p. 19

Page 34: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Another Example (non-schedulable)

Consider the following task set: τ1 = (3, 6, 6), p1 = 3,τ2 = (2, 4, 8), p2 = 2, τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

In this case, task τ2 misses its deadline!

Real Time Operating Systems and Middleware – p. 19

Page 35: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Another Example (non-schedulable)

Consider the following task set: τ1 = (3, 6, 6), p1 = 3,τ2 = (2, 4, 8), p2 = 2, τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

In this case, task τ2 misses its deadline!

Real Time Operating Systems and Middleware – p. 19

Page 36: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Notes about Priority Scheduling

Some considerations about the schedule shown before:The response time of the task with the highestpriority is minimum and equal to its WCETThe response time of the other tasks depends on theinterference of the higher priority tasksThe priority assignment may influence theschedulability of a task set

Problem: how to assign tasks’ priorities so that atask set is schedulable?

Real Time Operating Systems and Middleware – p. 20

Page 37: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Priority assignment

Real Time Operating Systems and Middleware – p. 21

Page 38: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Priority assignment

Given a task set, how to assign priorities?

There are two possible objectives:Schedulability (i.e. find the priority assignment thatmakes all tasks schedulable)Response time (i.e. find the priority assignment thatminimise the response time of a subset of tasks)

By now we consider the first objective only

An optimal priority assignment Opt is such that:If the task set is schedulable with another priorityassignment, then it is schedulable with priorityassignment OptIf the task set is not schedulable with Opt, then it isnot schedulable by any other assignment

Real Time Operating Systems and Middleware – p. 22

Page 39: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Optimal Priority Assignment

Given a periodic task set T with all tasks having relativedeadline Di equal to the period Ti (∀i, Di = Ti), andwith all offsets equal to 0 (∀i, ri,0 = 0):

The best assignment is the Rate Monotonic (RM)assignmentShorter period → higher priority

Given a periodic task set with deadline different fromperiods, and with all offsets equal to 0 (∀i, ri,0 = 0):

The best assignment is the Deadline MonotonicassignmentShorter relative deadline → higher priority

For sporadic tasks, the same rules are valid as forperiodic tasks with offsets equal to 0

Real Time Operating Systems and Middleware – p. 23

Page 40: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 41: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 42: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 43: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 44: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 45: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 46: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 47: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 48: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 49: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 50: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 51: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 52: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 53: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 54: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 55: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 56: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 57: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example revised

Consider the example shown before with deadlinemonotonic: τ1 = (3, 6, 6), p1 = 2, τ2 = (2, 4, 8), p2 = 3,τ3 = (2, 12, 12), p3 = 1

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 24

Page 58: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Presence of offsets

If instead we consider periodic tasks with offsets, thenthere is no optimal priority assignment

In other words,If a task set T1 is schedulable by priority O1 andnot schedulable by priority assignment O2,It may exist another task set T2 that is schedulableby O2 and not schedulable by O1.

For example, T2 may be obtained from T1 simplychanging the offsets!

Anyway, all offsets = 0 is the Worst Case ⇒ if T isschedulable when ∀i, ri,0 = 0 then all the task setsobtained from T by changing offsets are schedulable

Example: T = {(3, 7, 10), (5, 6, 10)}

Real Time Operating Systems and Middleware – p. 25

Page 59: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of non-optimality with offsets

Example: priority to τ1:

0 2 4 6 8 10 12 14 16 18 20

τ1

τ2

Changing the offset:

0 2 4 6 8 10 12 14 16 18 20

τ1

τ2

Real Time Operating Systems and Middleware – p. 26

Page 60: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of non-optimality with offsets

Example: priority to τ1:

0 2 4 6 8 10 12 14 16 18 20

τ1

τ2

Changing the offset:

0 2 4 6 8 10 12 14 16 18 20

τ1

τ2

Example: priority to τ2:

0 2 4 6 8 10 12 14 16 18 20

τ1

τ2

Changing the offset:

0 2 4 6 8 10 12 14 16 18 20

τ1

τ2

Real Time Operating Systems and Middleware – p. 26

Page 61: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Scheduling Analysis

Real Time Operating Systems and Middleware – p. 27

Page 62: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Analysis

Given a task set, how can we guarantee if it isschedulable of not?

The first possibility is to simulate the system to checkthat no deadline is missed;

The execution time of every job is set equal to theWCET of the corresponding task;

Periodic tasks with no offsets ⇒ sufficient to simulatethe schedule until the hyperperiod (H = lcm{Ti}).Offsets φi = ri,0 ⇒ simulate until 2H + φmax.If tasks periods are prime numbers the hyperperiodcan be very large!

Note: RM → hyperperiod; Cyclic Executive → MajorCycle

Real Time Operating Systems and Middleware – p. 28

Page 63: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Exercise: Compare the hyperperiods of this two tasksets:

T1 = 8, T2 = 12, T3 = 24

T1 = 7, T2 = 12, T3 = 25

In case of sporadic tasks, we can assume them toarrive at the highest possible rate, so we fall back to thecase of periodic tasks with no offsets!

Real Time Operating Systems and Middleware – p. 29

Page 64: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Utilisation Analysis

In many cases it is useful to have a very simple test tosee if the task set is schedulable.

A sufficient test is based on the Utilisation bound:The utilisation least upper bound for schedulingalgorithm A is the smallest possible utilisation Ulub

such that, for any task set T , if the task set’sutilisation U is not greater than Ulub (U ≤ Ulub), thenthe task set is schedulable by algorithm A

Real Time Operating Systems and Middleware – p. 30

Page 65: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Utilisation

Each task uses the processor for a fraction of time

Ui =Ci

Ti

The total processor utilisation is

U =∑

i

Ci

Ti

This is a measure of the processor’s load

Real Time Operating Systems and Middleware – p. 31

Page 66: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Necessary Condition

If U > 1 the task set is surely not schedulable

However, if U < 1 the task set may or may not beschedulable . . .

If U < Ulub, the task set is schedulable!!!“Gray Area” between Ulub and 1

We would like to have Ulub near to 1

Ulub = 1 would be optimal!!!

Real Time Operating Systems and Middleware – p. 32

Page 67: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Least Upper Bound

Real Time Operating Systems and Middleware – p. 33

Page 68: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Utilisation Bound for RM

We consider n periodic (or sporadic) tasks with relativedeadline equal to periods.

Priorities are assigned with Rate Monotonic;

Ulub = n(21/n − 1)

Ulub is a decreasing function of n;For large n: Ulub ≈ 0.69

n Ulub n Ulub

2 0.828 7 0.7283 0.779 8 0.7244 0.756 9 0.7205 0.743 10 0.7176 0.734 11 . . . Real Time Operating Systems and Middleware – p. 34

Page 69: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Schedulability Test

Therefore the schedulability test consist in:

Computing U =∑n

i=1

Ci

Ti

if U ≤ Ulub, the task set is schedulableif U > 1 the task set is not schedulableif Ulub < U ≤ 1, the task set may or may not beschedulable

Real Time Operating Systems and Middleware – p. 35

Page 70: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 71: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 72: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 73: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 74: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 75: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 76: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 77: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 78: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 79: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 80: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 81: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example

Task set T composed by 3 periodic tasks with U < Ulub: thesystem is schedulable.τ1 = (2, 8), τ2 = (3, 12), τ3 = (4, 16);

U = 0.75 < Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 36

Page 82: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example 2

By increasing the computation time of task τ3, the systemmay still be schedulableτ1 = (2, 8), τ2 = (3, 12), τ3 = (5, 16);

U = 0.81 > Ulub = 0.77

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 37

Page 83: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Utilisation Bound for DM

If relative deadlines are less than or equal to periods,instead of considering U =

∑ni=1

Ci

Ti

, we can consider:

U ′ =

n∑

i=1

Ci

Di

Then the test is the same as the one for RM (or DM),except that we must use U ′ instead of U .

Idea: τ = (C,D, T ) → τ ′ = (C,D,D)

τ ′ is a “worst case” for τIf τ ′ can be guaranteed, τ can be guaranteed too

Real Time Operating Systems and Middleware – p. 38

Page 84: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Pessimism

The bound is very pessimistic: most of the times, a taskset with U > Ulub is schedulable by RM.

A particular case is when tasks have periods that areharmonic:

A task set is harmonic if, for every two tasks τi, τj,either Ti is multiple of Tj or Tj is multiple of Ti.

For a harmonic task set, the utilisation bound is Ulub = 1

In other words, Rate Monotonic is an optimal algorithmfor harmonic task sets

Real Time Operating Systems and Middleware – p. 39

Page 85: Real Time Operating Systems and Middlewaredisi.unitn.it/~abeni/RTOS/2011/sched.pdf · Process → instance of a ... Let’s start considering an UP system A schedule σ(t) is a function

Example of Harmonic Task Set

τ1 = (3, 6), τ2 = (3, 12), τ3 = (6, 24);

U = 1 ;

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

τ1

τ2

τ3

Real Time Operating Systems and Middleware – p. 40