Transcript session two

Real-Time Scheduling

Mehdi Kargahi School of ECE University of Tehran

Common Approaches

   Clock-driven (time-driven)  Scheduling decisions are made at specific time instants, which are typically chosen a priori Weighted round-robin (processor-sharing)   Commonly used for scheduling time-shared applications The weights of jobs can speed up or retard the progress of each job toward its completion Priority-driven  Scheduling decisions are made when particular events in the system occur, e.g.,  A job becomes available    Processor becomes idle (a job is completed) Work-conserving: processor is busy whenever there is work to be done Priority driven schedulers can be static the priority assignment at run-time or dynamic depending on M. Kargahi (University of Tehran)

Clock-Driven Approaches: Overview

   Scheduling decision time: point in time when scheduler decides which job to execute next Scheduling decision time in clock-driven schedulers is defined a priori For example: scheduler periodically wakes up and generates a portion of the schedule  Special case: When job parameters are known a priori, schedule can be pre-computed offline, and stored as a table (table-driven schedulers) M. Kargahi (University of Tehran)

Weighted Round-Robin Approaches: Overview

      The WRR algorithm has been used for scheduling real-time traffic in high-speed switched networks A RR scheduler delays the completion of every job For precedence constrained jobs, the response time of a chain of jobs can be unduly large  WRR is not suitable for scheduling such jobs WRR approach does not require a sorted priority queue, only a RR queue  suitable for ultrahigh-speed networks, since queues with the required speed are expensive M. Kargahi (University of Tehran)

WRR, Sequential, and Piped Executions

J 1,1 J 1,2 J 2,1

P1 P2

J 1,1 &J 2,1

WRR

J 1,2 &J 2,2 J 1,1 J 2,1

P1 P2

J 1,2 J 2,2

Sequential execution  What if the results could be piped?

J 2,2

M. Kargahi (University of Tehran)

Priority-Driven Approaches: Overview

     Never leave processor idle when there is work to be done (such schedulers are also called

work-conserving

) Based on list-driven, greedy schedulers (tries to make locally optimal decisions) Examples: FIFO, LIFO, SETF, LETF, EDF An implementation of preemptive priority-driven scheduling:   Assign priorities to jobs Scheduling decisions are made when    Job becomes ready Processor becomes idle Priority of jobs change  At each scheduling decision time, choose ready task with the highest priority In non-preemptive case, scheduling decisions are made only when processor becomes idle M. Kargahi (University of Tehran)

Example: Priority-Driven Scheduling

 Preemptive  Non-preemptive J5 J6 J7 J8 Note the dynamic dispatching in the above schedule M. Kargahi (University of Tehran)

Effective Release Times and Deadlines

  Timing constraints are often inconsistent with precedence constraints Example:

d 1

>

d 2

, but

J 1

J 2

Effective timing constraints on a single processor:    Effective release time: Effective deadline:

d i eff r i eff

:  :  max{ min{

d i r i

, {

d

, {

r j eff j eff

| J

i

| J 

j

J  J

j

}} The effective release time/deadline of all jobs can be

i

}} computed in

O

(

n

2 ) where

n

is the number of jobs M. Kargahi (University of Tehran)

Effective Release Times and Deadlines

 In the above example, the effective release time of J 3 and its effective deadline is 8 is 2, M. Kargahi (University of Tehran)

Optimality of the EDF Algorithm

   EDF: Earliest Deadline First EDF algorithm: At any time, execute the available job with the earliest deadline Theorem: When preemption is allowed and jobs do not contend for resources, the EDF algorithm can produce a feasible schedule of a set J of jobs with arbitrary release times and deadlines on a processor if and only if J has feasible schedules   Note that the theorem applies even if tasks are not periodic If periodic, the task relative deadline, can be <, =, or > its period M. Kargahi (University of Tehran)

Optimality of the EDF Algorithm

 Proof: Assume that arbitrary schedule S meets timing constraints For S to not be an EDF schedule, we must have the following situation: Case 1: L(A)>L(B) M. Kargahi (University of Tehran)

Optimality of the EDF Algorithm

 Case 2: L(A)  L(B)    If we inductively repeat this procedure, we can eliminate all out-of order violations The resulting schedule may still fail to be an EDF schedule because it has idle intervals while some job is ready Such idle intervals can be eliminated by moving some jobs forward M. Kargahi (University of Tehran)

LRT (reverse EDF) Scheduling

 Latest Release Time (LRT)

J

1 , 3 (0, 6]

J

2 , 2 (5, 8]

J

3 , 2 (2, 7] 0 2

J

1 4

J

3 6

J

2 8  Question: Is LRT a priority-driven scheduling algorithm?

M. Kargahi (University of Tehran)

LST (MLF or LLF) Scheduling

   Least Slack-Time First (LST) Minimum Laxity First (MLF) or Least Laxity First (LLF) Slack (laxity):

d

is equal to at any time

d - t t

, the slack (or laxity) of a job with deadline minus the time required to complete the remaining portion of the job    MLF scheduling: The job with the smallest slack (laxity) has the highest priority at all times MLF is also optimal (proof is similar to EDF) Question: Which of EDF or MLF is preferable in practice?

M. Kargahi (University of Tehran)

Non-Optimality of EDF and LST

 Case 1: When preemption is not allowed    

J i

=(

r i

,

d i

,

e i

)

J

1 =(0, 10, 3)

J

2 =(2, 14, 6)

J

3 =(4, 12, 4) 0 0

J

1 2

J

1 2 4 4

J

2 6

J

3 6 8 10

J

3 12 10

J

2 12 8 No NP priority-driven alg. is optimal when jobs have arbitrary

ri

,

di

,

ei

 P1 Case 2: On more than one processor   

J

1 =(0, 4, 1)

J

2 =(0, 4, 1)

J

3 =(0, 5, 5) P1 P2 0 0

J

1

J

2

J

1

J

2 0 2 2 2

J

3 4 4 6 6 P2

J

3 0 2 M. Kargahi (University of Tehran) 4 5 14 14

Anomaly with NP-Priority Sch.

 When jobs have arbitrary release times and share resources , scheduling anomalies can occur even with one processor and preemptable jobs  Whether a set of jobs has predictable execution behavior depends not only on the parameters of jobs but also on the algorithm used to schedule the jobs M. Kargahi (University of Tehran)

Offline vs. Online Scheduling

  Offline scheduling  Inflexibility  Deterministic timing behavior for a deterministic system   Online scheduling  The parameters of each job are known only after the job is released  Complexity is not important Low run-time overhead The only option for unpredictable workloads   Flexibility and adaptability Reduced ability for best using of resources M. Kargahi (University of Tehran)

Example for an online scheduler

  Assume a

non-preemptive

job

J

1 ,1 (0, 2] Two options 1.

Start executing

J

1 at time 0 2.

Postpone the execution of

J

1 to some later time

x

 1   Selecting option 1: Selecting option 2: we may have we may have  A clairvoyant scheduler is required

J

2 ,1-

x

(

x

<1, 1]  miss

J

2

J

3 ,1 (

x

<1, 2]  miss

J

3 

No optimal online scheduling algorithm exists when some jobs are non-preemptable

 When all jobs are preemptable and there is only 1 processor we have optimal online algorithms such as EDF and LST M. Kargahi (University of Tehran)

Overloaded systems

    A system is overloaded when the jobs offered to the scheduler cannot be feasibly scheduled even by a clairvoyant scheduler Some measures   Value of

J i

=

e i

if

J i

meets its deadline, or 0 otherwise V (schedule) = sum of the values of all jobs in the schedule 

Competitive factor

for an online algorithm =

c

iff V (schedule) of any finite sequence of jobs produced by the alg. is at least

c

times of V (schedule) produced by an optimal clairvoyant alg.

c

=1 for EDF and LST, when jobs are preemptable, there is one processor, and the processor is not overloaded

c

=0 for EDF and LST, when the processor is overloaded  Ex.: J 1 ,2  (0,  ] & J 2 ,e(  ,  +e]  V (EDF)=0, while V (Best)=e M. Kargahi (University of Tehran)