Vous êtes sur la page 1sur 30

Chapter 5

Task Assignment and Scheduling


Concepts
Task assignment / scheduling
Classical uniprocessor scheduling
algorithms

INB47302 Real Time System 1


Concepts
(1) Task instance / processes
Task is generated when some specific event
occurs due to event occurrence
Is associated with a deadline by which it needs to
complete and produce results
Ex: a temperature sensing task in a chemical
plant might recur indefinitely with a certain period
because the temperature is sampled periodically
while a task handling a device interrupt might
recur at random instants

INB47302 Real Time System 2


Concepts
(2) Relative deadline vs Absolute deadline
Relative deadline
Counted from time of task occurrence
Time interval between the task arrival and the
corresponding deadline.
Absolute deadline
Counted from time 0
Is equal to the interval of time between the time
0 and the actual instant at which the deadline
occurs as measured by some physical clock

INB47302 Real Time System 3


Concepts
(3) Response time
Time duration from the occurrence of the
event generating the task to the time the
task produces its results
Case:
Hard RT as long as all their deadlines
are met no special advantage of
completing the tasks early
Soft RT try to execute the tasks in an
order that minimizes the average tasks
response time.

INB47302 Real Time System 4


Concepts
(4) Task precedence
If a task must be complete before another task
can start

T1
< (1) = 0
T4 <(2) = {1}
T2 T3 <(3) = {1}
<(4) = {1}
<(5) = {1,2,3}
T5 T6
<(6) = {1,3,4}
T7 <(7) = {1,3,4,6}
<(8) = {1,3,4,6,7}
T8

Figure 5.1 Precedence Graph Figure 5.2 Precedence Task

INB47302 Real Time System 5


Concepts
(5) Data Sharing
Tasks often need to share their results among
each other when one task needs to share the results
produced by another task dependable
May occur due to:
One task precedes the other check balance
need to used valid card & correct password
Concurrent tasks transfer to multi account
simultaneously
Overlapping tasks update withdraw from card
or online

INB47302 Real Time System 6


Task Assignment/Scheduling
On how the task are allocated at each processor.
Allocate the tasks by checking
all tasks permits to be feasibly scheduled
If not permits modify the allocation to try to render its
schedules feasible
Implement through algorithm:
Utilization balancing algorithm
Next fit algorithm for RM scheduling
Bin packing assignment algorithm for EDF
Myopic Offline Scheduling (MOS) algorithm
Focused addressing and bidding (FAB) algorithm
Buddy strategy
Assignment with precedence constraint.

INB47302 Real Time System 7


Task Assignment/Scheduling
Classes of RT scheduling algorithms:
(1) Based on how the scheduling points
a. Clock driven scheduling points are
determined by the interrupts received from
a clock
Table driven precomputed which task
would run when & store this schedule in a
table at the time the system is designed or
configured
Cyclic repeats a precomputed schedule

INB47302 Real Time System 8


Task Assignment/Scheduling
Classes of RT scheduling algorithms:
(1) Based on how the scheduling points
b. Event Driven scheduling points are defined by
certain events which precludes clock
interrupts
Simple priority based foreground
application is highest priority
Rate Monotonic Analysis (RMA) shorter
period, highest priority
Earliest Deadline First (EDF) shorter
deadline, highest priority

INB47302 Real Time System 9


Task Assignment/Scheduling
Classes of RT scheduling algorithms:
(1) Based on how the scheduling points
c. Hybrid scheduling points are defined
through the clocks interrupts and the
event occurrences
Round robin treats all tasks equally & all
tasks are assigned identical time slices
which held in a circular queue & taken up
1 after the other on a sequence

INB47302 Real Time System 10


Task Assignment/Scheduling
Classes of RT scheduling algorithms:
(2) Based on task acceptance test
a. Planning based accept for scheduling, if
can meet the deadline & cause other
scheduled tasks ok
b. Best effort all task arrived taken up for
scheduling and meet the deadline but not
guarantee

INB47302 Real Time System 11


Task Assignment/Scheduling
Classes of RT scheduling algorithms:
(3) Based on the target platform
a. Uniprocessor a computer system with a
single central processing unit.
b. Multiprocessor - A computer that has two or
more CPUs.
c. Distributed - A number of independent
computers linked by a network

INB47302 Real Time System 12


Task Assignment/Scheduling
Types:
a. Offline scheduling
Involves scheduling in advance of the operation,
with specifications of when the periodic tasks will
be run and slots for the sporadic /aperiodic tasks
in the event that they are invoked - scheduled
b. Online scheduling
The tasks are scheduled as they arrive in the
system
The algorithms used in this scheduling must be
fast
On demand

INB47302 Real Time System 13


Task Assignment/Scheduling
Types:
c. Static-priority
There are algorithms that assume that the
task priority does not change within a
mode
No changes within time

d. Dynamic-priority
Assume that priority can change with
time

INB47302 Real Time System 14


Task Assignment/Scheduling
Types:
e. Preemptive
When the tasks can be interrupted by other
tasks (and then resumed)
Wherever possible, critical tasks must be
allowed to interrupt less critical one when it
is necessary to meet deadlines
f. Nonpreemptive
When once a task begun, it must be run to
completion or until it gets blocked over a
resource

INB47302 Real Time System 15


Task Assignment/Scheduling
Assistance
Task dispatching policy
when tasks are inserted into and deleted from
the ready queues
whether a task is inserted at the head or the tail of
the queue for its active priority
Entry queuing policy
Specify the order in which entry calls are served
Allow programmer to specify

Served in FIFO not priority of the calling

tasks

INB47302 Real Time System 16


Task Assignment/Scheduling
Assistance
Protected data types
Help maintain dt consistency efficiently in a
memory sharing sys
If some portion of shared memory is to be accessed,
the compiler:
can execute protected operations to read that

portion from memory


Carryout whatever manipulation are called for by

the prog
Complete the access to the protected object by

writing back the modifications to the memory

INB47302 Real Time System 17


Task Assignment/Scheduling
Characteristics
a. Sufficient - If a +ve outcome guarantees
that all deadlines are always met
b. Necessary if test failure will indeed lead to a
deadline miss at some point during the system
execution

INB47302 Real Time System 18


Task Assignment/Scheduling
Characteristics
Ex: Consider a 2 task system. Let the release
times of tasks Ti and Tj be 1 and 2,
respectively; the deadlines be 7 and 5; and the
execution times/period be 3.25 and 2.
Task 2 deadline
S1 T2 T1

T1 T2

S2
T1 T2 T1 Task 1 deadline
Figure 5.2
S3

0 1 2 3 4 5 6 7 8 9
time
INB47302 Real Time System 19
Task Assignment/Scheduling
Characteristics
Ex: Consider a 2 task system. Let the release times of
tasks Ti and Tj be 1 and 2, respectively; the
deadlines be 7 and 5; and the execution
times/period be 3.25 and 2.
Explanation:
S1 meet both deadlines, however, suppose follow
the perfectly sensible policy of not keeping the
processor idle whenever there is a task waiting to
be run
S2 task S2 missing its deadline
S3 is a preemptive schedule. When T1 is
released, it starts executing. When T1 arrives, T2 is
preempted and run to completion, thus meeting its
deadline. Then T1 resumes from where it left off and
also meets its deadlineINB47302 Real Time System 20
Classical Uniprocessor Scheduling
Algorithms
Rate Monotonic Analysis
Rate Monotonic Scheduling Algorithm
It is a
uniprocessor static priority preemptive
scheme
Scheduling a set of tasks on a single
processor
procedure for assigning fixed priorities to
tasks to maximize their schedulability
A task set is considered schedulable if all
tasks meet all deadline all the time

INB47302 Real Time System 21


Classical Uniprocessor Scheduling
Algorithms
Rate Monotonic Analysis
Rate Monotonic Scheduling Algorithm
The priority of a task is inversely related to its
period.
If task Ti has a smaller period than task Tj ,Tj
has higher priority than Ti
Higher priority tasks can preempt lower
priority tasks
The algorithm is simple:
Assign the priority of each task according to its
period, so that the shorter the period the higher
the priority INB47302 Real Time System 22
Classical Uniprocessor Scheduling
Algorithms
Rate Monotonic Analysis
Rate Monotonic Scheduling Algorithm
Case study
Consider a system with only 2 tasks, which well
call Task 1 and Task 2. Assume these are both
periodic tasks with periods T1 and T2 and each
has a deadline that is the beginning of its next
cycle.
Task 1 has T1=50ms (deadline) and a worst
case execution time of C1=25ms (period).
Task 2 has T2=100ms (deadline) and
C2=40ms (period)
INB47302 Real Time System 23
Classical Uniprocessor Scheduling
Algorithms
Rate Monotonic Analysis
Rate Monotonic Scheduling
Algorithm
Case study
Case 1: Priority(t1) >
Priority(t2) both tasks
meet their respective
deadlines
Case 2: Priority(t2) >
Priority(t1) task 1
misses a deadline,
despite 10% idle time
INB47302 Real Time System 24

Figure 5.3
Classical Uniprocessor Scheduling
Algorithms
Rate Monotonic Analysis
Rate Monotonic Scheduling Algorithm
Application
Refer to case study, the period of Task 1 is
shorter than the period of Task 2.
So, assign the higher priority to Task 1. This
corresponds to Case 1 in Figure 5.3, which is
the priority assignment that succeeded in
meeting all deadlines

INB47302 Real Time System 25


Classical Uniprocessor Scheduling
Algorithms
Other Uniprocessor Scheduling Algorithms
Preemptive Earliest Deadline First (EDF) Algorithm
Is a dynamic priority scheduling algorithm
The task priorities are not fixed but change
depending on the closeness of their absolute
deadline
The processor always executes the task whose
absolute deadline is the earliest
Or called as the deadline monotonic scheduling
algorithm
All the assumptions are same with RMA except
the tasks do notINB47302
have to be periodic
Real Time System 26
Classical Uniprocessor Scheduling
Algorithms
Other Uniprocessor Scheduling Algorithms
Preemptive Earliest Deadline First (EDF) Algorithm
Ex: Consider the following set of (aperiodic) task arrivals to a
system

Task Arrival Time Execution Time @ period Absolute Deadline


T1 0 10 30
T2 4 3 10
T3 5 10 25

INB47302 Real Time System 27


Classical Uniprocessor Scheduling
Algorithms
Other Uniprocessor Scheduling Algorithms
Preemptive Earliest Deadline First (EDF) Algorithm
Ex: Consider the following set of (aperiodic) task
arrivals to a system T1 p = 4 run 1st, preempt

dt2 dt3 dt1 T2 p = 3 completed, d =


T1 T2 T3 T1 10
T3 p =10 completed, d =
25
0 4 8 16 24 T1 p = 6 completed, d =
30
When T1 arrives, it is the only task waiting to
run, and so starts executing immediately.
INB47302 Real Time System 28
Classical Uniprocessor Scheduling
Algorithms
Other Uniprocessor Scheduling Algorithms
Preemptive Earliest Deadline First (EDF) Algorithm
Ex: Consider the following set of (aperiodic) task
arrivals to a system
T2 arrives at time 4; since d2<d1, it has higher
priority than T1 and preempts it.
T3 arrives at time 5; however, since d3>d2, it
has lower priority than T2 and must wait for T2
to finish.
When T2 finishes (at time 7),T3 starts (since it
has higher priority than T1)
T3 runs until 17, at which point T1 resume and
run to completion
INB47302 Real Time System 29
Recall @ Understanding

Concepts

Task assignment / scheduling


Classical uniprocessor scheduling algorithms

INB47302 Real Time System 30