Professional Documents
Culture Documents
CPU scheduling:
Scheduling goals and algorithms
Scheduling decisions are made when an interrupt occurs only in a preemptive system.
Scheduling Goals
Maximize throughput and resource utilization.
Need to overlap CPU and I/O activities.
Minimize response time, waiting time and turnaround time. Share CPU in a fair way. May be difficult to meet all these goals-sometimes need to make tradeoffs.
Scheduling Algorithms
First Come First Served (FCFS)
Scheduler selects the process at the head of the ready queue; typically nonpreemptive Example: 3 processes arrive at the ready queue in the following order:
P1 ( CPU burst = 24 ms) P2 ( CPU burst = 3 ms) P3 ( CPU burst = 3 ms)
Scheduling Algorithms
First Come First Served (FCFS)
Example: Whats the average waiting time?
Scheduling Algorithms
Round Robin (RR)
FCFS + preemptive scheduling. Ready queue is treated as a circular queue. Each process gets the CPU for a time quantum (or time slice), typically 10 - 100 ms. A process runs until it blocks, terminates, or uses up its time slice.
Scheduling Algorithms
Round Robin (RR)
Example: Assuming a time quantum of 4 ms, whats the average waiting time?
Scheduling Algorithms
Round Robin (RR) RR pros & cons:
+Works well for short jobs; typically used in timesharing systems. High overhead due to frequent context switches. Increases average waiting time, especially if CPU bursts are the same length and need more than one time quantum.
Scheduling Algorithms
Priority Scheduling
Select the process with the highest priority. Priority based on some attribute of the process (e.g., memory requirements, owner of process, etc.)
Issue:
Starvation: low priority jobs may wait indefinitely. Can prevent starvation by aging (increase process priority as a function of the waiting time).
Scheduling Algorithms
Shortest Job First (SJF)
Special case of priority scheduling (priority = expected length of CPU burst) Non-preemptive version: scheduler chooses the process with the least amount of work to do (shortest CPU burst). Preemptive version: scheduler chooses the process with the shortest remaining time to completion -- a running process can be interrupted.
Scheduling Algorithms
Shortest Job First (SJF)
Example: Whats the average waiting time?
Scheduling Algorithms
Shortest Job First (SJF) SJF pros & cons:
+Better average response time. + Its the best you can do to minimize average response time-- can prove the algorithm is optimal. Difficult to predict the future. Unfair-- possible starvation (many short jobs can keep long jobs from making any progress).
Scheduling Algorithms
Multi-level Queues
Maintain multiple ready queues based on process type (e.g., interactive queue, CPU bound queue, etc.). Each queue has a priority; a process is permanently assigned to a queue. May use a different scheduling algorithm in each queue. Need to decide how to schedule between queues.
Scheduling Algorithms
Multi-level Feedback Queues
Adaptive algorithm: Processes can move between queues based on past behavior. Round robin scheduling in each queue -time slice increases in lower priority levels. Queue assignment:
Put new process in highest priority queue. If CPU burst takes longer than one time quantum, drop one level. If CPU burst completes before timer expires, move up one level.