SlideShare a Scribd company logo
Chapter 6
1
CPU Scheduling
Chapter 6
2
Classification of Scheduling Activity
 Long-term: which process to admit
 Medium-term: which process to swap in or out
 Short-term: which ready process to execute next
3
Long-Term Scheduling
 Determines which programs are admitted
to the system for processing
 Controls the degree of multiprogramming
 If more processes are admitted
• less likely that all processes will be blocked
• better CPU usage
• each process has smaller fraction of the CPU
 The long term scheduler may attempt to
keep a mix of processor-bound and I/O-
bound processes
4
Medium-Term Scheduling
 Swapping decisions based on the need to
manage multiprogramming
• Allows the long-term scheduler to admit more
processes than actually fit in memory
• but too many processes can increase disk
activity (paging), so there is some “optimum”
level of multiprogramming.
 Done by memory management software
(chapter 8)
5
Short-Term Scheduling
 Determines which process is going to execute
next (also called CPU scheduling)
 the focus of this chapter..
 invoked on a event that may lead to choosing
another process for execution:
• clock interrupts
• I/O interrupts
• operating system calls and traps, including I/O
• signals
6
The CPU-I/O Cycle
Silberschatz, Galvin, and Gagne 1999
“CPU-bound”
processes require
more CPU time than
I/O time
“I/O-bound”
processes spend
most of their time
waiting for I/O.
7
Histogram of CPU-burst Times
Silberschatz, Galvin, and Gagne 1999
8
Our focus
 Uniprocessor Scheduling: scheduling a
single CPU among all the processes in the
system
 Key Criteria:
• Maximize CPU utilization
• Maximize throughput
• Minimize waiting times
• Minimize response time
• Minimize turnaround time
9
Criteria
 Maximize CPU utilization
• Efficiency
• Need to keep the CPU busy
 Minimize waiting times
• Time spent waiting in READY queue
• Each process should get a fair share of the
CPU
10
Criteria
 Maximize throughput
• Process completions per time unit
 Minimize response time
• From a user request to the first response
• I/O bound processes
 Minimize turnaround time
• CPU-bound process equivalent of response
time
• Elapsed time to complete a process
11
User vs. System Scheduling Criteria
User-oriented
 Turnaround Time (batch systems): Elapsed time
from the submission of a process to its
completion
 Response Time (interactive systems): Elapsed
time from the submission of a request to the first
response
System-oriented
 CPU utilization
 fairness
 throughput: processes completed per unit time
12
Two Components of Scheduling Policies
Selection function
 which process in the ready queue is selected next
for execution?
Decision mode
 at what times is the selection function exercised?
• Nonpreemptive
 A process in the running state runs until it blocks or
ends
• Preemptive
 Currently running process may be interrupted and
moved to the Ready state by the OS
 Prevents any one process from monopolizing the
CPU
13
Policy vs. Mechanism
 Important in scheduling and resource
allocation algorithms
 Policy
• What is to be done
 Mechanism
• How to do it
 Policy: All users equal access
 Mechanism: round robin scheduling
 Policy: Paid jobs get higher priority
 Mechanism: Preemptive scheduling
algorithm
14
A running example to discuss various
scheduling policies
Process
Arrival
Time
Burst
Time
1
2
3
4
5
0
2
4
6
8
3
6
4
5
2
15
First Come First Served (FCFS)
 Selection function: the process that has
been waiting the longest in the ready
queue (hence, FCFS, FIFO queue)
 Decision mode: nonpreemptive
• a process runs until it blocks itself (I/O or other)
16
FCFS Drawbacks
 Favors CPU-bound processes
• A process that does not perform any I/O will
monopolize the processor!
• I/O-bound processes have to wait until CPU-
bound process completes
• They may have to wait even when their I/Os
have completed
 poor device utilization
• We could reduce the average wait time by
giving more priority to I/O bound processes
17
Shortest Job First (SJF)
 Selection function: the process with the shortest
expected CPU burst time
 Decision mode: non-preemptive
 I/O bound processes will be picked first
 We need to estimate the expected CPU burst time
for each process: on the basis of past behavior.
Shortest job
First (SJF)
18
Estimating the Required CPU Burst
 Can average all past history equally
 But recent history of a process is more likely
to reflect future behavior
 A common technique for that is to use
exponential averaging
• S[n+1] = a T[n] + (1-a) S[n] ; 0 < a < 1
• Puts more weight on recent instances
whenever a > 1/n
19
Exponentially Decreasing Coefficients
20
Exponential Averaging
 Set S[1] = 0 to give new processes high priority.
 Exponential averaging tracks changes in process
behavior much faster than simple averaging.
21
Shortest Job First: Critique
 SJF implicitly incorporates priorities: shortest
jobs are given preference.
• Typically these are I/O bound jobs
 Longer processes can starve if there is a
steady supply of shorter processes
 Lack of preemption not suitable in a time
sharing environment
• CPU bound process gets lower priority
• But a process doing no I/O at all could
monopolize the CPU if it is the first one in the
system
22
Shortest Remaining Time (SRT) =
Preemptive SJF
 If a process arrives in the Ready queue
with estimated CPU burst less than
remaining time of the currently running
process, preempt.
 Prevents long jobs from dominating.
• But must keep track of remaining burst
times
 Better turnaround time than SJF
• Short jobs get immediate preference
23
 Selection function: same as FCFS
 Decision mode: Preemptive
• Maximum time slice (typically 10 - 100 ms)
enforced by timer interrupt
• running process is put at the tail of the ready
queue
Round-Robin
24
Time Quantum for Round Robin
 must be substantially larger than process switch time
 should be larger than the typical CPU burst
 If too large, degenerates to FCFS
 Too small, excessive context switches (overhead)
25
Fairness vs. Efficiency
 Each context switch has the OS using the
CPU instead of the user process
• give up CPU, save all info, reload w/ status of
incoming process
• Say 20 ms quantum length, 5 ms context switch
• Waste of resources
 20% of CPU time (5/20) for context switch
• If 500 ms quantum, better use of resources
 1% of CPU time (5/500) for context switch
 Bad if lots of users in system – interactive users
waiting for CPU
• Balance found depends on job mix
26
Round Robin: Critique
 Still favors CPU-bound processes
• An I/O bound process uses the CPU for a time less than
the time quantum and then is blocked waiting for I/O
• A CPU-bound process runs for its whole time slice and
goes back into the ready queue (in front of the blocked
processes)
 One solution: virtual round robin (VRR, not in
book…)
• When a I/O has completed, the blocked process is
moved to an auxiliary queue which gets preference over
the main ready queue
• A process dispatched from the auxiliary queue gets a
shorter time quantum (what is “left over” from its
quantum when it was last selected from the ready
queue)

More Related Content

PPTX
UNIPROCESS SCHEDULING.pptx
PPTX
Process Scheduling in operating systems.pptx
PPT
Process Scheduling in Ope Spptystems rating
PPT
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
PDF
Ch6 cpu scheduling
PPTX
Chapter 3 - Operating System Scheduling.pptx
PPTX
CPU Scheduling.pptx this is operating system
PPTX
Operating Systems - CPU Scheduling Process
UNIPROCESS SCHEDULING.pptx
Process Scheduling in operating systems.pptx
Process Scheduling in Ope Spptystems rating
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
Ch6 cpu scheduling
Chapter 3 - Operating System Scheduling.pptx
CPU Scheduling.pptx this is operating system
Operating Systems - CPU Scheduling Process

Similar to pscheduling.ppt (20)

PDF
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
PPTX
Operating systems - Processes Scheduling
PPTX
Cpu_sheduling.pptx
PDF
PPTX
Scheduling algo(by HJ)
PPT
Chapter No 4 CPU Scheduling and Algorithms.ppt
PPT
Sceduling
PPTX
Process Scheduling Algorithms | Interviews | Operating system
PPT
scheduling
PPTX
Preemptive process example.pptx
PPT
Operating System Scheduling
PPTX
3Chapter Three- CPU Scheduling this is the best.pptx
PPT
ch_scheduling (1).ppt
PPT
operating system Scheduling process unit 3.ppt
DOCX
UNIT II - CPU SCHEDULING.docx
PPTX
Cpu scheduling
PPT
Ch05 cpu-scheduling
PPT
OS-operating systems- ch05 (CPU Scheduling) ...
PPT
Planificacion
PPTX
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
Operating systems - Processes Scheduling
Cpu_sheduling.pptx
Scheduling algo(by HJ)
Chapter No 4 CPU Scheduling and Algorithms.ppt
Sceduling
Process Scheduling Algorithms | Interviews | Operating system
scheduling
Preemptive process example.pptx
Operating System Scheduling
3Chapter Three- CPU Scheduling this is the best.pptx
ch_scheduling (1).ppt
operating system Scheduling process unit 3.ppt
UNIT II - CPU SCHEDULING.docx
Cpu scheduling
Ch05 cpu-scheduling
OS-operating systems- ch05 (CPU Scheduling) ...
Planificacion
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
Ad

More from ansariparveen06 (20)

PPT
Preprocessing of data mining process.ppt
PPT
8. Ozone and Environmental issue and solution.ppt
PPTX
ALP intro assembly language programing.pptx
PPT
cpphtp9_Exception handling in c++ .ppt
PPT
introduction to javascript concepts .ppt
PPT
java multi threading and synchronisation.ppt
PPTX
Environmental studies part2 bscit sem2.pptx
PPTX
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
PPT
exception-handling-in-java programming.ppt
PPTX
brief introduction to core java programming.pptx
PPTX
Module1 evs Environmental Pollution.pptx
PPTX
Internet_Banking e commerce in banking.pptx
PPTX
UNIT1 Decision Support System in BI.pptx
PPT
logic gate based on discrete mathematics.ppt
PPTX
Overview on how to Disciplining in life .pptx
PPT
presentation on java server pages vs servlet.ppt
PPT
Introduction to Java Servlets and JSP (1).ppt
PPTX
enterprise java - introduction to servlet.pptx
PPTX
Introduction to Operating - Systems.pptx
PDF
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
Preprocessing of data mining process.ppt
8. Ozone and Environmental issue and solution.ppt
ALP intro assembly language programing.pptx
cpphtp9_Exception handling in c++ .ppt
introduction to javascript concepts .ppt
java multi threading and synchronisation.ppt
Environmental studies part2 bscit sem2.pptx
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
exception-handling-in-java programming.ppt
brief introduction to core java programming.pptx
Module1 evs Environmental Pollution.pptx
Internet_Banking e commerce in banking.pptx
UNIT1 Decision Support System in BI.pptx
logic gate based on discrete mathematics.ppt
Overview on how to Disciplining in life .pptx
presentation on java server pages vs servlet.ppt
Introduction to Java Servlets and JSP (1).ppt
enterprise java - introduction to servlet.pptx
Introduction to Operating - Systems.pptx
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
Ad

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Complications of Minimal Access Surgery at WLH
PDF
Classroom Observation Tools for Teachers
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
master seminar digital applications in india
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Insiders guide to clinical Medicine.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Complications of Minimal Access Surgery at WLH
Classroom Observation Tools for Teachers
Supply Chain Operations Speaking Notes -ICLT Program
Week 4 Term 3 Study Techniques revisited.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial diseases, their pathogenesis and prophylaxis
master seminar digital applications in india
102 student loan defaulters named and shamed – Is someone you know on the list?
O7-L3 Supply Chain Operations - ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
VCE English Exam - Section C Student Revision Booklet
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Insiders guide to clinical Medicine.pdf

pscheduling.ppt

  • 2. 2 Classification of Scheduling Activity  Long-term: which process to admit  Medium-term: which process to swap in or out  Short-term: which ready process to execute next
  • 3. 3 Long-Term Scheduling  Determines which programs are admitted to the system for processing  Controls the degree of multiprogramming  If more processes are admitted • less likely that all processes will be blocked • better CPU usage • each process has smaller fraction of the CPU  The long term scheduler may attempt to keep a mix of processor-bound and I/O- bound processes
  • 4. 4 Medium-Term Scheduling  Swapping decisions based on the need to manage multiprogramming • Allows the long-term scheduler to admit more processes than actually fit in memory • but too many processes can increase disk activity (paging), so there is some “optimum” level of multiprogramming.  Done by memory management software (chapter 8)
  • 5. 5 Short-Term Scheduling  Determines which process is going to execute next (also called CPU scheduling)  the focus of this chapter..  invoked on a event that may lead to choosing another process for execution: • clock interrupts • I/O interrupts • operating system calls and traps, including I/O • signals
  • 6. 6 The CPU-I/O Cycle Silberschatz, Galvin, and Gagne 1999 “CPU-bound” processes require more CPU time than I/O time “I/O-bound” processes spend most of their time waiting for I/O.
  • 7. 7 Histogram of CPU-burst Times Silberschatz, Galvin, and Gagne 1999
  • 8. 8 Our focus  Uniprocessor Scheduling: scheduling a single CPU among all the processes in the system  Key Criteria: • Maximize CPU utilization • Maximize throughput • Minimize waiting times • Minimize response time • Minimize turnaround time
  • 9. 9 Criteria  Maximize CPU utilization • Efficiency • Need to keep the CPU busy  Minimize waiting times • Time spent waiting in READY queue • Each process should get a fair share of the CPU
  • 10. 10 Criteria  Maximize throughput • Process completions per time unit  Minimize response time • From a user request to the first response • I/O bound processes  Minimize turnaround time • CPU-bound process equivalent of response time • Elapsed time to complete a process
  • 11. 11 User vs. System Scheduling Criteria User-oriented  Turnaround Time (batch systems): Elapsed time from the submission of a process to its completion  Response Time (interactive systems): Elapsed time from the submission of a request to the first response System-oriented  CPU utilization  fairness  throughput: processes completed per unit time
  • 12. 12 Two Components of Scheduling Policies Selection function  which process in the ready queue is selected next for execution? Decision mode  at what times is the selection function exercised? • Nonpreemptive  A process in the running state runs until it blocks or ends • Preemptive  Currently running process may be interrupted and moved to the Ready state by the OS  Prevents any one process from monopolizing the CPU
  • 13. 13 Policy vs. Mechanism  Important in scheduling and resource allocation algorithms  Policy • What is to be done  Mechanism • How to do it  Policy: All users equal access  Mechanism: round robin scheduling  Policy: Paid jobs get higher priority  Mechanism: Preemptive scheduling algorithm
  • 14. 14 A running example to discuss various scheduling policies Process Arrival Time Burst Time 1 2 3 4 5 0 2 4 6 8 3 6 4 5 2
  • 15. 15 First Come First Served (FCFS)  Selection function: the process that has been waiting the longest in the ready queue (hence, FCFS, FIFO queue)  Decision mode: nonpreemptive • a process runs until it blocks itself (I/O or other)
  • 16. 16 FCFS Drawbacks  Favors CPU-bound processes • A process that does not perform any I/O will monopolize the processor! • I/O-bound processes have to wait until CPU- bound process completes • They may have to wait even when their I/Os have completed  poor device utilization • We could reduce the average wait time by giving more priority to I/O bound processes
  • 17. 17 Shortest Job First (SJF)  Selection function: the process with the shortest expected CPU burst time  Decision mode: non-preemptive  I/O bound processes will be picked first  We need to estimate the expected CPU burst time for each process: on the basis of past behavior. Shortest job First (SJF)
  • 18. 18 Estimating the Required CPU Burst  Can average all past history equally  But recent history of a process is more likely to reflect future behavior  A common technique for that is to use exponential averaging • S[n+1] = a T[n] + (1-a) S[n] ; 0 < a < 1 • Puts more weight on recent instances whenever a > 1/n
  • 20. 20 Exponential Averaging  Set S[1] = 0 to give new processes high priority.  Exponential averaging tracks changes in process behavior much faster than simple averaging.
  • 21. 21 Shortest Job First: Critique  SJF implicitly incorporates priorities: shortest jobs are given preference. • Typically these are I/O bound jobs  Longer processes can starve if there is a steady supply of shorter processes  Lack of preemption not suitable in a time sharing environment • CPU bound process gets lower priority • But a process doing no I/O at all could monopolize the CPU if it is the first one in the system
  • 22. 22 Shortest Remaining Time (SRT) = Preemptive SJF  If a process arrives in the Ready queue with estimated CPU burst less than remaining time of the currently running process, preempt.  Prevents long jobs from dominating. • But must keep track of remaining burst times  Better turnaround time than SJF • Short jobs get immediate preference
  • 23. 23  Selection function: same as FCFS  Decision mode: Preemptive • Maximum time slice (typically 10 - 100 ms) enforced by timer interrupt • running process is put at the tail of the ready queue Round-Robin
  • 24. 24 Time Quantum for Round Robin  must be substantially larger than process switch time  should be larger than the typical CPU burst  If too large, degenerates to FCFS  Too small, excessive context switches (overhead)
  • 25. 25 Fairness vs. Efficiency  Each context switch has the OS using the CPU instead of the user process • give up CPU, save all info, reload w/ status of incoming process • Say 20 ms quantum length, 5 ms context switch • Waste of resources  20% of CPU time (5/20) for context switch • If 500 ms quantum, better use of resources  1% of CPU time (5/500) for context switch  Bad if lots of users in system – interactive users waiting for CPU • Balance found depends on job mix
  • 26. 26 Round Robin: Critique  Still favors CPU-bound processes • An I/O bound process uses the CPU for a time less than the time quantum and then is blocked waiting for I/O • A CPU-bound process runs for its whole time slice and goes back into the ready queue (in front of the blocked processes)  One solution: virtual round robin (VRR, not in book…) • When a I/O has completed, the blocked process is moved to an auxiliary queue which gets preference over the main ready queue • A process dispatched from the auxiliary queue gets a shorter time quantum (what is “left over” from its quantum when it was last selected from the ready queue)