Presentation is loading. Please wait.

Presentation is loading. Please wait.

BFair: An Optimal Scheduler for Periodic Real-Time Tasks

Similar presentations


Presentation on theme: "BFair: An Optimal Scheduler for Periodic Real-Time Tasks"— Presentation transcript:

1 BFair: An Optimal Scheduler for Periodic Real-Time Tasks
Hang Su The University of Texas at San Antonio September 14, 2011 1

2 Roadmap of This Talk Introduction
Task and system models Traditional scheduling algorithms Performance and utilization bound comparisons Boundary fair (Bfair) scheduler for periodic tasks Scheduling decision at deadline boundary time of tasks Simulation and Discussions Reference 2 2

3 System Models Periodic task model: task Ti :
Worst case execution time (WCET) ci Period (relative/implicit deadline) pi Utilization ui = ci / pi ; U = Σ ui is system utilization p 2p time WCET: c WCET: c 3

4 Multiprocessor Real-Time Systems
Given number of processors: m A set of real-time tasks: Ti (ci, pi); i = 1,…n The scheduling problem: when and where to execute which task to meet all timing constraints? Objectives to consider System utilization: U<= m Scheduling overhead: scheduling decision points, preemption (context switch) points, and task migrations . Finish task well before its deadline does not lead to more system values. Just before the deadline is ok … 4 4

5 Scheduling Algorithms on Single Processor
EDF (Earliest Deadline First) Priority Assignment Policy: Always assign highest priority to the task with earliest deadline Utilization upper bound : 1 U<= 1 Example: T1=(1, 3), T2=(3, 5) (U= 1/3+3/5=14/15) T11 T12 T12 T12 T21 1 2 3 4 5 6 10 time

6 Always assign highest priority to the task with smallest period
Scheduling Algorithms on Single Processor RMS ( rate-monotonic [1] ) C.L. Liu 73' Utilization bound: n(21/n-1) Priority Assignment policy: Always assign highest priority to the task with smallest period

7 Scheduling Algorithm on Single Processor
Example(RMS): T1=(1, 3), T2=(3, 5) (U= 1/3+3/5=14/15) n(21/n-1) 1*(21/1 - 1 ) = 1 (n=1 ) 2*(21/2 – 1 ) = 2*( ) = (n=2) U= 1/3+3/5=14/15 = > 0.828 T11 T12 T12 T21 T12 T22 T31 T22 T22 T41 T32 T32 T22 T51 T32 IDLE 1 2 3 4 5 6 7 8 9 10 11 12 12 13 14 15

8 Traditional Approaches and Problems
Partitioned scheduling A subset of tasks  one processor; problem reduced to single processor scheduling (e.g., EDF or RMS) Semi-partitioned: most tasks have fixed assignment to processors, a few tasks may migrate between processors better utilization Global scheduling Single global queue: free processor fetch next highest priority task in the queue Global EDF and RMS  low system utilization 8

9 Pfair: Proportional Fair Scheduler
Proportional Fair Scheduler: Sanjoy Make progress fairly Fully utilized on multiple processors Proportional progress Allocation for task Ti before time t: x Allocation error: lagi = ui* t – x Fair for task Ti at time t if | lagi | < 1  x is either ui* t or ui* t For a general task set, the optimal algorithm, PF stands for proportional fairness, was proposed in The PF algorithm requires proportional progress for tasks at any time, that is, at any time t, a task Ti either get this amount or this amount of units and the absolute allocation error is restricted within one time unit. It also ensure that every task can meet its deadline. PF is optimal in the sense that it can achieve full system utilization. Following the same idea, some algorithms have been proposed to either increase the efficiency of each scheduling point, to consider asynchronous tasks or to incorporate sporadic tasks. <click> But, all of these algorithms need to make scheduling decision at every time unit. <click> 9 9

10 Pfair: Proportional Fair Scheduler
Variations of Pfair algorithms PD [Baruah’95] in [2] PD2 [Anderson’01] in [4][5] ER-fair [Anderson’00] in [3]

11 An Example T1=(1, 3), T2=(2, 5), T3=(2, 5), T4=(2, 3), T5=(1, 5)
m=U=wi =2, LCM = 15; 2 1 3 4 5 6 7 8 10 9 11 12 13 14 15 P2 P1 PF schedule 15 scheduling points 27 preemptions Now, lets look at an example first. Here we have 5 tasks. It is easy to see that the total utilization is 2 and we assume there are 2 resources. The least common multiple, that is LCM of this task set is 15 and because of the periodicity of the problem, in the following, we only consider the schedule from 0 to LCM. <click> Assuming the first task instance for each task arrives at time 0, following the PF algorithm, we can get the PF schedule as shown here. As I already mentioned, the PF algorithm needs to make scheduling decision at every time unit and thus we will have 15 scheduling points. From the schedule, we can see that there are 27 context switches in total. Only at time 3 and 6, 7 on second resource do not need a context switch. Can we do better? If we look from a different point of view. <click> Notice that, the red dotted lines are periodic boundaries of all tasks. <click> and tasks will claim to miss its deadline only at a boundary time. For example, no task will says: “I miss my deadline at time 2” since time 2 is not a period boundary at all. Following this motivation, we propose a new scheduling idea <click> Deadline miss only happens at periodic boundaries ! 11 11

12 Boundary Fair: A new approach
Dakai Zhu Idea Schedule ONLY at boundaries Boundary time bk = a * pi , b0=0, bi < bi+1 ; Allocate resources to tasks for the time units within two consecutive boundaries Maintain fairness at boundary time bk (Bfair) Ti get either ui* bk  or ui* bk  Two-step allocation Mandatory units to keep fairness Optional units for future urgent tasks That is, B-Fair, which is Boundary-Fair. The idea is to make scheduling decision only at period boundary, that is, the algorithm will allocate resources to tasks for the time units within two consecutive boundaries. To make sure that every task will finish before their deadline, we maintain fairness at the boundary time. For example, at time bk, a task Ti either get this amount or this amount of units. It is where B-fair comes from. The algorithm will be a two-step allocation. Since we allocate bulk time units together, each task may have some mandatory units need to be allocated to keep the fairness at the next boundary. All mandatory units allocation, the remaining time units will be allocate to future urgent tasks. First, let see why we need a two-step allocation. <click> 12 12

13 The Example: Bfair Schedule
T1=(1, 3), T2=(2, 5), T3=(2, 5), T4=(2, 3), T5=(1, 5) At boundary time 0: allocate [0  3) T T2 T3 T4 T5 Demand /5 6/ /5 Mandatory pending / / /5 Tasks T2, T3,T5 are eligible for the optional unit ? Go back to this example, we see that the red dotted lines are periodic boundaries for the task set. At boundary time 0, we want to allocate the time units between time 0 and time 3. Here time 3 is is the next periodic boundary. <click> For the tasks, the work demand during this period will be 1 for task 1 6/5 for task 2 etc. <click> That is, at least we need to allocate 1 unit to task 1, 2 and 3 and 2 units to task 4 to ensure the fairness for them at time 3. After the mandatory units allocation, <click> Task 2 and 3 will have 1/5 unit work pending and task 5 has 3/5 unit pending. Notice that there are 6 units in total to be allocated and we have allocated 5 units as mandatory units. There will be 1 optional unit left. <click> Here, task 2, 3 and 5 are all eligible for this optional unit. Which one should we allocate to? From P-fair scheduling, we have known that an incorrect allocation will lead to a deadline miss in the future. To pick the appropriate task for the optional unit, we will define dynamic priorities for them as discussed below. <click> P1 P2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 13 13

14 Algorithm for Bfair Scheduler
Define a set of boundaries: {b0, …, bL} bk < bk+1; b0 = 0, bL = LCM; k, Ti, bk is a multiple of pi; At bk, we allocate [bk , bk+1) Remaining work for Ti before bk RWik = wi* bk – allocated units for Ti Mandatory units: mik = max{ 0, RWik + wi*(bk+1 – bk) } Optional units if: m*(bk+1 – bk) >  mik Here is the formal presentation of the BF algorithm. We first define a set of boundary time points. These time points will be periodic boundaries for the tasks considered. They are all different and in an increasing order. The first one is at time 0, that is, we consider the synchronized tasks; and the last one is at time LCM. As I have mentioned, due to periodicity of the problem, we only consider a schedule within the LCM. At a boundary time bk, we will allocate the time units between bk and bk+1. Before the allocation, the remaining work for a task Ti is defined as the difference between its work demond and the actual allocation before bk. Notice that, the remaining work could be negative when a tasks allocation units is more then its work demand, that is, when it is over-allocated. Together with its remaining work and the work demand during this period, task Ti will have some mandatory to be allocated. As I said, the remaining work could be negative; and it is also possible that the work demand during current time period can not balance the over-allocation, and this part is still negative. Since we can not allocate minus 1 unit to a task, the mandatory unit allocated to task Ti will be maximum between 0 and this number. After the mandatory unit allocation, if the total time units to be allocated is bigger than the summation of all mandatory units, we will have some optional units to be allocated. <click> 14 14

15 Algorithm for Bfair Scheduler (cont.)
Eligible tasks Pending work:PWik=RWik + wi*(bk+1 – bk) - mik > 0 Not fully allocated: mik < bk+1 – bk Dynamic priority: urgency of future Character string: idea from P-fair [Baruah’96] k(Ti) = sign[bk+1*wi – bk*wi – (bk+1- bk)] (Ti, k) = k+1(Ti), …,  k+s(Ti) Minimum s such that k+s(Ti)  ‘+’ Time Factor (TF) if k+s(Ti) = ‘–’ First, which task is eligible to compete for the optional unit? The eligible tasks are the tasks that have pending work bigger than 0 and are not fully allocated. For the eligible tasks, we define dynamic priority, which is urgency indicator of the future. In general, it consists of two parts: a character string and a time factor. The character string is defined following the idea from P-fair. It shows which task requires full allocation in the future and is most likely to miss its deadline if the task does not get one optional unit. Notice that, the character string is defined at boundary time point and it ends with a character that is not equal to a ‘+’, which is different from P-fair. In P-fair, the last character in the character string must be a ‘0’. So, the length of this character string is much shorter than that of P-fair. If the last character is a ‘-’, the time factor is defined for the task as this equation shows. It indicates how much time one task need to collect enough work to balance the possible over-allocation at boundary time bk+s. A smaller number means more urgent. After we calculate the character string and the time factors for eligible tasks <click> 15 15

16 Algorithm for Bfair Scheduler (cont.)
For eligible tasks Ti and Tj Compare (Ti, k) and (Ti, k) Character by character: ‘+’ > ‘0’ > ‘–’ Bigger string has higher priority If tie and last character is ‘0’: arbitrary If tie and last character is ‘–’ Compare time factor (TF) smaller time factor has higher priority If tie again: arbitrary, e.g., smaller index High priority tasks get one optional unit each The priority comparison shows here. We first compare two eligible tasks’ character string in the alphabetical order, here, we have +>0>-. The bigger character string has the higher priority. It they are equal and the last character is 0, the tie can be break arbitrarily. If the last one is ‘- ’, we need to compare the tasks’ time factor. As I said a smaller number will have higher priority. Again, if they are equal, we can break the tie arbitrarily. For example, in this work, we give the higher priority to the task that has smaller index. Then, the high priority tasks will get one optional unit each. As discussed, the pending work of eligible task is bigger than 0, but is smaller than 1, so each eligible task can get one optional unit. <click> 16 16

17 The Example: Bfair Schedule (cont.)
T1=(1, 3), T2=(2, 5), T3=(2, 5), T4=(2, 3), T5=(1, 5) T T2 T3 T4 T5 Mandatory pending / / /5 Compared BF vs. PF: Scheduling Points: 7 vs. 15 Preemptions: vs. 27 string * * * * UF Optional P1 Now, let’s go back to this example. After allocating the mandatory units, we have task 2, 3, 5 are eligible tasks because they have pending work bigger than 0 and they are not fully allocated yet. <click> So, we compute their character string and all of them has a ‘-’, and we need to compare their time factors. <click> While it happens that all the time factors equal ‘0’. As I said, the task with smaller index will be given higher priority. <click> So task 2 will have higher priority and have the optional unit. Then, we have that task 1 and 3 get one unit each, and task 2 and 4 get 2 unit each in total. We pack this allocation on the resources and will get the schedule section look like this <click> Following the same procedure, we allocate the unit from 3 to 5, and 5 to 6 etc. we can get the schedule within LCM as this one. <click> Look at this schedule, and compare it with the PF schedule we generated before <click> We have 7 scheduling decision point instead of 15, and the number of context switch is reduced from 27 to 24. Here, we can see our new algorithm saves significantly number of scheduling points. You may have the question that, how fast it is for each scheduling point. <click> 1 2 3 4 3 1 2 4 5 P2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 17

18 Simulations and Discussions
Scheduling Points Execution time at each scheduling point Context switches Task Migrations

19 Scheduling Points Comparisons
Figure 4 from: Dakai Zhu, Xuan Qi*, An Optimal Boundary-Fair Scheduling Algorithm for Multiprocessor Real-Time Systems, Journal of Parallel and Distributed Systems, May 2011

20 Scheduling Points Comparisons(con.t)
Figure 5 from: Dakai Zhu, Xuan Qi*, An Optimal Boundary-Fair Scheduling Algorithm for Multiprocessor Real-Time Systems, Journal of Parallel and Distributed Systems, May 2011

21 Execution time at each scheduling point
Figure 6 from: Dakai Zhu, Xuan Qi*, An Optimal Boundary-Fair Scheduling Algorithm for Multiprocessor Real-Time Systems, Journal of Parallel and Distributed Systems, May 2011

22 Context Switches Figure 12 from: Dakai Zhu, Xuan Qi*, An Optimal Boundary-Fair Scheduling Algorithm for Multiprocessor Real-Time Systems, Journal of Parallel and Distributed Systems, May 2011

23 Context Switches(con.t)
Figure 13 from: Dakai Zhu, Xuan Qi*, An Optimal Boundary-Fair Scheduling Algorithm for Multiprocessor Real-Time Systems, Journal of Parallel and Distributed Systems, May 2011

24 Task Migrations Figure 14 and 15 from: Dakai Zhu, Xuan Qi*, An Optimal Boundary-Fair Scheduling Algorithm for Multiprocessor Real-Time Systems, Journal of Parallel and Distributed Systems, May 2011

25 Reference C. L. Liu and James W. Layland. Scheduling algorithms for multiprogramming in a hard real-time environment. J. ACM, 20(1):46– 61, 1973. S. K. Baruah, J. Gehrke, and C. G. Plaxton. Fast scheduling of periodic tasks on multiple resources. In Proc. of The International Parallel Processing Symposium, Apr J.H. Anderson and A. Srinivasan. Early-release fair scheduling. In Proc. of the 12th Euromicro Conference on Real-Time Systems, Jun J.H. Anderson and A. Srinivasan. Mixed pfair/erfair scheduling of asynchronous periodic tasks. In Proc. of the 13th Euromicro Conference on Real-Time Systems, Jun 2001. B. Andersson, S. Baruah, and J. Jonsson. Static-priority scheduling on multiprocessors. In Proc. of The 22th IEEE Real-Time Systems Symposium, pages 193–202, Dec. 2001

26 Questions and Comments
26


Download ppt "BFair: An Optimal Scheduler for Periodic Real-Time Tasks"

Similar presentations


Ads by Google