23
REAL TIME SYSTEM Scheduling

REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Embed Size (px)

Citation preview

Page 1: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

REAL TIME SYSTEM

Scheduling

Page 2: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Basics of Scheduling

Usually Fewer Processor than tasks Adherence to timing constraints like

deadline In a Multiprocessor (or MultiCore)

environment, A scheduling decision is a decision to execute a task, and it has the following three parts: assignment: which processor should

execute the task; ordering: in what order each processor

should execute its tasks; and timing: the time at which each task

executes.

Page 3: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Type of schedulers – Offline

Fully static schedulerDoesn't require mutex or semaphoreDifficult to realize

Difficult to predict execution timeTasks typically have data dependent

execution times Static order scheduler

Tasks assignment and ordering at design time

Defer until run time decision of when in physical time to execute a task

Depend on whether locks could be acquired or precedence constraints are satisfied

Page 4: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Type of scheduler- Online

Static assignment schedulerAssignment at design time rest at run

time Fully dynamic scheduler

When a processor become available scheduler decides which tasks should be assigned to it

Preemptive scheduler Tasks can be removed while still

executing and another task can be assigned the processorTasks may be blocked if it try to acquire a lock and the lock is not available

Non-preemptive scheduler

Page 5: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Times associated with a task Periodic tasks Sporadic tasks- repeat but timing is

irregular Priority or precedence constraints Tasks may have preconditions

Page 6: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Comparing Schedulers

Feasible schedule (fi<di) Optimal with respect to feasibility Processor utilization Maximum lateness

Lmax=max(fi-di) where i belongs to T Help us to analyze infeasible schedules For soft real time system positive Lmax is

not a problem Total completion time or Makespan

M=max(fi) – min(ri) for all i belonging to T

Page 7: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Implementation of a Scheduler For preemptive scheduling the scheduler is

invoked when any of several things occur: A timer interrupt occurs, for example at a jiffy

interval. An I/O interrupt occurs. An operating system service is invoked. A task attempts to acquire a mutex. A task tests a semaphore.

For interrupts, the scheduling procedure is called by the interrupt service routine

In the other cases, the scheduling procedure is called by the operating system procedure that provides the service

Page 8: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

RM – Rate monotonic

Static priority protocol optimal with respect to feasibility among

fixed priority uniprocessor schedulers for the above task model.

This scheduling strategy gives higher priority to a task with a smaller period

Cannot always achieve 100% utilization. In particular, RM schedulers are

constrained to have fixed priority.

Page 9: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

RM schedule for two tasks

Page 10: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

RM Schedule

Consider two tasks to be executed periodically on a single processor, where task 1 has period p1 = 4 and task 2 has period p2 = 6.Let the execution time of task 1 be e1 = 1. Find

the maximum value for the execution time e2 of task 2 such that the RM schedule is feasible.

Again let the execution time of task 1 be e1 = 1. Let non-RMS be a fixed-priority schedule that is not an RM schedule. Find the maximum value for the execution time e2 of task 2 such that non-RMS is feasible.

Page 11: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

EDF

simply executes the tasks in the same order as their deadlines, with the one with the earliest deadline going first

dynamic priority scheduling algorithm. If a task is repeatedly executed, it may be assigned

a different priority on each execution EDF is more expensive to implement than RM,

in practice its performance is generally superior First, RM is optimal with respect to feasibility only

among fixed priority schedulers, whereas EDF is optimal w.r.t. feasibility among dynamic priority schedulers

EDF also minimizes the maximum lateness EDF results in fewer preemptions

Page 12: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Priority inversion

It is a scheduling anomaly where a high-priority task is blocked while unrelated lower-priority tasks are executing

Page 13: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Mars Pathfinder: The Problem• Two tasks were critical for controlling

communication on the lander’s communication bus, the scheduler task (bc_sched) and the distribution task (bc_dist).

• Each of these tasks checked each cycle to be sure that the other had run successfully.

time = 0.125 s

bc_sched

bc_dist

bus active

Page 14: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Mars Pathfinder: The problem• bc_dist was blocked by a much lower priority

meteorological science task (ASI/MET)

• ASI/MET was preempted by several medium priority processes such as accelerometers and radar altimeters.

• bc_sched started and discovered that bc_dist had not completed. Under these circumstances, bc_sched reacted by reinitializing the lander’s hardware and software and terminating all ground command activities.

Page 15: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Problem resolution

• Logging designed into vxWorks enabled NASA and Wind River to reproduce the failure on Earth. This reproduction made the priority inversion obvious.

• NASA patched the lander’s software to enable priority inheritance.

Page 16: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Priority Inheritance protocol

when a task blocks attempting to acquire a lock, then the task that holds the lock inherits the priority of the blocked task

Page 17: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Priority ceiling Protocol

every lock or semaphore is assigned a priority ceiling equal to the priority of the highest-priority task that can lock it.

A task t can acquire a lock a only if the task’s priority is strictly higher than the priority ceilings of all locks currently held by other tasks

Page 18: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Multiprocessor scheduling

Scheduling tasks on multiple processor is even harder then scheduling tasks on a single scheduler

Hu level scheduling algorithmAssigns priority to each task t based on the levelit emphasizes the path through the precedence

graph with the greatest total execution timeOnce priorities are assigned to tasks, a list

scheduler sorts the tasks by priorities and assigns them to processors in the order of the sorted list as processors become available

Page 19: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Multiprocessor scheduling

A schedule for task 1-6 on two processorsMakespan is 4

Page 20: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Scheduling anomalies

Unexpected or counterintuitive behaviors emerge due to small changes in the operating condition of a system Improvements in performance at a local

level can result in degradations in performance at a global level,

Page 21: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Scheduling anomalies

Nine tasks scheduled on three processors

Execution time of tasks reduced by one time unit

Page 22: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Scheduling anomalies

Adding one more processor

Removing precedence between tasks 4,7, and 8

Page 23: REAL TIME SYSTEM Scheduling. Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadline In a Multiprocessor

Scheduling anomalies

Anomaly due to mutual exclusion locksTasks 2 and 4 contend for a mutex.If the execution time of task 1 is reduced,

then the order of execution of tasks 2 and 4 reverses, which results in an increased execution time.