SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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.
 

Destacado (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 a Ch6: CPU Scheduling

Similar a Ch6: CPU Scheduling (20)

ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
cloud computing chapter one in computer science
cloud computing chapter one in computer sciencecloud computing chapter one in computer science
cloud computing chapter one in computer science
 
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
 
ch6.ppt
ch6.pptch6.ppt
ch6.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
 
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
 

Más de Ahmar Hashmi

Más de 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
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

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