CPU Scheduling
Chapter 5
Objectives
CPU Scheduling Introduction
Basic Concepts
CPU Scheduler
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
Preemptive and Nonpreemptive Scheduling
Preemptive and Nonpreemptive Scheduling
Preemptive Scheduling and Race Conditions
Dispatcher
Scheduling Criteria and Metrics
Scheduling Algorithm Optimization Criteria
First- Come, First-Served (FCFS) Scheduling
Process | Burst Time |
P1 | 24 |
P2 | 3 |
P3 | 3 |
FCFS Scheduling (Cont.)
FCFS Scheduling (Cont.)
FCFS Scheduling (Cont.)
Suppose that the same processes arrived in the order:
P2 , P3 , P1
FCFS Scheduling (Cont.)
FCFS Scheduling (Cont.)
Shortest-Job-First (SJF) Scheduling
Types of Shortest-Job-First (SJF) Scheduling
Example of SJF
Process | Burst Time |
P1 | 6 |
P2 | 8 |
P3 | 7 |
P4 | 3 |
SJF Scheduling (Cont.)
SJF Scheduling (Cont.)
Example of Shortest-remaining-time-first
Preemptive SJF Gantt Chart
Process | Arrival Time | Burst Time |
P1 | 0 | 8 |
P2 | 1 | 4 |
P3 | 2 | 9 |
P4 | 3 | 5 |
Preemptive SJF Scheduling (Cont.)
Preemptive SJF Scheduling (Cont.)
Round Robin (RR)
Example of RR with Time Quantum = 4
Process | Burst Time |
P1 | 24 |
P2 | 3 |
P3 | 3 |
RR Scheduling (Cont.) – Waiting Time
RR Scheduling (Cont.)
RR Scheduling (Cont.)
Time Quantum and Context Switch Time
Turnaround Time Varies With The Time Quantum
80% of CPU bursts should be shorter than q
Priority Scheduling
Priority Scheduling
Example of Priority Scheduling
Process | Burst Time | Priority |
P1 | 10 | 3 |
P2 | 1 | 1 |
P3 | 2 | 4 |
P4 | 1 | 5 |
P5 | 5 | 2 |
Waiting Time
Priority Scheduling (Cont.)
Priority Scheduling (Cont.)
Priority Scheduling w/ Round-Robin
ProcessA arri Burst TimeT Priority
P1 4 3
P2 5 2
P3 8 2
P4 7 1
P5 3 3
FCFS Scheduling (Cont.)
FCFS Scheduling (Cont.)
Multilevel Queue
Multilevel Queue
Multilevel Feedback Queue
Example of Multilevel Feedback Queue
Thread Scheduling
Multiple-Processor Scheduling
Multiple-Processor Scheduling
Multicore Processors
Multithreaded Multicore System
Multithreaded Multicore System
Multithreaded Multicore System
Multiple-Processor Scheduling – Load Balancing
Multiple-Processor Scheduling – Processor Affinity
NUMA and CPU Scheduling