Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scheduling CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.

Similar presentations

Presentation on theme: "Scheduling CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han."— Presentation transcript:

1 Scheduling CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

2 Announcements Program Assignment #1 due Tuesday Feb. 15 at 11:55 pm –TA will explain parts b-d in recitation Read chapters 6 and 7

3 Scheduling A process can be switched out due to: –blocking on I/O –voluntarily yielding the CPU –being preemptive time sliced, i.e interrupted –termination The OS’s scheduler implements a scheduling policy that selects the next process to run from the ready queue, based on several criteria –CPU utilization - 40% to 90% –Throughput - # processes completed/second –Turnaround Time - how long it takes to execute that process –Waiting Time - sum of time waiting in the ready queue –Response Time - time until first response

4 Scheduling The dispatcher gives control of the CPU to the process selected by the scheduler, which involves –switching context –switching to user mode –jumping to the proper location in the user program to restart that program

5 Scheduling Context switch overhead affects the choice of time slice –context switches can take 10 microseconds to copy register state to/from memory on a 1 GHz CPU, that’s 10000 wasted cycles per context switch! –if the time slice is on the order of a context switch, then CPU spends most of its time context switching –Typically choose time slice to be large enough so that only 10% of CPU time is spent context switching –Most modern systems choose time slices of 10-100 ms

6 FCFS Scheduling First Come First Serve: order of arrival dictates order of scheduling If processes arrive in order P1, P2, P3, then Gantt chart of CPU service time is: ProcessCPU Service Time P124 P23 P33 P1P2P3 0 242730

7 FCFS Scheduling If processes arrive in reverse order P3, P2, P1, then Gantt chart of CPU service time is: ProcessCPU Service Time P124 P23 P33 P1P2P3 03630

8 FCFS Scheduling average wait time is (0+24+27)/3 = 17 seconds in top scenario average wait time is (0+3+6)/3 = 3 seconds in 2 nd scenario FCFS wait times are generally not minimal - vary a lot if order of arrival changed, which is especially true if the process service times vary a lot (are spread out) P1P2P3 03630 P1P2P3 0 242730

9 FCFS Scheduling If there is one CPU-bound process, and many I/O bound processes, then –convoy effect occurs: I/O bound processes finish their I/O and wait for one large process to complete or yield, then execute quickly, block on I/O, CPU-bound process resumes and the cycle keeps repeating itself

10 Shortest Job First Scheduling Choose the process/thread with the lowest service time –gives priority to shortest processes –minimizes the average wait time can prove this - out of 24 possibilities, this has the lowest average wait time intuition: moving a short process before a long one decreases the wait time of short processes more than it increases the wait time of long processes ProcessCPU Service Time P16 P28 P37 P43 03916 P1P3P2 24 av wait time = (0+3+9+16)/4 = 7 seconds

11 Shortest Job First Scheduling It is difficult to know the length of each job a priori –difficult to know the length of each CPU burst of a job So predict the burst length of each job/process/thread –for each thread, track its pattern of CPU usage, and keep a running average could be a sliding window instead, this is often an exponentially weighted average –Ave(n) = (1-  *CPU_usage(n) +  *Ave(n-1), where 0<  <1 –This can be rewritten Ave(n) =  (1-  )*  n-i-1 * CPU_usage(i) summed from i=0 to n-1 Can be preemptive, i.e. when a new job arrives in ready queue, if its service time is less than currently executing job’s service time, then it can preempt current job

12 Priority Scheduling SJF is a special case of priority scheduling, where priority is given to short jobs Any criteria can be used to decide on a priority –measurable characteristics of the process –external criteria Can be preemptive, i.e. higher priority process arrives in the ready queue and preempts a lower priority process Proces s CPU Servic e Time Priority P1103 P211 P324 P415 P552 P2 01616 P5P1P3 19 P4 18

13 Priority Scheduling Can starve low priority processes A solution is aging: as low priority processes age, their priority is increased –sample aging policy: if priorities range from 1- 128, can increase (decrement) the priority by 1 every T seconds –eventually, the low priority process will get scheduled on the CPU

14 Deadline Scheduling Hard real time systems require that certain processes must complete execution within a certain time, or the system crashes –robots Admission control policy –No notion of refusing admission to a new process for FCFS, SJF, and priority scheduling –Here, can’t admit a process if its deadline can’t be met –This is typical of many Quality-of-Service (QOS) scheduling policies in networking - can’t admit a new source of packets if its QOS deadlines or guarantees cannot be met ProcessCPU Service Time Deadline from now P0350575 P1125550 P24751050 P3250none P475200

15 Deadline Scheduling i  (p i ) Deadline 0 350 575 1 125 550 2 475 1050 3 250 (none) 4 75 200 p0p0 p1p1 p2p2 p3p3 p4p4 1275 1050550200 0 Allocates service by deadline May not be feasible p0p0 p1p1 p2p2 p3p3 p4p4 p0p0 p1p1 p2p2 p3p3 p4p4 575 Copyright © 2004 Pearson Education

16 Round Robin Scheduling The ready queue is treated as a circular queue, and the CPU scheduler rotates among the processes in the ready queue, giving each a time slice, after which it is preempted by a timer interrupt and the next process is started –useful for time sharing multitasking systems - most widely used scheduling algorithm –combines FCFS and preemption simple and fair, though wait times can be long –Fair: If there are n processes, each process gets 1/n of CPU –Simple: Don’t need to know service times a priori A process can finish before its time slice is up. The scheduler just selects the next process in the queue

17 Round Robin Scheduling Suppose we use a time slice of 4 ms, and ignoring context switch overhead Now P1 is time sliced out, and P2 and P3 are allowed to run sooner than FCFS average wait time is 5.66 ms ProcessCPU Service Time (ms) P124 P23 P33 P1 04710 P2 P1 1422182630 P1

18 Round Robin Scheduling Weighted Round Robin - each process is given some number of time slices, not just one per round this is a way to provide preferences or priorities even with preemptive time slicing

19 Multi-level Queue Scheduling Partitions ready queue into several queues –different processes have different needs, e.g. foreground and background –so don’t apply the same scheduling policy to every process, e.g. foreground gets RR, background gets FCFS Queues can be organized by priority, or each given a percentage of CPU, or a hybrid combination

20 Multi-level Feedback Queues Allows processes to move between queues Criteria for movement could depend upon: –age of a process: old processes move to higher priority queues –behavior of a process: could be CPU-bound processes move down the hierarchy of queues, allowing interactive and I/O-bound processes to move up give a time slice to each queue, with smaller time slices higher up if a process doesn’t finish by its time slice, it is moved down to the next lowest queue

Download ppt "Scheduling CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han."

Similar presentations

Ads by Google