cpu scheduling tanenbaum ch 2.4 silberchatz and galvin ch 5
TRANSCRIPT
![Page 1: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/1.jpg)
CPU Scheduling
Tanenbaum Ch 2.4
Silberchatz and Galvin Ch 5
![Page 2: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/2.jpg)
cs431-cotter 2
Basic Concepts• CPU - I/O Burst Cycle• CPU Burst Distribution
0
20
40
60
80
100
120
140
160
0 8 16 24 32
![Page 3: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/3.jpg)
cs431-cotter 3
CPU Scheduling
• Decision points:– Process switch from running to waiting state– Process switch from running to ready state– Process switch from waiting to ready state– Process terminates
• Scheduling types– non-preemptive– preemptive
![Page 4: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/4.jpg)
cs431-cotter 4
Task Dispatcher
• Functions:– Switching context– Switching to user mode– Jumping to PC location
• The time needed to stop one process and start up another is known as dispatch latency.
![Page 5: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/5.jpg)
cs431-cotter 5
Batch Interactive Real time
Categories of Scheduling Algorithms
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 6: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/6.jpg)
cs431-cotter 6
Figure 2-39. Some goals of the scheduling algorithm under different circumstances.
Scheduling Algorithm Goals
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 7: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/7.jpg)
cs431-cotter 7
First-come first-served Shortest job first Shortest remaining Time
next
Scheduling in Batch Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 8: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/8.jpg)
cs431-cotter 8
Scheduling Algorithms(First-come, First-served)
• Determine avg waiting time if: – (P1, P2, P3) or (P3, P2, P1)
Process Burst Time
P1 24
P2 3 P3 3
0 10 20 30
![Page 9: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/9.jpg)
cs431-cotter 9
Scheduling Algorithms(First-come, First-served)
• Determine avg waiting time if: – (P1, P2, P3)
Process Burst Time
P1 24
P2 3 P3 3
0 10 20 30
P1 ……………………………………………..P2…..P3…….
Waiting time:P1: 0P2: 24P3: 27
avg: 17
![Page 10: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/10.jpg)
cs431-cotter 10
Scheduling Algorithms(First-come, First-served)
• Determine avg waiting time if: – (P3, P2, P1)Process Burst Time
P1 24
P2 3 P3 3
0 10 20 30
P3….P2….P1………………………………………………...
Waiting time:P1: 6P2: 3P3: 0
avg: 3
![Page 11: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/11.jpg)
cs431-cotter 11
Scheduling Algorithms(Shortest Job First)
• Schedule jobs based on their length.• May be preemptive
– If a job is queued that is shorter than the remaining time on the current job, there is a switch.
• May be non-preemptive.– Once a job has started, it works to its normal switch.
![Page 12: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/12.jpg)
cs431-cotter 12
Scheduling Algorithms(Shortest Job First)
• Non-Preemptive / preemptive SJF
Process Arr. Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
![Page 13: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/13.jpg)
cs431-cotter 13
Scheduling Algorithms(Shortest Job First)
• Preemptive SJFProcess Arr. Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
P1..
P1|
![Page 14: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/14.jpg)
cs431-cotter 14
Scheduling Algorithms(Shortest Job First)
• Preemptive SJFProcess Arr. Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
P1..P2..
P1 P2 | |
![Page 15: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/15.jpg)
cs431-cotter 15
Scheduling Algorithms(Shortest Job First)
• Preemptive SJFProcess Arr. Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
P1..P2..P3
P1 P2 P3| | |
![Page 16: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/16.jpg)
cs431-cotter 16
Scheduling Algorithms(Shortest Job First)
• Preemptive SJFProcess Arr. Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
P1..P2..P3P2..
P1 P2 P3P4| | | |
![Page 17: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/17.jpg)
cs431-cotter 17
Scheduling Algorithms(Shortest Job First)
• Preemptive SJFProcess Arr. Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
P1..P2..P3P2..P4…….
P1 P2 P3P4| | | |
![Page 18: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/18.jpg)
cs431-cotter 18
Scheduling Algorithms(Shortest Job First)
• Preemptive SJFProcess Arr. Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
P1..P2..P3P2..P4…….P1……….
P1 P2 P3P4| | | |
![Page 19: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/19.jpg)
cs431-cotter 19
Scheduling Algorithms(Shortest Job First)
• Non-preemptive SJFProcess Arr. Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
0 10 20 30
P1…………..P3P2…….P4…….
P1 P2 P3P4| | | |
![Page 20: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/20.jpg)
cs431-cotter 20
Scheduling Algorithms(Shortest Job First)
• Determining the length of the jobs.• Use weighted average burst lengths
10
*)1(*1
nnn t
![Page 21: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/21.jpg)
cs431-cotter 21
Scheduling Algorithms(Shortest Job First)
2
1
![Page 22: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/22.jpg)
cs431-cotter 22
Round-robin scheduling Priority scheduling Multiple queues Shortest process next Guaranteed scheduling Lottery scheduling Fair-share scheduling
Scheduling in Interactive Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 23: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/23.jpg)
cs431-cotter 23
Round Robin Scheduling
• Developed in response to time-sharing systems.
• Each job is given control of the CPU for a short period - a time quantum. (In the range of 10-100 milliseconds.)
• Control then passes to the next job (FIFO?)• Average waiting time dependent on job size,
quantum size.
![Page 24: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/24.jpg)
cs431-cotter 24
Figure 2-41. Round-robin scheduling. (a) The list of runnable processes. (b) The list of runnable
processes after B uses up its quantum.
Round-Robin Scheduling
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 25: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/25.jpg)
cs431-cotter 25
Round Robin Scheduling
0 10 20 30
Process Burst Time
P1 6
P2 3 P3 1
P4 7
All processes arrive at T=0
Vary Quantum time from1 to 7. Calculate averageturnaround time (to job completion).
![Page 26: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/26.jpg)
cs431-cotter 26
Round Robin Scheduling
0 10 20 30
Process Burst Time
P1 6
P2 3 P3 1
P4 7
All processes arrive at T=0Quantum Average Size Turnaround
1 11
P1P2P3P4P1P2P4P1P2P4P1P4P1P4P1P4P4
![Page 27: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/27.jpg)
cs431-cotter 27
Round Robin Scheduling
0 10 20 30
Process Burst Time
P1 6
P2 3 P3 1
P4 7
All processes arrive at T=0Quantum Average Size Turnaround
1 112 11.5
P1..P2..P3P4..P1..P2P4..P1..P4..P4
![Page 28: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/28.jpg)
cs431-cotter 28
Round Robin Scheduling
0 10 20 30
Process Burst Time
P1 6
P2 3 P3 1
P4 7
All processes arrive at T=0Quantum Average Size Turnaround
1 112 11.53 10.75
P1. . P2. . P3P4. . P1. . P4. . .P4
![Page 29: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/29.jpg)
cs431-cotter 29
Round Robin Scheduling
10
11
12
9
8
13
1 2 3 4 5 6 7 Quantum
avg. turnaround
![Page 30: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/30.jpg)
cs431-cotter 30
Priority Scheduling
• Each process (or class of processes) is given a priority.
• Jobs are executed in priority order• Issue: If there are sufficient high priority
jobs, lower priority jobs may never get scheduled.
• One solution: Aging of processes. After a job has been in queue for a given period of time, raise its priority.
![Page 31: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/31.jpg)
cs431-cotter 31
Figure 2-42. A scheduling algorithm with four priority classes.
Priority Scheduling
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 32: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/32.jpg)
cs431-cotter 32
Multi-level queue Scheduling
• Partition the job space into distinct classes or queues– foreground / background– system / interactive / editing / batch / student– etc.
• Independently assign queueing service disciplines• Assign queue priorities
– Highest to lowest (empty one queue before starting next)– Divide time between queues
• 80 / 20 • 30 / 20 / 20 / 20 / 10
![Page 33: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/33.jpg)
cs431-cotter 33
Multilevel Feedback Queue Scheduling
• Similar to Multilevel queue scheduling, but jobs are allowed to move between queues.
• Avoids process starvation by allowing neglected jobs to move up to a higher queue.
• Differentiate queues by (for example) quantum size– queue 1 = 8 ms– queue 2 = 16 ms– queue 3 = FCFS
![Page 34: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/34.jpg)
cs431-cotter 34
Figure 2-43. (a) Possible scheduling of user-level threads with a 50-msec process quantum and threads that run 5 msec per
CPU burst.
Thread Scheduling (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 35: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/35.jpg)
cs431-cotter 35
Figure 2-43. (b) Possible scheduling of kernel-level threads with the same characteristics as (a).
Thread Scheduling (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 36: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/36.jpg)
cs431-cotter 36
Multiple Processor Scheduling
• CPU scheduling more complex when multiple CPUs are available
• Homogeneous processors within a multiprocessor are usual (heterogeneous processors found in distributed systems).
• Load sharing used with SMP. – Single queue, multiple servers.
• Asymmetric Multiprocessing (AMP)– Assign roles (system control, application processing)– Avoids system data sharing
![Page 37: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/37.jpg)
cs431-cotter 37
Benefits of Multiprocessors Process Scheduling
– Process inter-arrival time variation can be characterized by coefficient of variation = s / s• standard deviation of interarrival time / mean service time• ratio of 1 = exponential distribution. (your mileage may vary…)
– Differences between scheduling algorithms become much less important in multiprocessor systems
Single processor
Dual processorRR
to F
CF
Sth
rupu
t rat
io
Coefficient of Variation
![Page 38: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/38.jpg)
cs431-cotter 38
Benefits of Multiprocessors Thread Scheduling
• Allows true parallel processing within an application
• However, if there is significant interaction among threads, small differences in thread management & scheduling can have big results.
• General Approaches used– Load Sharing - (not necessarily load balancing)– Gang Scheduling - Schedule related threads together– Dynamic Scheduling - allow # of threads to vary
![Page 39: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/39.jpg)
cs431-cotter 39
Real-Time Scheduling
• System Response Classifications– Hard real-time System - requires response
guarantees– Soft real-time System – response not guaranteed
• Dispatch Latency
Interruptprocessing
conflicts dispatch
Real-timeprocessexecution
Dispatch latency
Response interval
![Page 40: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/40.jpg)
cs431-cotter 40
Summary
• Primary job of an OS is to schedule processes– Batch– Interactive– Real Time
• Selection of scheduling algorithm depends on optimization criteria
![Page 41: CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5](https://reader030.vdocuments.site/reader030/viewer/2022032516/56649c765503460f9492a99a/html5/thumbnails/41.jpg)
cs431-cotter 41
Questions• On a system with multilevel queue scheduling, would you expect to
see the same scheduling algorithms used on all levels, or would you expect them to be different? Justify your answer.
• Consider the following set of processes, with the length of the CPU burst time given in milliseconds. The processes are assumed to have arrived in the order P1, P2, P3, P4. Process Job Size
P1 10P2 1P3 2P4 5
Of the scheduling algorithms FCFS, SJF, and RR(qt=2) which algorithm offers the best waiting time?
• In many multiprocessing systems, although there is a fixed limit to the amount of time that a job can keep control of the CPU, in practice, the jobs are released earlier. Why?
• The book talked about the multiple queueing system used by CTSS. If a process needed 30 quanta to complete, how many times would it be swapped in to complete?
• How does Lottery Scheduling work? What is its principle advantage over, say, Guaranteed Scheduling?