0% found this document useful (0 votes)
66 views64 pages

Rts 3

This document discusses clock driven or time driven scheduling. It assumes a periodic task model with known parameters for each task. A static offline schedule is generated where scheduling decisions are made at predefined time instances. The schedule is stored in a table with the task to execute and the time of execution. A hardware timer triggers an interrupt at each scheduling point to execute the next task. Tick scheduling and cyclic scheduling are also discussed which use periodic timer interrupts to schedule tasks with the goal of minimizing unnecessary context switches between tasks and the scheduler. The optimal frame size in cyclic scheduling aims to allow each job to finish within a frame without preemption while meeting all deadlines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views64 pages

Rts 3

This document discusses clock driven or time driven scheduling. It assumes a periodic task model with known parameters for each task. A static offline schedule is generated where scheduling decisions are made at predefined time instances. The schedule is stored in a table with the task to execute and the time of execution. A hardware timer triggers an interrupt at each scheduling point to execute the next task. Tick scheduling and cyclic scheduling are also discussed which use periodic timer interrupts to schedule tasks with the goal of minimizing unnecessary context switches between tasks and the scheduler. The optimal frame size in cyclic scheduling aims to allow each job to finish within a frame without preemption while meeting all deadlines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 64

Clock Driven

Scheduling
K i z h e p p a t t Vi p i n
Assumptions
Applicable when system is mostly deterministic

A few aperiodic and sporadic jobs can be accommodated

Initially we will assume a periodic task model without sporadic tasks

 There are n periodic tasks in the system and n is fixed


 The parameters of all periodic tasks are known a priori and jitter is negligible
 Each job Ji,k is ready for execution at its release time ri,k

Remember we use the tuple (φi,pi,ei,Di ) to represent periodic tasks


Static Time Driven Scheduler
Since all system parameters are know a priori, we can
make a static offline schedule

If any aperiod job arrives, it is put into a queue

Whenever the processor is not executing a periodic task,


the job at the head of the queue executes

Eg: System executes 4 independent tasks


T1 = (4, 1), T2 = (5, 1.8), T3 = (20, 1), and T4 = (20, 2)

Hyperperiod of 4,5,20 is 20

Hence we need to schedule only till 20 time units after that


it can repeat
Static Time Driven Scheduler
T1 = (4, 1), T2 = (5, 1.8), T3 = (20, 1), and T4 = (20, 2)

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

These periods can be used for executing aperiodic


tasks
Clock Driven Scheduler
Implementation
Implementation
Precomputed schedule is stored in a table

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

The scheduler uses a (hardware) timer

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

tk Task (T(tk)) tk Task (T(tk))


0 T1 12 T2
1 T3 13.8 T1
2 T2 14.8 I
3.8 I 16 T1
4 T1 17 I
5 I 18 T2
6 T4 19.8 I
8 T2
9.8 T1
10.8 I
Scheduler Pseudocode
Input: Stored schedule (tk , T (tk )) for k = 0, 1, . . . N − 1.
Task SCHEDULER:
set the next decision point i and table entry k to 0;
set the timer to expire at tk .
do forever:
accept timer interrupt;
if an aperiodic job is executing, preempt the job;
current task T = T (tk);
increment i by 1;
compute the next table entry k = i mod(N);//So that k repeats after N
set the timer to expire at  i/N  H + tk;//Here Timer is free running Up
counter
if the current task T is I ,
let the job at the head of the aperiodic job queue execute;
else
let the task T execute;
sleep;
end SCHEDULER
Implementation
A periodic static schedule a cyclic schedule

This approach is called clock-driven/time-driven because each scheduling decision is


made at a specific time, independent of events, such as job releases and completions

The points at which scheduling happens are called scheduling points

Clock-driven systems never exhibit the anomalous timing behavior of priority-driven


systems
Tick Scheduling
Modern RTOS use a different clock driven approach for more simpler implementation
of clock driven scheduling

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

A tick is a predefined duration of time (practically a few milli-seconds)


Tick Scheduling

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

Ticks (Scheduling points) Scheduling happens only at the beginning of a tick

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

Unnecessary context switching

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

Every frame has length f called the frame size

Because scheduling decisions are made only at the beginning of every frame, there is no
preemption within each frame

If there are F frames in a hyper-period, hyper-period starting at (kF+1) where


k=(0,1,2,3…) is called a major cycle
Frames and Major Cycle

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

Too small frame size increases context switching time

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

So the main challenge here is to find the optimal frame size


Frames Size Constraints
Constraint 1
Ideally, we want the frames to be sufficiently long so that every job can start and
complete its execution within a frame  no preemption

f  max(ei)
1in

Constraint 2

To keep the size of scheduling table as short as possible, f should divide H


H%f = 0
This condition is satisfied when f divides the period of at least one task

pi/f - pi /f =0  pi%f = 0 for at least one i


Frames Size Constraints
If the condition is satisfied, there will be integer number of frames in a hyper-period

Multiple frame sizes might satisfy the previous criteria

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

t t' t+f t+2f t‘ + Di t‘ + pi t+3f

Release of next job of the task


Remember for periodic task, if
A job is released here relative deadline is not specified,
Absolute deadline for previous
job is here
Absolute deadline of job
Frames Size Constraints
Constraint 3
frame k frame k+1 frame k+2

t t' t+f t+2f t‘ + Di t‘ + pi t+3f

From the first constraint,


ei cannot be more than this
frame k frame k+1 frame k+2

t t' t+f t+2f t‘ + Di t‘ + pi t+3f

If t’=t, we can schedule the job in frame k


Frames Size Constraints
frame k frame k+1 frame k+2

t t' t+f t+2f t‘ + Di t‘ + pi t+3f

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)

We want k+1 frame in the interval [t’,t’+Di]


 t+2f at or before t’+Di
 t+2f  t’+Di
 2f-(t’-t)  Di
Since the minimum value of (t’-t) is gcd(pi,f)
2f-gcd(pi,f)  Di
Frame Size
Eg: System executes 4 independent tasks T1 = (4, 1), T2 = (5, 1.8), T3 = (20, 1), and T4
= (20, 2)

From constraint 1, f  2

From constraint 2, the candidate frame sizes are (factors of 20) : 1, 2, 4, 5, 20

Now check constraint 3 for each candidate frame size

Frame Size For T1 For T2 For T3 For T4


1 2*1-1 = 1 2*1-1= 1 2*1-1=1 2*1-1=1
2 2*2-2 = 2 2*2-1 = 3 2*2-2 = 2 2*2-2=2
4 2*4-4 = 4 2*4-1 = 7 2*4-4 = 4 2*4-4=4
5 2*5-1= 9 2*5-5 = 5 2*5-5 = 5 2*5-5 = 5
20 2*20-4 = 36 2*20-5=35 2*20-20=20 2*20-20=20
Frame Size
Eg: System executes 4 independent tasks T1 = (4, 1), T2 = (5, 1.8), T3 = (20, 1), and T4
= (20, 2)
Frame Size For T1 For T2 For T3 For T4
1 2*1-1 = 1 2*1-1= 1 2*1-1=1 2*1-1=1
2 2*2-2 = 2 2*2-1 = 3 2*2-2 = 2 2*2-2=2
4 2*4-4 = 4 2*4-1 = 7 2*4-4 = 4 2*4-4=4
5 2*5-1= 9 2*5-5 = 5 2*5-5 = 5 2*5-5 = 5
20 2*20-4 = 36 2*20-5=35 2*20-20=20 2*20-20=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
Job Slices
T = {(4, 1), (5, 2, 7), (20, 5)} find f

From constraint 1, f  5

From constraint 2, candidate frame sizes are (H=20), 1,2,4,5,20


Frame Size For T1 For T2 For T3
1 2*1-1 = 1 2*1-1= 1 2*1-1= 1
2 2*2-2 = 2 2*2-1 = 3 2*2-2 = 2
4 2*4-4 = 4 2*4-1 = 7 2*4-4 = 4
5 2*5-1= 9 2*5-5 = 5 2*5-5 = 5
20 2*20-4 = 36 2*20-5=35 2*20-20=20

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).

P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3

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

Feasible slots for T3 to execute


From here it is clear that in the best case we can divide T3 into 3 slices
Cyclic Schedule
For constructing a cyclic schedule, we must make decisions:
1. choosing a frame size
2. partitioning jobs into slices
3. placing slices in the frames

In general, these decisions cannot be made independently

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

In contrast, feasible schedules may exist if we choose smaller job slices


Cyclic Executives
Now we will modify our previously discussed scheduler to support cyclic scheduling

Cyclic executive is a table-driven cyclic scheduler for all types of jobs in a


multithreaded system

The new table will look like this

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

P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4

Can schedule aperiodic tasks here


Cyclic Executives Pseudocode
Input: Stored schedule: L(k) for k = 0, 1, . . . , F − 1;
Aperiodic job queue
Task CYCLIC EXECUTIVE:
the current time t = 0;
the current frame k = 0;
do forever
accept clock interrupt at time tf;
currentBlock = L(k);
t = t + 1;
k = t mod F;//F number of frames in a major cycle
sleep until the periodic task server completes;
while the aperiodic job queue is nonempty;
wake up the job at the head of the aperiodic job queue;
sleep until the aperiodic job completes;
remove the aperiodic job from the queue;
endwhile;
sleep until the next clock interrupt;
enddo;
end CYCLIC EXECUTIVE
Cyclic Executives
In addition to scheduling, the cyclic executive also checks for overruns at the
beginning of each frame
If the last job executed in the previous frame is not complete at that time, the cyclic
executive preempts the execution of the job if the last job is an aperiodic job
The job remains in the aperiodic job queue and will be resumed whenever there is
time again for aperiodic jobs
If the cyclic executive finds the periodic task still executing at the time of a clock
interrupt, a frame overrun occurs  some slice(s) scheduled in the previous frame
has executed longer than the time allocated to it by the precomputed cyclic schedule
The cyclic executive takes an appropriate action to recover from this frame overrun
Scheduling Aperiodic Tasks
Till now we were not giving much importance to aperiodic tasks

P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4

Can schedule aperiodic tasks here

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)

P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4

Slack is 1 for this frame Slack is 1 for this frame

P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4


0.5 1
A
A2
1

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

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4

Response time for A1 = 11.5-6.5 = 5


Response time for A2 = 15.5-8.1 = 6.4
Average response time = (5+6.4)/2 = 5.7
A2 is preempted here
With Slack Stealing

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

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4

Response time for A1 = 8.5-6.5 = 2


Response time for A2 = 12.5-8.1 = 4.4
Average response time = (2+4.4)/2 = 3.2
A2 is preempted here
Slack Stealing

P1 T 1 T2 T3,1 T1 T3,2 T1 T2 T1 T2 T1 T2 T3,3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4


0.5 0.5
A A
1 2
6.5 12.5

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

Frame 0 Frame 1 Frame 2 Frame 3 Frame 4

Response time for A1 = 8.5-6.5 = 2


Response time for A2 = 13.5-12.5 = 1
Average response time = (2+1)/2 = 1.5
Scheduling Sporadic Jobs
Sporadic jobs have hard deadlines

Their release times are unknown a priori

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

Scheduler can maintain a database with this info

We also assume all sporadic jobs are preemptable

At the beginning of frame t, acceptable test is done on sporadic job S(d,e)

Assume d(S) is in the frame l+1 and l  t  job should be scheduled in l th


or earlier
frames

Job can be scheduled only if


σc(t, l)  e
EDF Scheduling of Accepted Jobs
The accepted sporadic jobs are initially kept in an edf queue

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
S1(17,4.5)

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
S1(17,4.5) Total slack = 4 < 4.5 (e) hence rejected!!

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
S2(19,4)

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
S2(29,4) Total slack = 5.5 > 4 (e) accept

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


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 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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
S3(22,1.5)

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
slack = 2 > 1.5 (e)
S3(22,1.5)

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
If S is accepted, slack 3
for S2 = 2= (remaining
S3(22,1.5) exec time)

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
Accept S3

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
S3 finished remove
from Q

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
Slack = 1

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
If S+ is scheduled, available slack for S2 =0 <
1, remaining execution time. Reject S4

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs
Remove S2 from queue

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


EDF Scheduling of Accepted Jobs

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

Frame 5 Frame 6 Frame 7 Frame 8 Frame 9

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

Frame 10 Frame 11 Frame 12 Frame 13 Frame 14


Optimality of Cyclic EDF Algorithm
The cyclic EDF algorithm for scheduling sporadic jobs is an on-line algorithm

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

The advantage of the interrupt-driven alternative is outweighed with the possibility


of delayed execution of periodic job slices due to context switching
Handling Frame Overruns
A frame overrun can occur for many reasons
 When execution time is input data dependent and an unexpected combination of
input arrives
 Transient hardware fault
 Software flow

Easiest way is to terminate the job prematurely at the beginning of next frame and
log that info.

If necessary some recovery mechanism can handle it later

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

There is no need for concurrency control

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

Context switching and communication overhead can be kept low by choosing


appropriate frame size and job slices
Disadvantages Of Clock-Driven Scheduling
The release times of all jobs must be fixed

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

You might also like