Download presentation
Presentation is loading. Please wait.
Published byVerity Murphy Modified over 9 years ago
1
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling
2
6.2 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms
3
6.3 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Objectives Introduce CPU scheduling Basis for multiprogrammed operating systems Describe various CPU-scheduling algorithms Discuss evaluation criteria for selecting a CPU- scheduling algorithm
4
6.4 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Basic Concepts Maximum CPU utilization with multiprogramming CPU–I/O Burst Cycle Process execution = cycles of CPU execution and I/O waits CPU burst followed by I/O burst CPU bursts are main concern
5
6.5 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Histogram of CPU-burst Times
6
6.6 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition CPU Scheduler Short-term scheduler selects among processes in ready queue, allocates CPU Queue ordered in various ways Depends on algorithm
7
6.7 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition CPU Scheduler Scheduling decisions may take place when process: 1.Switches from running to waiting state 2.Switches from running to ready state 3.Switches from waiting to ready 4. Terminates 1 and 4 are nonpreemptive Process voluntarily yields CPU 2 and 3 are preemptive Process preempted; CPU reallocated
8
6.8 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Dispatcher Dispatcher gives control of CPU to process selected by short-term scheduler; this involves: Switching context Switching to user mode Jumping to proper location in user program to restart Dispatch latency – time dispatcher takes to stop one process and start another running
9
6.9 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms
10
6.10 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Scheduling Criteria CPU utilization – keep CPU busy as possible Throughput – # of processes that complete execution per time unit Turnaround time – amount of time to execute a particular process
11
6.11 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Scheduling Criteria Waiting time –time process has been waiting in ready queue Response time – amount of time from when request submitted until first response is produced Does not include device output
12
6.12 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Scheduling Algorithm Optimization Criteria Maximize CPU utilization Maximize throughput Minimize turnaround time Minimize waiting time Minimize response time
13
6.13 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms
14
6.14 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition First- Come, First-Served (FCFS) Scheduling Simplest algorithm Process that requests CPU first is allocate CPU first Easily manage by FIFO queue Process enters ready queue at tail CPU allocated to process at head Running process removed from queue Process runs to completion
15
6.15 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition First- Come, First-Served (FCFS) Scheduling ProcessBurst Time P 1 24 P 2 3 P 3 3 Suppose processes arrive in order: P 1, P 2, P 3 Gantt Chart for schedule: Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17
16
6.16 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition FCFS Scheduling (Cont.) Suppose processes arrive in order: P 2, P 3, P 1 Gantt chart schedule: Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case
17
6.17 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition FCFS Scheduling (Cont.) Convoy effect - short process behind long process E.g., one CPU-bound and many I/O-bound processes All I/O bound processes wait in ready queue for CPU- bound to give up CPU Lowers CPU and device utilization Compared to if shorter processes were allowed to go first
18
6.18 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Shortest-Job-First (SJF) Scheduling Each process knows length of next CPU burst CPU available => schedule process with smallest burst Ties scheduled in FCFS SJF is optimal – gives minimum average waiting time Difficulty: knowing length of next CPU request Could ask user Could make mathematical predictions E.g.,
19
6.19 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Example of SJF ProcessAril TimeBurst Time P 1 0.06 P 2 2.08 P 3 4.07 P 4 5.03 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
20
6.20 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Example of Shortest-remaining-time-first Add varying arrival times and preemption... ProcessAarri Arrival TimeTBurst Time P 1 08 P 2 14 P 3 29 P 4 35 Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec
21
6.21 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Priority Scheduling Priority number associated with each process SJF => priority scheduling algorithm Priority = inverse of next CPU burst time CPU allocated to process with highest priority E.g., smallest number = highest priority Can be Preemptive or Nonpreemptive
22
6.22 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Priority Scheduling Priority Scheduling may result in starvation Low priority processes may never execute Aging is possible solution Process’ priority increases with time
23
6.23 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Example of Priority Scheduling ProcessAarri Burst TimeTPriority P 1 103 P 2 11 P 3 24 P 4 15 P 5 52 Average waiting time = 8.2 msec
24
6.24 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Round Robin (RR) Each process gets unit of CPU time (time quantum q), usually 10-100 milliseconds After time elapsed, process is preempted, added to end of ready queue n processes in ready queue, time quantum q, Each process gets 1/n of CPU time CPU time in chunks of at most q time units No process waits more than (n-1)q time units
25
6.25 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Round Robin (RR) Timer interrupts every quantum to schedule next process If process finishes before time quantum, next process starts If process not finished, added to tail of queue Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high
26
6.26 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Example of RR with Time Quantum = 4 Time quantum = 4 ms ProcessBurst Time P 1 24 P 2 3 P 3 3 Average wait time: 5.66 ms (6 + 4 + 7) / 3 = 17 / 3 = 5.66
27
6.27 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Example of RR with Time Quantum = 4 Typically, higher average turnaround than SJF But better response time q should be large compared to context switch time q usually 10ms to 100ms, context switch < 10 µs
28
6.28 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Time Quantum and Context Switch Time
29
6.29 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Turnaround Time Varies With The Time Quantum 80% of CPU bursts should be shorter than q
30
6.30 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Multilevel Queue Ready queue partitioned into separate queues, e.g., foreground (interactive) background (batch) Processes cannot switch between queues Queue assignment is permanent Each queue has own scheduling algorithm, e.g., foreground – RR background – FCFS
31
6.31 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Multilevel Queue: Scheduling b/t Qs Fixed priority scheduling Serve all foreground then background Possibility of starvation Time slice Each queue gets certain amount of CPU time Time scheduled amongst processes, e.g., 80% to foreground in RR 20% to background in FCFS
32
6.32 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Multilevel Queue Scheduling
33
6.33 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Multilevel Feedback Queue Processes can move between various queues Aging implemented this way Multilevel-feedback-queue scheduler defined by: Number of queues Scheduling algorithms for each queue Method to determine when to upgrade a process Method to determine when to demote a process Method to determine which queue a process will enter
34
6.34 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Example of Multilevel Feedback Queue Three queues Q 0 – RR; q = 8 ms Q 1 – RR; 1 = 16 ms Q 2 – FCFS
35
6.35 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Example of Multilevel Feedback Queue New job enters Q 0, order is FCFS If process doesn’t finish in 8 ms, moved to Q 1 Q 1 order is FCFS If job does not finish in 16 ms, moved to Q 2 If no jobs in Q 0 and Q 1, jobs in Q 2 processed FCFS
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.