160 likes | 289 Views
COT 4600 Operating Systems Fall 2009. Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 3:00-4:00 PM. Lecture 29 – Tuesday November 30, 2010. Final exam – T December 9 4-6:50 PM Last time: Stack replacement algorithms The clock algorithm Today : Priority inversion
E N D
COT 4600 Operating Systems Fall 2009 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 3:00-4:00 PM
Lecture 29 – Tuesday November 30, 2010 Final exam – T December 9 4-6:50 PM Last time: Stack replacement algorithms The clock algorithm Today: Priority inversion Multi-level queue scheduling Comparison of scheduling algorithms Queuing Next Time: Review of the class. Lecture 29
Priority scheduling • Each thread/process has a priority and the one with the highest priority (smallest integer highest priority) is scheduled next. • Preemptive • Non-preemptive • SJF is a priority scheduling where priority is the predicted next CPU burst time • Problem Starvation – low priority threads/processes may never execute • Solution to starvation Aging – as time progresses increase the priority of the thread/process • Priority my be computed dynamically Lecture 29
Priority inversion • A lower priority thread/process prevents a higher priority one from running. • T3 has the highest priority, T1 has the lowest priority; T1 and T3 share a lock. • T1 acquires the lock, then it is suspended when T3 starts. • Eventually T3 requests the lock and it is suspended waiting for T1 to release the lock. • T2 has higher priority than T1 and runs; neither T3 nor T1 can run; T1 due to its low priority, T3 because it needs the lock help by T1. • Allow a low priority thread holding a lock to run with the higher priority of the thread which requests the lock Lecture 29
Estimating the length of next CPU burst • Done using the length of previous CPU bursts, using exponential averaging Lecture 29
Exponential averaging • =0 • n+1 = n • Recent history does not count • =1 • n+1 = tn • Only the actual last CPU burst counts • If we expand the formula, we get: n+1 = tn+(1 - ) tn-1+ … +(1 - )j tn-j+ … +(1 - )n +1 0 • Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor Lecture 29
Predicting the length of the next CPU burst Lecture 29
Multilevel queue • Ready queue is partitioned into separate queues each with its own scheduling algorithm : • foreground (interactive) RR • background (batch) FCFS • Scheduling between the queues • Fixed priority scheduling - (i.e., serve all from foreground then from background). Possibility of starvation. • Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., • 80% to foreground in RR • 20% to background in FCFS Lecture 29
Multilevel Queue Scheduling Lecture 29
Multilevel feedback queue • A process can move between the various queues; aging can be implemented this way • Multilevel-feedback-queue scheduler characterized by: • number of queues • scheduling algorithms for each queue • strategy when to upgrade/demote a process • strategy to decide the queue a process will enter when it needs service Lecture 29
Example of a multilevel feedback queue exam • Three queues: • Q0 – RR with time quantum 8 milliseconds • Q1 – RR time quantum 16 milliseconds • Q2 – FCFS • Scheduling • A new job enters queue Q0which is servedFCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1. • At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2. Lecture 29
Multilevel Feedback Queues Lecture 29
Unix scheduler • The higher the number quantifying the priority the lower the actual process priority. • Priority = (recent CPU usage)/2 + base • Recent CPU usage how often the process has used the CPU since the last time priorities were calculated. • Does this strategy raises or lowers the priority of a CPU-bound processes? • Example: • base = 60 • Recent CPU usage: P1 =40, P2 =18, P3 = 10 Lecture 29
Comparison of scheduling algorithms Lecture 29