RTOS-Session4
RTOS-Session4
Purushotham BV
utham74@gmail.com
1
Clock Driven Scheduling
5.1 Notations and Assumptions
5.2 Static, Timer-driven Scheduler
5.3 General Structure of Cyclic Schedules
5.4 Cyclic Executives
5.5 Improving the Average Response Time of Aperiodic Jobs
5.6 Scheduling Sporadic Jobs
5.7 Practical Considerations and Generalizations
5.8 Algorithm for Constructing Static Schedules
5.9 Pros and Cons of Clock-driven Scheduling
5.10 Summary
2
5.1 Notations and Assumptions
4
5.2 Static, Time-Driven Scheduler
10
Pseudo code for Clock-Driven Scheduler
11
5.3 General Structure of Cyclic Schedules
12
Frames and Major Cycles
13
Frame Size Constraints
• How to choose frame length?
– To avoid preemption and every jobs to start and complete
execution within a single frame: Choose frame size f,
f ≥ max(e1, e2, …, en) of every task (Equation 1)
– To minimize the number of entries in the cyclic schedule, the
hyper-period should be an integer multiple of the frame size ( ⇒f
divides the period pi evenly for at least one task):
∃i : mod(pi, f ) = 0 (Equation 2)
– The scheduler to check jobs complete by their deadline, should
be at least one frame boundary between release time of a job
and its deadline:
2*f – gcd(pi, f ) ≤ Di for i = 1, 2, …, n (Equation 3)
• All 3 constraints should be satisfied
Structure of a Cyclic Schedule
Solution:
• As per Equation 1 ( 1st Constraint) , the frame size
should be greater than 3 ( larger than the execution time
of the 3 tasks)
• As per Equation 2 ( 2nd Constraint), the possible values
of frame size are 3,4,5,10,11,15,20,22
i.e. (floor(pi/f) – (pi/f)) = 0 or theoretically all possible
divisors of the various periods (15, 20 and 22) can be the
possible frame sizes.
Solution (Contd.,)
• As per Equation 3(3rd Constraint), only 3 , 4 and 5
satisfies the condition 2*f – gcd (pi, f ) ≤ Di
( or f ≤ Di is preliminary condition to satisfy the 3 rd
constraint)
Lets take f=5 and period =20, GCD(20,5)=5
Therefore 2*f – gcd(pi, f ) = 2*5-5=5 ≤ Di because 5 ≤20
Lets take f=11 and p=22 GCD is 11 and 2*11-11=11 is
greater than 22 and condition does not satisfy
20
Explanation (Contd.,)
• You may question why we choose to decompose (20, 5) into
three subtasks.
• To satisfy Eq. (5.1), it suffices for us to partition each job in
the task into two slices, one with execution time 3 and the
other with execution time 2. However, a look at the schedule
in Figure shows the necessity of three slices. It would not be
possible to fit the two tasks (20, 3) and (20, 2) together with
T1 and T2 in five frames of size 4. T1, with a period of 4,
must be scheduled in each frame. T2, with a period of 5,
must be scheduled in four out of the five frames.
• (The fact that the relative deadline of T2 is 7 does not help.)
This leaves one frame with 3 units of time for T3. The other
frames have only 1 unit of time left for T3. We can schedule
two subtasks each with 1 unit of execution time in these
frames, but there is no time in any frame for a subtask with
execution time 2.
Steps to be Followed while
Constructing a Cyclic Schedule
• Cyclic schedule has the following constraints
– Choosing frame size.
– Partitioning tasks into slices.
– Placing slices in frames.
– Reduction of context switching and communication overhead.
22
5.4 Cyclic Executives
• Clock-driven scheduler modified to accommodate the
restriction that scheduling decisions are made only at
frame boundaries.
• The cyclic executive refers to a scheduler that
deterministically interleaves and sequentializes the
execution of periodic-tasks on a CPU according to a given
cyclic schedule.
• Each job slice is a procedure.
• The cyclic executive executes a single do loop.
• Starting from the beginning of each frame and executes
the slices scheduled in the frame.
• Cyclic executive mean a table-driven cyclic scheduler for
all types of jobs in a multithreaded system.
Cyclic Executives (Contd.,)
• It makes scheduling decisions only at the beginning of
each frame
• At the beginning of the next frame, the available slack is 2. It resumes A1,
which completes at time 8.5.
• At the time, the first slice in the current block is executed, since the aperiodic
job queue is empty.
• Upon completion of the slice at time 9.5, the cyclic executive checks the
aperiodic job queue and finds A2 ready, and lets A2 execute.
• When the job completes at time 10, the cyclic executive finds the aperiodic job
queue empty and lets the periodic task server execute the next job slice in the
current block.
• At time 11, it finds A3 and lets the job execute during the last unit of time in
the frame, as well as in the beginning of the next frame. The job completes by
time 13.
• According to this schedule, the response times of the jobs are 4.5, 0.5, and
2.5, with an average of 2.5.
Implement Slack Stealing
• The initial amount of slack in each frame can be pre computed along
with the cyclic schedule and stored in the table.
• It is necessary to keep track of the amount of available slack and
update when consumes the slack using an interval timer.
• At the beginning of each frame, the cyclic executive sets the timer to
the value of the initial slack in the frame.
• The timer counts down whenever an aperiodic job executes ahead of
any slice in the current block.
• When the timer expires, indicating that there is no more slack,
• The cyclic executive preempts the executing aperiodic job and lets the
execution of the next job slice in the current block begin.
• This scheme is practical only when the temporal parameters of
periodic tasks are in orders of hundreds of milliseconds or seconds.
Average Response Time
35
Average Response Time (Contd.,)
• When tasks are scheduled on FIFO basis
E[ i ]
i na
W0
W
i 1 (1 U ) (1 U ) 2
[1 U A / (1 U )]
• Where
i E[ i 2 ]
na
W0
i 1 2
• Behavior of average response time of some aperiodic
tasks as function of UA
• Average queuing time is inversely proportional to the
square of aperiodic bandwidth.
• Jobs in queue for ith periodic task
E[ i ] W0
Wi 2
(1 U ) (1 U ) [1 U H / (1 U )][1 (U H ui ) / (1 U )]
36
Average Queuing Time v/s Total Average
Utilization
37
5.6 Scheduling Sporadic jobs
38
Acceptance Test
40
A Cyclic Executive with Sporadic and Aperiodic Task Scheduling Capability
41
Explanation of Example and Schedule
42
Explanation of Example and Schedule
43
Optimality of Cyclic EDF Algorithm
44
5.7 Practical Considerations and Generalizations
45
Handling Frame Overruns
• There are multiple reasons associated with a frame run.
– When a execution time parameter is valid for one set of data
values, its value may increase for a rare combination of similar
values.
– Transient hardware faults may increase frame overruns.
– A bug undetected during debugging and testing could pose a
problem.
• Digital controller is a typical example.
• Overruns can be handled by continuing to execute the
offending task.
• Postponing task executions can produce delayed
schedules.
46
Mode Changes
47
Aperiodic Mode Changes
48
Source Code for Mode Changer
49
Sporadic Mode Change
• Sporadic tasks have hard deadline.
• 2 scheduling approaches
– Treat sporadic task as ordinary task and schedule
• provided task rejection feature is supported by application when mode
can not be changed.
– Using a computer controlled bulldozer to poll and select the
appropriate task.
50
General Workloads and Multiprocessor
Scheduling
• In some cases clock driven approach is applicable to varying
work load.
– Examples of such case include a bus arbitrator which interleaves
data transmission between different I/O devices.
• Here clock driven approach is applicable to mixed workloads
(tasks other than periodic tasks.)
• Constraint to be satisfied - all task parameters should be
known a priori.
– To achieve the above static schedule has to be developed offline.
– Precedent constraints among tasks with relative dependencies
have to be satisfied.
– It is easier to schedule such tasks on several processors using a
global clock.
– While scheduling such tasks clock drifts on processors need to
be ignored.
• E.g: Boeing 777 Airplane Information Management System (AIMS)
51
5.8 Algorithm for Constructing Static
Schedules
• To construct a static
schedule
– First choose a minor
frame length for a
set of periodic tasks.
– Tasks need to be
segmented satisfying
their deadline
constraints.
– Tasks should be non
preemptable in
nature.
55
Part of a Network-Flow Graph
56
Maximum flow and feasible
preemptive schedule.
• For the above graph maximum flow is at most
equal to the sum of the execution times of all
tasks to be scheduled in a major cycle.
• Set of flows from task vertices to frame vertices
gives the maximum flow.
– As seen from example T1(4,1), T2(5,2,7) and
T3(20,5) has frame sizes 2 and 4.
– Maximum flow of the graph is 18 which is the
makespan equal to the hyperperiod of all tasks.
57
Example illustrating network-flow
formulation
58
Maximum flow and feasible
preemptive schedule.
• For the above graph maximum flow is at most equal to
the sum of the execution times of all tasks to be
scheduled in a major cycle.
• Set of flows from task vertices to frame vertices gives
the maximum flow.
– As seen from example T1(4,1), T2(5,2,7) and T3(20,5) has
frame sizes 2 and 4.
– Maximum flow of the graph is 18 which is the makespan
equal to the hyperperiod of all tasks.
59
Generalization to Arbitrary Release Times
and Deadlines
• Network-flow formulation can easily be generalized to
develop schedules of independent tasks.
• Release times of tasks from 1 to N can be generalized to
create schedules with latest deadlines upto 2N-1.
60
Postprocessing
• Feasible schedule may not always meet constraints
imposed by cyclic schedule.
– Examples include precedence order of tasks and restrictions
on preemptions.
• Network-flow graph is created based on the assumption
that tasks are independent.
• This leads to wrong order of scheduling tasks.
• Schedule so developed can be transformed into a
schedule following precedence constraints by swapping
the time allocations.
• Optimality cannot be guaranteed in such schedule
transformations. 61
5.9 Pros and Cons of Clock-Driven
Scheduling
• Primary advantage of Clock-driven approach is its
simplicity.
• Factors involving complex dependencies, communication
delays, resource dependencies can be taken into account
while incorporating the same in a real time situation.
• Feasibility can be guaranteed only if there are no deadlocks
and unpredictable delays.
• Static schedule can be indicated by a table of start and
completion times.
• Tasks can be scheduled statically in different operation
modes.
• No concurrency control is required.
62
Pros and Cons of Clock-Driven Scheduling
(Contd.,)
• Precedence constraints and dependency issues are taken
care by the choice of the schedule.
• Context switching and communication overhead can be
kept low by choosing a large frame size.
• Releases of sporadic and aperiodic tasks are said to be
event-triggered.
• Clock driven approaches are time-triggered.
• In time-triggered systems, external events are queued and
polled periodically.
• Periods are integer multiples of the frame size.
• Design choice simplifies construction of static schedules
and eliminates waste in slack time. 63
Disadvantages of Clock-Driven
Approach
• System is rigid and brittle and incorporating flexibility is
cumbersome.
• Release times of all tasks are fixed as compared to priority
driven systems which have arbitrary release times.
• All combinations of periodic tasks must execute at the same
time and a priori knowledge of task parameters is
mandatory.
– Not suitable for applications that must be reconfigured on-line
and have a mix of periodic tasks and cannot be predicted prior
to beginning execution.
• Pure clock driven approach is not suitable for systems
containing both hard and soft real time applications.
64
5.10 Summary