RT Scheduling

Embed Size (px)

Citation preview

  • 8/9/2019 RT Scheduling

    1/68

    Scheduling Goal To understand the role that scheduling and schedulability analysis

    plays in predicting that real-time applications meet their deadlines

    Topics Simple process model

    The cyclic executive approach Process-based scheduling Utilization-based schedulability tests Response time analysis for PS and !" #orst-case execution time

    Sporadic and aperiodic processes Process systems $ith " % T Process interactions& bloc'ing and priority ceiling protocols (n extendible process model "ynamic systems and on-line analysis Programming priority-based systems

  • 8/9/2019 RT Scheduling

    2/68

    Scheduling

    )n general& a scheduling scheme provides t$o features*

    (n algorithm for ordering the use of system resources +inparticular the ,PUs

    ( means of predicting the $orst-case behaviour of the system$hen the scheduling algorithm is applied

    The prediction can then be used to confirm the temporalre.uirements of the application

  • 8/9/2019 RT Scheduling

    3/68

    Simple Process Model

    The application is assumed to consist of a fixed set ofprocesses (ll processes are periodic& $ith 'no$n periodsThe processes are completely independent of each

    other (ll system/s overheads& context-s$itching times and soon are ignored +i0e& assumed to have zero cost

    (ll processes have a deadline e.ual to their period +that

    is& each process must complete before it is nextreleased

    (ll processes have a fixed $orst-case execution time

  • 8/9/2019 RT Scheduling

    4/68

    Standard Notation

    BCDIJNPRT

    Ua-z

    #orst-case bloc'ing time for the process +if applicable#orst-case computation time +#,!T of the process"eadline of the processThe interference time of the processRelease 1itter of the process2umber of processes in the systemPriority assigned to the process +if applicable#orst-case response time of the process3inimum time bet$een process releases +process period

    The utilization of each process +e.ual to ,4TThe name of a process

  • 8/9/2019 RT Scheduling

    5/68

    Cyclic Executives

    5ne common $ay of implementing hard real-timesystems is to use a cyclic executive6ere the design is concurrent but the code is producedas a collection of procedures

    Procedures are mapped onto a set of minor cycles thatconstitute the complete schedule +or ma1or cycle3inor cycle dictates the minimum cycle time3a1or cycle dictates the maximum cycle time

    Has the advantage of being fully deterministic

    Has the advantage of being fully deterministic

  • 8/9/2019 RT Scheduling

    6/68

    Consider Process Set

    Process Period ,T ,omputation Time ,C

    a 25 10b 25 8

    c 50 5 d 50 4 e 100 2

  • 8/9/2019 RT Scheduling

    7/68

    Cyclic Executive

    loop wait_fo _i!te "#t$ # oced" e_fo _a$ # oced" e_fo _b$ # oced" e_fo _c$ wait_fo _i!te "#t$ # oced" e_fo _a$ # oced" e_fo _b$ # oced" e_fo _d$ # oced" e_fo _e$ wait_fo _i!te "#t$ # oced" e_fo _a$ # oced" e_fo _b$ # oced" e_fo _c$ wait_fo _i!te "#t$ # oced" e_fo _a$ # oced" e_fo _b$ # oced" e_fo _d$end loop $

  • 8/9/2019 RT Scheduling

    8/68

    Time-line for Process Set

    a b c

    Interrupt

    a b d

    Interrupt

    e a b c

    Interrupt Interrupt

  • 8/9/2019 RT Scheduling

    9/68

    Properties

    2o actual processes exist at run-time7 each minor cycleis 1ust a se.uence of procedure callsThe procedures share a common address space andcan thus pass data bet$een themselves0 This data does

    not need to be protected +via a semaphore& for examplebecause concurrent access is not possible (ll 8 process periods must be a multiple of the minorcycle time

  • 8/9/2019 RT Scheduling

    10/68

    Problems with Cycle Executives

    The difficulty of incorporating processes $ith long periods7the ma1or cycle time is the maximum period that can beaccommodated $ithout secondary schedulesSporadic activities are difficult +impossible9 to incorporate

    The cyclic executive is difficult to construct and difficult tomaintain : it is a 2P-hard problem

    (ny 8process; $ith a sizable computation time $ill need tobe split into a fixed number of fixed sized procedures +this

    may cut across the structure of the code from a soft$areengineering perspective& and hence may be error-prone3ore flexible scheduling methods are difficult to support"eterminism is not re.uired& but predictability is

  • 8/9/2019 RT Scheduling

    11/68

    Process- ased Scheduling

    Scheduling approaches

    ixed-Priority Scheduling + PS !arliest "eadline irst +!"

  • 8/9/2019 RT Scheduling

    12/68

    !ixed-Priority Scheduling "!PS#

    This is the most $idely used approach and is the mainfocus of this course !ach process has a fixed& static & priority $hich iscomputer pre-run-time

    The runnable processes are executed in the orderdetermined by their priority)n real-time systems& the 8priority; of a process isderived from its temporal re.uirements& not its

    importance to the correct functioning of the system or itsintegrity

  • 8/9/2019 RT Scheduling

    13/68

    Earliest $eadline !irst "E$!# Scheduling

    The runnable processes are executed in the orderdetermined by the absolute deadlines of the processesThe next process to run being the one $ith the shortest+nearest deadline

    (lthough it is usual to 'no$ the relative deadlines ofeach process +e0g0 >?ms after release & the absolutedeadlines are computed at run time and hence thescheme is described as dynamic

  • 8/9/2019 RT Scheduling

    14/68

    %alue- ased Scheduling "% S#

    )f a system can become overloaded then the use ofsimple static priorities or deadlines is not sufficient7 amore adaptive scheme is neededThis often ta'es the form of assigning a value to each

    process and employing an on-line value-basedscheduling algorithm to decide $hich process to runnext

  • 8/9/2019 RT Scheduling

    15/68

    Preemption and Non-preemption

    #ith priority-based scheduling& a high-priority process maybe released during the execution of a lo$er priority one)n a preemptive scheme& there $ill be an immediate s$itchto the higher-priority process#ith non-preemption & the lo$er-priority process $ill beallo$ed to complete before the other executesPreemptive schemes enable higher-priority processes to bemore reactive& and hence they are preferred

    (lternative strategies allo$ a lo$er priority process tocontinue to execute for a bounded timeThese schemes are 'no$n as deferred preemption orcooperative dispatchingSchemes such as !" and

  • 8/9/2019 RT Scheduling

    16/68

    !PS and &ate Monotonic Priority 'ssignment

    !ach process is assigned a +uni.ue priority based onits period7 the shorter the period& the higher the priority)0e& for t$o processes i and %&

    This assignment is optimal in the sense that if anyprocess set can be scheduled +using pre-emptivepriority-based scheduling $ith a fixed-priorityassignment scheme& then the given process set canalso be scheduled $ith a rate monotonic assignmentscheme2ote& priority @ is the lo$est +least priority

    P j P iT jT i >&P io it7. is

    -- eac i!'ta!ce of t e ta') ca! a=e a -- diffe e!t # io it7

    entry

    e =ice1 &&&.$ entry e =ice2 &&&.$ pragma P io it7 P i.$end e =e '$

    P i i C ili 1 2i

  • 8/9/2019 RT Scheduling

    44/68

    Priority Ceiling 1oc2ing

    Protected ob1ects need to maintain the consistency oftheir data3utual exclusion can be guaranteed by use of thepriority model

    !ach protected ob1ect is assigned a ceiling priority $hichis greater than or e.ual to the highest priority of any ofits calling tas's#hen a tas' calls a protected operation& its priority isimmediately raised to that of the protected ob1ect)f a tas' $ishing to enter a protected operation isrunning then the protected ob1ect cannot be alreadyoccupied

    C ili 1 2i

  • 8/9/2019 RT Scheduling

    45/68

    Ceiling 1oc2ing

    !ach protected ob1ect is assigned a priority using apragma)f the pragma is missing& P io it7 9a't is assumedP o a>_? o is raised if the calling tas'/s active

    priority is greater than the ceiling)f an interrupt handler is attached to a protectedoperation and the $rong ceiling priority has been set&then the program becomes erroneous

    #ith ceiling loc'ing& an effective implementation $ill usethe thread of the calling tas' to execute not only theprotected operation but also to execute the code of anyother tas's that are released as a result of the call

    E l f C ili P i it

  • 8/9/2019 RT Scheduling

    46/68

    Example of Ceiling Priority

    protected @ate_Co!t o( is

    pragma P io it7 28.$

    entry to#_ !d_C(o'e$

    procedure #e!$

    private @ate 3 Boo(ea! 3; /a('e$

    end @ate_Co!t o($

    protected body @ate_Co!t o( is

    entry to#_ !d_C(o'e

    when @ate is

    begin

    @ate 3; /a('e$

    end; procedure #e! is

    begin

    @ate 3; T "e$

    end $end @ate_Co!t o($

    E l

  • 8/9/2019 RT Scheduling

    47/68

    Example

    (ssume tas' T& priority >B& calls to#_ !d_C(o'e andis bloc'ed0 Iater tas' & priority >E& calls #e! 0 Thethread executing $ill underta'e the follo$ingoperations* the code of #e! for evaluate the barrier on the entry and note that T can no$

    proceed the code to#_ !d_C(o'e for T evaluate the barrier again

    continue $ith the execution of after its call on the protectedob1ect

    There is no context s$itch

    ' ti P i iti

  • 8/9/2019 RT Scheduling

    48/68

    'ctive Priorities

    ( tas' entering a protected operation has its priorityraised

    ( tas' s active priority might also change during*

    tas' activation a tas' inherits the active priority of the parenttas' $hich created it +to avoid priority inversion during a rendezvous the tas' executing a rendezvous $ill

    inherit the active priority of the caller if it is greater than itscurrent active priority

    2ote* no inheritance $hen $aiting for tas' termination

    $i t hi g

  • 8/9/2019 RT Scheduling

    49/68

    $ispatching

    The order of dispatching is determined by the tas's/active priorities"efault is preemptive priority based2ot defined exactly $hat this means on a multi-

    processor system5ne policy defined by annex*/I/ _Ait i!_P io it7#hen a tas' becomes runnable it is placed at the bac'

    on the run .ueue for its priority7 $hen it is preempted& itis placed at the front

    E t 3 P li i

  • 8/9/2019 RT Scheduling

    50/68

    Entry 3ueue Policies

    ( programmer may choose the .ueuing policy for atas'/s entry .ueue and the select statementT$o predefined policies* /I/ _ "e"i! +default andP io it7_ "e"i!

    #ith P io it7_ "e"i! and the select statement& analternative that is open and has the highest priority tas'.ueued +of all open alternatives is chosen)f there are t$o open $ith e.ual priority tas's& the one$hich appears textually first in the program is chosenTas's are .ueued in active priority order& if active prioritychanges then no re.ueuing ta'es place7 if the basepriority changes& the tas' is removed and re.ueued

    $ynamic Priorities

  • 8/9/2019 RT Scheduling

    51/68

    $ynamic Priorities

    Some applications re.uire the base priority of a tas' to change

    dynamically* e0g0& mode changes& or to implement dynamicscheduling schemes such as earliest deadline scheduling

    Pac2age Specification

  • 8/9/2019 RT Scheduling

    52/68

    Pac2age Specification

    with da&Ta')_Ide!tificatio!$

    use da$ package da&D7!a>ic_P io itie' is

    procedure et_P io it7 P io it7 3 7'te>& !7_P io it7$ T 3 Ta')_Ide!tificatio!&Ta')_Id 3;

    Ta')_Ide!tificatio!&C" e!t_Ta').$

    function @et_P io it7 T 3 T_Ide!tificatio!&Ta')_Id3; Ta')_Ide!tificatio!&C" e!t_Ta').

    return 7'te>& !7_P io it7$ -- ai'e Ta')i! _? o if ta') a' te >i!ated -- Bot ai'e P o a>_? o if a N"((_Ta')_Id i' #a''ed

    private -- !ot '#ecified b7 t e (a! "a eend da&D7!a>ic_P io itie'$

    $ynamic Priorities

  • 8/9/2019 RT Scheduling

    53/68

    $ynamic Priorities

    The effect of a change of base priorities should be assoon as practical but not during an abort deferredoperation and no later than the next abort completionpoint

    ,hanging a tas'/s base priority can affect its activepriority and have an impact on dispatching and .ueuing

    P S 4

  • 8/9/2019 RT Scheduling

    54/68

    P.S 4

    P5S)N supports priority-based scheduling& and has optionsto support priority inheritance and ceiling protocolsPriorities may be set dynamically#ithin the priority-based facilities& there are four policies*

    ) 5* a process4thread runs until it completes or it is bloc'ed Round-Robin* a process4thread runs until it completes or it is bloc'edor its time .uantum has expired

    Sporadic Server* a process4thread runs as a sporadic server 5T6!R* an implementation-defined

    or each policy& there is a minimum range of priorities thatmust be supported7 C> for ) 5 and round-robinThe scheduling policy can be set on a per process and a perthread basis

    P S 4

  • 8/9/2019 RT Scheduling

    55/68

    P.S 4

    Threads may be created $ith a system contention option& in $hich case they compete $ith other systemthreads according to their policy and priority

    (lternatively& threads can be created $ith a processcontention option $here they must compete $ith otherthreads +created $ith a process contention in the parentprocess )t is unspecified ho$ such threads are scheduled relative to

    threads in other processes or to threads $ith global contention

    ( specific implementation must decide $hich to support

    Sporadic Server

  • 8/9/2019 RT Scheduling

    56/68

    Sporadic Server

    ( sporadic server assigns a limited amount of ,PUcapacity to handle events& has a replenishment period& abudget& and t$o prioritiesThe server runs at a high priority $hen it has somebudget left and a lo$ one $hen its budget is exhausted#hen a server runs at the high priority& the amount ofexecution time it consumes is subtracted from its budgetThe amount of budget consumed is replenished at thetime the server $as activated plus the replenishmentperiod#hen its budget reaches zero& the server/s priority is setto the lo$ value

    ther !acilities

  • 8/9/2019 RT Scheduling

    57/68

    .ther !acilities

    P5S)N allo$s*

    priority inheritance to be associated $ith mutexes+priority protected protocolF ),PP

    message .ueues to be priority orderedfunctions for dynamically getting and setting a thread/sprioritythreads to indicate $hether their attributes should be

    inherited by any child thread they create

    &T /ava Threads and Scheduling

  • 8/9/2019 RT Scheduling

    58/68

    &T /ava Threads and Scheduling

    There are t$o entities in Real-Time Lava $hich can bescheduled*

    Rea(ti>eT ead' +and No ea#Rea(ti>eT ead'7!?=e!t a!d(e +and Bo"!d 7!c?=e!t a!d(e

    5b1ects $hich are to be scheduled must implement the c ed"(ab(e interface specify their

    E c ed"(i! Pa a>ete '

    E Re(ea'ePa a>ete 'E Fe>o 7Pa a>ete '

    &eal Time /ava

  • 8/9/2019 RT Scheduling

    59/68

    &eal-Time /ava

    Real-Time Lava implementations are re.uired to support atleast >H real-time priority levels

    (s $ith (da and P5S)N& the larger the integer value& thehigher the priority2on real-time threads are given priority levels belo$ theminimum real-time priority2ote& scheduling parameters are bound to threads atthread creation time7 if the parameter ob1ects are changed&they have an immediate impact on the associated thread

    Ii'e (da and Real-Time P5S)N& Real-Time Lava supportsa pre-emptive priority-based dispatching policyUnli'e (da and RT P5S)N& RT Lava does not re.uire apreempted thread to be placed at the head of the run

    .ueue associated $ith its priority level

    The Schedulable nterface

  • 8/9/2019 RT Scheduling

    60/68

    The Schedulable nterface

    public interface c ed"(ab(e extends %a=a&(a! &R"!!ab(eG public void addTo/ea'ibi(it7 .$ public void e>o=e/ o>/ea'ibi(it7 .$

    public Fe>o 7Pa a>ete ' etFe>o 7Pa a>ete ' .$ public void 'etFe>o 7Pa a>ete ' Fe>o 7Pa a>ete ' >e>o 7.$

    public Re(ea'ePa a>ete ' etRe(ea'ePa a>ete ' .$ public void 'etRe(ea'ePa a>ete ' Re(ea'ePa a>ete ' e(ea'e.$

    public c ed"(i! Pa a>ete ' et c ed"(i! Pa a>ete ' .$

    public void 'et c ed"(i! Pa a>ete ' c ed"(i! Pa a>ete ' 'c ed"(i! .$

    public c ed"(e et c ed"(e .$ public void 'et c ed"(e c ed"(e 'c ed"(e .$

    H

    Scheduling Parameters

  • 8/9/2019 RT Scheduling

    61/68

    Scheduling Parameters

    public abstract class c ed"(i! Pa a>ete 'G public c ed"(i! Pa a>ete ' .$ H

    public class P io it7Pa a>ete ' extends c ed"(i! Pa a>ete 'G

    public P io it7Pa a>ete ' int # io it7.$

    public int etP io it7 .$ ete 'G

    public I>#o ta!cePa a>ete ' int # io it7, int i>#o ta!ce.$ public int etI>#o ta!ce .$ public void 'etI>#o ta!ce int i>#o ta!ce.$ &&&

    H

    &T /ava0 Scheduler

  • 8/9/2019 RT Scheduling

    62/68

    &T /ava0 Scheduler

    Real-Time Lava supports a high-level scheduler $hosegoals are* to decide $hether to admit ne$ schedulable ob1ects according

    to the resources available and a feasibility algorithm& and to set the priority of the schedulable ob1ects according to the

    priority assignment algorithm associated $ith the feasibilityalgorithm

    6ence& $hilst (da and Real-Time P5S)N focus on staticoff-line schedulability analysis& Real-Time Lavaaddresses more dynamic systems $ith the potential foron-line analysis

    The Scheduler

  • 8/9/2019 RT Scheduling

    63/68

    The Scheduler

    public abstract class c ed"(eG public c ed"(e .$ protected abstract void addTo/ea'ibi(it7 c ed"(ab(e '.$ protected abstract void e>o=e/ o>/ea'ibi(it7 c ed"(ab(e '.$

    public abstract boolean i'/ea'ib(e .$

  • 8/9/2019 RT Scheduling

    64/68

    The Scheduler

    Thec ed"(e

    is an abstract classThe i'/ea'ib(e method considers only the set ofschedulable ob1ects that have been added to itsfeasibility list +via the addTo/ea'ibi(it7 and

    e>o=e/ o>/ea'ibi(it7 methodsThe method c a! eIf/ea'ib(e chec's to see if itsset of ob1ects is still feasible if the given ob1ect has itsrelease and memory parameters changed)f it is& the parameters are changedStatic methods allo$ the default scheduler to be .ueriedor setRT Lava does not re.uire an implementation to providean on-line feasibility algorithm

    The Priority Scheduler

  • 8/9/2019 RT Scheduling

    65/68

    The Priority Scheduler

    class P io it7 c ed"(e extends c ed"(eG public P io it7 c ed"(e .

    protected void addTo/ea'ibi(it7 c ed"(ab(e '.$ ...

    public void fi e c ed"(ab(e c ed"(ab(e 'c ed"(ab(e.$

    public int etFa6P io it7 .$ public int etFi!P io it7 .$ public int etNo >P io it7 .$

    public static P io it7 c ed"(e i!'ta!ce .$ &&&H

    tandard preemptive priority based scheduling

    ther !acilities

  • 8/9/2019 RT Scheduling

    66/68

    .ther !acilities

    Priority inheritance and ),,P +called priority ceilingemulationSupport for aperiodic threads in the form of processinggroups7 a group of aperiodic threads can be lin'edtogether and assigned characteristics $hich aid thefeasibility analysis

    Summary

  • 8/9/2019 RT Scheduling

    67/68

    Summary

    ( scheduling scheme defines an algorithm for resourcesharing and a means of predicting the $orst-casebehaviour of an application $hen that form of resourcesharing is used0#ith a cyclic executive& the application code must bepac'ed into a fixed number of minor cycles such that thecyclic execution of the se.uence of minor cycles +thema1or cycle $ill enable all system deadlines to be metThe cyclic executive approach has ma1or dra$bac's manyof $hich are solved by priority-based systemsSimple utilization-based schedulability tests are not exact

    Summary

  • 8/9/2019 RT Scheduling

    68/68

    Summary

    Response time analysis is flexible and caters for* Periodic and sporadic processes =loc'ing caused by )P, ,ooperative scheduling (rbitrary deadlines

    Release 1itter ault tolerance 5ffsets

    (da& RT P5S)N and RT Lava support preemptive

    priority-based scheduling (da and RT P5S)N focus on static off-line schedulabilityanalysis& RT Lava addresses more dynamic systems$ith the potential for on-line analysis