CPU Scheduling Basic Concepts 4 Maximum CPU utilization
CPU Scheduling: Basic Concepts 4 Maximum CPU utilization obtained with multiprogramming - several processes are kept in memory, while one is waiting for I/O, the OS gives the CPU to another process < OS does CPU scheduling 4 CPU scheduling depends on the observation that processes cycle between CPU execution and I/O wait. The original slides were copyright Silberschatz, Galvin and Gagne, 2005 10/19/2021 CSE 30341: Operating Systems Principles page 1
Alternating Sequence of CPU And I/O Bursts CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait 10/19/2021 CSE 30341: Operating Systems Principles page 2
Histogram of CPU-burst Times Typical CPU-burst duration CPU bursts are short lived 10/19/2021 CSE 30341: Operating Systems Principles page 3
CPU Scheduler 4 Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them 4 CPU scheduling decisions may take place when a process: 1. 2. 3. 4. Switches from running to waiting state (e. g. I/O request) Switches from running to ready state (e. g. Interrupt) Switches from waiting to ready (e. g. I/O completion) Terminates 4 Scheduling under 1 and 4 is non-preemptive (cooperative) 4 All other scheduling is preemptive - have to deal with possibility that operations (system calls) may be incomplete 10/19/2021 CSE 30341: Operating Systems Principles page 4
Dispatcher 4 Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: < switching context < switching to user mode < jumping to the proper location in the user program to restart that program 4 Dispatch latency – time it takes for the dispatcher to stop one process and start another running < Should be as low as possible 10/19/2021 CSE 30341: Operating Systems Principles page 5
Scheduling Criteria 4 CPU utilization (max) – keep the CPU as busy as possible 4 Throughput (max) – # of processes that complete their execution per time unit 4 Turnaround time (min) – amount of time to execute a particular process 4 Waiting time (min) – amount of time a process has been waiting in the ready queue 4 Response time (min) – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) 4 In typical OS, we optimize each to various degrees depending on what we are optimizing the OS 10/19/2021 CSE 30341: Operating Systems Principles page 6
Optimization criteria 4 Max CPU utilization 4 Max throughput 4 Min turnaround time 4 Min waiting time 4 Min response time 4 Analysis using Gantt chart (illustrates when processes complete) 10/19/2021 CSE 30341: Operating Systems Principles page 7
First-Come, First-Served (FCFS) Scheduling Process Burst Time P 1 24 P 2 3 P 3 3 n Suppose that the processes arrive in the order: P 1 , P 2 , P 3 The Gantt Chart for the schedule is: P 1 P 2 0 24 P 3 27 30 n Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 n Average waiting time: (0 + 24 + 27)/3 = 17 Operating System Concepts 5. 8 Silberschatz, Galvin and Gagne © 2005
FCFS Scheduling (Cont. ) Suppose that the processes arrive in the order P 2 , P 3 , P 1 n The Gantt chart for the schedule is: P 2 P 3 P 1 0 3 6 n Waiting time for P 1 = 6; P 2 = 0; P 3 = 3 n Average waiting time: (6 + 0 + 3)/3 = 3 n Much better than previous case 30 n Convoy effect short process behind long process Operating System Concepts 5. 9 Silberschatz, Galvin and Gagne © 2005
Shortest-Job-First (SJR) Scheduling 4 Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time 4 Two schemes: < nonpreemptive – once CPU given to the process, it cannot be preempted until completes its CPU burst < preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF) 4 SJF is optimal – gives minimum average waiting time for a given set of processes 10/19/2021 CSE 30341: Operating Systems Principles page 10
- Slides: 10