lecture04e
lecture04e
Slides from
Dr Colin Perkins
Real-Time and Embedded Systems
University of Glasgow
1
Lecture Outline
• Assumptions and notation for clock-driven scheduling
• Handling periodic jobs
– Static, clock-driven schedules and the cyclic executive
• Handling aperiodic jobs
– Slack stealing
• Handling sporadic jobs
• Advantages and disadvantages of clock driven scheduling
Clock-Driven Scheduling 2
Assumptions
• Clock-driven scheduling applicable to deterministic systems
• A restricted periodic task model:
– The parameters of all periodic tasks are known a priori
– For each mode of operation, system has a fixed number, n, periodic tasks
• For task Ti each job Ji,k is ready for execution at its release time ri,k and is
released pi units of time after the previous job in Ti such that ri,k = ri,k-1 + pi
• Variations in the inter-release times of jobs in a periodic task are negligible
T2 = (10, 3, 6) ⇒ ϕ2 = 0 p2 = 10 e2 = 3 D2 = 6
J1,1 released at 0, deadline 6
J1,2 released at 10, deadline 16
…
T3 = (10, 3) ⇒ ϕ3 = 0 p3 = 10 e3 = 3 D3 = 10
J1,1 released at 0, deadline 10
J1,2 released at 10, deadline 20
…
Clock-Driven Scheduling 4
Static, Clock-driven Cyclic Scheduler
• Since the parameters of all jobs with hard deadlines are known
can construct a static cyclic schedule in advance
– Processor time allocated to a job equals its maximum execution time
– Scheduler dispatches jobs according to the static schedule, repeating each
hyperperiod
– Static schedule guarantees that each job completes by its deadline
• No job overruns ⇒ all deadlines are met
Feasible intervals
Execution times T1 T3 T2 T1 T4 T2 T1 T2 T1 T1 T2 T1
0 4 8 12 16 20
Clock-Driven Scheduling 7
Implementing a Cyclic Scheduler
Input: stored schedule (tk, T(tk)) for k = 0, 1, n – 1.
Task SCHEDULER:
set the next decision point i = 0 and table entry k = 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;
set the timer to expire at [i / n] * H + tk;
if the current task T is I,
let the job at the head of the aperiodic queue execute;
else
let the task T execute;
sleep;
end do.
End SCHEDULER.
Clock-Driven Scheduling 8
Structured Cyclic Schedules
• Arbitrary table-driven cyclic schedules flexible, but inefficient
– Relies on accurate timer interrupts, based on execution times of tasks
– High scheduling overhead
• Easier to implement if structure imposed:
– Make scheduling decisions at periodic intervals (frames) of length f
– Execute a fixed list of jobs with each frame, disallowing pre-emption
except at frame boundaries
– Require phase of each periodic task to be a non-negative integer multiple
of the frame size
• The first job of every task is released at the beginning of a frame
• ϕ = k⋅f where k is a non-negative integer
• Gives two benefits:
– Scheduler can easily check for overruns and missed deadlines at the end of
each frame
– Can use a periodic clock interrupt, rather than programmable timer
Clock-Driven Scheduling 9
Frame Size Constraints
• How to choose frame length?
– To avoid preemption, want jobs to start and complete execution within a
single frame:
Feasible intervals
Execution times T1 T3 T2 T1 T4 T2 T1 T2 T1 T1 T2 T1
0 2 4 6 8 10 12 14 16 18 20
Clock-Driven Scheduling 11
Job Slices
• Sometimes, a system cannot meet all three frame size constraints
simultaneously
• Can often solve by partitioning a job with large execution time
into slices (sub-jobs) with shorter execution times/deadlines
– Gives the effect of preempting the large job, so allow other jobs to run
– Sometimes need to partition jobs into more slices than required by the
frame size constraints, to yield a feasible schedule
• Example:
– Consider a system with T1 = (4, 1), T2 = (5, 2, 7), T3 = (20, 5)
– Cannot satisfy constraints: Eq.1 ⇒ f ≥ 5 but Eq.3 ⇒ f ≤ 4
– Solve by splitting T3 into T3,1 = (20, 1), T3,2 = (20, 3) and T3,3 = (20,1)
Copyright © 2006 University of Glasgow
Clock-Driven Scheduling 12
Building a Structured Cyclic Schedule
• To construct a cyclic schedule, we need to make three kinds of
design decisions:
– Choose a frame size based on constraints
– Partition jobs into slices
– Place slices in frames
• These decisions cannot be taken independently:
– Ideally want as few slices as possible, but may be forced to use more to get
a feasible schedule
Clock-Driven Scheduling 13
Implementation: A Cyclic Executive
• Modify previous table-driven cyclic scheduler to be frame based,
schedule all types of jobs in a multi-threaded system
• Table that drives the scheduler has F entries, where F = H
f
– Each corresponding entry L(k) lists the names of the job slices that are
scheduled to execute in frame k; called a scheduling block
– Each job slice implemented by a procedure, to be called in turn
• Cyclic executive executed by the clock interrupt that signals the
start of a frame:
– Determines the appropriate scheduling block for this frame
– Executes the jobs in the scheduling block in order
– Starts job at head of the aperiodic job queue running for remainder of
frame
• Less overhead than pure table driven cyclic scheduler, since only
interrupted on frame boundaries, rather than on each job
Clock-Driven Scheduling 14
Scheduling Aperiodic Jobs
Clock-Driven Scheduling 15
Scheduling Aperiodic Jobs: Slack Stealing
• Inflexible
– Pre-compilation of knowledge into scheduling tables means that if
anything changes materially, have to redo the table generation
– Best suited for systems which are rarely modified once built
• Other disadvantages:
– Release times of all jobs must be fixed
– All possible combinations of periodic tasks that can execute at the same
time must be known a priori, so that the combined schedule can be pre-
computed
– The treatment of aperiodic jobs is very primitive
• Unlikely to yield acceptable response times if a significant amount of soft real-
time computation exists
Clock-Driven Scheduling 20
Summary
• We have discussed:
– Static, clock-driven schedules and the cyclic executive
– Handling aperiodic jobs
• Slack stealing
– Handling sporadic jobs
– Advantages and disadvantages of clock driven scheduling
• Clock-driven scheduling applicable to static systems, small number of
aperiodic jobs
• The next lecture begins our study of priority scheduling for more
dynamic environments
Clock-Driven Scheduling 21