Scheduling Nei Sistemi Real-time

Embed Size (px)

DESCRIPTION

Scheduling nei sistemi real-time

Citation preview

  • 1Periodic TaskScheduling

    2

    Problem formulation

    For each periodic task, guarantee that:

    each job tik is activated at rik = (k-1)Ti each job tik completes within dik = rik + Di

    ti (Ci, Ti) job tik

    rik dik

  • 815

    Rate Monotonic (RM) Each task is assigned a fixed priority

    proportional to its rate [Liu & Layland 73].

    0

    500 10025 75

    tA

    tB

    0

    tC

    40 80

    100

    16

    How can we verify feasibility?

    Each task uses the processor for a fractionof time:

    i

    ii T

    CU =

    Hence the total processor utilization is:

    =

    =n

    i i

    ip T

    CU

    1

    Up is a misure of the processor load

  • 917

    A necessary condition

    If Up > 1 the processor is overloadedhence the task set cannot be schedulable.

    However, there are cases in which Up < 1but the task is not schedulable by RM.

    18

    An unfeasible RM schedule

    0 9 18

    6 120 183

    3 6 12

    9

    15

    15

    deadline miss

    t1

    t2

    944.094

    63

    =+=pU

  • 10

    19

    Utilization upper bound

    833.093

    63

    =+=pU

    0 9 18

    6 120 183

    3 6 12

    9

    15

    15

    t1

    t2

    NOTE: If C1 or C2 is increased,t2 will miss its deadline!

    20

    A different upper bound

    184

    42

    =+=pU

    The upper bound Uub depends on thespecific task set.

    0

    4 120 8 16

    t1

    t24 128 16

  • 11

    21

    The least upper bound

    1

    G

    Uub

    Ulub

    . . .

    22

    A sufficient condition

    If Up Ulub the task set is certainlyschedulable with the RM algorithm.

    If Ulub < Up 1 we cannot say anythingabout the feasibility of that task set.

    NOTE

  • 12

    23

    Ulub for RM

    In 1973, Liu and Layland proved that for aset of n periodic tasks:

    ( )12 /1lub -= nRM nU

    for n Ulub ln 2

    24

    RM Schedulability

    010203040

    50607080

    90100

    1 2 3 4 5 6 7 8 9 10

    69%

    n

    CPU%

  • 13

    25

    RM Guarantee Test

    We compute the processor utilization as:

    =

    =n

    i i

    ip T

    CU

    1

    ( )12 /1 - np nU Guarantee Test (only sufficient):

    26

    Basic Assumptions

    A1. Ci is constant for every instance of tti

    A2. T i is constant for every instance of tti

    A3. For each task, Di = Ti

    A4. Tasks are independent: no precedence relations no resource constraints

  • 14

    27

    RM Optimality

    RM is optimal among all fixed priorityalgorithms:

    If there exists a fixed priority assignmentwhich leads to a feasible schedule for G, thenthe RM assignment is feasible for G.

    If G is not schedulable by RM, then it cannotbe scheduled by any fixed priority assignment.

    28

    Critical InstantFor any task ti, the longest response time occurswhen it arrives together with all higher priority tasks.

    t1

    t2R2

    t1

    t2R2

  • 17

    33

    Earliest Deadline First (EDF)

    Each job receives an absolute deadline:

    di,k = ri,k + Di

    At any time, the processor is assigned to thejob with the earliest absolute deadline.

    Under EDF, any task set can utilize theprocessor up to 100%.

    34

    EDF Example

    0 9 18

    6 120 183

    3 6 12

    9

    15

    15

    t1

    t2

    94.094

    63

    =+=pUDi = Ti

  • 18

    35

    The RM unfesible schedule

    0 9 18

    6 120 183

    3 6 12

    9

    15

    15

    deadline miss

    t1

    t2

    944.094

    63

    =+=pU

    36

    EDF Optimality

    EDF is optimal among all algorithms:

    If there exists a feasible schedule for G, thenEDF will generate a feasible schedule.

    If G is not schedulable by EDF, then it cannotbe scheduled by any algorithm.

  • 19

    37

    EDF Optimality [Dertouzos 74]

    s

    tEt fE dE dk

    tk

    tE

    Transforming ss in ss

    s(t) = s(tE)

    s(tE) = s(t)fk = fE dE dk

    Feasibility is preserved

    38

    EDF schedulability

    In 1973, Liu and Layland proved that for aset of n periodic tasks:

    1lub =EDFU

    This means that a task set G is schedulableby EDF if and only if

    Up 1

  • 22

    43

    RM vs. EDF

    Its more efficient

    It reduces context switches

    EDF

    It is simpler to implement oncommercial operating systems

    More predictable during overloads

    RM

    44

    Extension to tasks with D < T

    ri,k di,k

    Ci

    tti

    Di

    Ti

    ri,k+1

    Deadline Monotonic:pi 1/Di (static)

    Earliest Deadline First:pi 1/di (dynamic)

    Scheduling algorithms

  • 1Handling sharedresources

    Problems caused bymutual exclusion

    2

    Critical sectionst2t1

    globlalmemory buffer

    write readx = 3;y = 5;

    a = x+1;b = y+2;c = x+y;

    int x;int y;

    wait(s)

    signal(s)

    wait(s)

    signal(s)

  • 23

    Blocking on a semaphore

    CS

    t1 t2

    CS

    p1 > p2

    t1

    t2

    D

    It seems that the maximum blockingtime for t1 is equal to the length ofthe critical section of t2, but

    4

    Schedule with no conflicts

    BCT

    priority

    SCT

    MT

  • 35

    Conflict on a critical section

    BCT

    priority

    SCT

    MT

    B

    6

    Conflict on a critical section

    BCT

    priority

    SCT

    MT

    B

  • 47

    Priority Inversion

    A high priority task is blocked by a lower-priority task a for an unbounded interval of time.

    SolutionIntroduce a concurrency control protocol foraccessing critical sections.

    8

    Resource Access Protocols

    Non Preemptive Protocol (NPP)

    Highest Locker Priority (HLP)

    Priority Inheritance Protocol (PIP)

    Priority Ceiling Protocol (PCP)

    Stack Resource Policy (SRP)

  • 815

    Problem with HLP

    CS

    test

    t1

    CS

    t2

    t1

    t2

    p1p2

    t1 blocks just in case ...

    16

    Priority Inheritance Protocol[Sha, Rajkumar, Lehoczky, 90]

    A task in a CS increases its priority only ifit blocks other tasks.

    A task in a CS inherits the highest priorityamong those tasks it blocks.

    PCS = max {Pk | tk blocked on CS}

  • 917

    Schedule with PIPpriority

    t1

    t2

    t3p1

    p3

    direct blocking

    push-through blocking

    18

    Types of blocking Direct blocking

    A task blocks on a locked semaphore

    Push-through blockingA task blocks because a lower priority taskinherited a higher priority.

    BLOCKING:a delay caused by a lower priority task

  • 10

    19

    Identifying blocking resources

    A task ti can be blocked by thosesemaphores used by lower priority tasksand

    directly shared with ti (direct blocking) or

    shared with tasks having priority higher thanti (push-through blocking).

    Theorem:ti can be blocked at most onceby each of such semaphores

    20

    Examplepriority

    B Ct1t2t3

    A

    C

    DB

    A

    D

    t1 can be blockedonce by t2 (on A2 or C2) andonce by t3 (on B3 or D3)

    t2 can be blockedonce by t3 (on B3 or D3)

    t3 cannot be blocked