Real - Time systems - Week 4: Basic concepts of scheduling

Real-time computing  fast computing  Increase of computing power  improvement of the performance  Graham’s theorem  If a task set is optimally scheduled on a multiprocessor with some priority assignment, a fixed number of processors, fixed execution times, and precedence constraints, then increasing the number of processors, reducing execution times, or weakening the precedence constraints can increase the schedule length

pdf52 trang | Chia sẻ: nguyenlam99 | Lượt xem: 793 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Real - Time systems - Week 4: Basic concepts of scheduling, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
NLT, SoICT, 2015 Real-time Systems Ngo Lam Trung Dept. of Computer Engineering Week 4: Basic concepts of scheduling NLT, SoICT, 2015 Contents  Introduction of scheduling Constraints of real-time tasks Classification of scheduling algorithms Scheduling anomalies NLT, SoICT, 2015 Introduction Why do we need scheduling?  There are always more tasks than processors.  Multiple tasks run concurrently on uniprocessor system. Scheduling policy: the criterion to assign the CPU time to concurrent tasks Scheduling algorithm: the set of rules that determines the order in which tasks are executed What is the main difference between scheduling in RTOS and GPOS? NLT, SoICT, 2015 An illustration of scheduling (1)  All activated tasks enters “ready queue” at first.  The scheduler selects one task in the Ready queue according to the tasks’ priorities allocated based on the scheduling algorithm.  The selected task is dispatched and becomes in “running” state.  After the selected task is completed, it is removed from the Ready queue. Ready queue Scheduler runningtask Start/ dispatched preempted terminate activate Wait queues Wait/blockedreleased NLT, SoICT, 2015 Preemption  The running task can be interrupted at any point, so that a more important task that arrives can immediately gain the processor.  The to-be-preempted task is interrupted and inserted to the ready queue, while CPU is assigned to the most important ready task which just arrived.  Preemption is the solution for dynamic OS.  Why preemption is needed in real-time systems?  Exception handling of a task  Treating with different criticalities of tasks, permits to anticipate the execution of the most critical activities  Efficient scheduling to improve system responsiveness  FreeRTOS NLT, SoICT, 2015 Notation of scheduling (1) J = {J1,,Jn} A set of tasks :R+N A schedule  A function mapping from time to task to assign task to CPU  If (t)=i for t[t1,t2), task Ji is executed during time duration [t1,t2).  If (t)=0, the CPU is idle. Simple translation  CPU time is divided in to time slices [t1,t2)  During a time slice (t)=const, representing the task that is executed NLT, SoICT, 2015 Notation of scheduling(2) Idle J1 J2 J3 idle 3 2 1 t1 t2 t3 t4 (t) Context switching are performed at these times A time slice Notation of scheduling (2) NLT, SoICT, 2015 Notation of scheduling (3) Preemptive schedule  A schedule in which the running task can be arbitrarily suspended at any time, to assign the CPU to another task Feasible schedule  A schedule that all tasks can be completed according to a set of specified constraints Schedulable set of tasks  A set of tasks that has at least one feasible schedule by some scheduling algorithm NLT, SoICT, 2015 Example of preemptive schedule (t) 3 2 1 J1 J2 J3 t t t t NLT, SoICT, 2015 Types of task constraints Timing constraints Precedence constraints Resource constraints NLT, SoICT, 2015 Timing constraints Timing constraints:  Constraints on execution time, is the time that must be meet in order to achieve the desired behavior.  Typical constraint: deadline - Relative deadline: deadline is specified with respect to the arrival time - Absolute deadline: deadline is specified with respect to time zero. Classification of real-time tasks  Hard : completion after deadline can cause catastrophic consequence  Soft : missing deadline decreases the performance of the system but does not jeopardize its correct behavior NLT, SoICT, 2015 fi di finishing absolute time deadline Task parameters(1) Ci Execution time Si start time ai arrival time Xi Laxity Di relative deadline Li Lateness Ci fi time time NLT, SoICT, 2015 Task parameters(2)  Other task parameters  Response time: different between the finishing time and the request time Ri = fi - ri  Criticality: Hard or Soft  Value vi: relative importance of task with respect to the other tasks  Lateness: the delay of a task completion with respect to its deadline Li = fi –di  Tardiness or Exceeding time: Ei = max(0,Li) is the time a task stays active after its deadline.  Laxity or Slack time Xi = di – ai – Ci is the maximum time a task can be delayed on its activation to complete within its deadline NLT, SoICT, 2015 Task parameters(3) Regularity of task activation  Periodic tasks: infinite sequence of identical activities (jobs) activated at constant rate  Aperiodic: infinite sequence of identical activities (jobs) with irregular activation  Sporadic: aperiodic tasks where consecutive activation are separated by some minimum inter- arrival time NLT, SoICT, 2015 Periodic task and aperiodic task NLT, SoICT, 2015 Precedence constraints Tasks can have precedence constraint:  A task has to be executed after another task is completed Notation:  Precedence relations are described by a directed acyclic graph G.  : task Ja is a predecessor of task Jb  : task Ja is an immediate predecessor of Jb NLT, SoICT, 2015 An example of precedence relations J1 J2 J3 J5J4 To be executed earlier To be executed later NLT, SoICT, 2015 An example of deriving precedence relations Motors and encoders Sensors CPU board Motor drivers NLT, SoICT, 2015 Tasks  J1: read sensors input  J2: read encoder values  J3: calculate control commands J1 J2 J4 J5 J3  J4: control left wheel  J5: control right wheel NLT, SoICT, 2015 Resource constraints Resource  Any software structure that can be used by the process to advance its execution  Ex: data structure, a set of variables, main memory area, a file, a piece of program, a set of registers of a peripheral device Private resource:  A resource dedicated to a particular process Shared resource:  A resource that can be used by more tasks NLT, SoICT, 2015 Shared resource & critical section Many shared resources do not allow simultaneous access  require mutual exclusion Critical section  A piece of code under mutual exclusion constraints  Created by synchronization mechanism When tasks have resource constrains, they have to be synchronized NLT, SoICT, 2015 An example of mutual exclusion Wait(s) Critical section Signal(s) Wait(s) Critical section Signal(s) Higher priority J1 Lower priority J2 Shared resource R Critical section is created by using the binary semaphore s NLT, SoICT, 2015  Scheduling with preemption Higher priority J1 Lower priority J2 critical sectionnormal execution preempts blocked Locks resource Unlocks resource An example of mutual exclusion NLT, SoICT, 2015 Waiting state caused by resource constraint READY RUN WAITING activation Termination scheduling preemption Signal free resource Wait on busy resource NLT, SoICT, 2015 Definition of scheduling problems Given  J = {J1,,Jn}: A set of tasks  P = {P1,,Pm}: A set of processors  R = {R1,,Rr}: A set of resources  With precedence constraints and timing constraints Scheduling problem:  Assigning processors from P and resource from R to tasks from J under given constraints NLT, SoICT, 2015 Complexity of scheduling algorithm Complexity of scheduling decision problem  NP-complete in general  Has strong influence on the performance of dynamic real-time systems Practical approach:  Simplify computer architecture: uniprocessor  Adopt additional conditions: preemptive model, priority, task activation  Result in different classes of problem that can be solved by different scheduling algorithms NLT, SoICT, 2015 Classification of scheduling algorithms (1) Preemptive  The running task can be interrupted at any time. Non-preemptive  A task, once started, is executed by the processor until completion without interruption by any other tasks. NLT, SoICT, 2015 Preemptive & non-preemptive algorithms Higher priority task Lower priority task The arrival time of the lower priority task time time The lower priority task is preempted by the higher priority task The arrival time of the higher priority task NLT, SoICT, 2015 Classification of scheduling algorithms (1) Static  Scheduling decisions are based on fixed parameters, assigned to tasks before their activations. Dynamic  Scheduling decisions are based on dynamic parameters that may change during system evolution. NLT, SoICT, 2015 Static & dynamic algorithms Ready queue Scheduler runningtask dispatch Task1: 1 Task2: 5 Task3:2 Fixed priorities Ready queue Scheduler runningtask dispatch Task1: 1 Task2: 5 Task3:2 Dynamically determined priorities refers NLT, SoICT, 2015 Off-line  Scheduling decision is executed on the entire task set before actual task execution. On-line  Scheduling decisions are taken at runtime every time a new task enters the system or when a running task terminates. Classification of scheduling algorithms (2) NLT, SoICT, 2015 Off-line & on-line algorithms Ready queue Scheduler runningtask dispatch Task3 exe Task1 exe Task2 exe Given schedule Ready queue Scheduler runningtask dispatch Dynamically generates a schedule refers Accepts large complexity Small run-time overhead Poor flexibility Large run-time overhead Good flexibility NLT, SoICT, 2015 Optimal  (1) Minimizes some given cost function defined over the task set.  (2) If no cost function is given, optimal algorithm only fail to meet deadline only if no other algorithm can meet the deadline. Heuristic  Searches for a feasible schedule using an objective function (heuristic function).  Does not guarantee to find the optimal schedule. Classification of scheduling algorithms (3) NLT, SoICT, 2015 Guarantee-based algorithms(1)  In hard real-time systems, feasibility of the schedule should be guaranteed before task execution.  In order to guarantee feasibility:  Static real-time systems: - Off-line scheduling is used. Requires high predictability, and the system becomes inflexible.  Dynamic real-time systems: - On-line scheduling with acceptance test NLT, SoICT, 2015 Dynamic realtime schedule READY RUN WAITING Termination scheduling preemption Signal free resource Wait on busy resource ACCEPTANCE TEST Yes No Activation NLT, SoICT, 2015 Guarantee-based algorithms(2) Acceptance test in on-line scheduling  For every arrival of new task Jnew, it is checked whether J’=J {Jnew} is schedulable or not.  If J’ is schedulabe, Jnew is accepted.  Otherwise, Jnew is rejected.  Generally based on worst-case assumption Demerit: unnecessary rejection Merit: detecting potential overload situations  Can avoid domino effects NLT, SoICT, 2015 Domino effect  A dangerous phenomena under transient overload  The arrival of a new task causes all previously guaranteed tasks to miss their deadlines. Jnew J1 J2 J3 J4 New task arrival NLT, SoICT, 2015 Best-effort algorithms  In soft real-time systems, some deadline misses can be acceptable.  Ex. Multimedia applications Best-effort algorithms  Accepts all tasks that arrived  Aborts some tasks under real overload conditions  Cannot guarantee feasibility Demerit: domino effect Merit: good average performance & avoiding unnecessary rejection NLT, SoICT, 2015 Metrics for performance evaluation(1) Performance of scheduling algorithms is evaluated by a cost function. An optimal scheduling algorithm generates a schedule that minimizes a given cost function. Examples of cost functions  Average response time  Total completion time  Weighted sum of completion times  Maximum lateness  Maximum number of late tasks  Utility functions NLT, SoICT, 2015 Cost functions table NLT, SoICT, 2015 Example 0 2 4 6 8 10 12 14 16 18 20 22 24 26 t J1 J2 J3 J4 J5 d1 L1=3 d2 L2=2 d3 L3=1 d4 L4=1 d5 L5=2 Lmax = L1 =3 0 2 4 6 8 10 12 14 16 18 20 22 24 26 t J2 J3 J4 J5 J1 d1 L1=23 d2 L2=-4 d3 L3=-5 d4 L4=-5 d5 L5=-4 Lmax = L1 =23 Minimize Lmax Only one task fails deadline NLT, SoICT, 2015 Utility function  A kind of cost function with respect to the completion time of a task  Evaluates lateness in a real-time task that depends on the completion time  Typical utility functions  Non real-time  Soft  On-time  Firm  To evaluate whole schedule, the cumulative value of utility function values of all tasks is used. NLT, SoICT, 2015 Examples of cost functions v(fi) on time fidi (c) v(fi) v(fi)v(fi) firm di (d) (b)(a) Non real - time fi fi soft di NLT, SoICT, 2015 Scheduling anomalies Real-time computing  fast computing  Increase of computing power  improvement of the performance Graham’s theorem  If a task set is optimally scheduled on a multiprocessor with some priority assignment, a fixed number of processors, fixed execution times, and precedence constraints, then increasing the number of processors, reducing execution times, or weakening the precedence constraints can increase the schedule length. NLT, SoICT, 2015 Examples of Graham’s theorem(1) J = {J1,,J9}: A task set  Sorted by decreasing priorities  Has the precedence constraints in next slide Three processors Optimal schedule *  in Figure next slide  Global completion time is 12 NLT, SoICT, 2015 Task precedence constraints J1 (3) J2 (2) J3 (2) J9 (9) J5 (4) J8 (4) J7 (4) J6 (4) J4 (2) priority(Ji) > priority(Jj) for all i < j NLT, SoICT, 2015 Optimal schedule 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t J3 J6 J8 J2 J4 J5 J7 J1 J9 optimal schedule of task set J on a three-processor machine P1 P2 P3  Find the global completion time if • Extra processors are added • Tasks execution time are reduced • Precedence constrain is weakened NLT, SoICT, 2015 Examples of Graham’s theorem(2)  Increasing the number of processors  Global completion time is 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t J3 J6 J8 J2 J4 J5 J7 J1 J9 Schedule of task set J on a four-processor machine P1 P2 P3 P4 NLT, SoICT, 2015 Examples of Graham’s theorem(3) Reducing computation time  Global completion time is 13 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t J3 J6 J8 J2 J4 J5 J7 J1 J9 Schedule of task set J on a three-processor machine with computation times reduced by one unit of time P1 P2 P3 NLT, SoICT, 2015 Examples of Graham’s theorem(4) Weakening precedence constraints  Global completion time is 16 J1 (3) J2 (2) J3 (2) J9 (9) J5 (4) J8 (4) J7 (4) J6 (4) J4 (2) Precedence graph of task set J obtained by removing the constraints on task J5 and J6 NLT, SoICT, 2015 Examples of Graham’s theorem(4) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 t J3 J6 J8 J2 J4 J5 J7 J1 J9 Schedule of task set J on a three-processor machine with precedence constraints weakened P1 P2 P3 Weakened precedence constraints  Global completion time is 16 NLT, SoICT, 2015 Examples of Graham’s theorem(5)  Anomalies under resource constrains  In real-time tasks with shared resource  Global completion time is increased by reducing the computation time. 0 2 4 6 8 10 12 14 16 18 20 22 24 26 t J1 J5J3 J4 J2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 t J1 J5J3 J4 J2 tc = 17 tc = 22

Các file đính kèm theo tài liệu này:

  • pdfrt2015_week4_5902_8446.pdf
Tài liệu liên quan