SlideShare a Scribd company logo
1 of 33
Silberschatz, Galvin and Gagne ©20026.1
Chapter 6: CPU Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Multiple-Processor Scheduling
Real-Time Scheduling
Algorithm Evaluation
Silberschatz, Galvin and Gagne ©20026.2
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.
CPU burst distribution
Silberschatz, Galvin and Gagne ©20026.3
Alternating Sequence of CPU And I/O
Bursts
Silberschatz, Galvin and Gagne ©20026.4
Histogram of CPU-burst Times
Silberschatz, Galvin and Gagne ©20026.5
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:
1. Switches from running to waiting state.
2. Switches from running to ready state.
3. Switches from waiting to ready.
4. Terminates.
Scheduling under 1 and 4 is nonpreemptive.
All other scheduling is preemptive.
Silberschatz, Galvin and Gagne ©20026.6
Dispatcher
Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler; this
involves:
switching context
switching to user mode
jumping to the proper location in the user program to restart
that program
Dispatch latency – time it takes for the dispatcher to stop
one process and start another running.
Silberschatz, Galvin and Gagne ©20026.7
Scheduling Criteria
CPU utilization – keep the CPU as busy as possible
Throughput – # of processes that complete their
execution per time unit
Turnaround time – amount of time to execute a particular
process
Waiting time – amount of time a process has been waiting
in the ready queue
Response time – amount of time it takes from when a
request was submitted until the first response is
produced, not output (for time-sharing environment)
Silberschatz, Galvin and Gagne ©20026.8
Optimization Criteria
Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
Silberschatz, Galvin and Gagne ©20026.9
First-Come, First-Served (FCFS)
Scheduling
Process Burst Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17
P1 P2 P3
24 27 300
Silberschatz, Galvin and Gagne ©20026.10
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order
P2 , P3 , P1 .
The Gantt chart for the schedule is:
Waiting time for P1 = 6;P2 = 0; P3 = 3
Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case.
Convoy effect short process behind long process
P1P3P2
63 300
Silberschatz, Galvin and Gagne ©20026.11
Shortest-Job-First (SJR)
Scheduling
Associate with each process the length of its next CPU
burst. Use these lengths to schedule the process with the
shortest time.
Two schemes:
nonpreemptive – once CPU given to the process it cannot
be preempted until completes its CPU burst.
preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF).
SJF is optimal – gives minimum average waiting time for
a given set of processes.
Silberschatz, Galvin and Gagne ©20026.12
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
SJF (non-preemptive)
Average waiting time = (0 + 6 + 3 + 7)/4 - 4
Example of Non-Preemptive SJF
P1 P3 P2
73 160
P4
8 12
Silberschatz, Galvin and Gagne ©20026.13
Example of Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
SJF (preemptive)
Average waiting time = (9 + 1 + 0 +2)/4 - 3
P1 P3P2
42 110
P4
5 7
P2 P1
16
Silberschatz, Galvin and Gagne ©20026.14
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.
:Define4.
10,3.
burstCPUnexttheforvaluepredicted2.
burstCPUoflenghtactual1.
≤≤
=
=
+
αα
τ 1n
th
n nt
( ) .t nnn ταατ −+== 11
Silberschatz, Galvin and Gagne ©20026.15
Prediction of the Length of the Next CPU
Burst
Silberschatz, Galvin and Gagne ©20026.16
Examples of Exponential
Averaging
α =0
τn+1 = τn
Recent history does not count.
α =1
τn+1 = tn
Only the actual last CPU burst counts.
If we expand the formula, we get:
τn+1 = α tn+(1 - α) α tn -1 + …
+(1 - α )j
α tn -1 + …
+(1 - α )n=1
tn τ0
Since both α and (1 - α) are less than or equal to 1, each
successive term has less weight than its predecessor.
Silberschatz, Galvin and Gagne ©20026.17
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 the predicted
next CPU burst time.
Problem ≡ Starvation – low priority processes may never
execute.
Solution ≡ Aging – as time progresses increase the
priority of the process.
Silberschatz, Galvin and Gagne ©20026.18
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.
Performance
q large ⇒ FIFO
q small ⇒ q must be large with respect to context switch,
otherwise overhead is too high.
Silberschatz, Galvin and Gagne ©20026.19
Example of RR with Time Quantum =
20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
The Gantt chart is:
Typically, higher average turnaround than SJF, but better
response.
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Silberschatz, Galvin and Gagne ©20026.20
Time Quantum and Context Switch
Time
Silberschatz, Galvin and Gagne ©20026.21
Turnaround Time Varies With The Time
Quantum
Silberschatz, Galvin and Gagne ©20026.22
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; (i.e., serve all from foreground
then from background). Possibility of starvation.
Time slice – each queue gets a certain amount of CPU time
which it can schedule amongst its processes; i.e., 80% to
foreground in RR
20% to background in FCFS
Silberschatz, Galvin and Gagne ©20026.23
Multilevel Queue Scheduling
Silberschatz, Galvin and Gagne ©20026.24
Multilevel Feedback Queue
A process can move between the various queues; aging
can be implemented this way.
Multilevel-feedback-queue scheduler defined by the
following parameters:
number of queues
scheduling algorithms for each queue
method used to determine when to upgrade a process
method used to determine when to demote a process
method used to determine which queue a process will enter
when that process needs service
Silberschatz, Galvin and Gagne ©20026.25
Example of Multilevel Feedback
Queue
Three queues:
Q0 – time quantum 8 milliseconds
Q1 – time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is served FCFS. When it
gains CPU, job receives 8 milliseconds. If it does not finish
in 8 milliseconds, job is moved to queue Q1.
At Q1 job is again served FCFS and receives 16 additional
milliseconds. If it still does not complete, it is preempted
and moved to queue Q2.
Silberschatz, Galvin and Gagne ©20026.26
Multilevel Feedback Queues
Silberschatz, Galvin and Gagne ©20026.27
Multiple-Processor Scheduling
CPU scheduling more complex when multiple CPUs are
available.
Homogeneous processors within a multiprocessor.
Load sharing
Asymmetric multiprocessing – only one processor
accesses the system data structures, alleviating the need
for data sharing.
Silberschatz, Galvin and Gagne ©20026.28
Real-Time Scheduling
Hard real-time systems – required to complete a critical
task within a guaranteed amount of time.
Soft real-time computing – requires that critical processes
receive priority over less fortunate ones.
Silberschatz, Galvin and Gagne ©20026.29
Dispatch Latency
Silberschatz, Galvin and Gagne ©20026.30
Algorithm Evaluation
Deterministic modeling – takes a particular predetermined
workload and defines the performance of each algorithm
for that workload.
Queueing models
Implementation
Silberschatz, Galvin and Gagne ©20026.31
Evaluation of CPU Schedulers by
Simulation
Silberschatz, Galvin and Gagne ©20026.32
Solaris 2 Scheduling
Silberschatz, Galvin and Gagne ©20026.33
Windows 2000 Priorities

More Related Content

What's hot

CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OSharini0810
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3Dwight Sabio
 
Processor / CPU Scheduling
Processor / CPU SchedulingProcessor / CPU Scheduling
Processor / CPU SchedulingIzaz Roghani
 
cpu scheduling
cpu schedulingcpu scheduling
cpu schedulinghashim102
 
Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )HimanshuSharma1389
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinUniversitas Pembangunan Panca Budi
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSMargrat C R
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentationusmankiyani1
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Shreya Kumar
 

What's hot (20)

Ch6
Ch6Ch6
Ch6
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
Os prj ppt
Os prj pptOs prj ppt
Os prj ppt
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
Processor / CPU Scheduling
Processor / CPU SchedulingProcessor / CPU Scheduling
Processor / CPU Scheduling
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 
Scheduling
SchedulingScheduling
Scheduling
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
 
Sa by shekhar
Sa by shekharSa by shekhar
Sa by shekhar
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Ch05
Ch05Ch05
Ch05
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.
 

Viewers also liked

Scheduling Criteria-R.D.Sivakumar
Scheduling Criteria-R.D.SivakumarScheduling Criteria-R.D.Sivakumar
Scheduling Criteria-R.D.SivakumarSivakumar R D .
 
Social Service Management - Tooling Event België 2015
Social Service Management - Tooling Event België 2015Social Service Management - Tooling Event België 2015
Social Service Management - Tooling Event België 2015TOPdesk
 
Galvin-operating System(Ch6)
Galvin-operating System(Ch6)Galvin-operating System(Ch6)
Galvin-operating System(Ch6)dsuyal1
 
Scan scheduling 50 1
Scan scheduling 50 1Scan scheduling 50 1
Scan scheduling 50 1myrajendra
 
NIMM Service Desk Self Assessment
NIMM Service Desk Self AssessmentNIMM Service Desk Self Assessment
NIMM Service Desk Self AssessmentAndy Savvides
 
Jan2007 Establishing A Service Desk Draft
Jan2007   Establishing A Service Desk DraftJan2007   Establishing A Service Desk Draft
Jan2007 Establishing A Service Desk DraftIT Service and Support
 

Viewers also liked (8)

Scheduling Criteria-R.D.Sivakumar
Scheduling Criteria-R.D.SivakumarScheduling Criteria-R.D.Sivakumar
Scheduling Criteria-R.D.Sivakumar
 
Itil in one_hour
Itil in one_hourItil in one_hour
Itil in one_hour
 
Social Service Management - Tooling Event België 2015
Social Service Management - Tooling Event België 2015Social Service Management - Tooling Event België 2015
Social Service Management - Tooling Event België 2015
 
Galvin-operating System(Ch6)
Galvin-operating System(Ch6)Galvin-operating System(Ch6)
Galvin-operating System(Ch6)
 
Scan scheduling 50 1
Scan scheduling 50 1Scan scheduling 50 1
Scan scheduling 50 1
 
NIMM Service Desk Self Assessment
NIMM Service Desk Self AssessmentNIMM Service Desk Self Assessment
NIMM Service Desk Self Assessment
 
Jan2007 Establishing A Service Desk Draft
Jan2007   Establishing A Service Desk DraftJan2007   Establishing A Service Desk Draft
Jan2007 Establishing A Service Desk Draft
 
ROM
ROMROM
ROM
 

Similar to Ch6: CPU Scheduling

6 cpu scheduling
6 cpu scheduling6 cpu scheduling
6 cpu schedulingBaliThorat1
 
ch6_CPU Scheduling.ppt
ch6_CPU Scheduling.pptch6_CPU Scheduling.ppt
ch6_CPU Scheduling.pptridham29
 
scheduling.ppt
scheduling.pptscheduling.ppt
scheduling.pptJohn100878
 
Various CPU Scheduling Algorithms in OS.ppt
Various CPU Scheduling Algorithms in OS.pptVarious CPU Scheduling Algorithms in OS.ppt
Various CPU Scheduling Algorithms in OS.ppttaricvilla
 
ch6 (2).ppt operating system by williamm
ch6 (2).ppt operating system by williammch6 (2).ppt operating system by williamm
ch6 (2).ppt operating system by williammsidrayounas2004
 
ch5_EN_CPUSched_2022.pdf
ch5_EN_CPUSched_2022.pdfch5_EN_CPUSched_2022.pdf
ch5_EN_CPUSched_2022.pdfCuracaoJTR
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt fileDwight Sabio
 
Ch5 cpu-scheduling
Ch5 cpu-schedulingCh5 cpu-scheduling
Ch5 cpu-schedulingAnkit Dubey
 
Operating System - CPU Scheduling Introduction
Operating System - CPU Scheduling IntroductionOperating System - CPU Scheduling Introduction
Operating System - CPU Scheduling IntroductionJimmyWilson26
 
cpu sheduling.pdf
cpu sheduling.pdfcpu sheduling.pdf
cpu sheduling.pdfogpaeog
 
OS-CPU-Scheduling-chap5.pptx
OS-CPU-Scheduling-chap5.pptxOS-CPU-Scheduling-chap5.pptx
OS-CPU-Scheduling-chap5.pptxDrAmarNathDhebla
 
Operating systems chapter 5 silberschatz
Operating systems chapter 5 silberschatzOperating systems chapter 5 silberschatz
Operating systems chapter 5 silberschatzGiulianoRanauro
 

Similar to Ch6: CPU Scheduling (20)

ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
6 cpu scheduling
6 cpu scheduling6 cpu scheduling
6 cpu scheduling
 
ch6_CPU Scheduling.ppt
ch6_CPU Scheduling.pptch6_CPU Scheduling.ppt
ch6_CPU Scheduling.ppt
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
scheduling.ppt
scheduling.pptscheduling.ppt
scheduling.ppt
 
Various CPU Scheduling Algorithms in OS.ppt
Various CPU Scheduling Algorithms in OS.pptVarious CPU Scheduling Algorithms in OS.ppt
Various CPU Scheduling Algorithms in OS.ppt
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
ch6 (2).ppt operating system by williamm
ch6 (2).ppt operating system by williammch6 (2).ppt operating system by williamm
ch6 (2).ppt operating system by williamm
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
ch5_EN_CPUSched_2022.pdf
ch5_EN_CPUSched_2022.pdfch5_EN_CPUSched_2022.pdf
ch5_EN_CPUSched_2022.pdf
 
cpu scheduling.ppt
cpu scheduling.pptcpu scheduling.ppt
cpu scheduling.ppt
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
 
Ch5 cpu-scheduling
Ch5 cpu-schedulingCh5 cpu-scheduling
Ch5 cpu-scheduling
 
Operating System - CPU Scheduling Introduction
Operating System - CPU Scheduling IntroductionOperating System - CPU Scheduling Introduction
Operating System - CPU Scheduling Introduction
 
U2-LP2.ppt
U2-LP2.pptU2-LP2.ppt
U2-LP2.ppt
 
CH06.pdf
CH06.pdfCH06.pdf
CH06.pdf
 
cpu sheduling.pdf
cpu sheduling.pdfcpu sheduling.pdf
cpu sheduling.pdf
 
OS-CPU-Scheduling-chap5.pptx
OS-CPU-Scheduling-chap5.pptxOS-CPU-Scheduling-chap5.pptx
OS-CPU-Scheduling-chap5.pptx
 
Operating systems chapter 5 silberschatz
Operating systems chapter 5 silberschatzOperating systems chapter 5 silberschatz
Operating systems chapter 5 silberschatz
 

More from Ahmar Hashmi

32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_Firewalls
32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_Firewalls32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_Firewalls
32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_FirewallsAhmar Hashmi
 
31 Network Security
31 Network Security31 Network Security
31 Network SecurityAhmar Hashmi
 
28 Network Management_SNMP
28 Network Management_SNMP28 Network Management_SNMP
28 Network Management_SNMPAhmar Hashmi
 
26 Remote Logging_Electronic_Mail_and_File_Transfer
26 Remote Logging_Electronic_Mail_and_File_Transfer26 Remote Logging_Electronic_Mail_and_File_Transfer
26 Remote Logging_Electronic_Mail_and_File_TransferAhmar Hashmi
 
24 Congestion Control_and_Quality_of_Service
24 Congestion Control_and_Quality_of_Service24 Congestion Control_and_Quality_of_Service
24 Congestion Control_and_Quality_of_ServiceAhmar Hashmi
 
23 Process to_Process_Delivery_UDP_TCP_and_SCTP
23 Process to_Process_Delivery_UDP_TCP_and_SCTP23 Process to_Process_Delivery_UDP_TCP_and_SCTP
23 Process to_Process_Delivery_UDP_TCP_and_SCTPAhmar Hashmi
 
22 Network Layer_Delivery_forwarding_and_Routing
22 Network Layer_Delivery_forwarding_and_Routing22 Network Layer_Delivery_forwarding_and_Routing
22 Network Layer_Delivery_forwarding_and_RoutingAhmar Hashmi
 
21 Network Layer_Address_Mapping_Error_Reporting_and_Multicasting
21 Network Layer_Address_Mapping_Error_Reporting_and_Multicasting21 Network Layer_Address_Mapping_Error_Reporting_and_Multicasting
21 Network Layer_Address_Mapping_Error_Reporting_and_MulticastingAhmar Hashmi
 
20 Network Layer_Internet_Protocol
20 Network Layer_Internet_Protocol20 Network Layer_Internet_Protocol
20 Network Layer_Internet_ProtocolAhmar Hashmi
 
19 Network Layer_Logical_Addressing
19 Network Layer_Logical_Addressing19 Network Layer_Logical_Addressing
19 Network Layer_Logical_AddressingAhmar Hashmi
 
18 Virtual Circuit_Networks_Frame_Relay_and_ATM
18 Virtual Circuit_Networks_Frame_Relay_and_ATM18 Virtual Circuit_Networks_Frame_Relay_and_ATM
18 Virtual Circuit_Networks_Frame_Relay_and_ATMAhmar Hashmi
 
16 Wireless WANs_Cellular_Telephone_and_Satellite_Networks
16 Wireless WANs_Cellular_Telephone_and_Satellite_Networks16 Wireless WANs_Cellular_Telephone_and_Satellite_Networks
16 Wireless WANs_Cellular_Telephone_and_Satellite_NetworksAhmar Hashmi
 
15 Connecting LANs_Backbone_Networks_and_Virtual_LAN
15 Connecting LANs_Backbone_Networks_and_Virtual_LAN15 Connecting LANs_Backbone_Networks_and_Virtual_LAN
15 Connecting LANs_Backbone_Networks_and_Virtual_LANAhmar Hashmi
 
13 Wired Lans_Ethernet
13 Wired Lans_Ethernet13 Wired Lans_Ethernet
13 Wired Lans_EthernetAhmar Hashmi
 

More from Ahmar Hashmi (20)

32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_Firewalls
32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_Firewalls32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_Firewalls
32 Security in_Internet_IP_SEC_SSL/TLS_PGN_VPN_and_Firewalls
 
31 Network Security
31 Network Security31 Network Security
31 Network Security
 
30 Cryptography
30 Cryptography30 Cryptography
30 Cryptography
 
29 Multimedia
29 Multimedia29 Multimedia
29 Multimedia
 
28 Network Management_SNMP
28 Network Management_SNMP28 Network Management_SNMP
28 Network Management_SNMP
 
27 WWW and_HTTP
27 WWW and_HTTP27 WWW and_HTTP
27 WWW and_HTTP
 
26 Remote Logging_Electronic_Mail_and_File_Transfer
26 Remote Logging_Electronic_Mail_and_File_Transfer26 Remote Logging_Electronic_Mail_and_File_Transfer
26 Remote Logging_Electronic_Mail_and_File_Transfer
 
25 DNS
25 DNS25 DNS
25 DNS
 
24 Congestion Control_and_Quality_of_Service
24 Congestion Control_and_Quality_of_Service24 Congestion Control_and_Quality_of_Service
24 Congestion Control_and_Quality_of_Service
 
23 Process to_Process_Delivery_UDP_TCP_and_SCTP
23 Process to_Process_Delivery_UDP_TCP_and_SCTP23 Process to_Process_Delivery_UDP_TCP_and_SCTP
23 Process to_Process_Delivery_UDP_TCP_and_SCTP
 
22 Network Layer_Delivery_forwarding_and_Routing
22 Network Layer_Delivery_forwarding_and_Routing22 Network Layer_Delivery_forwarding_and_Routing
22 Network Layer_Delivery_forwarding_and_Routing
 
21 Network Layer_Address_Mapping_Error_Reporting_and_Multicasting
21 Network Layer_Address_Mapping_Error_Reporting_and_Multicasting21 Network Layer_Address_Mapping_Error_Reporting_and_Multicasting
21 Network Layer_Address_Mapping_Error_Reporting_and_Multicasting
 
20 Network Layer_Internet_Protocol
20 Network Layer_Internet_Protocol20 Network Layer_Internet_Protocol
20 Network Layer_Internet_Protocol
 
19 Network Layer_Logical_Addressing
19 Network Layer_Logical_Addressing19 Network Layer_Logical_Addressing
19 Network Layer_Logical_Addressing
 
18 Virtual Circuit_Networks_Frame_Relay_and_ATM
18 Virtual Circuit_Networks_Frame_Relay_and_ATM18 Virtual Circuit_Networks_Frame_Relay_and_ATM
18 Virtual Circuit_Networks_Frame_Relay_and_ATM
 
17 SONET/SDH
17 SONET/SDH17 SONET/SDH
17 SONET/SDH
 
16 Wireless WANs_Cellular_Telephone_and_Satellite_Networks
16 Wireless WANs_Cellular_Telephone_and_Satellite_Networks16 Wireless WANs_Cellular_Telephone_and_Satellite_Networks
16 Wireless WANs_Cellular_Telephone_and_Satellite_Networks
 
15 Connecting LANs_Backbone_Networks_and_Virtual_LAN
15 Connecting LANs_Backbone_Networks_and_Virtual_LAN15 Connecting LANs_Backbone_Networks_and_Virtual_LAN
15 Connecting LANs_Backbone_Networks_and_Virtual_LAN
 
14 Wireless LAN
14 Wireless LAN14 Wireless LAN
14 Wireless LAN
 
13 Wired Lans_Ethernet
13 Wired Lans_Ethernet13 Wired Lans_Ethernet
13 Wired Lans_Ethernet
 

Recently uploaded

ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 

Recently uploaded (20)

ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 

Ch6: CPU Scheduling

  • 1. Silberschatz, Galvin and Gagne ©20026.1 Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation
  • 2. Silberschatz, Galvin and Gagne ©20026.2 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. CPU burst distribution
  • 3. Silberschatz, Galvin and Gagne ©20026.3 Alternating Sequence of CPU And I/O Bursts
  • 4. Silberschatz, Galvin and Gagne ©20026.4 Histogram of CPU-burst Times
  • 5. Silberschatz, Galvin and Gagne ©20026.5 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: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready. 4. Terminates. Scheduling under 1 and 4 is nonpreemptive. All other scheduling is preemptive.
  • 6. Silberschatz, Galvin and Gagne ©20026.6 Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency – time it takes for the dispatcher to stop one process and start another running.
  • 7. Silberschatz, Galvin and Gagne ©20026.7 Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process Waiting time – amount of time a process has been waiting in the ready queue Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)
  • 8. Silberschatz, Galvin and Gagne ©20026.8 Optimization Criteria Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time
  • 9. Silberschatz, Galvin and Gagne ©20026.9 First-Come, First-Served (FCFS) Scheduling Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: Waiting time for P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 P1 P2 P3 24 27 300
  • 10. Silberschatz, Galvin and Gagne ©20026.10 FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P2 , P3 , P1 . The Gantt chart for the schedule is: Waiting time for P1 = 6;P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case. Convoy effect short process behind long process P1P3P2 63 300
  • 11. Silberschatz, Galvin and Gagne ©20026.11 Shortest-Job-First (SJR) Scheduling Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes: nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst. preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). SJF is optimal – gives minimum average waiting time for a given set of processes.
  • 12. Silberschatz, Galvin and Gagne ©20026.12 Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (non-preemptive) Average waiting time = (0 + 6 + 3 + 7)/4 - 4 Example of Non-Preemptive SJF P1 P3 P2 73 160 P4 8 12
  • 13. Silberschatz, Galvin and Gagne ©20026.13 Example of Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (preemptive) Average waiting time = (9 + 1 + 0 +2)/4 - 3 P1 P3P2 42 110 P4 5 7 P2 P1 16
  • 14. Silberschatz, Galvin and Gagne ©20026.14 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. :Define4. 10,3. burstCPUnexttheforvaluepredicted2. burstCPUoflenghtactual1. ≤≤ = = + αα τ 1n th n nt ( ) .t nnn ταατ −+== 11
  • 15. Silberschatz, Galvin and Gagne ©20026.15 Prediction of the Length of the Next CPU Burst
  • 16. Silberschatz, Galvin and Gagne ©20026.16 Examples of Exponential Averaging α =0 τn+1 = τn Recent history does not count. α =1 τn+1 = tn Only the actual last CPU burst counts. If we expand the formula, we get: τn+1 = α tn+(1 - α) α tn -1 + … +(1 - α )j α tn -1 + … +(1 - α )n=1 tn τ0 Since both α and (1 - α) are less than or equal to 1, each successive term has less weight than its predecessor.
  • 17. Silberschatz, Galvin and Gagne ©20026.17 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 the predicted next CPU burst time. Problem ≡ Starvation – low priority processes may never execute. Solution ≡ Aging – as time progresses increase the priority of the process.
  • 18. Silberschatz, Galvin and Gagne ©20026.18 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. Performance q large ⇒ FIFO q small ⇒ q must be large with respect to context switch, otherwise overhead is too high.
  • 19. Silberschatz, Galvin and Gagne ©20026.19 Example of RR with Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24 The Gantt chart is: Typically, higher average turnaround than SJF, but better response. P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162
  • 20. Silberschatz, Galvin and Gagne ©20026.20 Time Quantum and Context Switch Time
  • 21. Silberschatz, Galvin and Gagne ©20026.21 Turnaround Time Varies With The Time Quantum
  • 22. Silberschatz, Galvin and Gagne ©20026.22 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; (i.e., serve all from foreground then from background). Possibility of starvation. Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR 20% to background in FCFS
  • 23. Silberschatz, Galvin and Gagne ©20026.23 Multilevel Queue Scheduling
  • 24. Silberschatz, Galvin and Gagne ©20026.24 Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way. Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service
  • 25. Silberschatz, Galvin and Gagne ©20026.25 Example of Multilevel Feedback Queue Three queues: Q0 – time quantum 8 milliseconds Q1 – time quantum 16 milliseconds Q2 – FCFS Scheduling A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1. At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.
  • 26. Silberschatz, Galvin and Gagne ©20026.26 Multilevel Feedback Queues
  • 27. Silberschatz, Galvin and Gagne ©20026.27 Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available. Homogeneous processors within a multiprocessor. Load sharing Asymmetric multiprocessing – only one processor accesses the system data structures, alleviating the need for data sharing.
  • 28. Silberschatz, Galvin and Gagne ©20026.28 Real-Time Scheduling Hard real-time systems – required to complete a critical task within a guaranteed amount of time. Soft real-time computing – requires that critical processes receive priority over less fortunate ones.
  • 29. Silberschatz, Galvin and Gagne ©20026.29 Dispatch Latency
  • 30. Silberschatz, Galvin and Gagne ©20026.30 Algorithm Evaluation Deterministic modeling – takes a particular predetermined workload and defines the performance of each algorithm for that workload. Queueing models Implementation
  • 31. Silberschatz, Galvin and Gagne ©20026.31 Evaluation of CPU Schedulers by Simulation
  • 32. Silberschatz, Galvin and Gagne ©20026.32 Solaris 2 Scheduling
  • 33. Silberschatz, Galvin and Gagne ©20026.33 Windows 2000 Priorities