10.07.2015 Views

Real-Time Scheduling - gmitWEB

Real-Time Scheduling - gmitWEB

Real-Time Scheduling - gmitWEB

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong>• Process control plants, robotics, air trafficcontrol, telecommunications• <strong>Real</strong> <strong>Time</strong> Computing is defined as:-– “a type of computing where the correctness ofthe system depends not only on the logicalresult of the computation, but also on the timeat which the results are produced”<strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong>• <strong>Scheduling</strong>– the determination of the policies that decidewhich tasks execute when multiple tasks areready to execute.– A design concern, it fundamentally involvesdecisions that optimise the overall systemperformance according to some criteria.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 1April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 2<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• System designer decides on the schedulingapproach– Win 2000 is preemptive, swapping out lowpriority tasks when a higher priority becomesready.• In many embedded systems, hardwareinterrupts drive some tasks.– Serial communication handled this way inWindows.<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Commonly– Schedulers use a run-to-completion or apreemptive policy to control execution.• Most common policies in RTS arepreemptive.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 3April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 4<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Two keys to good RT design arerepeatability and predictability.– Fighter aircraft require computers to managethe flight control surfaces.• Frequent and timely updates to airfoil position andthrust application.– A change that comes too late is no better thanone that does not come at all.<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Pace makers– A pulse to the heart just after there is a beat caninduce fibrillation.• Both these are a BAD THING• RTS use one or more scheduling algorithmto control when a task begins and whetheror not a task may be suspended duringexecution and prior to completion.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 5April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 6


<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Not a trivial thing.– High priority tasks can be scheduled inisolation, but may be blocked from executionby lower priority tasks.– Blocking is unavoidable in preemptivescheduling with shared resources.• It must be bounded to identify worst case blocking.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 7<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Key priorities– ensuring that hard tasks complete or start by theirdeadline, and that as many soft tasks also complete orstart by their deadline• not fairness and minimum average response time– most contemporary real-time systems• designed to be as responsive as possible to real-time tasks• when deadline approaches, the task is scheduled– typically require deterministic response times in therange of milliseconds to sub milliseconds.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 8<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Various alternatives to Round Robin• Using priority driven non preemptivescheduler– real-time task is added to head of queue to runafter current– if current is a slow low priority task, time isunacceptable if it is running at a critical time.• There are better approaches:-April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 9<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Combine priority with clock based interrupts– Preemption point occurs at regular intervals, lowerpriority preempted by higher.• delays of milliseconds usually, may not be adequate for moredemanding application.• For demanding applications, use an immediatepreemptive scheduler.– OS responds to interrupt almost immediately.– Unless system is in critical code lockout sectionApril 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 10<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• The approach taken to scheduling dependson– 1) does the system perform a schedulabilityanalysis– 2) if it does, is it done statically or dynamically– 3) does the result of the analysis produce aschedule according to which tasks aredispatched at run time.<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• The classes of algorithm available based onthis– Static table driven– Static priority driven preemtive– Dynamic planning– Dynamic best effortApril 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 11April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 12


<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Static Table Driven– Applicable mainly to periodic tasks, thisperforms a static analysis of feasible schedules.• Result is a schedule of dispatching.– Input for analysis - periodic arrival times,execution time, periodic ending deadline,relative priority of tasks.– The scheduler tries to develop schedule to meetall needs.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 13<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Static Table Driven– Is inflexible - any change to tasks requiresschedule to be redone.– Earliest Deadline first is an example of this typeof scheduling algorithm.• A set of tasks is schedulable if the sum of taskloading is less than 100%.• Not stable, if the load is above 100%, somethingfails, but can’t predict what.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 14<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Static Priority Driven Preemptive– A static analysis is done, and the result is usedto assign priorities to tasks.• A traditional priority driven preemptive schedulercan then be used.– Usually, in a real-time system, the priority isrelated to the time constraints on the tasks.– Rate Monotonic scheduling assigns prioritiesbased on their periods.<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Dynamic Planning Based– Feasibility is determined at run-time rather thanan offline analysis prior to the start ofexecution.– An arriving task is accepted only if it is feasibleto meet its time constraints.– Requires constant reworking of the schedule toaccommodate new tasks and existing ones.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 15April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 16<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong><strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>– If a new task can be scheduled in withoutadverse affects (missed deadlines) to theexisting tasks already scheduled, then theschedule is revised.• Dynamic Best Effort– There is no feasibility analysis.– System tries to meet all deadlines and abortsany started process whose deadline is missed.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 17– A new task is assigned a priority based on thecharacteristics of task.– It uses some form of deadline scheduling.– Typically, the tasks are aperiodic and staticscheduling is not possible.– Until a deadline arrives or until a task iscomplete, do not know whether timingconstraint will be met (major disadvantage).– It is easier to implement than the others.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 18


<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Two main approaches:-– Deadline & Rate Monotonic scheduling.• Contemporary RT systems are designed tostart the real-time tasks as rapidly aspossible– emphasise rapid interrupt handling and taskdispatching.<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Most real-time apps are more concernedwith completing/starting tasks at the mostvaluable times rather than speed.– Must take into account dynamic resourcedemands and conflicts, processing overloadsand hardware or software faults.• Priorities alone will not be sufficientinformation for scheduling.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 19April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 20<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• No matter what approach is taken, some generalinformation will be required:-– ready time - when the task becomes ready for execution• periodic task - (regular intervals)• aperiodic task – may know time in advance or become awareonly when task becomes ready.– Starting or completion deadline– Processing time – supply/measure– Resources required<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Information about tasks– priority - relative importance of the task• hard real-time systems may have “absolute” priority– fails if deadline is missed.• If the system is to continue operation– then the priority is supplied as a guide for the scheduler.– subtask structure - task may be composed ofmandatory task and optional taskApril 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 21April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 22Deadline <strong>Scheduling</strong>• Several considerations:-– Which task to schedule next.– What preemption is allowed.• Can minimise the missed deadlines using certainpreemption policies and scheduling tasks withearliest deadline (either starting or completion).Deadline <strong>Scheduling</strong>• To preempt or not to preempt– Makes sense notto preempt with startingdeadlines specified.• Task must block itself after completing mandatoryor critical portion allowing other tasks’ startingdeadlines to be met.• Priority Driven Nonpreemptive SchedulerApril 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 23April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 24


<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong><strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Preempt when completion deadlines are specified.– May be possible to allow all tasks to meet deadlines inthis way.– Priority Driven Preemptive Scheduler (on preemptionpoints) or an ImmediatePreemptive Scheduler.• Example given below, with two tasks to collectand process data from two sensors A and B.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 25April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 26<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• By scheduling to give priority at anypreemption point to earliest deadline– all system requirements are met.• The tasks are periodic and predictable– can use static table driven scheduling approach.• What about aperiodic tasks?April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 27 April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 28• Example:-<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>Process Arrival <strong>Time</strong> Execution <strong>Time</strong> Starting DeadlineA 10 20 110B 20 20 20C 40 20 50D 50 20 90E 60 20 70April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 29April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 30


<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• If, always schedule ready task with EDFand let run to completion– straightforward, but using this, B will be missedas A already started.• Performance will improve if deadlines canbe known in advance of ready time.– Known as Earliest Deadline with unforced idletimes:-April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 31<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• ED Unforced Idle <strong>Time</strong>– Always schedule eligible task with ED andallow it run to completion.• The eligible task may not be ready. The processorwill remain idle even though there are other readyprocesses. The processor may remain idle.– The result is that even though maximumutilisation is not achieved, all schedulingrequirements are met.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 32<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Rate Monotonic <strong>Scheduling</strong> (RMS)– A way to resolve the multitask schedulingconflicts for periodic tasks.– Assigns priorities on the basis of a tasks period(shorter the period, higher the priority)– Priority is determined at design time andremains fixed. It is a static/fixed schedulingpolicy.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 33<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• Can compute schedulability using a singleutilisation bound for the entire set of tasks.– Will the system meet all hard deadlies?C1 C2C3Cnn+ + + ... ≤ n(2− 1)T T T T1 2 3– C = Execution <strong>Time</strong>– T = Period of a task– Sum of UtilisationsApril 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 34n1<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• RMS assumes that the end of a tasks period is ahard deadline and that all tasks are preemptible atany time.• If the condition is not met, a more detailedanalysis must be performed.• The upper bound converges to 69% as napproaches infinity.– Not unusual for a utilisation of 90% to be set forschedulability guarantee.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 35<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>• With known utilisations, requirements candetermine if all tasks can be scheduledsuccessfully.• Even though it is possible to schedule moreperiodic tasks with EDF, RMS has beenadopted because:-– Performance difference is small in practiceApril 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 36


<strong>Real</strong>-<strong>Time</strong> <strong>Scheduling</strong>– Most hard RE systems have soft RTcomponents• These can be executed at lower priority to absorbthe processor idle time not used with RMS.– Stability is easier to achieve with RMS• Need to guarantee deadlines of essential tasks if alldeadlines cannot be met.• Can be done with RMS by structuring essentialtasks to have short periods or modifying the RMSpriorities to account for essential tasks.April 05 <strong>Real</strong> <strong>Time</strong> <strong>Scheduling</strong> 37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!