2. Scheduling for Real-Time Systems Roadmap for Section 2 Task - - PowerPoint PPT Presentation

2 scheduling for real time systems roadmap for section 2
SMART_READER_LITE
LIVE PREVIEW

2. Scheduling for Real-Time Systems Roadmap for Section 2 Task - - PowerPoint PPT Presentation

2. Scheduling for Real-Time Systems Roadmap for Section 2 Task Assignment and Scheduling Uni- vs. Multi-Processor Scheduling Algorithms Critical Sections and Priority Inversion HPI Embedded Systems 2 Programming Task Assignment and


slide-1
SLIDE 1
  • 2. Scheduling for Real-Time Systems
slide-2
SLIDE 2

HPI

Embedded Systems Programming

2

Roadmap for Section 2

Task Assignment and Scheduling Uni- vs. Multi-Processor Scheduling Algorithms Critical Sections and Priority Inversion

slide-3
SLIDE 3

HPI

Embedded Systems Programming

3

Task Assignment and Scheduling

Objective:

allocation and scheduling of tasks on processors to ensure that deadlines are met

Problem statement:

Given a set of tasks, task precedence constraints, task

characteristics, and deadlines, we are asked to devise a feasible allocation/schedule on a given computer

Task

consumes resources (cpu, memory, input data) produces results

Precedence constraints: Ti needs output from Tj

slide-4
SLIDE 4

HPI

Embedded Systems Programming

4

Task Dependency Graph

Characteristics:

Precedence-relation "<“ Release time Deadline (hard, soft) Relative deadline: absolute deadline - release time

slide-5
SLIDE 5

HPI

Embedded Systems Programming

5

Periodicity

Periodic: released periodically, every Pi seconds

Period Pi Runs once every period (not exactly every Pi sec)

Sporadic: not periodic, invoked irregularly

Upper bound on invocation rate Aperiodic: sporadic but without bounded invocation rate

Example:

Sensor is read every 10 ms. If value exceeds threshold, signal is send out Sensor task is periodic; period p = 10ms Task that sends the signal is sporadic Maximum invocation rate for this sporadic task?

slide-6
SLIDE 6

HPI

Embedded Systems Programming

6

Feasibility of a Schedule

Task assignment/schedule is feasible if all tasks start

after their release times and complete before their deadlines

Schedule S: Set of processors x Time

Set of tasks S(i,t) is the task scheduled to be running on processor i at time t Offline scheduling: precomputed schedule Online scheduling: tasks are scheduled at arrival Must be fast Static-priority algorithms: tasks' priorities do not change within a

mode (Rate Monotonic Scheduling - RMS)

Dynamic-priority algorithms: priority changes with time (Earliest

Deadline First - EDF)

slide-7
SLIDE 7

HPI

Embedded Systems Programming

7

Preemptive vs. non-preemptive Scheduling

Preemptive: tasks can be interrupted by other tasks More flexible Critical task must be allowed to interrupt less critical ones Non-preemptive: task runs until completion or blocking

  • S1: sub optimal; non-preemptive
  • S2: T2 misses deadline; non-

preemptive

  • S3: preemptive; resource optimal
  • Overhead for preemption;

bookkeeping

  • Preemption not always possible:

disk write

slide-8
SLIDE 8

HPI

Embedded Systems Programming

8

Uni-processor Scheduling

Traditional rate-monotonic scheduling (RMS)

Periodic, preemptable tasks Deadlines equal task period Set of n tasks is schedulable if total processor utilization is no

greater than n(2 1/n-1)

Task priorities are static; inversely related to periods Optimal static-priority uniprocessor algorithm Some results for deadline ≠ period

Rate monotonic deferred server (DS)

Similar to RMS Can handle both: periodic and sporadic tasks

slide-9
SLIDE 9

HPI

Embedded Systems Programming

9

Uni-processor Scheduling (contd.)

Earliest deadline first (EDF):

Tasks are preemptible Task with earliest deadline has highest priority Optimal uni-processor algorithm If a task set is not schedulable on a single processor by EDF,

there is no other algorithm that can successfully schedule that task set

Precedence and exclusion conditions:

RMS & EDF assume independent preemptible tasks Only processing requirements are taken into account;

memory, I/O, other resource requirements negligible

slide-10
SLIDE 10

HPI

Embedded Systems Programming

10

Uni-processor Scheduling (contd.)

Multiple task versions:

System has primary and alternative version of tasks Vary in execution time and quality of output Primary: full-fledged task; top quality output Alternative: bare-bone; lower-quality (acceptable) output; take

less much execution time

Schedule may pick alternative tasks during overload

IRIS tasks (increased reward with increased service):

Quality of output is monotonically nondecreasing function of

execution time

Example: iterative algorithms for computation of π

slide-11
SLIDE 11

HPI

Embedded Systems Programming

11

Multiprocessor Scheduling

Task assignment problem generally is NP-hard Use heuristics

slide-12
SLIDE 12

HPI

Embedded Systems Programming

12

Multiprocessor Scheduling

Utilization balancing algorithm:

Assigns tasks to processors one by one Balanced utilization at end of each step Preemptive tasks

Next-fit algorithm:

Works in conjunction with RMS uni-processor algorithm Divides task set into classes Processors are exclusively assigned to tasks Preemptive tasks

slide-13
SLIDE 13

HPI

Embedded Systems Programming

13

Multiprocessor Scheduling (contd.)

Bin-packing algorithm:

Assigns tasks to processors so, that utilization does not exceed

given threshold

Threshold is set so that uni-processor algorithm is able to

schedule assigned tasks

Preemptive tasks

Myopic offline scheduling algorithm:

Deals with non-preemptive tasks Builds schedule using a search process

Focused addressing and bidding algorithm:

Tasks arrive at individual processors If schedule not feasible: processor may offload some of its

workload onto other processors

Other processors may voluntarily take over tasks

slide-14
SLIDE 14

HPI

Embedded Systems Programming

14

Multiprocessor Scheduling (contd.)

Buddy strategy:

Three categories: underloaded, fully loaded, and overloaded

processors

Overloaded processors ask underloaded ones to take over

some load

Assignment with precedence constraints:

Takes precedence constraints into account Trial-and-error process: assign communicating processes onto

same processor

slide-15
SLIDE 15

HPI

Embedded Systems Programming

15

Scheduling Problems

Critical Sections:

Source of anomalous behavior: priority inversion Lower-priority tasks can block higher-priority tasks Priority inheritance/priority ceiling protocols: finite upper bound to

the period of priority inversion

Mode Changes:

Mission can have multiple phases Different task sets Different priorities/arrival rates How to add/delete tasks of the task list

Fault-Tolerant Scheduling:

Schedule backups in the event of failure

slide-16
SLIDE 16

HPI

Embedded Systems Programming

16

Rate Monotonic Scheduling (RMS)

Applicable when

  • All tasks in a given task set are periodic
  • Tasks have relative deadlines that are identical to their periods, respectively

We use the following notation:

n - number of tasks in a task set ei - execution time for task Ti Pi - period for Pi, when periodic Ii - k-th period of Ti starts at Ii + (k-1)Pi 


phase of task Ti

di - relative deadline of Ti Di - absolute deadline of Ti

  • ri - release time of Ti
slide-17
SLIDE 17

HPI

Embedded Systems Programming

17

RMS Schedulability

There exists a sufficient condition for RMS-

schedulability:

For a processor utilization less than 


n(21/n-1), 
 all tasks will meet their deadlines under RMS


(let n be the number of tasks in the task set).

slide-18
SLIDE 18

HPI

Embedded Systems Programming

18

Discussion of RMS Schedulability

Assumption: phasings = 0 T1: highest priority; non-interrupted

e 1 ≤ P1 necessary and sufficient condition for schedulability

T2: how much time remains in [0, P2] for execution?

In [0,t] T1 has started ⎡t/P1⎤ iterations In addition, we need e2 time for execution of T2 We are looking for t ∈ [0,P2] with t = ⎡t/P1⎤ e1 + e2 ⎡t/P1⎤ changes only at multiples of P1 in amounts of e1 Looking for k with: k P1 ≥ ke1 + e2 and kP1 ≤ P2

  • > this is the necessary and sufficient condition for 


schedulability of T2

analog for T3: we are looking for t ∈ [0,P3] with 


t = ⎡t/P1⎤ e1 + ⎡t/P2⎤ e2 + e3 Again, need to check only at multiples of P1 and P2

slide-19
SLIDE 19

HPI

Embedded Systems Programming

19

Example for RMS Schedula- bility

slide-20
SLIDE 20

HPI

Embedded Systems Programming

20

Graphical Representation of RMS-Schedulability

Wi(t): total amount of work carried by tasks T1, T2,..., Ti, initiated in

interval [0,t].

Wi(t) = ∑i

j=1 ej ⎡t/Pj⎤

Wi(t) is constant and changes only with release of new tasks at τi Ti is RMS-schedulable when min i ∈ τi Wi(t) ≤ t

slide-21
SLIDE 21

HPI

Embedded Systems Programming

21

Sporadic Tasks

Naive approach: reserve slots for sporadic Tasks 


  • > wasting of CPU resources

Example: 2.5 out of 10 slots reserved Deferred server: "virtual slots" for sporadic tasks Processor executes other tasks when no sporadic tasks pending Sporadic task has maximum priority and interrupts anything else Deferred server utilization > 50% may lead to missed deadlines

Ps = 6 (DS); es = 3; Us = 3/6 = 50% P1 = 6 (T1); DS back-to-back: no chance for T1

slide-22
SLIDE 22

HPI

Embedded Systems Programming

22

Transient Overload

Problematic with RMS Tasks are prioritized according to their periods

  • > non-critical tasks may end up with a higher priority than

critical tasks

  • > on overload, critical tasks may miss their deadline

Example:

T3 is non-critical T1, T2, T4 are critical

Idea: split T4 in T4’

with P4’ = P4/2,

e4’ = e4/2, a4’ = a4/2

  • > on overload, the non-critical task T3 misses ist deadline

i ei ai (avg.) Pi 1 20 10 100 2 30 25 150 3 80 40 210 4 100 20 400

slide-23
SLIDE 23

HPI

Embedded Systems Programming

23

Earliest Deadline First (EDF)

execute task with earliest absolute deadline first dynamic priority scheduling algorithm task priorities change depending on closeness of their

absolute deadline

deadline monotonic scheduling algorithm

Task Arrival Time Execution Time Absolute Deadline T1 10 30 T2 4 3 10 T3 5 10 25

tasks do not have to be periodic

  • ptimal uni-processor scheduling algorithm
slide-24
SLIDE 24

HPI

Embedded Systems Programming

24

EDF Schedulability

When all tasks in a task set are periodic with

their relative deadlines == periods, the following statement holds:

(no simple test in other cases)

» If the total utilization of the task set is not

greater than 1, the task set can be feasibly scheduled on a single processor by the EDF algorithm«

slide-25
SLIDE 25

HPI

Embedded Systems Programming

25

Critical Sections

Binary semaphores Lower priority task may block higher priority task

  • T3 has lock; blocks T1
  • T2 interrupts T3

Priority inversion

slide-26
SLIDE 26

HPI

Embedded Systems Programming

26

Priority Inheritance Protocol

TL blocks TH (by owning a semaphore)...

TL inherits temporarily priority of TH Every lower priority task may block higher priority task

exactly once per critical section

Priority inheritance protocol may create deadlocks

NORMAL TIME_CRITICAL

Time TL locks resource TH starts, request resource TH continues to completion TL is boosted until it frees resource TL runs as scheduled

slide-27
SLIDE 27

HPI

Embedded Systems Programming

27

Priority Ceiling Protocol

Priority ceiling of a semaphore is highest priority of any

task that may lock semaphore

Priority owner of lock = priority ceiling

Critical Section Accessed By Priority Ceiling S1 T1, T2 P(T1) S2 T1, T2, T3 P(T1) S3 T3 P(T3) S4 T2, T3 P(T2)

  • Priority ceiling protocol prevents deadlocks
slide-28
SLIDE 28

HPI

Embedded Systems Programming

28

Requirements for a RT OS

The OS (operating system) must be multithreaded and preemptive The OS must support thread priority A system of priority inheritance must exist The OS must support predictable thread synchronization

mechanisms

In addition, the OS behavior must be predictable. This means real-time system developers must have detailed information about the system interrupt levels, system calls, and timing: The maximum time during which interrupts are masked by the OS and by device

drivers must be known.

The maximum time that device drivers use to process an interrupt, and specific

IRQ information relating to those device drivers, must be known.

The interrupt latency (the time from interrupt to task run) must be predictable and

compatible with application requirements.

slide-29
SLIDE 29

HPI

Embedded Systems Programming

29

Further Reading

Jane W.S. Liu, Real Time Systems, Prentice

Hall, ISBN 0-13-099651-3, 2000.

C.M. Krishna and Kang G. Shin, Real-Time

Systems, McGraw-Hill, ISBN: 0-07-057043-4, 1997.

Hermann Kopetz, Real-Time Systems: Design

Principles for Distributed Embedded Applications, Kluwer Academic Publishers, ISBN 0-79-239894-7, 1997.