Realtime System Fundamentals Scheduling and Prioritybased scheduling Page
Realtime System Fundamentals : Scheduling and Priority-based scheduling Page 1 B. RAMAMURTHY cse 321 -fall 2014 9/10/2020
Realtime scheduling Page 2 Realtime system scheduling as in: cse 321 -fall 2014 Earliest deadline scheduling (EDS) Starting deadline Completion deadline Dynamic priority scheduling Rate monotonic scheduling (RMS) Periodic tasks are prioritized by the frequency of repetition (high priority to tasks with shorter periods) Preemptive scheduling Fixed priority scheduling Schedulability according to RMS Σ(Ci/Ti) <= n(21/n-1) Cyclic executives (pre-scheduled) Concepts of cycle, slot and frame Repeated execution times 9/10/2020
Task State Diagram Task admitted New Resources allocated Ready rr t en v E cu c o Blocked cse 321 -fall 2014 Dis pat c ed hed ; cpu allo cat ed Waiting for event Page 3 k Tas exit Run 9/10/2020
Deadline driven scheduling Page 4 Parameters: ready time, starting deadline, completion deadline, processing time, resource requirement, priority, preemptive or non-preemptive cse 321 -fall 2014 9/10/2020
Deadline Scheduling Page 5 Process Arrival Time Execution Time Ending Deadline A(1) 0 10 20 A(2) 20 10 40 A(3) 40 10 60 A(4) 60 10 80 A(5) 80 10 100 • • • B(1) 0 25 50 B(2) 50 25 100 • • • cse 321 -fall 2014 9/10/2020
deadline A 1 B 1 A 2 B 1 A 3 B 2 A 4 B 2 A 5 B 2 A 1 A 2 B 1 A 3 A 4 A 5, B 2 (missed) A 1 (missed) A 2 A 3 A 4 (missed) A 5, B 2 B 1 A 2 A 3 B 2 A 5 A 1 A 2 B 1 A 3 A 4 A 5, B 2 A 1 B 1 A 2 B 1 A 3 B 2 A 4 B 2 A 5 Fixed-priority scheduling; A has priority Fixed-priority scheduling; B has priority Earliest-deadline scheduling using completion deadlines B 1 cse 321 -fall 2014 Page 6 9/10/2020
Aperiodic Task set Page 7 Arrival Time Execution Time Starting Deadline A 10 20 110 B 20 20 20 C 40 20 50 D 50 20 90 E 60 20 70 Use earliest deadline with unforced idle time cse 321 -fall 2014 9/10/2020
Rate-monotonic scheduling Page 8 First proposed by Liu. For RMS, the highest-priority task is the one with the shortest period, the second highest-priority task is the one with the second shortest period, and so on. Schedulability according to RMS Σ(Ci/Ti) <= n(21/n-1) cse 321 -fall 2014 9/10/2020
Resources & Critical Resources Page 9 Shared resources: need mutual exclusion Tasks cooperating to complete a job Tasks contending to access a resource Tasks synchronizing Critical resources and critical region A important synchronization and mutual exclusion primitive / resource is “semaphore” cse 321 -fall 2014 9/10/2020
Critical sections and Semaphores Page 10 When multiples tasks are executing there may be sections where only one task could execute at a given time: critical region or critical section There may be resources which can be accessed only be one of the processes: critical resource Semaphores can be used to ensure mutual exclusion to critical sections and critical resources cse 321 -fall 2014 9/10/2020
Semaphore Implementation Page 11 Define a semaphore as a class: class Semaphore { int value; // semaphore value process. Queue L; // process queue //operations wait() signal() } In addition, two simple utility operations: block() suspends the process that invokes it. wakeup() resumes the execution of a blocked process P. cse 321 -fall 2014 9/10/2020
Semantics of wait and signal Page 12 Semaphore operations now defined as S. wait(): S. value--; if (S. value < 0) { add this process to S. L; block(); // block a process } S. signal(): S. value++; if (S. value <= 0) { remove a process P from S. L; wakeup(); // wake a process } cse 321 -fall 2014 9/10/2020
Semaphores for CS Page 13 Semaphore is initialized to 1. The first process that executes a wait() will be able to immediately enter the critical section (CS). Now other processes wanting to enter the CS will each execute the wait() thus decrementing the value of S, and will get blocked on S. (If at any time value of S is negative, its absolute value gives the number of processes waiting blocked. ) When a process in CS departs, it executes S. signal() which increments the value of S, and will wake up any one of the processes blocked. The queue could be FIFO or priority queue. cse 321 -fall 2014 9/10/2020
Semaphores Page 14 Semaphore init() Semaphore wait() Semaphore signal() cse 321 -fall 2014 9/10/2020
Priority Inversion Page 15 When we allow concurrent task to execute and with semaphore and mailboxes and other synchronization primitives, it is possible that a low priority task may come to block a high priority task. This situation is known as priority inversion. What happened on Mars? cse 321 -fall 2014 9/10/2020
Priority inversion (Priority: t 1>t 2>t 3) Page 16 blocked task 1 task 2 Critical section task 3 0 cse 321 -fall 2014 1 2 3 4 5 6 7 8 time 9 10 9/10/2020
Problem: Priority inversion Solution 1: Priority Inheritance Page 17 blocked task 1 Task 2 delayed task 2 Critical section task 3 0 cse 321 -fall 2014 1 2 Priority of t 1 inherited Priority reverted To t 3 3 4 5 6 7 8 time 9 10 9/10/2020
Solution 2: Priority Ceiling Protocol Page 18 Acquire S 1 CS Used by Priority Ceiling S 1 t 1, t 2 P(t 1) S 2 t 1, t 2, t 3 P(t 1) S 3 t 3 P(t 3) Release S 1 task 1 Attempt to Acquire S 1 No way task 2 Acquire S 1 Acquire S 2 Release S 2 Critical section task 3 0 cse 321 -fall 2014 1 2 Acquire S 2 3 4 5 6 7 8 time 9 10 9/10/2020
- Slides: 18