3445.Chapter 3 RTS

Embed Size (px)

DESCRIPTION

Real Time System Chapter 3

Citation preview

  • Chapter 3 Task Assignment and Scheduling3.1 Introduction3.2 Rate monotonic analysis3.3 Other uniprocessor scheduling algorithms3.4 Task assignment3.5 Fault-tolerant schedulingObjective : Look at techniques for allocating & scheduling task to ensure deadline is met

  • Real-Time Systems (Dr Shamala)*IntroductionReal-time computing objective :Execute, by appropriate deadlines its control tasksObjective of Chapter:Techniques for allocating & scheduling tasks on processors to ensure that deadlines are met.

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Scheduling 1970Scheduling research growthYears

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*The allocation/scheduling problem can be stated as follows:Given a set of factors affecting allocation/schedulingTasks (consumes resources)number of tasks, prioritiestask characteristicsperiodicitytiming constraintstask precedence constraints (best described using precedence graph)resource requirementsinter-task interactions We are asked to devise a feasible allocation / schedule on a given computer

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Precedence Graph

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Precedence GraphThe arrows indicate which task has precedence over the other task.We denote the precedence task set of task T by
  • Real-Time Systems (Dr Shamala)*Precedence Graph (Cont.)
  • Real-Time Systems (Dr Shamala)*Precedence Graph (Cont.)We can also write :i < j to indicate that task Ti must precede task Tj. It can also be written as :j > iThe precedence operator is transitive:i< j and j < k i < k For economic representation: Only the list of immediate ancestors in the precedence set:E.g. < (5) = {2,3} since
  • Real-Time Systems (Dr Shamala)*Each task has :Each task requires resources. Eg. Processor execution time, memory or access to a busResources examples:Resources may be (depending to its usage):Exclusively held by a taskRelease Time of a task- the time at which all the data that are required to begin executing the task are available.Deadline the time at which the task must complete its execution. (Deadline maybe hard or soft). Relative deadline = Absolute deadline release time

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Each task (cont.)Task Periodic every Pi seconds, the constraints is that it has to run exactly once every period.Every period is generally DeadlineSporadic not periodic but has an upper bound on the rate in which it has to be invoked. Irregular intervalsAperiodicNot periodic but has no upper bound

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Precedence constraintsinter-task relationshipprecedence graph(T) : precedent-task set of task T i j : task Ti precedes task Tj

    Resource requirementsexclusivenonexclusive

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Characteristics of task assignment/scheduling

    feasible schedulea valid schedule by which every task completes by its deadlinetask assignmentin case of multiple processorsfor a set of processors P, time t, set of tasks , the schedule S is a function such thatS: P t S(i, t) : task scheduled to run on processor i at time tonline (dynamically) vs offline scheduling (precomputed)Static(doesnt change within a mode) vs dynamic priority algorithmpreemptive vs nonpreemptive scheduling

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Inter-task interactionsinter-task communicationsynchronousasynchronousmutual exclusion problem (synchronization)priority inversionchained blockingdeadlock

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Assignment / scheduling problemsMost problems pertaining are more than two processors must make do with heuristics. Heuristics are motivated by the fact that uniprocessor scheduling are tractable. Thus, multiprocessor schedule are divided into two (2) steps:1) assign tasks to processors2) Run a uniprocessor schedule to schedule the task allocated to each processor. If one or more schedules cannot be feasible, then we must either return to the allocation step and change the allocation or declare that a schedule cannot be found.

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Developing a multiprocessor schedule Make an allocationSchedule each processor based on the allocationAre all these schedules feasibleCheck stopping criterionOutput schedule Declare FailureStopChange AllocationContinue

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Uniprocessor scheduling algorithmstraditional rate-monotonic (RM)rate-monotonic deferred server (DS)earliest deadline first (EDF)precedence and exclusion conditionsmultiple task versionsIRIS tasksincreased reward with increased servicemode changesOverview

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Multiprocessor schedulingutilization balancing algorithmnext-fit algorithmbin-packing algorithmmyopic offline scheduling algorithmfocused addressing and bidding algorithmassignment with precedence constraintsCritical sectionsFault-tolerant scheduling

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Notationnnumber of tasks in task setciexecution time of task iTiperiod of periodic task iIi phase of periodic task idirelative deadline of task iDi absolute deadline of task irirelease time of task i

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Commonly Used ApproachesWeighted round-robin approachtasks waiting in the FIFO queuea task with weight wt get wt time slices every roundsuitable for scheduling real-time traffic in high-speed switched networksa switch downstream can begin to transmit an earlier portion of the message upon receipt of the portion, without having to wait for the arrival of the later portionno need for sorted priority queue speedup of scheduling

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Priority-driven approachnever leaves any resource idle intentionallygreedy scheduling, list scheduling, work-conserving schedulingmost scheduling algorithms used in nonreal-time systems are priority-drivenpreemptive vs. nonpreemptive

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Clock-driven(time-driven) approachtasks and their timing constraints are known a priori except for aperiodic tasksrelies on hardware timersa static scheduleconstructed off-linecyclic schedule: periodic static scheduleclock-driven schedule: cyclic schedule for hard real-time tasksforeground/background approachforeground: interrupt-driven schedulingbackground: cyclic executive (Big loop)

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*code blockcode block...LoopISRISRISRinterruptBackgroundForegroundinterruptISR: interrupt service routineForeground/Background Systems

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*A clock-driven schedulerInput: Stored schedule (tk, (tk)) for k = 0, 1, , N-1Task SCHEDULER:set the next decision point i and table entry k to 0;set the timer to expire at tk;do forever:accept timer interrupt;if an aperiodic job is executing, preempt the job;current task = (tk);increment i by 1;compute the next table entry k = i mod N;set the timer to expire at fl(i/N)H + tk { fl: floor function H: hyperperiod N: #tasks in H}if the current task is an idle interval (or idle task), let the job at the head of the aperiodic job queue execute;else, let the task execute;sleep;end SCHEDULER

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*3.2 Rate Monotonic AnalysisAssumptionsA1. No nonpreemptible parts in a task, and negligible preemption costA2. Resource constraint on CPU time onlyA3. No precedence constraints among tasks A4. All tasks periodicA5. Relative deadline = period

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Rate-Monotonic Scheduling(RMS)Overviewrate monotonic prioritythe higher rate, the higher priorityschedulability guaranteed if utilization rate is below a certain limitfor feasible schedulesfi = 1/Ti : frequency (=rate)ci or Ci : execution time

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*3.3 Other Uniprocessor Scheduling AlgorithmsPeriod transformation for transient overloada modified form of RM schedulingDynamic schedulingearliest deadline first schedulingleast laxity first schedulingScheduling of IRIS tasksimprecise computationScheduling of aperiodic tasksMode change

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Period TransformationPeriod transformation for transient overloadchanges the period to cope with transient overloads (in terms of RM scheduling)actually, to cope with semantic criticality in RM schedulingexampletasks: T1: T1 = 12, C1 = 4, C1+ = 7 [Ci+: worst case] T2: T2 = 22, C2 = 10, C2+ = 14utilization rates: average = 0.79, worst case = 1.22problem: if T2 is hard rt and T1 is soft (or not), how can we guarantee T2s deadline in case of transient overload, and T1s deadline in the average case?

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*(continued)solution: boost priority of T2 by reducing its period replace T2 by T2: T2 = T2 /2, C2 = C2 /2, C2+ = C2 +/2an alternative: lower the priority of T1 by lengthening its periodin this case, double the value of parametersthe new deadline must be ok

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Earliest Deadline First SchedulingAlso know as Deadline MonotonicEDF schedulingdynamic priority based, deadline monotonic schedulingPropertiesEDF is optimal for uniprocessorsfor periodic tasks with their relative deadline equal to periods: if the total utilization of the task set is no greater than 1, the task set can be feasibly scheduled on a single processor by EDF.Allows preemptions.

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Procedure1. Sort task instances that require execution in time interval [0, L] in reverse topological order.2. Initialize the deadline of the kth instance of task Ti to (k-1)Ti + di, if necessary3. Revise the deadlines in reverse topological order.4. Select the task with earliest deadline to execute

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Uniprocessor Scheduling of IRIS TasksIntroductionNot necessary to run to completion. Iterative algorithms.Task of this type are known as increased reward with increased service (IRIS)reward function R(x)typically

    where r(x) is monotonically nondecreasing in x.m, o : execution time of the mandatory and optional parts, respectively

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*3.4 Task AssignmentAssignment of tasks to processorsuse heuristics cannot guarantee that an allocation will be found that permits all task to be feasibly scheduled.consider communication costs precedence of task completion.Sometime an allocation algorithm uses communication costs as part of its allocation criterion.

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*

    Utilization-balancing algorithm

    Objective to balance processor utilization, and proceeds by allocating the tasks one by one and selecting the least utilized processor.Considers running multiple copies for fault-tolerance systems.

    for each task Ti, doallocate one copy of Ti to each of the ri least utilized processorsupdate the processor allocation to account for the allocation of Tiend do

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*

    A Next-fit algorithm for RM scheduling

    Used in conjunction with RMseparation of allocation and schedulingsimplifies the scheduler to a local oneallocation: centralized, scheduler: distributedobjectives: to partition a task set so that each partition is scheduled later for execution on a processor by RM schedulingto use as few processors as possibletask characteristicseach task has constant period and deadline constraintsindependent, no precedence constraints

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*allocation algorithmn tasksui : utilization factor of TiPi,j : set of tasks assigned to a processorNk : number of class-k processors used so fartasks are divided into M classes such that

    assigns k class-k tasks to each class-k processor, keeping the utilization factor of the class-M processor less than ln 2

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Algorithm Next-Fit-Mfor k = 1 to M do set Nk = 1;set i = 1;while i
  • Real-Time Systems (Dr Shamala)*

    Bin-packing assignment algorithm for EDF

    periodic independent preemptible tasksbin-packing problem: assign tasks such that the sum of utilization factors does not exceed 1, and minimize the number of processors neededfirst fit decreasing algorithmInitialize i to 1. Set U(j) = 0, for all j.(L : a list of tasks with their utilizations sorted in descending order, nT : # tasks )while i

  • Real-Time Systems (Dr Shamala)*Myopic Offline Scheduling (MOS) AlgorithmOffline Algorithm given in advance arrival times, execution time and deadline.Non-pre-emptive taskNot only processor resources but also others resources such as memory etc.Schedule TreeMOS proceeds by building up a schedule tree.Each node represents an assignment and scheduling of a subset of the tasks. The root of the schedule tree is an empty schedule.Each child of a node consists of a schedule of its parent node, extended by one task. A leaf of this tree consist of the schedule of the entire task set.

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Myopic Offline Scheduling (MOS) Algorithmalgorithmi) start with an empty partial scheduleii) determine if the current partial schedule is strongly feasible then proceed; else backtrackiii) extend the current partial schedule by one task(1) apply the heuristic function to the first Nk tasks in the task set(2) choose the task with the smallest heuristic value to extend the current schedule2 Questions which one task & when to stop

    Real-Time Systems (Dr Shamala)

  • Develop a node if it is strongly feasible. If not feasible, we backtrack that is we mark that node as hopeless and then go back to its parents

  • Real-Time Systems (Dr Shamala)*

    Focused addressing and bidding (FAB)

    Introductiononlinedistributed environment, loosely coupledboth critical and noncritical taskslocal scheduler: handles (critical) tasks arriving at a given nodeglobal scheduler: schedules noncritical tasks across processor boundaryglobal state

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*FAB cont.algorithms for global schedulingto which node the task should be sentnoncooperative algorithm-if enough resources for critical yes; else no for non-critical.random scheduling algorithm-if a processor load is exceeding its threshold then another processor is chosen randomly.focused addressing algorithm overloaded processor checks its surplus info. and selects a processor which it feels it is able to process the task within its deadline. Prob: surplus info may be outdated.bidding algorithm simultaneous lightly loaded to bid (Request For Bids)flexible algorithm
  • Real-Time Systems (Dr Shamala)*focused addressing algorithmFAS: focused addressing surplus, tunable parameterlocally unschedulable tasks sent to the node with the highest surplus ( > FAS)if no such node is found, the task is rejected

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*bidding algorithmfirst, select k nodes with sufficient surplusk: chosen to maximize the chances of finding a nodea request-for-bid(RFB) message is sent to these nodesthose nodes that receive RFB messagecalculate a bid ( = likelihood that the task can be guaranteed)send the bid to the bidder node if the bid > minimum bid reqdthe bidder sends the task to node that offers the best bidif no good bid available, reject the task

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*symbolspi: a processor node with a newly arriving task that is not locally guaranteedps: a node that is selected by FA algorithmpt: a node that receives RFB messagethe flexible algorithm (FAB algorithm)pi selects k nodes with sufficient surplusif the largest value of the surplus > FASthe node with that surplus is chosen as focused node(ps)pi sends the task to ps immediatelyalso, pi sends in parallel a RFB message to the remaining k-1 nodes. RFB contains info on pswhen a node receives the RFB messageit calculates a bid, sends the bid to ps if ps exists

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*(continued)when the task reaches ps it first invokes the local scheduler and checks the feasibilityif it succeeds, all the bids for the task will be ignored if it fails, ps evaluates the bids, sends the task to the node responding with the highest bid, and sends this info to pi in case there is no focused node, pi will handle the biddingif ps cannot guarantee the task and if there is no good bid available, then corrective actions follow

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*(original node) pinetworkps (focused node)bidding

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*The Buddy StrategySame as FAB in the sense that if the processor is overloaded it will try to offload some task to lightly loaded processor. However, it differs in the manner in which it finds the lightly loaded tasks:Each processor has 3 thresholds of loading:U:Under (TU), F: full (TF) and T: over (TV)If a processor has a transition from F/T to U it broadcast an announcement to this effect. This broadcast is not to all processors but to a subset and this effect is known as a buddy effect.

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*3.5 Fault-Tolerant SchedulingIntroductionin case of hardware failureSystems have sufficient reserve capacity and sufficiently fast failure-response mechanism. multiple processors with a set of periodic tasksmultiple copies of each version of a task executed in parallelthe approach taken : ghost copies of tasksembedded into the scheduleneed not be identical to the primary copiesthe tasks concerned are those that were to have been run by the failing processor

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Fault-tolerant scheduleshould be able to run one or more copies of each version (or iteration) of a task despite the failure of up to nsust processorOutput of each fault-tolerant processorhas a ghost schedule + 1+ primary schedulesmakes room for ghosts by shifting primary copies. feasible pair of a ghost schedule and a primary scheduleif both schedules can be merged/adjusted to be feasible

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Ghostseach version of a task must have ghost copies scheduled on nsust distinct processorsghosts are conditionally transparent, only iftwo ghost copies may overlap in the schedule of a processor if no other processor carries the copies of both tasks (that is, if the primary copies of both tasks are not assigned to the same processor)primary copies may overlap the ghosts only if there is sufficient slack time in the schedule to continue to meet all the deadlines

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Algorithm FA1Ha: assignment procedure, Hs: EDF scheduling procedure1. Run Ha to obtain a candidate allocation of copies to processors.2. Run Hs for ghost and primary copies on a processor i.if the resulting schedule is found infeasible, return to step 1otherwise, record the position of the ghost copies in ghost schedule Gi, and the position of the primary copies in schedule Si. (the primary copies will always be schedule according to S regardless of any ghost happen or not)Limitation:- primary tasks are needlessly delayed when the ghost do not have to be executed. While all task will meet their deadlines, it is frequently best to complete execution of the task early to provide slack time.

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Algorithm FA21. Run Ha to obtain a candidate allocation of copies to processors.2. Run Hs for ghost and primary copies on a processor i.if the resulting schedule is found infeasible, return to step 1otherwise, record the position of the ghost copies in ghost schedule Gi. Assign static priorities to the primary tasks in the order in which they finish executing.3. Run a static-priority preemptive scheduler for primary copies with the priorities to obtain Si

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)*Exampleghosts: g4, g5, g6 primaries: h1, h2, h3

    h1 h2 h3 g4 g5 g6release time 2 5 3 0 0 9execution time 2 2 4 2 2 2deadline 6 8 15 5 6 12

    for the primary copies of g4 and g5 case 1: they are allocated to the same processorcase 2: they are on different processors

    Real-Time Systems (Dr Shamala)

  • Real-Time Systems (Dr Shamala)* 0 5 10 15 0 5 10 15 0 5 10 15g4g6g4, g5g5g6h1h3h2h3ghost schedule of p if g4 and g5 cannot overlapghost schedule of p if g4 and g5 can overlapfeasible primary schedule of p if g4 and g5 can overlap

    Real-Time Systems (Dr Shamala)

    *ghost copies of tasksembedded into the schedule and activated whenever a processor carrying one of their corresponding primary or previously activated ghost copies fails