2Basics of Scheduling Usually Fewer Processor than tasks Adherence to timing constraints like deadlineIn 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; andtiming: the time at which each task executes.
3Type of schedulers – Offline Fully static schedulerDoesn't require mutex or semaphoreDifficult to realizeDifficult to predict execution timeTasks typically have data dependent execution timesStatic order schedulerTasks assignment and ordering at design timeDefer until run time decision of when in physical time to execute a taskDepend on whether locks could be acquired or precedence constraints are satisfied
4Type of scheduler- Online Static assignment schedulerAssignment at design time rest at run timeFully dynamic schedulerWhen a processor become available scheduler decides which tasks should be assigned to itPreemptive schedulerTasks 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 availableNon-preemptive scheduler
5Times associated with a task Periodic tasksSporadic tasks- repeat but timing is irregularPriority or precedence constraintsTasks may have preconditions
6Comparing Schedulers Feasible schedule (fi<di) Optimal with respect to feasibilityProcessor utilizationMaximum latenessLmax=max(fi-di) where i belongs to THelp us to analyze infeasible schedulesFor soft real time system positive Lmax is not a problemTotal completion time or MakespanM=max(fi) – min(ri) for all i belonging to T
7Implementation 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 routineIn the other cases, the scheduling procedure is called by the operating system procedure that provides the service
8RM – 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 periodCannot always achieve 100% utilization.In particular, RM schedulers are constrained to have fixed priority.
10RM ScheduleConsider 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.
11EDFsimply executes the tasks in the same order as their deadlines, with the one with the earliest deadline going firstdynamic priority scheduling algorithm.If a task is repeatedly executed, it may be assigned a different priority on each executionEDF is more expensive to implement than RM, in practice its performance is generally superiorFirst, RM is optimal with respect to feasibility only among fixed priority schedulers, whereas EDF is optimal w.r.t. feasibility among dynamic priority schedulersEDF also minimizes the maximum latenessEDF results in fewer preemptions
12Priority inversionIt is a scheduling anomaly where a high-priority task is blocked while unrelated lower-priority tasks are executing
13Mars 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 = sbc_schedbc_distbus active
14Mars 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.
15Problem resolutionLogging 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.
16Priority 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
17Priority 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
18Multiprocessor scheduling Scheduling tasks on multiple processor is even harder then scheduling tasks on a single schedulerHu 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
19Multiprocessor scheduling A schedule for task 1-6 on twoprocessorsMakespan is 4
20Scheduling anomaliesUnexpected or counterintuitive behaviors emerge due to small changes in the operating condition of a systemImprovements in performance at a local level can result in degradations in performance at a global level,
21Scheduling anomalies Nine tasks scheduled on three processors Execution time of tasks reduced by one time unit
22Scheduling anomalies Adding one more processor Removing precedence between tasks 4,7, and 8
23Scheduling anomalies Anomaly due to mutual exclusion locks Tasks 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.