380 likes | 389 Views
This summary covers real-time operating systems, scheduling algorithms, and Mars Rover Pathfinder case study, including RTOS characteristics, scheduling policies, modeling for analysis, preemptive scheduling, RTOS scheduling strategies, and RMS algorithm.
E N D
RT Operating Systems& Scheduling “ delivers the results of processing in a given time span” Georgio Butazzo, “Predictable scheduling Algorithms and applications”, 3rd edition
Mars Rover Pathfinderdeadlines missed in 1997prob = priority inversion • VxWorks RTOS kernel • A few days into mission, Pathfinder sporadically missing deadlines • Watchdog timer generated system resets loss of data. • Reason: xxxxxx • T1 information bus manager • T2 communication task • T3 meteorological data collection • Mutex controlled shared information bus • priorities ? Blocked
Characteristics of RTOS • Determinism: delay till acknowledging event • Responsiveness: time to service complete response time = Determinism + responsiveness • User control: priority • Reliability: failure can cause loss of life or $$$$$. • Fail-soft operation: but with reduced service level • Rover – Mars, spacecraft, industrial control, flight control,.. • RTOS: RT Linux, VxWorks (intel), Windows CE, QNX – Neutrino, LynxOS, tinyOS • General purpose OS Min response time, Max throughput fairness
Scheduling review : FCFS – FIFO • Firstcome, firstserved (FCFS) • 1st task that arrives executed first, followed by 2nd, 3rd..etc … • FCFS process may wait longtime ex: ProcessTotal Run Time P1 12 seconds P2 3 seconds P3 8 seconds P1 12 sec. P2 3sec P3 8 sec arrival order: P1, P2, P3 P3 8 sec P1 12 sec. arrival order: P2, P3, P1 P2
Round Robin - review • Sequential Process execution – timer generated fixed time slice • predetermined static order • Task executes till slice expires or complete
Real-Time Scheduling Policiesgoal: ensure predictability EDF (Earliest Deadline First), RMS (Rate-Monotonic Scheduling) • Static table-driven • Suitable for periodic tasks/earliest-deadline first scheduling • Requires Static analysis of feasible schedule • Static priority-driven preemptive RMS • Static analysis priority • priority-driven scheduler • Dynamic - (evaluate priorities on the fly) • schedule using previously scheduled tasks and new arrival • new one is accepted if all tasks meets constraints • Dynamic best effort • No feasibility analysis is performed • Assigned a priority to the new arrival then apply earliest deadline first • System tries to meet all deadlines and aborts any started process whose deadline is missed
Modeling RT Scheduling for analysis • Periodic task (T) • period • Deadline • processing time / Execution time Ci Ui= Ti Period of T Deadline of T Task’s CPU utilization: Processing time of T Ci = task (execution time) CPU utilization U = U1 + U2 +...+ Un < 1 processor utilization factor
System Model – Assumptions • Assumptions: • Periodic tasks without precedence • tasks are assumed mutually independent • No OS overhead – simplified view • metrics: • Guarantee miss ratio = 0 (hard real-time) • Guarantee Probability(missed deadline) < X% (firm real-time) • Minimize miss ratio (firm real-time) • Minimize tardiness; maximize usefulness (soft real-time)
Real time scheduling: Periodicsystem model - fyi • Timing constraints of a periodic task ti is specified by (s, e, D, p) • si-(scheduled) Starting Time of Task i • ei-Processing time of i • fi-Finish time of i • Di-Deadline of i • pi-Period of i • ri-Rate of i = (1/pi)
Preemptive Scheduling • Threads assigned priorities • statically assigned (constant ) • or dynamically assigned ( variable) • ShortestJobFirst • Preemptive scheduling: • highest priority task executes • Can preempt lower priority task
Preemptive Scheduling Example Accelerometer update • 3 tasks; eg Aircraft navigation • Task 3 : High priority, gathers accelerometer data / 5ms • Task 2 : Medium, collect gyro data & take action every 40 ms • Task 1 : Low priority, display update, built in test Gyro update Display update
Preemptive Scheduling Problems • resources hogged by high priority task • Starves low priority tasks • Priority inversion: • High priority task blocked By lower priority task !
RTOS Scheduling: Rate Monotonic Scheduling - RMS • Assume n tasks invoked periodically with: FYI • periods T1, … ,Tn(real-time constraints) • worst-case execution times (WCET) C1, … ,Cn • assumes no mutexes, semaphores, or blocking I/O • no precedence constraints • fixed priorities • preemptive scheduling • smallest period highest priority • Theorem: If any priority assignment yields a feasible schedule, then priorities ordered by period (smallest period has highest priority) also yields a feasible schedule. • RMS is optimal in the sense of feasibility. • every task completes once within its designated period
Periodic Real-time task set P=period The start time of a new instance of a job is the deadline of the last instance
RMS example 1:Two tasks with different periods • Some Task (2) will not finish within its period . Non-preemptive schedule not feasible. C1 T1 C2 T2
RMS example 1:usepreemptive • Preemptive scheduling with higher priority for T2 C1 T1 C2 T2
RMS example 1: preemptive C1 C1 • Preemptive schedule red task assigned higher priority - feasible. blue task takes longer. preempted
RMS:task Alignment C1 T1 • Completion time of lower priority task worst when it starts withhigher priority tasks. • sufficient to consider worst case: All tasks start at same time. • Theorem: Worst-case phasing of a task occurs when it arrives simultaneously with all its higher priority tasks. • Theorem: for a set of independent, periodic tasks, if each task meets its first deadline, with worst-case task phasing, the deadline will always be met.
Rate Monotonic Analysis (RMA):analyzing schedule feasibility • equations to analyze tasks. • applies to independent, periodic tasks, but - extended to address • priority inversion ; • task interactions • aperiodic tasks • Focus :periodic tasks using • UB (utilization Bound) • & RT (response time) tests
C1Cn 1/ n --- + .... + --- < U(n) = n(2 - 1) T1Tn RMS UB-Utilization Bound Test • UB test: n independent periodic tasks scheduled by RMS will always meet its deadlines, for all task phasings, if U(1) = 1.0 U(4) = 0.756 U(7) = 0.728 U(2) = 0.828 U(5) = 0.743 U(8) = 0.724 U(3) = 0.779 U(6) = 0.734 U(9) = 0.720 • guaranteed schedulable if utilization less than bound • Excess CPU time used for non-critical tasks
UB Test: Example 13 tasks • Total utilization U = .200 + .267 + .286 = .753 < U(3) = .779 • UB test : task set above schedulable Ci Ui= Ti
t 1 t 2 t 3 Example 1Timeline note: execution schedule – not unique 200 100 0 300 400 Highest frequency lowest frequency Scheduling Points
Example 2: UB Given: • Analyze: schedulable, Draw timeline. • What is total utilization if C3 = 2 ? C T U Task t1: 1 4 Task t2: 2 6 Task t3: 1 10 Ci Ui= Ti
0 20 5 10 15 Taskt1 Taskt2 Taskt3 Solution: Example 2 UB Test a. total utilization? .25 + .34 + .10 = .69 b. Is task set schedulable?Yes: .69 < U(3) = .779 c. Draw the timeline. d. total utilization if C3 = 2 ? .25 + .34 + .20 = .79 > U(3) = .779
UB test conservativeRT(Response Time a.k.a completion time) More Precise Test • UB 3 outcomes: 0 < U < U(n) Success U(n) < U < 1.00 Inconclusive 1.00 < U Overload • RT Response more precise
Interference term form higher priority tasks RT Test • Response time (RT) or Completion Time test: let a = response time of task i. :::: computed by the following formula: • Test terminates when a= a • Task i is schedulable if its response time is before its deadline: a < Ti n i - 1 i a å å n a = C + C where a = C n+1 i j 0 j T j = 1 j = 1 j n n+1 n • test repeated for every task ti if required • i.e. the value of i will change depending upon the task you are looking at • Stop test once current iteration yields a value of an+1 beyond the deadline (else, you may never terminate). • The ‘square bracketish’ ‘ceiling’ function, NOT brackets • Ceiling function ::: smallest following integer, eg ceiling(1.4) = 2
C T U Task t1: 20 100 0.200 Task t2: 40 150 0.267 Task t3: 100 350 0.286 Example 1b using RT; t1 20 40 • Applying to examle I; if compute time of t1 20 40; Is task set schedulable? 0.4 40 • Utilization of T1 & T2: 0.667 < U(2) = 0.828 • first two tasks schedulable by UB test • When 3rd task added, Utilization : 0.953 > U(3) = 0.779 • UB inconclusive • apply RT test ONLY for task 3 ( T1 , T2 schedulable)
å a0 = C = C + C + C = 40 + 40 + 100 = 180 j 1 2 3 j = 1 i - 1 2 a0 a0 å å a1 = C + C = C + C i j 3 j T T j = 1 j = 1 j j 180 180 = 100 + ( 40 ) + ( 40 ) = 100 + 80 + 80 = 260 100 150 Applying RT for task 3 • RT test :does t3meets its first deadline: i = 3 3
2 a1 260 260 + C = 100 + (40) + (40) = 300 a2 = c2 å j T 100 150 j = 1 j 2 a2 300 300 a3 c3 = + C = 100 + (40) + (40) = 300 å j T 100 150 j = 1 j a3 = a2 = 300 Done! Example 1b: Applying RT for task 3 • Task t3 schedulable using RT a3 = 300 < T3 = 350 Task 3 response time < its period
t 1 t 2 t 3 t completes at t = 300 3 Task t1: C1 = 40 T1 = 100 Task t2: C2 = 40 T2 = 150 Task t3: C3 = 100 T3 = 350 Task T1 compute time Increased 20 40 Timeline Example 1busing RT 0 300 100 200 40 40 20 10 10 60
Exercise 2: Applying UB & RT Test Task t1: C1 = 1 T1 = 4 Task t2: C2 = 2 T2 = 6 Task t3: C3 = 2 T3 = 10 a) Apply UB test b) Draw timeline c) Apply RT test
0 20 5 10 15 Taskt1 Taskt2 Taskt3 All work completed at t = 6 Solution: Applying UB & RT Tests Task t1: C1 = 1 T1 = 4 Task t2: C2 = 2 T2 = 6 Task t3: C3 = 2 T3 = 10 a) UB test t1and t2OK -- no change from previous exercise .25 + .34 + .20 = .79 > .779 ==> Test inconclusive for t3 b) Timeline
3 å a = C = C + C + C = 1 + 2 + 2 = 5 0 j 1 2 3 j = 1 2 2 a a 6 5 6 5 å å 0 1 = = a a = = C C + + C C = = + + 2 2 + + 2 2 2 + 2 + 2 = 6 2 + 2 + 2 = 6 1 1 2 1 3 3 j j T T 6 6 4 4 j j = = 1 1 j j c) Applying RT Test for (i=3) Done
C T U Task t1: 20 100 0.200 Task t2: 40 150 0.267 Task t3: 100 350 0.286 Example 1c : Applying RT • same problem as example 1, increase t1 20 45; is task set schedulable? 0.45 45 • Utilization of first two tasks: 0.717 < U(2) = 0.828 • first two tasks schedulable by UB test
2 a 1 270 270 + C = 100 + (45) + (40) = 315 a = C å j 2 3 T 100 150 j = 1 j a = C = C + C + C = 45 + 40 + 100 = 185 å 0 j 1 2 3 2 a 2 315 315 j = 1 a = C + C = 100 + (45) + (40) = 400 å 3 3 j T 100 150 j = 1 j i - 1 2 a a å å 0 0 a = C + C = C + C 1 i j 3 j T T j = 1 j = 1 j j 185 185 = 100 + ( 45 ) + ( 40 ) = 100 + 90 + 80 = 270 100 150 Task t1: C1 = 45 T1 = 100 Task t2: C2 = 40 T2 = 150 Task t3: C3 = 100 T3 = 350 Example 1c: Applying RT for i=3 3 • RT test used to determine if t3 meets its first deadline: i = 3 a3 GT 350 STOP Not sched
Summary of schedule analysis • UB test: simple - conservative. • RT test: more precise - more complicated. • UB and RT tests assumptions: • single processor • Periodic tasks - non interacting • Deadlines always at end of period • no interrupts • Rate-monotonic priorities are assigned • zero context switch overhead
Scheduling: Larger Problem Space –fyimore in RTOS scheduling III • Uni-processor vs multiprocessor vs distributed system • Periodic – sporadic - aperiodic tasks • Independent - interdependent tasks • Preemptive - non-preemptive • Tick scheduling / event-driven scheduling • Static (at design time) vs dynamic (at run-time) • Off-line (pre-computed schedule), on-line (scheduling decision at runtime) • Handle transient overloads • Support Fault tolerance