Friday, September 10, 1993 Suspend and resume Permit suspension of process. Add two more process states: SuspendedReady and SuspendedRunning and operations Suspend/Activate: Suspend: Ready -> SuspendedReady Suspend: Running -> SuspendedRunning Activate: SuspendedReady -> Ready Activate: SuspendedRunning -> Running and also New: -> SuspendedReady Suspend processes, e.g., suspend before swapping, suspend if process misbehaving but want to examine it later, suspend in terms of short term load fluctuations (load balancing) ------------------------------------------------------------------------------- Scheduling strategy (at three levels) - Long term scheduling: which jobs should be allowed to compete actively for the resources of the system [New operation] - Medium-term scheduling: which processes should be allowed to compete for CPU (given other resources have been allocated to them) [Suspend and Activate operations] - Short term scheduling: which ready process should be assigned to CPU [Dispatch and TimeSlice over operations] ------------------------------------------------------------------------------- Potential scheduling criteria: - fairness (all processes treated the same; no indefinite postponment) - efficiency (CPU busy 100% of time) - response time (minimize response time for interactive users) - predictability (job runs in about same amount of time) - turnaround (minimize time batch users must wait for output) - throughput (maximize number of jobs processed per time unit) - degrade gracefully under heavy load Many of these goals conflict! (e.g., response time and fairness) ------------------------------------------------------------------------------- CPU scheduling strategies (short term scheduling) - Runs very frequently. Performance critical (e.g., in algorithm as well as in implementation) - Extensively studied; modelled - Terminology: preemptive scheduling: processes that are logically runnable can be temporarily suspended nonpreemptive scheduling: processes permitted to run to completion (or blocking) ------------------------------------------------------------------------------- First-Come, First-Served Scheduling (nonpreemptive) First process needing CPU gets allocated CPU (FIFO queue) Average wait time can be quite long (and inconsistent) p1 - 4; p2 - 3; p3 - 15; 3 2/3 also consider p3; p2; p1 11 ------------------------------------------------------------------------------- Shortest job first scheduling (nonpreemptive). minimize average waiting time consider example from before (p2; p1; p3) 3 1/3 Provably optimal! (each process contributes to overall average waiting time so put the one that contributes the least, i.e., the shortest, the first. Longest last contributes to no one's waiting time... BUT: cannot *know* length of next CPU request. May predict based on behavior but process can behave inconsistently. ------------------------------------------------------------------------------- Shortest remaining time first scheduling (preemptive) As in sjf but preempt if newly arriving process has shorter CPU time burst than the time remaining on the present process' SJF and SRTF both still have problem of not knowing the future and also problem of *starvation* ------------------------------------------------------------------------------- General concept: Priority scheduling priority is associated with each process. CPU allocation goes to process with highest priority. In SJF, priority based on length of CPU use, for example. Possible solution to starvation: aging (priority increases as process waits in system) Unix nice: priority decreases as CPU use increases Possible solution to insuring interactive response: process has higher priority after returning from i/o interrupt (but can be circumvented) ------------------------------------------------------------------------------- Round Robin Scheduling (preemptive) Designed for timesharing systems. Time quantum (time slice) defined (10 to 100 milliseconds). Ready list is FIFO queue of processes CPU allocated to first process on list. When quantum expires, process placed at end of list. as before: p3 - 15; p2 - 3; p1 - 4; quantum = 4 p3(4---11 remains); p2(3); p1(4); p3(4--7); p3 (4--3); p3(3) Average wait before first start: 3 Simulates SJF/SRTF Doesn't require that you know CPU time Does not cause starvation ------------------------------------------------------------------------------- Compare turnaround times for FCFS and SJF with the p3; p2; p1 order FCFS 18 1/3 SJF 10 2/3 RR (q4) 13 1/3 # context switches 4 RR problem---context switch overhead if quantum too small RR degenerates to FCFS if quantum too large Rule of thumb from text: 80% of cpu bursts shorter than time quantum -------------------------------------------------------------------------------