Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7.

Slides:



Advertisements
Similar presentations
CPU Management CT213 – Computing Systems Organization.
Advertisements

SCHEDULING Kshama Desai Bijal Shah Kishore Putta Kashyap Sheth.
CS4315A. Berrached:CMS:UHD1 CPU Scheduling Chapter 7.
Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 7 Scheduling.
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Chap 5 Process Scheduling. Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Operating Systems CPU Scheduling. Agenda for Today What is Scheduler and its types Short-term scheduler Dispatcher Reasons for invoking scheduler Optimization.
Chapter 3: CPU Scheduling
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
Scheduling in Batch Systems
Chapter 6: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 6: CPU Scheduling Basic.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Processes and Threads 6.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
Chapter 5-CPU Scheduling
Scheduling. Model of Process Execution Ready List Ready List Scheduler CPU Resource Manager Resource Manager Resources Preemption or voluntary yield AllocateRequest.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
Slide 7-1 Copyright © 2004 Pearson Education, Inc. Scheduling: the act of sharing.
Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 6: CPU Scheduling
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
Operating Systems Lecture Notes CPU Scheduling Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Scheduling Strategies Operating Systems Spring 2004 Class #10.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 11/29/2015 Chapter 6: CPU Scheduling l Basic Concepts l Scheduling Criteria l Scheduling Algorithms l Multiple-Processor Scheduling l Real-Time Scheduling.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 5 CPU Scheduling Slide 1 Chapter 5 CPU Scheduling.
6.1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 7 Scheduling.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
1 Uniprocessor Scheduling Chapter 3. 2 Alternating Sequence of CPU And I/O Bursts.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Lecture 4 CPU scheduling. Basic Concepts Single Process  one process at a time Maximum CPU utilization obtained with multiprogramming CPU idle :waiting.
CPU scheduling.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
1 Module 5: Scheduling CPU Scheduling Scheduling Algorithms Reading: Chapter
Basic Concepts Maximum CPU utilization obtained with multiprogramming
1 Lecture 5: CPU Scheduling Operating System Fall 2006.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
1 Chapter 5: CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU SCHEDULING.
Chapter 5a: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Process management Information maintained by OS for process management
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Operating System Concepts
Chapter5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Scheduling.
Outline Announcements Process Scheduling– continued
Outline Announcement Process Scheduling– continued
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Presentation transcript:

Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7

Slide 7-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 7 Scheduling

Slide 7-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms – FCFS (FIFO) – SJN – Priority Scheduling – Round Robin Scheduling –Multilevel Queue –Multilevel Feedback Queue

Slide 7-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 CPU Scheduling A multiprogramming OS allows more than one process to be loaded in main memory at a time. Processes share the CPU using time-multiplexing A process execution consists of a cycle of CPU computation--I/O operations. I/O operations require orders of magnitude more time to complete. Basic Idea: When the running process requests an I/O operation, allocate CPU to another process.

Slide 7-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 CPU Scheduler CPU Scheduler: the part of the Process Manager that is responsible for –handling removal of running process from CPU –Selection of another process Two major issues: Scheduling mechanism: how is it all done? Scheduling policy: –when is it time for a process to be removed from CPU? –Which ready process should be allocated the CPU next?

Slide 7-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Model of Process Execution Ready List Ready List Scheduler CPU Resource Manager Resource Manager Resources Preemption or voluntary yield AllocateRequest Done New Process job “Ready” “Running” “Blocked”

Slide 7-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Scheduler as CPU Resource Manager Scheduler Process Units of time for a time-multiplexed CPU ReleaseReady to run Dispatch Release Ready List

Slide 7-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 The Scheduler Ready Process Enqueuer Ready List Ready List Dispatcher Context Switcher Context Switcher Process Descriptor Process Descriptor CPU From Other States Running Process

Slide 7-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Process/Thread Context R1 R2 Rn... Status Registers Functional Unit Left Operand Right Operand Result ALU PC IR Ctl Unit

Slide 7-10 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Context Switching CPU New Thread Descriptor Old Thread Descriptor

Slide 7-11 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Scheduling Mechanism CNTD When a process is moved to the Ready-List –Process Descriptor (PD) is updated –the enqueuer places a pointer to PD in the Ready-List When the Scheduler switches CPU from one process to another process –the Context-Switcher saves the state of the current process in its PD. How context-switching occurs depends on how CPU multiplexing technique used: –voluntary multiplexing –involuntary multiplexing

Slide 7-12 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Invoking the Scheduler Need a mechanism to call the scheduler Voluntary call –Process blocks itself –Calls the scheduler Involuntary call –External force (interrupt) blocks the process –Calls the scheduler

Slide 7-13 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Voluntary CPU Sharing yield(p i.pc, p j.pc) { memory[p i.pc] = PC; PC = memory[p j.pc]; } p i can be “automatically” determined from the processor status registers yield(*, p j.pc) { memory[p i.pc] = PC; PC = memory[p j.pc]; }

Slide 7-14 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 More on Yield yield(*, p j.pc);... yield(*, p i.pc);... yield(*, p j.pc);... p i and p j can resume one another’s execution Suppose p j is the scheduler: // p_i yields to scheduler yield(*, p j.pc); // scheduler chooses p k yield(*, p k.pc); // p k yields to scheduler yield(*, p j.pc); // scheduler chooses...

Slide 7-15 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Voluntary Sharing Every process periodically yields to the scheduler Relies on correct process behavior –Malicious –Accidental Need a mechanism to override running process

Slide 7-16 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Involuntary CPU Sharing Interval timer –Device to produce a periodic interrupt –Programmable period IntervalTimer() { InterruptCount--; if(InterruptCount <= 0) { InterruptRequest = TRUE; InterruptCount = K; } SetInterval(programmableValue) { K = programmableValue: InterruptCount = K; }

Slide 7-17 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Contemporary Scheduling Involuntary CPU sharing – timer interrupts –Time quantum determined by interval timer – usually fixed size for every process using the system –Sometimes called the time slice length

Slide 7-18 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Scheduling Mechanism-- Dispatcher After state of "old" process is saved by context- switcher, the CPU is allocated to the Dispatcher –Dispatcher state is loaded on CPU Dispatcher selects one of the ready processes enqueued in the Ready-List. Dispatcher performs another context-switch from itself to selected process (saves its state and loads state of selected process). The Process Descriptor of selected process is changed from Ready to Running.

Slide 7-19 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Choosing a Process to Run Mechanism never changes Strategy = policy the dispatcher uses to select a process from the ready list Different policies for different requirements Ready Process Enqueue Ready List Ready List Dispatch Context Switch Context Switch Process Descriptor Process Descriptor CPU Running Process

Slide 7-20 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Policy Considerations Policy can control/influence: –CPU utilization –Average time a process waits for service –Average amount of time to complete a job Could strive for any of: –Equitability –Favor very short or long jobs –Meet priority requirements –Meet deadlines

Slide 7-21 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Optimal Scheduling Suppose the scheduler knows each process p i ’s service time,  p i  -- or it can estimate each  p i  : Policy can optimize on any criteria, e.g., –CPU utilization –Waiting time –Deadline To find an optimal schedule: –Have a finite, fixed # of p i –Know  p i  for each p i –Enumerate all schedules, then choose the best

Slide 7-22 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 However... The  (p i ) are almost certainly just estimates General algorithm to choose optimal schedule is O(n 2 ) Other processes may arrive while these processes are being serviced Usually, optimal schedule is only a theoretical benchmark – scheduling policies try to approximate an optimal schedule

Slide 7-23 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Model of Process Execution Ready List Ready List Scheduler CPU Resource Manager Resource Manager Resources Preemption or voluntary yield AllocateRequest Done New Process job “Ready” “Running” “Blocked”

Slide 7-24 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Simplified Model Ready List Ready List Scheduler CPU Resource Manager Resource Manager Resources AllocateRequest Done New Process job “Ready” “Running” “Blocked” Simplified, but still provide analysis result Easy to analyze performance No issue of voluntary/involuntary sharing Preemption or voluntary yield

Slide 7-25 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Nonpreemptive Schedulers Ready List Ready List Scheduler CPU Done New Process Try to use the simplified scheduling model Only consider running and ready states Ignores time in blocked state: –“New process created when it enters ready state” –“Process is destroyed when it enters blocked state” –Really just looking at “small phases” of a process Blocked or preempted processes

Slide 7-26 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Estimating CPU Utilization Ready List Ready List Scheduler CPU Done New Process System p i per second Each p i uses 1/  units of the CPU Let = the average rate at which processes are placed in the Ready List, arrival rate Let  = the average service rate  1/  = the average  (p i )

Slide 7-27 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Estimating CPU Utilization Ready List Ready List Scheduler CPU Done New Process Let = the average rate at which processes are placed in the Ready List, arrival rate Let  = the average service rate  1/  = the average  (p i ) Let  = the fraction of the time that the CPU is expected to be busy  = # p i that arrive per unit time * avg time each spends on CPU  = * 1/  = /  Notice must have <  (i.e.,  < 1) What if  approaches 1?

Slide 7-28 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Talking About Scheduling... Let P = {p i | 0  i < n} = set of processes Let S(p i )  {running, ready, blocked} Let  (p i ) = Time process needs to be in running state (the service time) Let W(p i ) = Time p i is in ready state before first transition to running (wait time) Let T TRnd (p i ) = Time from p i first enter ready to last exit ready (turnaround time) Batch Throughput rate = inverse of avg T TRnd Timesharing response time = W(p i )

Slide 7-29 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) p0p0 T TRnd (p 0 ) =  (p 0 ) = 350 W(p 0 ) =

Slide 7-30 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) p0p0 p1p1 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = = 475 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) =

Slide 7-31 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) p0p0 p1p1 p2p2 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = = 950 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) =

Slide 7-32 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) p0p0 p1p1 p2p2 p3p3 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = = 950 T TRnd (p 3 ) = (  (p 3 ) +T TRnd (p 2 )) = = 1200 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) = 475 W(p 3 ) = T TRnd (p 2 ) =

Slide 7-33 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = = 950 T TRnd (p 3 ) = (  (p 3 ) +T TRnd (p 2 )) = = 1200 T TRnd (p 4 ) = (  (p 4 ) +T TRnd (p 3 )) = = 1275 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) = 475 W(p 3 ) = T TRnd (p 2 ) = 950 W(p 4 ) = T TRnd (p 3 ) =

Slide 7-34 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 FCFS Average Wait Time i  (p i ) p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = = 950 T TRnd (p 3 ) = (  (p 3 ) +T TRnd (p 2 )) = = 1200 T TRnd (p 4 ) = (  (p 4 ) +T TRnd (p 3 )) = = 1275 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) = 475 W(p 3 ) = T TRnd (p 2 ) = 950 W(p 4 ) = T TRnd (p 3 ) = 1200 W avg = ( )/5 = 2974/5 = Easy to implement Ignores service time, etc Not a great performer

Slide 7-35 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Predicting Wait Time in FCFS In FCFS, when a process arrives, all in ready list will be processed before this job Let  be the service rate Let L be the ready list length W avg (p) = L*1/  1/  L  Compare predicted wait with actual in earlier examples

Slide 7-36 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) p4p4 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 4 ) = 0 750

Slide 7-37 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) p1p1 p4p4 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = = 200 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 1 ) = 75 W(p 4 ) =

Slide 7-38 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) p1p1 p3p3 p4p4 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = = 200 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 1 ) = 75 W(p 3 ) = 200 W(p 4 ) =

Slide 7-39 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) p0p0 p1p1 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = = 800 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = = 200 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 0 ) = 450 W(p 1 ) = 75 W(p 3 ) = 200 W(p 4 ) =

Slide 7-40 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = = 800 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = = 200 T TRnd (p 2 ) =  (p 2 )+  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = = 1275 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 0 ) = 450 W(p 1 ) = 75 W(p 2 ) = 800 W(p 3 ) = 200 W(p 4 ) =

Slide 7-41 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = = 800 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = = 200 T TRnd (p 2 ) =  (p 2 )+  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = = 1275 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 0 ) = 450 W(p 1 ) = 75 W(p 2 ) = 800 W(p 3 ) = 200 W(p 4 ) = 0 W avg = ( )/5 = 1525/5 = Minimizes wait time May starve large jobs Must know service times

Slide 7-42 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest-Job-Next (SJN) Scheduling SJN is optimal – gives minimum average waiting time for a given set of processes

Slide 7-43 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Preemptive Schedulers Ready List Ready List Scheduler CPU Preemption or voluntary yield Done New Process Highest priority process is guaranteed to be running at all times –Or at least at the beginning of a time slice Dominant form of contemporary scheduling But complex to build & analyze

Slide 7-44 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Example of Non-Preemptive SJN 2.0

Slide 7-45 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Example of Preemptive SJN 2.0 Average waiting time = ( )/4 = 0.5

Slide 7-46 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Priority Scheduling

Slide 7-47 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Priority Scheduling i  (p i ) Pri p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 4 )+  (p 2 )+  (p 1 ) )+  (p 3 ) = = 1275 T TRnd (p 1 ) =  (p 1 )+  (p 3 ) = = 375 T TRnd (p 2 ) =  (p 2 )+  (p 1 )+  (p 3 ) = = 850 T TRnd (p 3 ) =  (p 3 ) = 250 T TRnd (p 4 ) =  (p 4 )+  (p 2 )+  (p 1 )+  (p 3 ) = = 925 W(p 0 ) = 925 W(p 1 ) = 250 W(p 2 ) = 375 W(p 3 ) = 0 W(p 4 ) = 850 W avg = ( )/5 = 2400/5 = Reflects importance of external use May cause starvation Can address starvation with aging

Slide 7-48 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Deadline Scheduling Real Time Systems –Processes must complete their task by specific deadlines –Main performance criteria –Scheduler must have complete knowledge of service time of each process All function must be predictable– no virtual memory –A process is admitted to ready list only if OS can guarantee deadline can be met.

Slide 7-49 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Deadline Scheduling i  (p i ) Deadline (none) p0p0 p1p1 p2p2 p3p3 p4p Allocates service by deadline May not be feasible p0p0 p1p1 p2p2 p3p3 p4p4 p0p0 p1p1 p2p2 p3p3 p4p4 575

Slide 7-50 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (RR) Scheduling

Slide 7-51 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 W(p 0 ) = 0 050

Slide 7-52 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 W(p 0 ) = 0 W(p 1 ) = p1p1

Slide 7-53 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = p2p2 p1p1

Slide 7-54 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = p3p3 p2p2 p1p1

Slide 7-55 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = p4p4 p3p3 p2p2 p1p1

Slide 7-56 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = p0p0 p4p4 p3p3 p2p2 p1p1

Slide 7-57 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = p4p4 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3

Slide 7-58 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 T TRnd (p 1 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 550

Slide 7-59 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 T TRnd (p 1 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p

Slide 7-60 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p

Slide 7-61 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 2 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p0 p2p2 p2p2 p2p2 p2p

Slide 7-62 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 2 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 W avg = ( )/5 = 500/5 = Equitable Most widely-used Fits naturally with interval timer p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p0 p2p2 p2p2 p2p2 p2p T TRnd _ avg = ( )/5 = 4350/5 = 870

Slide 7-63 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 RR with Overhead=10 (TQ=50) i  (p i ) p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 2 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 60 W(p 2 ) = 120 W(p 3 ) = 180 W(p 4 ) = 240 W avg = ( )/5 = 600/5 = Overhead must be considered p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p0 p2p2 p2p2 p2p2 p2p T TRnd _ avg = ( )/5 = 5220/5 =

Slide 7-64 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Multi-Level Queue Extension of priority scheduling, which also combines other strategies Ready list is partitioned into multiple sub-lists Each process is assigned to a queue based on some criteria (type, priority, etc.) –E.g. one Q for foreground processes and one for background processes Scheduler: * in-queue strategy * cross-queue strategy –E.g. In-queue strategy: RR for foreground Q and FCFS for background A –Cross-queue strategy: Serve higher-level processes first

Slide 7-65 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Multi-Level Queue Example: –Cross-Queue Strategy: Each queue get a percentage of CPU time (in a round robin fashion) which it can schedule among its processes. –E.g. Level 1: 80% of CPU time Level 2: 20% of CPU time

Slide 7-66 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Multi-Level Queues Ready List 0 Ready List 1 Ready List 2 Ready List 3 Scheduler CPU Preemption or voluntary yield Done New Process All processes at level i run before any process at level j At a level, use another policy, e.g. RR

Slide 7-67 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Multi-Level Feedback Queue

Slide 7-68 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Example:Multi-Level Feedback Queue Gives shorter jobs higher priority without needing to predict a job’s service time requirement.

Slide 7-69 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Contemporary Scheduling Involuntary CPU sharing -- timer interrupts –Time quantum determined by interval timer -- usually fixed for every process using the system –Sometimes called the time slice length Priority-based process (job) selection –Select the highest priority process –Priority reflects policy With preemption Usually a variant of Multi-Level Queues

Slide 7-70 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 BSD 4.4 Scheduling Involuntary CPU Sharing Preemptive algorithms 32 Multi-Level Queues –Queues 0-7 are reserved for system functions –Queues 8-31 are for user space functions –nice influences (but does not dictate) queue level

Slide 7-71 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Windows NT/2K Scheduling Involuntary CPU Sharing across threads Preemptive algorithms 32 Multi-Level Queues –Highest 16 levels are “real-time” –Next lower 15 are for system/user threads Range determined by process base priority –Lowest level is for the idle thread

Slide 7-72 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Bank Teller Simulation Tellers at the Bank T1T1 T1T1 T2T2 T2T2 TnTn TnTn … Model of Tellers at the Bank Customers Arrivals

Slide 7-73 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Simulation Kernel Loop simulated_time = 0; while (true) { event = select_next_event(); if (event->time > simulated_time) simulated_time = event->time; evaluate(event->function, …); }

Slide 7-74 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Simulation Kernel Loop(2) void runKernel(int quitTime) { Event *thisEvent; // Stop by running to elapsed time, or by causing quit execute if(quitTime next; simTime = thisEvent->getTime(); // Set the time // Execute this event thisEvent->fire(); delete(thisEvent); }; }