Liu Chapter 3456
Liu Chapter 3456
1
Temporal Parameters
Relative deadline, Di
Ji
Time axis
Release time ri ei Absolute
deadline, di
Temporal Parameters
Relative deadline, Di
Ji Ji Ji
A B C
Time axis
Release time ri Absolute
ei,A ei,B ei,C deadline, di
– For a preemptible job, the execution time may be broken down into
more than one interval
• ei,A + ei,B + ei,C = ei
2
Temporal Parameters
0 10 20 30 40
Relative deadline of this task = 8
Absolute deadline of ith job in this task = 10 i
Temporal Parameters
• Example
– p1 = 3, p2 = 4, p3 = 10, then H = 60
– e1 = 1, e2 = 1, e3 = 3, then
• u1 = e1 / p1 = 0.33
• u2 = 0.25
• u3 = 0.3
– Total utilization
• {60/3 1 + 60/4 1 + 60/10 3}/60 = 53/60 = 0.88
0 10 20 30 40 50 60
H = 60
3
Aperiodic and Sporadic Tasks
Signal Tracker
processor
Track
data
4
Precedence Relation
• Ji Jj Ji precedes Jj
– Partial order relation
• Precedence graph, G = (J, )
(0,7] (2,9] (4,11] (6,13] (8,15]
Periodic independent
(2,5] (5,8] (8,11] (11,14] (14,17]
Periodic dependent
(0,5] (4,8] (5,20]
(0,6] J
(2,10]
2/3 1/2
• Preemptivity
– Non-preemptable For example, data frame in token ring
• Tied to a particular resource
• Job may still be preemptable on other resources
– Cost of preemption Context switch time
• Criticalness
– Associate weight with jobs to indicate criticalness w.r.t other jobs
• For example, flight controller > navigation > fuel minimizer
5
Scheduler Performance
• Feasible schedule
– i, Ji starts at or after its release time and completes by its deadline
• Optimal algorithm
– Always produces a feasible schedule if such a schedule exists
• Performance measures
– Number of tardy jobs
Tardiness/lateness
= tci - di
Scheduler Performance
• Feasible schedule
– i, Ji starts at or after its release time and completes by its deadline
• Optimal algorithm
– Always produces a feasible schedule if such a schedule exists
• Performance measures
– Number of tardy jobs
• Maximum or average tardiness max(0,tci - di)
• Maximum or average absolute lateness tci - di
• Maximum or average response time tci - ri
• Makespan: i,j, ri = rj; makespan = max(tci - ri)
6
Overview of Real-Time Scheduling
(Chapter 4 of Book by J. Liu)
• Two main kinds of scheduling algorithms
1
Clock-Driven Scheduler
A B C D C A C
Frame 1 Frame 2 Frame 3
t1 t2 t3 t4
• Assumptions
– All the parameters of hard real-time jobs are fixed and known
– Schedule is computed off-line and stored for use at run-time
• “Table-driven” scheduler
Priority-Driven Scheduler
• Examples
– FIFO (First-In-First-Out), LIFO (Last-In-First-Out), SETF
(Shortest-Execution-Time-First), LETF (Longest-Execution-Time-
First)
• Priority-driven schedulers never leave the processor idle
when there is work to be done
– “Work conserving” schedulers
• Preemptive priority-driven scheduling
– Decisions are made when a job becomes ready, a processor
becomes idle, priorities of jobs change
• Choose a ready task with the highest priority
• Non-preemptive priority-driven scheduling
– Decisions are made only when the processor becomes idle
2
Priority-Driven Schedules
J1 , 3
J3 , 2
J2 , 1 J4 , 2
J5 , 2 J6 , 4
J7 , 4 J8 , 1
P1 J1 J4 J7 J6
Preemptive
P2 J2 J3 J7 J5 J8
J5
J1 , J2 , J3 , J4 ,
J6 , J7 , J8
Time
5 10
Priority-Driven Schedules
J1 , 3
J3 , 2
J2 , 1 J4 , 2
J5 , 2 J6 , 4
J7 , 4 J8 , 1
P1 J1 J4 J5 J6
Non-
preemptive P2 J2 J3 J7 J8
J5
J1 , J2 , J3 , J4 ,
J6 , J7 , J8
Time
5 10
3
Priority-Driven Schedules
J2 , 2 J3 , 1
J1 , 1 J4 , 1
J5 , 3
J8 , 3 J7 , 1
J6 , 2
P1 J1 J2 J3 J6 J4
SETF Non-
preemptive P2 J5 J8 J7
P1 J5 J1 J2 J6 J4
LETF Non-
preemptive P
2 J8 J3 J7
J1 J2 J6 J7
SETF Non- Choose J
preemptive P2 J8 J5 J3 J4 Time instead of8 J at
5
5 10 the beginning
J1 (2,10)
(2,8)
J2 (0,7)
(0,7) J5 (1,8) J7 (6,21)
(2,8) (6,21)
4
Effective Release Times & Effective Deadlines
5
Earliest-Deadline-First (EDF) Algorithm
• Proof of theorem:
– Show that any feasible schedule of J can be systematically
transformed into an EDF schedule
• Consider the following feasible schedule
I1 I2
Idle
Ji Jk
rk dk di
• Case 1: rk is after I1
– Jk cannot be scheduled in I1
– The two jobs are already scheduled on the EDF basis in these intervals
• Proof of theorem:
– Show that any feasible schedule of J can be systematically
transformed into an EDF schedule
• Consider the following feasible schedule
I1 I2
Idle
Ji Jk
rk dk di
Jk Jk Ji
• Case 2: rk is before I1
– Adjust existing feasible schedule by swapping Ji with corresponding
portion of Jk
» New schedule is still a feasible schedule
6
Earliest-Deadline-First (EDF) Algorithm
• Proof of theorem:
– Show that any feasible schedule of J can be systematically
transformed into an EDF schedule
• Consider the following feasible schedule
I1 I2
Idle
Ji Jk
rk dk di
Jk Jk Ji
• Proof of theorem:
– Show that any feasible schedule of J can be systematically
transformed into an EDF schedule
• Consider the following feasible schedule
I1 I2
Idle
Ji Jk
rk dk di
Jk Jk Ji
EDF
Schedule Jk Jk Ji
7
Latest-Release-Time (LRT) Algorithm
J1 J3 J2
0 1 2 3 4 5 6 7 8 9 10
J1 , 3 (0,6) J2 , 2 (5,8)
J1 J1 J3 J2
0 1 2 3 4 5 6 7 8 9 10
8
EDF/LST are not Always Optimal
• Non-preemptable jobs
J3 misses its
• EDF schedule: Not possible deadline at t = 12
J1 J2 J3
0 5 10 15
• Feasible schedule
J1 J3 J2
0 5 10 15
0 1 2 3 4 5 6
• Feasible schedule:
J3
J1 J2
0 1 2 3 4 5 6
9
Problem with Priority-Driven Schedulers
J2 , [2,6] (0,10) 15
10
Time
J3 , 8 (4,15)
5
J4 , 10 (0,20)
e2
0 1 2 3 4 5 6
• EDF for e2 = 6:
P1 J1 J3
P2 J2 J4
0 5 10 15 20
10
Problem with Priority-Driven Schedulers
Completion
J2 , [2,6] (0,10) 15
10
Time
J3 , 8 (4,15)
5
J4 , 10 (0,20)
e2
0 1 2 3 4 5 6
• EDF for e2 = 2: Rule is that task cannot be shifted to another processor
P1 J1
P2 J2 J4 J3 J4
0 5 10 15 20
J2 , [2,6] (0,10) 15
10
Time
J3 , 8 (4,15)
5
J4 , 10 (0,20)
e2
0 1 2 3 4 5 6
• EDF for e2 = 3: J4 misses its deadline!
P1 J1
P2 J2 J4 J3 J4
0 5 10 15 20
11
Problem with Priority-Driven Schedulers
Completion
J2 , [2,6] (0,10) 15
10
Time
J3 , 8 (4,15)
5
J4 , 10 (0,20)
e2
0 1 2 3 4 5 6
• EDF for e2 = 4:
P1 J1 J4
P2 J2 J3
0 5 10 15 20
J2 , [2,6] (0,10) 15
10
Time
J3 , 8 (4,15)
5
J4 , 10 (0,20)
e2
0 1 2 3 4 5 6
• EDF for e2 = 5:
P1 J1 J4
P2 J2 J3
0 5 10 15 20
12
Clock-Driven Scheduling
(Chapter 5 of the Book by J. Liu)
• Notations
– n periodic tasks T1 , …, Tn
• Ti : Each job is released pi units of time after the previous job in Ti
– (i , pi , ei , Di) di,1 di,1 di,1
Time tk 1 J3,1
2 J2,1
3.8 I
4 J1,2
19.8 J1,1
1
Static Timer-Driven Scheduler
• Input
– Table of (tk , T(tk)), 0 k N-1
– Scheduler
i = 0; k = 0;
setTimer(t0); sleep;
on interrupt
if (executing aperiodic job) preempt the job;
J = T(tk); i = i+1; k = i mod N;
setTimer(tk + i/N * H);
if (J == I) wakeup(aperiodic)
else wakeup(J);
sleep();
• Example
– T1 = (4,1), T2 = (5,1.8), T3 = (20,1), T4 = (20,2)
Execution
Period time
• Default phase = 0
• Default relative deadline
= period
– Hyperperiod = ?
2
Static Timer-Driven Scheduler
• Example
– T1 = (4,1), T2 = (5,1.8), T3 = (20,1), T4 = (20,2)
– Hyperperiod H = 20
Use for aperiodic and sporadic jobs
J1,2
J1,3
J1,4
J1,5
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Cyclic Schedule
t t+f t + 2f t + 3f t + 4f t+H
Invoked as procedure calls
3
Frame Constraints
• 1) f max(ei)
– f should be sufficiently large so that every job can complete in a
single frame
t t+f t + 2f t + 3f t + 4f t+H
Frame Constraints
• 1) f max(ei)
– f should be sufficiently large so that every job can complete in a
single frame
• 2) f divides H
– Ti s.t. f divides pi
• 3) f must be sufficiently small so that between the release
time and deadline of every job, there is at least one frame
t t+f t + 2f t + 3f t + 4f t+H
4
Frame Constraints
• 1) f max(ei)
• 2) f divides H, i.e., Ti s.t. f divides pi
• 3) f must be sufficiently small so that between the release
time and deadline of every job, there is at least one frame
– If t > t, we must have: • In [t,t+H), first job of Ti starts at a
• t + 2f t + Di , 2f - (t - t) Di frame boundary
• t - t gcd(pi , f), 2f - gcd(pi , f) D•i If gcd(f,pi) = a, jobs of Ti start at
m*b*a where pi = b*a and frames
start at k*c*a where f = c*a
Why?
• t - t = (m*b - k*c)*a
• If t > t, then min (t - t) = a
t t + Di t + pi
t t+f t + 2f t + 3f t + 4f t+H
Frame Constraints
• 1) f max(ei)
• 2) f divides H, i.e., Ti s.t. f divides pi
• 3) f must be sufficiently small so that between the release
time and deadline of every job, there is at least one frame
– If t > t, we must have: Since max(gcd(pi,f) f,
• t + 2f t + Di , 2f - (t - t) Di both conditions
• t - t gcd(pi , f), 2f - gcd(pi , f) Di are captured by::
– If t = t, we must have f Di
• 2f - gcd(pi , f) Di
t t + Di t + pi
t t+f t + 2f t + 3f t + 4f t+H
5
Frame Constraints
• Example:
– T1 = (4,1), T2 = (5,1.8), T3 = (20,1), T4 = (20,2), f = ?
• 1) f max(ei)
– f max(1, 1.8, 1, 2)
– I.e., f 2
• 2) f divides H, i.e., Ti s.t. f divides pi
– f divides either 4, 5, or 20
– I.e., f {1,2,4,5,10,20}
– Combining with condition (1), f {2,4,5,10,20}
• 3) 2f - gcd(pi , f) Di
– 2f - gcd(4,f) 4 f {2,4}
– 2f - gcd(5,f) 5 f {2}
– 2f - gcd(20,f) 20 f {2,4,5,10,20}
• f=2
Frame Constraints
• Example:
– T1 = (4,1), T2 = (5,1.8), T3 = (20,1), T4 = (20,2), f = ?
– Frame size f = 2
– Note that no job crosses a frame boundary
J1,2
J1,3
J1,4
J1,5
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
6
Frame Constraints
• Example:
– T1 = (15,1,14), T2 = (20,2,26), T3 = (22,3), f = ?
• 1) f max(ei)
– f max(1,2,3)
– I.e., f 3
• 2) f divides H, i.e., Ti s.t. f divides pi
– f divides 15 or 20 or 22
– I.e., f {1,2,3,4,5,10,11,15,20,22}
– Combining with (1), f {3,4,5,10,11,15,20,22}
• 3) 2f - gcd(pi , f) Di
– 2f - gcd(15,f) 14 f {3,4,5}
– 2f -gcd(20,f) 26 f {3,4,5,10,11,15,20,22}
– 2f - gcd(22,f) 22 f {3,4,5,11,10,22}
• f {3,4,5}
Frame Constraints
7
Frame Constraints
Frame Constraints
J3c,1
J1,2
J1,3
J1,4
J1,5
8
Cyclic Executive
Slack Stealing
“Slack Stealing”
9
Slack Stealing
A3
Slack-Stealing
Schedule
Original
Schedule
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
10
Scheduling Sporadic Jobs
• Example
– S1(17,4.5) is released at time 3
• Slack in frames 2 to 4, c(2,4) = 4, Reject S1
– S2(29,4) is released at time 5
• Slack in frames 3 to 7, c(3,7) = 5.5 & no other job, Accept S2
– S3(22,1.5) is released at time 11
• Slack in frames 4 to 5, c(4,5) = 2 & 2 = 1.5, Accept S3. Now, 2 = 0
e2 - 2 e3 - 3
– S4(44,5.0) is released at time 14
• Slack in frames 5 to 11, c(5,11) = 7-2-0.5 = 4.5, Reject S4
0 4 78 10 12 15 16 20 24 27 28 30 32 35 36 39 40 44 47 48 50 52
S1(17,4.5) 3.5 23.5 43.5
S2(29,4)
S3(22,1.5)
S4(44,5)
11
Scheduling Sporadic Jobs
0 4 78 10 12 15 16 20 24 27 28 30 32 35 36 39 40 44 47 48 50 52
S1(17,4.5) 3.5 23.5 43.5
S2(29,4.5)
S3(22,1.5)
S4(44,5)
Control
12
Practical Considerations
• Frame overruns
– E.g., due to hardware or software faults
– Abort the job?
• Useful for applications where late results are useless
– Application must be able to handle or recover from this
• Problem in some applications
– Aborting the job can cause inconsistent system state
– Preempt the job as soon as it exits its critical section (if any)
– Schedule as an aperiodic job
– Another option
• Let the job complete
• Do this only if
– Result will still be useful
– It is ok for periodic jobs to be occasionally late
Practical Considerations
• Mode changes
– System is reconfigured
• Set of tasks is replaced by a new set of tasks
– Need to bring new scheduling table + code of the new tasks into
the memory
• Implement as a “mode change job”
13
Practical Considerations
• Mode changes
– System is reconfigured
• Set of tasks is replaced by a new set of tasks
– Need to bring new scheduling table + code of the new tasks into
the memory
• Implement as a “mode change job”
– For example, consider a car navigation system in “cruising mode”
Practical Considerations
14
Constructing Static Schedules
Sink
• Edge (j , sink) Source (f), ek
z
– Capacity of the edge is f
(ek), ek (f), 0
• If a job is scheduled across multiple (f), 0
frames, then we must slice it into Jk
corresponding subjobs F (f), 0
• Example
– T1 = (4,1), T2 = (5,2,7), T3 = (20,5)
• Possible frame sizes 2 or 4 (ignore f max(ei) constraint)
• Hyperperiod = 20 5 jobs of T1 , 4 jobs of T2 , and 1 job of T3
– f = 4 F = 5, i.e., there are 5 frames
(1), 1 (4), 1
(2), 2 (4), 2
(5), 5 (4), 4 (4), 1
(4), 4 (4), 3
(4), 3
(4), 3
(4), 4
•Task T3 has to be
split into 3 subtasks
15
Constructing Static Schedules
• Non-independent tasks
– Precedence constraints
• “Ji precedes Jk”
• Make Ji’s release at or before Kk’s release
• And Ji’s deadline at or before Jk’s deadline
• If the slices of Ji and Jk are scheduled in the wrong order, then just
swap them
– Critical sections / nonpreemptable jobs
• NP-hard even on one processor
16
Chapter 6 (Book by Liu)
Priority-Driven Scheduling of Periodic Tasks
• Assumptions
– Tasks are independent
– No aperiodic or sporadic tasks
• Static assumption
– Ensures that uniprocessor algorithm can be used for multiprocessor
systems
P1
P2
Set of tasks Pk
Static allocation of tasks
among processors Set of processors
• Why not have a common task queue for all the processors?
– In the worst case, the performance of dynamic multiprocessor
scheduling can be poor
Use EDF: Jm+1,1 has the lowest priority
– Example (because it has the longest deadline)
• Ti = (1, 2) for 1 ≤ i ≤ m
• Tm+1 = (1 + , 1) Jm+1,1 misses its deadline!
Jm,1 Jm-1,2
Pm 2 1
Set of processors
1
Priority-Driven Scheduling of Periodic Tasks
• Why not have a common task queue for all the processors?
– In the worst case, the performance of dynamic multiprocessor
scheduling can be poor
– Example
• Ti = (1, 2) for 1 ≤ i ≤ m
• Tm+1 = (1 + , 1) However, there is a static schedule
assuming m 2 < 1
• Problem 1
– We do not know how to determine the worst-case and best-case
performance of dynamic systems
– Hence, most current hard real-time systems are static
T3 T3 T3 T3
T2 T2
T2 A T2 B C T2 D T2
T1 T1 T1 T1 A T1 B T1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
– T2 runs in background of T1
– T3 runs in background of T1 and T2
2
Priority-Driven Scheduling of Periodic Tasks
T1 T1
T1 T1 T1
T3 A B T3 T3
T2 T2 T2 T2 T2
3
Priority-Driven Scheduling of Periodic Tasks
Schedulable utilization
J1,1 J2,1 J1,2 J2,1 J2,1 J1,3 J2,2 J1,4 J2,2 J2,2
J1,4
0 1 2 3 4 5 6 7 8 9 10
1.2 + 2.2 = 3.4 < 3.5
4
Schedulable utilization
5
Schedulable Utilization of the EDF Algorithm
0 1 2 3 4 5 6 7 8 9 10
0.6 2.6 3.3 4.6 6.6 7.9 8.6
• Example
– Digital robot controller
• Control law: e = 8 ms, every 10 ms
– U = 0.8 feasible
• Add “Built-In Self-Test” task: emax = 50 ms, p = as short as possible
but ≤ 1000 ms
– U = 0.8 + 50/x = 1, x = 250 ms
• Add telemetry: e = 15 ms, p = large, but d = small
– Reduce self-test to once per 1000 ms
– U = 0.8 + 50/1000 + 15/y = 1
– y = 100 ms = min(d, p)
Large
d = 100 ms
6
Optimality of RM and DM
0 1 2 3 4 J2,1
5 6 7 8 9 10
C
Optimality of RM and DM
• Simply Periodic Tasks
– Definition: A system of periodic tasks is simply periodic if for every pair
of tasks Ti and Tk in the system where pi < pk, pk is an integer multiple of
pi .
• Theorem 6.3
– A system of simply periodic, independent, preemptable tasks whose
relative deadlines are equal to or larger than their periods is schedulable
on one processor according to the RM algorithm iff its total utilization ≤ 1.
• Theorem 6.4
– A system T of independent, preemptable periodic tasks that are in phase
and have relative deadlines equal to or less than their respective periods
can be feasibly scheduled on one processor according to the DM
algorithm whenever it can be feasibly scheduled according to any fixed-
priority algorithm.
• Corollary:
– The RM algorithm is optimal among all fixed-priority algorithms
whenever the relative deadlines of all tasks are proportional to their
periods.
7
Schedulability Test for Fixed-Priority Tasks with
Short Response Times
• Critical Instants
– A critical instant of a task Ti is a time instant which is such that
• (1) The job in Ti released at the instant has the maximum response
time of all jobs in Ti, if the response time of every job in Ti is equal to
or less than the relative deadline Di of Ti, and
• (2) The response time of the job released at the instant is greater than
Di if the response time of some jobs in Ti exceeds Di.
– The response time of a job in Ti released at a critical instant is the
maximum (possible) response time
• Denote this by Wi.
• Theorem 6.5
– In a fixed-priority system where every job completes before the
next job in the same task is released, a critical instant of any task Ti
occurs when one of its job Ji,c is released at the same time as a job
in every higher-priority task, i.e., ri,c = rk,lk for some lk for every k
= 1, , i-1.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
8
Schedulability Test for Fixed-Priority Tasks with
Short Response Times
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
9
Practical Factors
• Definitions
– A (ready) job Ji is blocked when it is prevented from executing by
a lower-priority job. The lower priority job executes while Ji
waits.
– A priority inversion occurs whenever a lower-priority job
executes while some higher-priority job waits
• Practical factors
– Nonpreemptability
– Self-suspension
– Context switches
– Limited priority levels
– Tick scheduling
– Varying priority in fixed-priority systems
Nonpremptability
0 1 2 3 4 5 6 7 8 9 10
10
Self-Suspension
Ji,l
Jk,j Jk,j+1
Context Switches
11
Limited Priority Levels
1 = 5 2 = 13 3 = 16 4 = 17 5 = 27 6 = 30
5 13 16 25 27 30
12
Limited Priority Levels
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
1 = 5 2 = 10 3 = 15 4 = 20 5 = 25 6 = 30
5 10 15 20 25 30
1 = 1 2 = 3 3 = 6 4 = 10 5 = 17 6 = 30
1 3 6 10 17 30
13
Limited Priority Levels
14