COT 4600 Operating Systems Fall 2009 Dan C

  • Slides: 16
Download presentation
COT 4600 Operating Systems Fall 2009 Dan C. Marinescu Office: HEC 304 Office hours:

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 ¨ n Final exam – T December

Lecture 29 – Tuesday November 30, 2010 ¨ n Final exam – T December 9 4 -6: 50 PM Last time: Stack replacement algorithms ¨ The clock algorithm ¨ n Today: Priority inversion ¨ Multi-level queue scheduling ¨ Comparison of scheduling algorithms ¨ Queuing ¨ n Next Time: ¨ Review of the class. Lecture 29 2

Priority scheduling n n n Each thread/process has a priority and the one with

Priority scheduling n n n 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 3

Priority inversion n n n A lower priority thread/process prevents a higher priority one

Priority inversion n n n A lower priority thread/process prevents a higher priority one from running. T 3 has the highest priority, T 1 has the lowest priority; T 1 and T 3 share a lock. T 1 acquires the lock, then it is suspended when T 3 starts. Eventually T 3 requests the lock and it is suspended waiting for T 1 to release the lock. T 2 has higher priority than T 1 and runs; neither T 3 nor T 1 can run; T 1 due to its low priority, T 3 because it needs the lock help by T 1. Allow a low priority thread holding a lock to run with the higher priority of the thread which requests the lock Lecture 29 4

Estimating the length of next CPU burst n Done using the length of previous

Estimating the length of next CPU burst n Done using the length of previous CPU bursts, using exponential averaging Lecture 29 5

Exponential averaging n n =0 ¨ n+1 = n ¨ Recent history does not

Exponential averaging n n =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 6

Predicting the length of the next CPU burst Lecture 29 7

Predicting the length of the next CPU burst Lecture 29 7

Multilevel queue n n Ready queue is partitioned into separate queues each with its

Multilevel queue n n 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. , n 80% to foreground in RR n 20% to background in FCFS Lecture 29 8

Multilevel Queue Scheduling Lecture 29 9

Multilevel Queue Scheduling Lecture 29 9

Multilevel feedback queue n n A process can move between the various queues; aging

Multilevel feedback queue n n 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 10

Example of a multilevel feedback queue exam n Three queues: Q 0 – RR

Example of a multilevel feedback queue exam n Three queues: Q 0 – RR with time quantum 8 milliseconds ¨ Q 1 – RR time quantum 16 milliseconds ¨ Q 2 – FCFS ¨ n Scheduling A new job enters queue Q 0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q 1. ¨ At Q 1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q 2. ¨ Lecture 29 11

Multilevel Feedback Queues Lecture 29 12

Multilevel Feedback Queues Lecture 29 12

Unix scheduler n n n The higher the number quantifying the priority the lower

Unix scheduler n n n 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: P 1 =40, P 2 =18, P 3 = 10 Lecture 29 13

Comparison of scheduling algorithms Round Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job

Comparison of scheduling algorithms Round Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest Remaining Job Next Throughput May be low is quantum is too small Not emphasized May be low is quantum is too small High Response time Shortest average response time if quantum chosen correctly May be poor Good for I/O bound but poor for CPUbound processes Good for short processes But maybe poor for longer processes Lecture 29 14

IO-bound Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest Remaining

IO-bound Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest Remaining Job Next No distinction between CPU-bound and IO-bound Gets a high priority if CPUbound processes are present No distinction between CPU-bound and IO-bound Infinite Does not postponem occur ent Does not occur May occur for CPU bound processes Lecture 29 May occur for processes with long estimated running times 15

Overhead CPUbound Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest

Overhead CPUbound Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest Remaining Job Next Low The lowest Can be high Complex data structures and processing routines Can be high Routine to find the shortest job for each reschedule Can be high Routine to find the minimum remaining time for each reschedule No distinction between CPU-bound and IO-bound Gets a low priority if IObound processes are present Lecture 29 No distinction between CPU-bound and IO-bound 16