Module 4
Module 4
MODULE 4
Task constraints, Task scheduling: Aperiodic task scheduling: EDD. EDF, LDF, EDF with
precedence constraints.
Periodic task scheduling: Rate monotonic and Deadline monotonic, Real time Kernel-
Structure, State transition diagram, Kernel primitives.
From a process point of view, a resource is any software structure that can be
used by the process to advance its execution.
Typically, a resource can be a data structure, a set of variables, a main
memory area, a file, a piece of program, or a set of registers of a peripheral
device.
A resource dedicated to a particular process is said to be private, whereas a
resource that can be used by more tasks is called a shared resource.
To maintain data consistency, many shared resources do not allow
simultaneous accesses but require mutual exclusion among competing tasks.
They are called exclusive resources.
Consider two tasks J1 and J2 that share an exclusive resource R on which two operations (such as
insert and remove) are defined.
The code implementing such operations is thus a critical section that must be executed in mutual
exclusion.
If a binary semaphore s is used for this purpose, then each critical section must begin with a wait(s)
primitive and must end with a signal(s) primitive.
Prepared by Divya Harikumar,Asst.Professor,SCTCE
If preemption is allowed and J1 has a higher priority than J2, then J1 can block in the
15
situation depicted in Figure
Here, task J2 is activated first, and, after a while, it enters the critical section and locks the
semaphore.
While J2 is executing the critical section, task J1 arrives, and, since it has a higher priority,
it preempts J2 and starts executing.
A simple algorithm that solves this problem was found by Jackson and it is
called Earliest Due Date (EDD) and can be expressed by the Jackson’s rule
Figure illustrates an example in which the task set cannot be feasibly scheduled.
Still, however, EDD produces the optimal schedule that minimizes the maximum
lateness. Notice that, since J4 misses its deadline, the maximum lateness is greater
than zero {Lmax = L4 ==2).
If tasks are not synchronous but can have arbitrary arrival times, then
preemption becomes an important factor.
If preemption is allowed, a task can be interrupted if a more important task
arrives.
Horn found an elegant solution to the problem of scheduling a set of n
independent tasks on a uniprocessor system, when tasks may have dynamic
arrivals and preemption is allowed (1 | preem \ Lmax)
The algorithm, called Earliest Deadline First (EDF), can be expressed by the
following theorem
• The complexity of the algorithm is O(n) per task, since inserting the newly
arrived task into an ordered queue(the ready queue) of n elements may require
up to n steps.
• Hence, the overall complexity of EDF for the whole task set is O(n2)
If there exists a feasible schedule for a task set J, then EDF is able to find it.
The proof can easily be extended to show that EDF also minimizes the
maximum lateness.
An algorithm that minimizes the maximum lateness is also optimal in the
sense of feasibility. The contrary is not true.
Let σ be the schedule produced by a generic algorithm A and let σEDF be the
schedule obtained by the EDF algorithm.
Since preemption is allowed, each task can be executed in disjointed time
intervals.
Without loss of generality, the schedule σ can be divided into time slices of
one unit of time each.
Figure : Proof of the optimality of the EDF algorithm, a. schedule σ at time t = 4. b . new schedule
obtained after a transposition.
34
For each time slice t, the algorithm verifies whether the task σ (t) scheduled
in the slice t is the one with the earliest deadline, E(t).
If it is, nothing is done, otherwise a transposition takes place and the slices at
t and tE are exchanged (see Figure).
In particular, the slice of task E(t) is anticipated at time t, while the slice of
task σ (t) is postponed at time tE
After each transposition the maximum lateness cannot increase; therefore,
EDF is optimal.
When tasks have dynamic activations and the arrival times are not known a
priori, the guarantee test has to be done dynamically, whenever a new task
enters the system.
Let J be the current set of active tasks, which have been previously
guaranteed, and let Jnew be a newly arrived task.
In order to accept Jnew in the system we have to guarantee that the new task set
J' = J U{Jnew} is also schedulable.
To guarantee that the set J' is feasibly schedulable by EDF, we need to show
that, in the worst case, all tasks in J' will complete before their deadlines.
This means that we have to show that, for each task, the worst-case finishing
time fi is less than or equal to its deadline di.
Prepared by Divya Harikumar,Asst.Professor,SCTCE
we can assume that all tasks in J' (including Jnew) are ordered by increasing
40 deadlines, so that J1 is the task with the earliest deadline.
Moreover, since tasks are pre-emptable, when Jnew arrives at time t some
tasks could have been partially executed.
Thus, let Ci(t) be the remaining worst-case execution time of task Ji .
Hence, at time t, the worst-case finishing time of task Ji can be easily
computed as
Two algorithms are used that minimize the maximum lateness by assuming
synchronous activations and preemptive scheduling, respectively.
Latest Deadline First (1 / prec,sync / Lmax)
Earliest Deadline First (1 / prec,preem / Lmax)
Lawler presented an optimal algorithm that minimizes the maximum lateness of a set
of tasks with precedence relations and simultaneous arrival times.
The algorithm is called Latest Deadline First (LDF) and can be executed in polynomial
time with respect to the number of tasks in the set.
Given a set J of n tasks and a directed acyclic graph (DAG) describing their
precedence relations.
LDF builds the scheduling queue from tail to head: among the tasks without
successors or whose successors have been all selected, LDF selects the task with the
latest deadline to be scheduled last.
This procedure is repeated until all tasks in the set are selected.
At run time, tasks are extracted from the head of the queue, so that the first task
inserted in the queue will be executed last, whereas the last task inserted in the queue
will be executed first.
Prepared by Divya Harikumar, Asst.Professor, SCTCE
Let J be the complete set of tasks to be scheduled , let 𝜞 ⊆ J be the subset of tasks
43
without successors, and let Jl be the task in 𝜞 with the latest deadline dl.
If σ is any schedule that does not follow the EDL rule, then the last scheduled task, say
Jk, will not be the one with the latest deadline; thus dk ≤ dl .
Since Jl is scheduled before Jk, let us partition 𝜞 into four subsets, so that 𝜞 = AU {Jl}
U B U {Jk}
In σ the maximum lateness for 𝜞 is greater or equal to Lk = f — dk , where
Moving Jl to the end of the schedule cannot increase the maximum lateness in 𝜞,
which proves the optimality of LDF.
To do that, let σ* be the schedule obtained from σ after moving task Jl to the end of
the queue and shifting all other tasks to the left.
44
Moving Jl to the end of the schedule does not increase the maximum lateness in F.
This means that scheduling the task Jl to the last with the latest deadline minimizes the
maximum lateness in 𝜞.
Then, removing this task from J and repeating the argument for the remaining n - 1
tasks in the set J - {Jl}, LDF can find the second-to-last task in the schedule, and so on.
The complexity of the LDF algorithm is O(n) since for each of the n steps it needs to visit
the precedence graph to find the subset F with no successors.
Given a set 𝜞 of n periodic tasks, the processor utilization factor U is the fraction
of processor time spent in the execution of the task set.
The Rate Monotonic (RM) scheduling algorithm is a simple rule that assigns
priorities to tasks according to their request rates.
Specifically, tasks with higher request rates (that is, with shorter periods) will have
higher priorities.
Since periods are constant, RM is a fixed-priority assignment.
Priorities are assigned to tasks before execution and do not change over time.
RM is intrinsically preemptive: the currently executing task is preempted by a newly
arrived task with shorter period.
RM is optimal among all fixed priority assignments in the sense that no other fixed-
priority algorithms can schedule a task set that cannot be scheduled by RM.
In order to prove the optimality of the RM algorithm, we first show that a critical
instant for any task occurs whenever the task is released simultaneously with all
higher-priority tasks.
Let 𝜞= {τ1, τ2,... , τn} be the set of periodic tasks ordered by increasing periods, with τn
being the task with the longest period.
According to RM, τn will also be the task with the lowest priority.
The response time of task τn is delayed by the interference of τi with higher priority.
Advancing the release time of τi may increase the completion time of τn.
The response time of τn is largest (worst) when it is released simultaneously with τi.
Given two periodic tasks τ1 and τ2 , with T1< T2, if the schedule is feasible by an
arbitrary priority assignment, then it is also feasible by RM. That is, RM is
optimal.
Therefore, a rough estimate when n≥ 𝟏𝟎 is that RMS can meet all of the deadlines if total
CPU utilization, U, is less than 70%. The other 30% of the CPU can be dedicated to lower-
priority, non-real-time tasks.
Prepared by Divya Harikumar,Asst.Professor,SCTCE
73
The Deadline Monotonic (DM) priority assignment weakens the "period equals
deadline" constraint within a static priority scheduling scheme.
This algorithm was proposed as an extension of Rate Monotonic where tasks can have
a relative deadline less than their period.
Specifically, each periodic task τi is characterized by four parameters:
The feasibility of a set of tasks with deadlines unequal to their periods could be
guaranteed using the Rate-Monotonic schedulability test, by reducing task’s periods
to relative deadlines:
This test is sufficient but not necessary for guaranteeing the schedulability of the task set
since the actual interference can be smaller than Ii, since τi may terminate earlier.
To find a sufficient and necessary schedulability test for DM, the exact interleaving of
higher-priority tasks must be evaluated for each process.
In general, this procedure is quite costly since, for each task τi , it requires the
construction of the schedule until Di.
Hence an efficient method was proposed for evaluating the exact interference on
periodic tasks and derived a sufficient and necessary schedulability test for DM.
The longest response time Ri of a periodic task τi is computed, at the critical instant,
as the sum of its computation time and the interference due to preemption by higher-
priority tasks:
(1)
Example
In order to guarantee τ4, we have to calculate R4 and verify that R4 < D4.