RTES Lecture05

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Priority-driven Scheduling of

Periodic Tasks (1)

Real-Time and Embedded Systems (M)


Lecture 5
Lecture Outline

• Assumptions
• Fixed-priority algorithms
– Rate monotonic
– Deadline monotonic
• Dynamic-priority algorithms
– Earliest deadline first
– Least slack time
• Relative merits of fixed- and dynamic-priority scheduling
• Schedulable utilization and proof of schedulability
Copyright © 2006 University of Glasgow

Material in lectures 5 & 6 corresponds to chapter 6 of Liu’s book


All rights reserved.
Assumptions

• Priority-driven scheduling of periodic tasks on a single processor


• Assume a restricted periodic task model:
– A fixed number of independent periodic tasks exist
• Jobs comprising those tasks:
– Are ready for execution as soon as they are released
– Can be pre-empted at any time
– Never suspend themselves
• New tasks only admitted after an acceptance test; may be rejected
• The period of a task defined as minimum inter-release time of jobs in task
– There are no aperiodic or sporadic tasks
– Scheduling decisions made immediately upon job release and completion
• Algorithms are event driven, not clock driven
• Never intentionally leave a resource idle
Copyright © 2006 University of Glasgow

– Context switch overhead negligibly small; unlimited priority levels


All rights reserved.
Dynamic versus Static Systems

• Recall from lecture 3:


– If jobs are scheduled on multiple processors, and a job can be dispatched to
any of the processors, the system is dynamic
– If jobs are partitioned into subsystems, each subsystem bound statically to
a processor, we have a static system
– Difficult to determine the best- and worst-case performance of dynamic
systems, so most hard real-time systems built are static
• In static systems, the scheduler for each processor schedules the
jobs in its subsystem independent of the schedulers for the other
processors

⇒ Results demonstrated for priority-driven uniprocessor systems are


Copyright © 2006 University of Glasgow

applicable to each subsystem of a static multiprocessor system


– They are not applicable to dynamic multiprocessor systems
All rights reserved.
Fixed- and Dynamic-Priority Algorithms

• A priority-driven scheduler is an on-line scheduler


– It does not pre-compute a schedule of tasks/jobs: instead assigns priorities
to jobs when released, places them on a run queue in priority order
– When pre-emption is allowed, a scheduling decision is made whenever a
job is released or completed
– At each scheduling decision time, the scheduler updates the run queues and
executes the job at the head of the queue

• Jobs in a task may be assigned the same priority (task level fixed-
priority) or different priorities (task level dynamic-priority)
• The priority of each job is usually fixed (job level fixed-priority);
but some systems can vary the priority of a job after it has started
Copyright © 2006 University of Glasgow

(job level dynamic-priority)


– Job level dynamic-priority usually very inefficient
All rights reserved.
Rate Monotonic Scheduling
• Best known fixed-priority algorithm is rate monotonic scheduling
• Assigns priorities to tasks based on their periods
– The shorter the period, the higher the priority
– The rate (of job releases) is the inverse of the period, so jobs with higher
rate have higher priority
• Very widely studied and used

• For example, consider a system of 3 tasks:


– T1 = (4, 1) ⇒ rate = 1/4
– T2 = (5, 2) ⇒ rate = 1/5
– T3 = (20, 5) ⇒ rate = 1/20
Copyright © 2006 University of Glasgow

– Relative priorities: T1 > T2 > T3


All rights reserved.
Example: Rate Monotonic Scheduling
Time Ready to run Running Time Ready to run Running
0 10
1 11
2 12
3 13
4 14
5 15
6 16
7 17
8 18
9 19

J1,1 J1,2 J1,3 J1,4 J1,5


Released

T1 = (4, 1)
J2,1 J2,2 J2,3 J2,4
T2 = (5, 2)
Copyright © 2006 University of Glasgow

J3,1
T3 = (20, 5)
All rights reserved.

0 4 8 12 16 20
Deadline Monotonic Scheduling

• The deadline monotonic algorithm assigns task priority according


to relative deadlines – the shorter the relative deadline, the higher
the priority
• When relative deadline of every task matches its period, then rate
monotonic and deadline monotonic give identical results
• When the relative deadlines are arbitrary:
– Deadline monotonic can sometimes produce a feasible schedule in cases
where rate monotonic cannot
– But, rate monotonic always fails when deadline monotonic fails

• Deadline monotonic preferred to rate monotonic


Copyright © 2006 University of Glasgow

– If deadline ≠ period
All rights reserved.
Dynamic-Priority Algorithms

• Discussed several dynamic-priority algorithms in lecture 3:


– Earliest deadline first (EDF)
• The job queue is ordered by earliest deadline
– Least slack time first (LST)
• The job queue is ordered by least slack time
• Two variations:
– Strict LST – scheduling decisions are made also whenever a queued job’s slack
time becomes smaller than the executing job’s slack time – huge overheads, not
used
– Non-strict LST – scheduling decisions made only when jobs release or complete
– First in, first out (FIFO)
• Job queue is first-in-first-out by release time
– Last in, first out (LIFO)
• Job queue is last-in-first-out by release time
Copyright © 2006 University of Glasgow

• Focus on EDF as commonly used example


All rights reserved.
Example: Earliest Deadline First
Time Ready to run Running Time Ready to run Running

J1,1 J1,2 J1,3 J1,4 J1,5 J1,6


Released

T1 = (2, 1)
J2,1 J2,2 J2,3
T2 = (5, 2.5)
Copyright © 2006 University of Glasgow
All rights reserved.

0 1 2 3 4 5 6 7 8 9 10
Relative Merits

• Fixed- and dynamic-priority scheduling algorithms have different


properties; neither appropriate for all scenarios

• Algorithms that do not take into account the urgencies of jobs in


priority assignment usually perform poorly
– E.g FIFO, LIFO
• The EDF algorithm gives higher priority to jobs that have missed
their deadlines than to jobs whose deadline is still in the future
– Not necessarily suited to systems where occasional overload unavoidable
• Dynamic algorithms like EDF can produce feasible schedules in
cases where RM and DM cannot
Copyright © 2006 University of Glasgow

– But fixed priority algorithms often more predictable, lower overhead


All rights reserved.
Example: Comparing Different Algorithms

• Compare performance of RM, EDF, LST and FIFO scheduling


• Assume a single processor system with 2 tasks:
– T1 = (2, 1)
– T2 = (5, 2.5) H = 10

• The total utilization is 1.0 ⇒ no slack time


– Expect some of these algorithms to lead to missed deadlines!
– This is one of the cases where EDF works better than RM/DM
Copyright © 2006 University of Glasgow
All rights reserved.
Example: RM, EDF, LST and FIFO
J1,1 J1,2 J1,3 J1,4 J1,5
Deadlines
J2,1 J2,2

FIFO J1,1 J2,1 J1,2 J1,3 J2,2 J1,4 J1,5

LST J1,1 J2,1 J1,2 J2,1 J1,3 J2,2 J1,4 J2,2 J1,5 J2,2

EDF J1,1 J2,1 J1,2 J2,1 J1,3 J2,2 J1,4 J2,2 J1,5 J2,2

RM J1,1 J2,1 J1,2 J2,1 J1,3 J2,1 J2,2 J1,4 J2,2 J1,5 J2,2

0 2 4 6 8 10
Copyright © 2006 University of Glasgow

• Demonstrate by exhaustive simulation that LST and EDF meet


deadlines, but FIFO and RM don’t
All rights reserved.
Schedulability Tests

• Simulating schedules is both tedious and error-prone… can we


demonstrate correctness without working through the schedule?

• Yes, in some cases. This is a schedulability test


– A test to demonstrate that all deadlines are met, when scheduled using a
particular algorithm
– An efficient schedulability test can be used as an on-line acceptance test;
clearly exhaustive simulation is too expensive
Copyright © 2006 University of Glasgow
All rights reserved.
Schedulable Utilization

• Recall: a periodic task Ti is defined by the 4-tuple (φi, pi, ei, Di)
with utilization ui = ei / pi
n
• Total utilization of the system U = " ui where 0 ≤ U ≤ 1
i=1

• A scheduling algorithm can feasibly schedule any system of


!
periodic tasks on a processor if U is equal to or less than the
maximum schedulable utilization of the algorithm, UALG
– If UALG = 1, the algorithm is optimal

• Why is knowing of UALG important? It gives a schedulability test,


Copyright © 2006 University of Glasgow

where a system can be validated by showing that U ≤ UALG


All rights reserved.
Schedulable Utilization: EDF

• Theorem: a system of independent preemptable periodic tasks


with Di = pi can be feasibly scheduled on one processor using
EDF if and only if U ≤ 1
– UEDF = 1 for independent, preemptable periodic tasks with Di = pi
[Expected since EDF proved optimal
in lecture 3 – see the book for proof]
– Corollary: result also holds if deadline longer than period: UEDF = 1 for
independent preemptable periodic tasks with Di ≥ pi

• Notes:
Copyright © 2006 University of Glasgow

– Result is independent of φi
– Result can also be shown to apply to strict LST
All rights reserved.
Schedulable Utilization: EDF

• What happens if Di < pi for some i? The test doesn’t work…


– E.g. T1 = (2, 0.8), T2=(5, 2.3, 3)
J2,1 is preempted and misses deadline

J1,1 J2,1 J1,2 J2,1 J1,3 J2,2 J1,4 J2,2

0 1 2 3 4 5 6 7

• However, there is an alternative test:


– The density of the task, Ti, is δi = ei / min(Di, pi)
– The density of the system is Δ = δ1 + δ2 + … + δn
– Theorem: A system T of independent, preemptable periodic tasks can be
feasibly scheduled on one processor using EDT if Δ ≤ 1.
• Note:
Copyright © 2006 University of Glasgow

– This is a sufficient condition, but not a necessary condition – i.e. a system


is guaranteed to be feasible if Δ ≤ 1, but might still be feasible if Δ > 1
All rights reserved.

(would have to run the exhaustive simulation to prove)


Schedulable Utilization: EDF

• How can you use this in practice?


– Assume using EDF to schedule multiple periodic tasks, known execution
time for all jobs
⇒ Choose the periods for the tasks such that the schedulability test is met

• Example: a simple digital controller:


– Control-law computation task, T1, takes e1 = 8 ms, sampling rate is 100 Hz
(i.e. p1 = 10 ms)
⇒ u1 is 0.8
⇒ the system is guaranteed to be schedulable
– Want to add a built-in self test task, T2, taking 50ms - will the system still
work?
Copyright © 2006 University of Glasgow
All rights reserved.
Schedulable Utilization of RM

• Theorem: a system of n independent preemptable periodic tasks


with Di = pi can be feasibly scheduled on one processor using RM
if and only if U ≤ n⋅(21/n – 1)
URM(n)

– URM(n) = n⋅(21/n – 1) 0.9


– For large n → ln 2
(i.e. n → 0.69314718056…) 0.8

– [Proof in book - complicated!] 0.7

0.6 n
2 4 6 8 10 12 14 16 18
Copyright © 2006 University of Glasgow

– U ≤ URM(n) is a sufficient, but not necessary, condition – i.e. a feasible rate


monotonic schedule is guaranteed to exist if U ≤ URM(n), but might still be
possible if U > URM(n)
All rights reserved.
Schedulable Utilization of RM

• What happens if the relative deadlines for tasks are not equal to
their respective periods?
• Assume the deadline is some multiple υ of the period: Dk = υ⋅pk
• It can be shown that:

0
2 " 0 4 " 4 0.5
2
22
1
U RM (n," ) = 1 n((2" ) n #1) + 1# " for 0.5 4 " 4 1
2
2 *$ " + 1' 1 n#1 -
2" (n #1),& ) #1/ " = 2,3,...
Copyright © 2006 University of Glasgow

23 ,+% " ( /.
All rights reserved.

!
Schedulable Utilization of RM
n υ = 4.0 υ = 3.0 υ = 2.0 υ = 1.0 υ = 0.9 υ = 0.8 υ = 0.7 υ = 0.6 υ = 0.5
2 0.944 0.928 0.898 0.828 0.783 0.729 0.666 0.590 0.500
3 0.926 0.906 0.868 0.779 0.749 0.708 0.656 0.588 0.500
4 0.917 0.894 0.853 0.756 0.733 0.698 0.651 0.586 0.500
5 0.912 0.888 0.844 0.743 0.723 0.692 0.648 0.585 0.500
6 0.909 0.884 0.838 0.734 0.717 0.688 0.646 0.585 0.500
7 0.906 0.881 0.834 0.728 0.713 0.686 0.644 0.584 0.500
8 0.905 0.878 0.831 0.724 0.709 0.684 0.643 0.584 0.500
9 0.903 0.876 0.829 0.720 0.707 0.682 0.642 0.584 0.500

∞ 0.892 0.863 0.810 0.693 0.687 0.670 0.636 0.582 0.500

Di > pi ⇒ Schedulable Di < pi ⇒ Schedulable


utilization increases utilization decreases
Copyright © 2006 University of Glasgow

Di = pi
All rights reserved.
Summary

Key points:
• Different priority scheduling algorithms
– Earliest deadline first, least slack time, rate monotonic, deadline monotonic
– Each has different properties, suited for different scenarios
• Scheduling tests, concept of maximum schedulable utilization
– Examples for different algorithms

Next lecture: practical factors, more schedulability tests…


Copyright © 2006 University of Glasgow
All rights reserved.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy