engg4420 chapter 4 lecture 2 - university of guelph

19
CLOCKDRIVEN SCHEDULING Scheduling points are determined by timer interrupts Clock driven schedulers make their scheduling decisions regarding which task to run next, only at the clock interrupt points Clockdriven schedulers are also called offline schedulers because these schedulers fix the schedule before the system starts to run (predetermines which task will run when). These schedulers incur very little run time overhead The exact time of occurrence of these tasks cannot be predicted. SHORTCOMING OF THIS CLASS OF SCHEDULERS is that they cannot satisfactorily handle aperiodic and sporadic tasks As a result, these schedulers are also called static schedulers. IMORTANT CLOCKDRIVEN SCHEDULERS ARE: Tabledriven 1) Cyclic schedulers 2) ENGG4420 CHAPTER 4 LECTURE 2 November1212 8:51 PM CHAPTER 4 By Radu Muresan University of Guelph Page 1

Upload: others

Post on 03-Dec-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

CLOCK‐DRIVEN SCHEDULING

Scheduling points are determined by timer interrupts

Clock driven schedulers make their scheduling decisions regarding which task to run next, only at the clock interrupt points

Clock‐driven schedulers are also called off‐line schedulers because these schedulers fix the schedule before the system starts to run (predetermines which task will run when).

These schedulers incur very little run time overhead•

The exact time of occurrence of these tasks cannot be predicted. 

SHORTCOMING OF THIS CLASS OF SCHEDULERS  is that they cannot satisfactorily handle aperiodic and sporadic tasks 

As a result, these schedulers are also called static schedulers.

IMORTANT CLOCK‐DRIVEN SCHEDULERS ARE:Table‐driven 1)Cyclic schedulers2)

ENGG4420 ‐ CHAPTER 4 ‐ LECTURE 2November‐12‐128:51 PM

CHAPTER 4 By Radu Muresan University of Guelph Page 1

Page 2: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

TABLE DRIVEN SCHEDULING

Table‐driven schedulers usually precompute which task would run and when and store this schedule in a table at the time the system is designed or configured.The application programmer can be given the freedom to select his own schedule for the set of tasks in the application and store the schedule in a table called schedule table to be used by the scheduler at the run time.

An important question for this type of scheduler is what would be the SIZE OF THE SCHEDULE TABLE that would be required for a given set of tasks in system ?

CHAPTER 4 By Radu Muresan University of Guelph Page 2

Page 3: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

THE SIZE OF THE SCHEDULE TABLE

Given a set of n tasks ST = {Ti}, then the entries in the schedule table will replicate themselves after the major cycle of the set ST.

The major cycle of the set ST is the Least Common Multiple of the periods of all the tasks in ST: LCM(p1, p2, ..., pn), where p1, p2, ..., pn are the periods of T1, T2, ..., Tn.

For any given task set it is sufficient to store the entries only for LCM(p1, p2, ..., pn) duration in the schedule table.

DEFINITION: a major cycle of a set of tasks is an interval of time on the time line such that in each major cycle, the different tasks recur identically.

The above reasoning assumed that all tasks are in phase meaning that Φi = 0.

CHAPTER 4 By Radu Muresan University of Guelph Page 3

Page 4: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

THEOREM: The major cycle of a set of tasks ST = {T1, T2, ..., Tn) is LCM{p1, p2, ..., pn} even when the tasks have arbitrary phasing.PROOF. Let's assume that the occurrences of a task Ti in a major cycle are as shown below.

In figure above there are k‐1 occurrences of the task Ti in the major cycle M.

The first occurrence of Ti starts at φ•The major cycle M ends x time units after the last occurrence of Ti (i.e., Ti(k‐1)).

Of course this scenario must be the same in all major cycles.•

M = (k‐1)*pi + φ + x;                      (1)○

Inspecting the figure above we can conclude that for a task to repeat identically in each major cycle we need to have:

M = (k ‐ 1)*pi + pi = k*pi;               (2)○

Now, for the task Ti to have identical occurrence times in each major cycle, φ + x must equal to pi. Substituting this in Eq. (1) we get:

As a result of (2) M contains an integral multiple of pi and this argument holds for each task in the set.

THEREFORE, M = LCM({p1, p2, ..., pn}).•

CHAPTER 4 By Radu Muresan University of Guelph Page 4

Page 5: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

CYCLIC SCHEDULERS

Many small embedded applications are based on cyclic schedulers that are simple, efficient, and easy to program. For example a temperature controller within a computer controlled air conditioner.

Each task in the task set to be scheduled repeats identically in every major cycle.

The major cycle is divided into one or more minor cycles and each minor cycle is called a frame.

THE SCHEDULING POINTS of a cyclic scheduler occur at frame boundaries. As a result, a task can start executing only at the beginning of a frame.

The frame boundaries are defined through interrupts generated by a periodic timer.

Each tasks is assigned to run in one or more frames○The assignment of tasks to frames is stored in a schedule table.○

A cyclic scheduler repeats a precomputed schedule that is stored for one major cycle.

CHAPTER 4 By Radu Muresan University of Guelph Page 5

Page 6: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

SELECTING THE SIZE OF THE FRAME

The size of the frame to be used by the scheduler is an important design parameter and needs to be chosen carefully. 

Minimum context switching1)Minimization of table size2)Satisfaction of task deadline3)

A frame size should satisfy the following 3 constraints:•

MINIMUM CONTEXT SWITCHINGThis constraint aims to minimize the number of context switching during task execution. As a result, a task should complete running within its assigned frame. Otherwise the task might have to be suspended and restarted in a later frame.

To avoid unnecessary context switches, the selected frame size should be larger than the execution time of each task.

FORMALLY the constraint is:                   max ({ei}) ≤ F                        (1)Where, ei is the execution time of the task Ti, and F is the frame size.Note that this constraint imposes a lower‐bound on frame size, i.e., the frame size F must not be smaller than max ({ei}).

CHAPTER 4 By Radu Muresan University of Guelph Page 6

Page 7: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

MINIMIZATION OF TABLE SIZE

The constraint 2 requires that the number of entries in the schedule table should be minimized in order to reduce the storage requirements.

No fractional minor cycles in M so we don't need to store the table for more than one M

Minimization of the number of entries to be stored in the schedule table can be achieved when the minor cycle F squarely divides the major cycle M.

CHAPTER 4 By Radu Muresan University of Guelph Page 7

Page 8: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

SATISFACTION OF TASK DEADLINE

Constraint 3 imposes that between the arrival of a task and its deadline, there must exist at least one full frame ‐ this constraint arises from the fact that a task can only be taken up for scheduling at the start of a frame.

If between the arrival and completion of a task not even one frame exists, a situation as shown in figure above might arise ‐‐ in this case the task arrives a little after the kth frame and can't be taken for scheduling until frame (k+1).

However, if the execution time e of T is greater than x then T misses its deadline.

We therefore, need a full frame to exist between the arrival of a task and its deadline.

CHAPTER 4 By Radu Muresan University of Guelph Page 8

Page 9: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

THE FORMULATION OF CONSTRAINT 3

Assume that a single frame is sufficient to complete T•

2F ‐ Δt ≤ d; or 2F ≤ Δt + d○The worst case scenario for a task to meet its deadline occurs for its instance that has the minimum separation from the start of frame (in this case the task would have to wait the longest before its execution can start)

The determination of the minimum separation value (i.e., min(Δt) for a task among all instances of the task would help in determining a feasible frame size.

The task can complete before its deadline if:•

Next theorem shows that min(Δt) = GCD(F, pi); =>•

Here GCD is the greatest common multiple.•

CHAPTER 4 By Radu Muresan University of Guelph Page 9

Page 10: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

THEOREM ‐MINIMUM SEPARATION

THEOREM. The minimum separation of the task arrival from the corresponding frame start time (min(Δt)) considering all instances of a task Ti is equal to GCD(F, pi). (GCD means greatest common divisor)

PROOF: Let g = GCD(F, pi) => g must divide squarely F and pi;Let Ti be a task with 0 phasing;Assume that the Theorem is violated for certain integers m and n, such that Ti(n) occurs in the mth

frame and the difference between the start time of mth frame and the arrival of nth instance of the task Ti is less than g;That is,

We proved that the minimum separation can't be smaller than GCD(F, pi).

CHAPTER 4 By Radu Muresan University of Guelph Page 10

Page 11: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

SELECTING A FRAME SIZE

For a given task set it is possible that more than one frame size satisfies all the 3 constraints. In such cases, it is better to choose the shortest frame size. This is because the schedulability of a task set increases as more number of frames become available in a major cycle.

A suitable frame size for a task set does not assure a feasible schedule for the task set. It may so happen that there are not enough number of frames available in a major cycle to be assigned to all the task instances.

Next we show 2 examples. In Example 1 we can find a suitable frame size that satisfies all 3 constraints.

In such cases, to find a feasible frame size we might have to split the task (or a few tasks) that is (are) causing the violation of the constraints into smaller sub‐tasks that can be scheduled in different frames.

It is difficult to come up with a set of guidelines to identify the exact task that is to be split, and the parts into which it needs to be split. This can therefore be done by trial and error.

However, it is possible that a suitable frame size may not exist for many problems (Example 2):

CHAPTER 4 By Radu Muresan University of Guelph Page 11

Page 12: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

EXAMPLE 1

A cyclic scheduler is to be used to run the following set of periodic tasks on a uniprocessor: T1:(4, 1); T2:(5, 1); T3:(20, 1); T4:(20, 1.5).

Select an appropriate frame size.SOLUTION. For the given task set, an appropriate frame size is the one that satisfies all the 3 required constraints. Below we determine a suitable frame size F that satisfies all 3 constraints.Constraint 1. Let F be an appropriate frame size, then max {1, 1, 1, 1.5} ≤ F. From this constraint F ≥ 1.5;

1.

Constraint 2. The major cycle M for the given task set is given by M = LCM(4, 5, 20, 20) = 20. M should be an integral multiple of the frame size F, i.e., M mod F = 0. This consideration implies that    ∈ 2, 4, 5, 10, 20 . Note: Frame size of 1 has been ruled out since it would violate the constraint 1. 

2.

Constraint 3. To satisfy this constraint, we need to check whether a selected frame size F satisfies the inequality: 2F ‐ GCD(F, pi) ≤ di; for each pi.

3.

Next page shows the calculations for Constraint 3.

CHAPTER 4 By Radu Muresan University of Guelph Page 12

Page 13: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

CHAPTER 4 By Radu Muresan University of Guelph Page 13

Page 14: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

EXAMPLE 2

Consider the following set of periodic real‐time tasks to be scheduled by a cyclic scheduler:T1:(4, 1); T2:(5, 2); T3:(20, 5).

Determine the frame size for the task set.SOLUTION. Using Constraint 1 => F ≥ 5;Using Constraint 2 => M = LCM(4, 5, 20) = 20As a result the set of values for F is {5, 10, 20}.

To overcome this problem, we need to split the task that is making the task set unschedulable;

It is easy to observe that task T3 has the largest execution time, and consequently due to Constraint 1 makes the feasible frame size quite large.

T3,1 = (20, 1, 20); T3,2 = (20, 2, 20); T3,3 = (20, 2, 20).

We try to split T3 into 3 sub‐tasks. After splitting T3 into 3 tasks, we have:

Now the new possible values of F are 2 and 4. We can check that after splitting the tasks, F = 2 and F = 4 are feasible frame sizes ‐‐ we pick the smallest one.

Checking for a frame size that satisfies Constraint 3, we can find that no value of F is suitable. 

CHAPTER 4 By Radu Muresan University of Guelph Page 14

Page 15: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

ALGORITHM FOR CONSTRUCTING STATIC SCHEDULES

The INF algorithm iteratively tries to find a feasible cyclic schedule of the system for a possible frame size at a time, starting from the largest possible frame size in order of decreasing frame sizes. 

A feasible schedule thus found tells us how to decompose some tasks into subtasks if their decomposition is necessary. 

If the algorithm fails to find a feasible schedule after all the possible frame sizes have been tried, the given tasks do not have a feasible cyclic schedule that satisfies the frame size constraints even when tasks can be decomposed into subtasks.

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan82

Scheduling Independent Preemptable Tasks; The Iterative Network-Flow (INF) Algorithm

The general problem of choosing minor frame length for a given set of periodic tasks, segmenting the tasks if necessary, and scheduling the tasks that meet all their deadlines is NP-hard

Step 1: Find all possible frame sizes of the system that meet the frame size constrains 2 and 3 but not necessarily constraint 1;

Step 2: Apply INF algorithm starting with the largest possible frame;

The INF algorithm iteratively tries to find a feasible cyclic schedule of the system for a possible frame size at a time, starting with the largest value Example that meets constraints (2) and (3) but not 1

T1=(4,1); T2=(5,2,7) and T3=(20,5) Frame sizes: 2 and 4

CHAPTER 4 By Radu Muresan University of Guelph Page 15

Page 16: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan83

Network-Flow Graph The algorithm used in

each iteration is based on the network-flow formulation of the preemptive scheduling problem

In this formulation we ignore the tasks to

which the jobs belong we name the jobs in a

major cycle of F frames as J1, J2, ..., JN

the constraints are represented by a graph

The graph contains the following vertices, edges Job vertex Ji, i=1, ..., N Frame vertex j, j=1,..., F Vertices source and sink Edges (Ji,j) if job Ji can be

scheduled in frame j edge capacity = f

Edges from source to every job vertex Ji edge capacity = ei

Edges from every frame vertex to the sink edge capacity = f

J1, J2, ..., JN is an enumeration of all tasks instances that need to be scheduled in the major cycle M that contains F frames.

Here a job can be understood as an instance of a task.•

CHAPTER 4 By Radu Muresan University of Guelph Page 16

Page 17: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan84

Network Flow Graph Algorithm

A flow of an edge is a positive number that satisfies the following constraints: < the edge capacity

∑(flow into vertexes) = ∑(flow out)

Flow of a network-flow graph = ∑(all flows into the sink)

Problem: Find the maximum flow of network-flow graph

J1 J2 JN

1 2 3 F

Jobs/Major cycle

Frames/Major cycle

source

(ei), ei

Ji(f), h x

(f), h

(f), ei+ek-h

sink

(f), 0. . .

F

z(f), 0

Jk(ek), ek

(f), ek

(f) ei-h

y

(f), 0

Jobs Frames

A flow of an edge is a nonnegative number that satisfies the following two constraints: 

(1) It is no greater than the capacity of the edge and (2) with the exception of the source and sink, the sum of the flows of all the edges into every vertex is equal to the sum of the flows of all the edges out of the vertex. This slide shows part of a network‐flow graph. The label “(capacity), flow” of each edge gives its capacity and flow. This graph indicates that job Ji can be scheduled in frames x and y and the job Jk can be scheduled in frames y and z. 

A flow of a network‐flow graph, or simply a flow, is the sum of the flows of all the edges from the source and it should equal to the sum of the flows of all the edges into the sink. 

There are many algorithms for finding the maximum flows of network‐flow graphs. The time complexity of the straightforward ones is O((N+F)^3). 

CHAPTER 4 By Radu Muresan University of Guelph Page 17

Page 18: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan85

Maximum Flow and Feasible Preemptive Schedule

The flow of an edge (Ji,j) gives the amount of time in frame j allocated to job Ji

The maximum flow ≤ ∑ (all job times per major cycle)

The set of flows of edges from job vertices to frame vertices that gives the maximum flow represents a feasible preemptive schedule of the jobs in the frame

source

J1+4

J1+2

J1+3

J1+1

J1+5

J2+1

J2+2

J2+3

J2+4

J3+1

(1),1

(1),1

(1),1

(1),1

(1),1

(2), 2

(2), 2

(2), 2

(2), 2

(2), 2

(4),1

(4),1

(4),1

(4),1

(4),2

(4),2

(4),1

(4),1

(4),2

(4),4

(4),4

(4),4

(4),3

(4),3

(4),2

(4),0

(4),3

(4),0

2

3

4

5

(4),2

1

sink

Clearly, the maximum flow of a network‐flow graph defined above is at most equal to the sum of the execution times of all the jobs to be scheduled in a major cycle. 

The set of flows of edges from job vertices to frame vertices that gives this maximum flow represents a feasible preemptible schedule of the jobs in the frames. Specifically, the flow of an edge (Ji, j) from a job vertex Ji to a frame vertex j gives the amount of time in frame j allocated to job Ji. 

This figure considers the previous example with tasks T1, T2, and T3. The possible frame sizes that satisfy Constraints 2 and 3 are f= 4 and 2. The network‐flow graph used in the first iteration when f=4 is shown in this figure. 

We want every job to be scheduled in a frame which begins no sooner than its release time and ends no later than its deadline. This is reason for the edges from the job vertices to the frame vertices. 

The maximum flow of this graph is 18, which is the total execution time of all the jobs in a hyperperiod. Hence, the flows of edges from the job vertices to the frame vertices represent a schedule of the tasks.

It is possible that the maximum flow of a network‐flow graph is less than the sum of the execution times of all N jobs. This fact indicates that the given tasks have no feasible schedule with the frame size used to generate the graph.

CHAPTER 4 By Radu Muresan University of Guelph Page 18

Page 19: ENGG4420 CHAPTER 4 LECTURE 2 - University of Guelph

WORK PAGE EXAMPLE

CHAPTER 4 By Radu Muresan University of Guelph Page 19