Download CPU Scheduling: Max CPU Utilization, Three-Level Scheduling, and Algorithms and more Slides Operating Systems in PDF only on Docsity!
Lecture 9
Chapter 5: CPU Scheduling (cont)
Basic Concepts
- Maximum CPU utilization obtained with multiprogramming
- CPU–I/O Burst Cycle : Process execution consists of a cycle of CPU execution and I/O wait - Alternating Sequence of CPU and I/O Bursts
- Histogram of CPU-burst Times
CPU Scheduler
- Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them
- CPU scheduling decisions may take place when a process:
- Switches from running to waiting state
- Switches from running to ready state
- Switches from waiting to ready
- Terminates
- Scheduling under 1 and 4 is nonpreemptive
- Processes keep CPU until it releases either by terminating or I/O wait.
- All other scheduling is preemptive
cooperative scheduling let a process run until it blocks on I/O, terminates or voluntarily releases the CPU (system call) Ready Running Blocke d
Ready Running Blocke d
preemptive scheduling follow clock interrupts (ex: 50Hz) to forcibly switch processes (demote the “Running” to “Ready”)
Two kinds of CPU-scheduling algorithms
Scheduling Criteria
- CPU utilization – keep the CPU as busy as possible - Typically between 40% to 90%
- Throughput – # of processes that complete their execution per time unit - Depends on the length of process
- Turnaround time – amount of time to execute a particular process - Sum of wait for memory, ready queue, execution, and I/O.
- Waiting time – amount of time a processDocsity.com
Scheduling Algorithm Optimization Criteria
- Max CPU utilization
- Max throughput
- Min turnaround time
- Min waiting time
- Min response time
- In most cases, systems optimize average measure
Shortest-Job-First (SJF) Scheduling
- Associate with each process the length of its next CPU burst. - Use these lengths to schedule the process with the shortest time - shortest-next-CPU-burst
- SJF is optimal
- Gives minimum average waiting time for a given set of processes
- The difficulty is knowing the length of the next CPU request
A B C D E
Arrival times
Shortest JobFirst (SJF)
SJF^ A^ B^ C^ D^ E^ Mean
Determining Length of Next CPU
Burst
- Can only estimate the length
- Can be done by using the length of previous CPU bursts - using exponential averaging 4. Define : 3. , 0 1 2. predictedvaluefor thenextCPU burst
- actual lengthof CPU burst
≤ ≤
=
=
α α
τ (^) n 1
tn nth
τ (^) n = 1 =α tn + ( 1 −α) τ (^) n.
choose the process whose remaining run time is shortestExample of SJF (preemtive)
allows new short jobs to get good service
A B C D E Mean
A B C D E
Arrival times
Priority Scheduling
- A priority number (integer) is associated with each process
- The CPU is allocated to the process with the highest priority (smallest integer ≡ highest priority) - Preemptive - Nonpreemptive
- SJF is a priority scheduling where priority is
Round Robin (RR)
- Each process gets a small unit of CPU time ( time quantum ), usually 10-100 milliseconds. - After this time has elapsed, the process is preempted and added to the end of the ready queue.
- If there are n processes in the ready queue and the time quantum is q , then each process gets 1/ n of the CPU time in chunks of at most q time units at once. - No process waits more than ( n - 1) q time units.Docsity.com
Examples of RR
A B C D E
Arrival times
A B C D E Mean
A B C D E Mean
Turnaround Time Varies With The Time Quantum
Multilevel Queue
- Ready queue is partitioned into separate queues: - foreground (interactive) - background (batch)
- Each queue has its own scheduling algorithm
- foreground – RR
- background – FCFS
- Scheduling must be done between the queues
- Fixed priority scheduling;