Rts 3
Rts 3
Scheduling
K i z h e p p a t t Vi p i n
Assumptions
Applicable when system is mostly deterministic
Hyperperiod of 4,5,20 is 20
P1 J1,1 J3,1 J2,1 J1,2 J4,1 J2,2 J1,3 J2,3 J1,4 J1,5 J2,4
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
If we are not interested in specific job of a task, we can represent the jobs with the corresponding task
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Processor is idle while jobs are ready. It is OK Priority driven will look like this
since we are not doing priority driven scheduling.
This is some arbitrary algorithm
T T T
P1 T 1 T2 T3 T1 T2 T4 T1 T2 T1 T2 T1
4 4 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Static Time Driven Scheduler
T1 = (4, 1), T2 = (5, 1.8), T3 = (20, 1), and T4 = (20, 2)
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Each entry (tk,T(tk)) gives a decision time tk and T(tk) which is the name of the task to be
executed, or I, which stands for processor idle
At every tk the scheduler configures the timer and when the timer expires gets an
interrupt
Upon getting the interrupt, the timer is configured to tk+1 and the task T(tk+1) is next to
the processor
After scheduling a job, the scheduler suspends (sleeps) until next interrupt
Clock driven/Time driven Approach
Time Task
1 T1
Expired 2 T2
Counter
Scheduler
3 T3
4 T1
Reload 5 T2
Schedule
Processor Memory
Table for the Example
T1 = (4, 1), T2 = (5, 1.8), T3 = (20, 1), and T4 = (20, 2)
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
In this scheme, there is no need to load the timer with different values at the scheduling
points
Instead the timer gives regular (periodic) interrupts at predefined time instances called
ticks and each tick acts as a scheduling point
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Clock driven with arbitrary scheduling points
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Tick Scheduling
Cyclic Schedulers
A major drawback of tick scheduler is unnecessary context switching (remember both
scheduler and tasks and running on same processor. So when scheduler is invoked,
running task has to be suspended which requires a context switching)
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
It would have been great if we can find the tick in such a way that it minimizes this
context switching and avoid arbitrary timer values
Cyclic Scheduler
The scheduling decision times partition the time line into intervals called frames
Because scheduling decisions are made only at the beginning of every frame, there is no
preemption within each frame
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
A Major Cycle
A Frame
Frames and Major Cycle
T1 = (4, 1), T2 = (5, 1.8), T3 = (20, 1), and T4 = (20, 2)
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T2 T1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Large frame sizes will make tasks to miss deadlines This was supposed finish by 20
f max(ei)
1in
Constraint 2
They are called candidate frame sizes and from the candidates, we will choose one
Frames Size Constraints
Constraint 3
frame k frame k+1 frame k+2
If t’>t, job cannot be scheduled in frame k, since at the scheduling point (t), the job is
not yet released.
In this case it can be scheduled only in frame k+1
It will complete its execution before t+2f (due to the first constraint)
From constraint 1, f 2
P1 T 1 T 3 T2 T1 T4 T2 T1 T2 T1 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Job Slices
T = {(4, 1), (5, 2, 7), (20, 5)} find f
From constraint 1, f 5
From here f 4
Job Slices
Jobs with large execution time should be partitioned into slices (i.e.,
Sub-jobs) with smaller execution times
Eg: we partition the program into procedures, each of which is to be executed non-
preemptively
Divide each job in (20, 5) into a chain of three slices with execution times 1, 3, and 1
the task (20, 5) now consists of three subtasks (20, 1), (20, 3) and (20, 1).
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Job Slices
But why choose 3 slices, why not 2 slices with execution time 4 and 1?
To answer that we need to look at the schedule with out T3 since other tasks also
influenced the choice of f
P1 T 1 T2 T1 T1 T2 T1 T2 T1 T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
The more slices a job is partitioned into, the higher the context switch and
communication overhead partition jobs into minimal slices
There may not be any feasible schedule for the choices of frame size and job slices
because it is impossible to pack the large job slices into the frames by their deadlines
k L(k)
0 T1,T2,T3,1 P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3
1 T1,T3,2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2 T1,T2
3 T1,T2 Frame 0 Frame 1 Frame 2 Frame 3 Frame 4
4 T1,T2,T3,3 A Major Cycle
The table has F entries, where F is the number of frames per major cycle
Cyclic Executives
Each entry k lists the names of the job slices that are scheduled to execute in frame k,
denoted by L(k) and is called a scheduling block, or simply a block
It also let aperiodic sporadic tasks to run when the processor is free
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
We just mentioned they can be scheduled when the processor is free in a frame
They always get lower priority compared to the job slices of periodic tasks(who have
hard deadlines)
But remember there is no advantage to completing a job with a hard deadline early
Scheduling Aperiodic Tasks
On the other hand, an aperiodic job is released and executed by the system in
response to an event
The sooner an aperiodic job completes, the more responsive the system is
So our goal is now to improve the response time of aperiodic tasks at the same time
not violating the hard-deadlines of periodic tasks
Slack Stealing
In this method aperiodic jobs are executed ahead of periodic jobs whenever possible
(as long as their deadlines are not broken)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
6.5 8.1
With normal scheduling
AA A
P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3
1 2 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
A A
P1 T 1 T2 T3,1 T1 T3,2 T1 T2 A2 T1 T2 T1 T2 T3,3
1 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
P1 T 1 T1
A A T2
T2 T3,1 T3,2 T1 T2 T1 T1 T2 T3,3
1 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
So, it is impossible to guarantee a priori that all sporadic jobs can complete in time
Acceptance Test for Sporadic Jobs
Scheduler perform an acceptance test when each sporadic job is released
It checks whether the newly released sporadic job can be feasibly scheduled with all
the jobs in the system at the time
Current jobs include the periodic jobs or scheduled sporadic jobs which are not yet
completed
If it is possible to complete the newly released sporadic job without breaking the
deadlines of already scheduled jobs, it is accepted, otherwise rejected
Acceptance Test for Sporadic Jobs
We assume that worst case execution (e) time of sporadic job is known
Whenever all the slices of periodic tasks scheduled in each frame are completed, the
cyclic executive lets the jobs in the sporadic job queue to execute
Since edf is based on deadlines, a sporadic job accepted later may finish earlier than
a job accepted earlier
But remember once a job is accepted, it won’t be removed from the queue even if a
higher priority job comes later and there is not enough slack for it due this job
Acceptance Test for Sporadic Jobs
In practical implementation, the acceptance test will be consists of two parts
1. The scheduler first determines whether the current total amount of slack in the
frames before the deadline of job S is at least equal to the execution time e of S. If the
answer is no, it rejects S. If the answer is yes, the second step is carried out
2. In the second step, the scheduler determines whether any sporadic job in the
system will complete late if it accepts S. If the acceptance of S will not cause any
sporadic job in the system to complete too late, it accepts S; otherwise, it rejects S
EDF Scheduling of Accepted Jobs
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2
S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S3
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2 S3
S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S3
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2 S3 S3
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2 S3 S3 S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
S4(28,1)
Job Q
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2 S3 S3 S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S2
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
S4(28,1)
Job Q
S2
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2 S3 S3 S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
S2 S2
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
S2 S3 S3 S2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Accepted
Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Sporadic
Job Q
S2 S2
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
Compared to any algorithm that tests for acceptance at the beginning of frame, cyclic
EDF is optimal
It is not optimal when compared with algorithms that perform acceptance tests at
arbitrary times
Interrupt-driven scheduler which does an acceptance test upon the release of each
sporadic job will do a better job
Easiest way is to terminate the job prematurely at the beginning of next frame and
log that info.
Premature termination of overrun jobs may put the system in some inconsistent state
and may affect system integrity
So one way is to preempt it at the beginning of next frame and remaining part of the
job can be run as an aperiodic job
Advantages Of Clock-Driven Scheduling
Simplicity
Can take into account complex dependencies, communication delays etc. making
sure there will be no deadlock and unpredictable delays
Precedence constraints and other types of dependency can be taken care of by the
choice of the schedule, Hence, there is no need for any synchronization mechanism
When the workload is periodic and the schedule is cyclic, timing constraints can be
checked and enforced at each frame boundary
All combinations of periodic tasks that might execute at the same time must be
known a priori so a schedule for the combination can be precomputed
The pure clock-driven approach is not suitable for many systems that contain both
hard and soft real-time applications