100% found this document useful (1 vote)
105 views34 pages

RT2021 Chap5

- Bratley's algorithm finds a feasible schedule for non-preemptive tasks on a uniprocessor. It starts with an empty schedule and represents all possible schedules in a tree structure. - It calculates the finishing time of each task by considering the finishing time of its predecessor task, its arrival time, and execution time. - It finds a path in the tree that represents a feasible schedule where no task misses its deadline.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
105 views34 pages

RT2021 Chap5

- Bratley's algorithm finds a feasible schedule for non-preemptive tasks on a uniprocessor. It starts with an empty schedule and represents all possible schedules in a tree structure. - It calculates the finishing time of each task by considering the finishing time of its predecessor task, its arrival time, and execution time. - It finds a path in the tree that represents a feasible schedule where no task misses its deadline.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Real-time Systems

Week 5:
Aperiodic real time scheduling

Ngo Lam Trung


Dept. of Computer Engineering

NLT, SoICT, 2021


Contents
❑ Notation of scheduling algorithms
❑ Aperiodic scheduling algorithms
Jackson's algorithm
Horn's algorithm
Bratley's algorithm

❑ Scheduling with precedence constraints

NLT, SoICT, 2021


Notation of scheduling algorithms
❑ A scheduling algorithm involves in a scheduling problem
with
A class of task set,
An optimality criterion, and
A machine environment.

❑ Systematic notation of scheduling algorithms:


 | | 
: machine environment
- Uniprocessor, multiprocessor, distributed architecture etc
: tasks & resource characteristics
- preemptive, independent, precedence constrained,
synchronous activations …
: optimality criterion
NLT, SoICT, 2021
Notation of scheduling algorithms
❑ Examples
1|prec|Lmax
- Minimizes the maximum lateness of a task set with
precedence constraints on a uniprocessor machine.
3|no_preem| fi
- Minimizes the sum of finishing times of a non-preemptive
task set on a 3 processor machine.
2|sync|Latei
- Minimizes the number of late tasks of a task set with
synchronous arrival times on a 2 processor machine.

NLT, SoICT, 2021


Jackson's algorithm (1|sync|Lmax)
❑A uniprocessor scheduling algorithm of a task
set with synchronous arrival times
All tasks have the same arrival time

❑ Forsynchronous arrival times, the scheduling


problem only considers execution times &
deadlines
Task set notation:

NLT, SoICT, 2021


Jackson's rule
❑ Theorem 3.1 (Jackson's rule)
Given a set of n independent tasks (i.e. no resource &
precedence constraints), any algorithm that executes
the tasks in order of non-decreasing deadline is optimal
with respect to minimizing the maximum lateness.
Earliest Due Date (EDD)

NLT, SoICT, 2021


Examples
❑ Example 1

J1 J2 J3 J4 J5
Ci 1 1 1 3 2
di 3 10 7 8 5

d1 d5 d3 d4 d2

J1 J5 J3 J4 J2

0 1 2 3 4 5 6 7 8 9 10 t

a feasible schedule produced by Jackson’s algorithm

NLT, SoICT, 2021


Examples
❑ Example 2

J1 J2 J3 J4 J5
Ci 1 2 1 4 2
di 2 5 4 8 6

d1 d3 d2 d5 d4

J1 J3 J2 J5 J4

0 1 2 3 4 5 6 7 8 9 10 t

an infeasible schedule produced by Jackson’s algorithm

NLT, SoICT, 2021


Proof: Jackson’s
❑ Jackson’s theorem can be proved by a simple
interchange argument.
❑ Let σ be a schedule produced by algorithm A.
❑ ifA is different than EDD, then there exist 2 tasks
Ja and Jb with da < db such that Jb immediately
precedes Ja in σ
❑ Let σ’ be a schedule obtained from σ by
interchanging Ja and Jb, so that Ja immediately
precedes Jb in σ’
❑ We’ll show 𝐿𝑚𝑎𝑥 𝑎𝑏 > 𝐿′𝑚𝑎𝑥(𝑎𝑏)

NLT, SoICT, 2021


Proof: Jackson’s theorem

σ Jb Ja

σ’ Ja Jb

a0 fb fa ’ fb ’ = fa da db t

NLT, SoICT, 2021


Guarantee
❑ Guarantee test:
All tasks can complete before their deadlines
The worst-case finishing time fi is less than or equal to its
deadline di

Suppose a set of task J1, J2, J3 … Jn is listed by increasingly


deadline, thus in the worst-case finishing time fi

If d1<d2<…<dn, the feasibility condition under EDD is


given by checking n conditions

NLT, SoICT, 2021


❑ What if the task set is not synchronous?

→ Horn's algorithm (1|preem|Lmax)

NLT, SoICT, 2021


Horn's theorem
❑ Theorem 3.2
Given a set of n independent tasks with
arbitrary arrival times, any algorithm that at
any instant executes the task with the earliest
absolute deadline among all the ready tasks
is optimal with respect to minimizing the
maximum lateness.

Earliest deadline first (EDF)

Time complexity of EDF: O(n2)


NLT, SoICT, 2021
Example

J1 J2 J3 J4 J5
ai 0 0 2 3 6
Ci 1 2 2 2 2
Di 2 5 4 10 9

J1

J2

J3

J4

J5
0 1 2 3 4 5 6 7 8 9 10 11 t

NLT, SoICT, 2021


EDF optimality
❑ : a schedule generated by algorithm A
❑ EDF: a schedule generated by EDF (not equal to )

❑ (t):
the task executing in the time slice [t,t+1) in 

❑ E(t):
the ready task with the earliest deadline at time t

❑ tE(t):
the time ( t) at which the next slice of task E(t) begins its
execution in the current schedule

NLT, SoICT, 2021


EDF optimality

J1 σ(t) = 4 , σ(tE) = 2

J2

J3

J4
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t
t=4 tE=6

J1 σ(t) = 4 , σ(tE) = 2

J2

J3

J4
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t
t=4 tE=6
NLT, SoICT, 2021
❑ Lmax = max(f2-d2, f4-d4)
❑ L’max = max(f’2-d2, f’4-d4)
❑ d2<d4
❑ f’2 < f2
❑ In the worst case when σ(t) are the time slice that each
task finishes
f2 = f’4

❑ f’2-d2 < f2-d2


❑ f’4-d4 = f2-d4 < f2-d2
❑ ➔ L’max < Lmax

NLT, SoICT, 2021


Guarantee
❑ Guaranteetest has to be done dynamically,
whenever a new task enters the system.
❑ Given new task Jnew arrives at t.
❑ The new task set (including Jnew) is listed with
increasing deadline
❑ Guarantee test:
The worst-case finishing time fi is less than or equal
to its deadline di
Ci(t): remaining worst-case execution time of task Ji at
time t

NLT, SoICT, 2021


Non-preemptive scheduling
❑ Scheduling problem of finding a feasible schedule of
non-preemptive tasks
NP-hard

❑ When arrival times are known a priori, the scheduling


problems are treated by branch-and-bound algorithms.
Bratley's algorithm
Spring kernel

NLT, SoICT, 2021


Bratley's algorithm (1|no_preem|feasible)
❑ Finds a feasible schedule of non-preemptive
tasks

❑ Start with empty schedule


❑ Present all possible schedules with a tree-
structure
❑ Calculate finishing time of each task considering
the finishing time of the predecessor, the arrival
time, & the execution time
❑ Finds a path of a feasible schedule
NLT, SoICT, 2021
Bratley's algorithm (1|no_preem|feasible)
J1 J2 J3 J4
J1‘misses J3's
deadline f1 Finishing
ai 4 time
1 1f3 0 (arrival time)
J1's a1+C1=4+2 = 6 f2+C3=2+2 = 4
C 2 f12>a32) 2 (execution time)
(because
Finishing time f1(because f2<a1) i
The order of a1+C1=4+2 = 6 di 7 5 6 4 (abs. deadline)
execution
6 2
2 Feasible
3
J1 J2 J3 J4 schedule

6 4 6
4 3
J1 J3 J4 J1 J2

6 5
J2 misses 6 6
deadline J1 J3
J1 J3
because
f1 = 6 > 5 = d 2
J1
NLT, SoICT, 2021
Bratley's algorithm (1|no_preem|feasible)

J1 J2 J3 J4
❑ Found a feasible schedule: ai 4 1 1 0
J4→J2→J3→J1
Ci 2 1 2 2
di 7 5 6 4

J1

J2

J3

J4

0 1 2 3 4 5 6 7

NLT, SoICT, 2021


Scheduling with precedence constraints
❑ NP-hard problem
❑ Applying assumptions
Synchronous activation: LDF algorithm
Pre-emptive tasks set: EDF with precedence constraints

NLT, SoICT, 2021


Latest Deadline First (LDF) (1|prec, sync|Lmax)
❑ Given a task set J and a directed acyclic graph
representing its precedence constraints
❑ Scheduling algorithm

• Select the subtask J’ of J with no


successor
• In J’, select the task j with the
latest deadline
• Put j into a LIFO queue
• Repeat until all tasks are put into
the LIFO queue Tasks with no successor
• The tasks in the queue will be
pop out for execution scheduling

LIFO execution

NLT, SoICT, 2021


Example

➔ LDF achieves
smaller Lmax
➔ EDF is not
optimal under
precedence
constraints

NLT, SoICT, 2021


LDF optimality
❑ Let J be the complete set of tasks to be scheduled
❑ Γ ∈ 𝐽 be the subset of tasks without successors
❑ Ji be the task in Γ with the latest deadline di.
❑ Jk be the last scheduled task
❑ If the schedule 𝜎 does not follow the LDF rule then
dk < d i
❑ Partition Γ into four subsets
Γ = 𝐴 ∪ 𝐽𝑖 ∪ 𝐵 ∪ {𝐽𝑘}
❑ We’ll show moving 𝐽𝑖 to the end of the schedule will not
increase 𝐿𝑚𝑎𝑥, thus show LDF’s optimality

NLT, SoICT, 2021


LDF optimality
❑ Partition Γ with original schedule 𝜎
Γ = 𝐴 ∪ 𝐽𝑖 ∪ 𝐵 ∪ 𝐽𝑘
𝐿𝑚𝑎𝑥(Γ) ≥ 𝑓 − 𝑑𝑘
❑ Schedule 𝜎 ∗ obtained by moving 𝐽𝑖 to the end of the
schedule
Γ = 𝐴 ∪ 𝐵 ∪ {𝐽𝑘} ∪ 𝐽𝑖

NLT, SoICT, 2021


LDF optimality

𝐿𝑚𝑎𝑥(Γ) ≥ 𝑓 − 𝑑𝑘


➔ 𝐿 𝑚𝑎𝑥 (Γ) ≤ 𝐿𝑚𝑎𝑥 (Γ)
NLT, SoICT, 2021
EDF with precedence constraints
❑ Scheduling problem: (1|prec, preem|Lmax)
❑ Difficulty: EDF is not optimal with precedence constraints
❑ Provided task 𝐽𝑎, 𝐽𝑏 ∈ 𝐽 that 𝐽𝑎 → 𝐽𝑏(immediate
predecessor)
➔Starting time of Jb and deadline of Ja will be modified to
replace precedence constraint

Modifying
timing Scheduling
constraints with EDF
J J’ 𝜎

NLT, SoICT, 2021


Modifying timing constraints
❑ Starting time

➔ Modifying release time of Jb

NLT, SoICT, 2021


Modifying timing constraints
❑ Deadline

➔ Modifying deadline of Ja

NLT, SoICT, 2021


Proof of optimality

❑ New timing constraints preserve precedence constraints


and original deadline constraints
➔ Schedulability of task set is preserved
NLT, SoICT, 2021
Example
❑ Given seven tasks A, B, C, D, E, F, G with precedence
relations

All tasks arrive at time t = 0, have deadline D = 20, and


computation time 2, 3, 3, 5, 1, 2, 5, respectively.
Modify their arrival times and deadlines to schedule them
by EDF.

NLT, SoICT, 2021


Summary

NLT, SoICT, 2021

You might also like