Operating Systems CMPSC 473 Processes (contd.) September 01, 2010 - Lecture 4 Instructor: Bhuvan Urgaonkar.

Slides:



Advertisements
Similar presentations
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Operating Systems Chapter 6
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.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Processes and Their Scheduling.
CPU Scheduling Algorithms
Chapter 3: CPU Scheduling
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
02/06/2008CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
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.
02/04/2008CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
6/25/2015Page 1 Process Scheduling B.Ramamurthy. 6/25/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (2) Process Management 10/03/2008 Yang Song (Prepared by Yang Song and.
Chapter 5-CPU Scheduling
7/12/2015Page 1 Process Scheduling B.Ramamurthy. 7/12/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
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 – 7 th Edition, Feb 2, 2005 Basic Concepts Maximum CPU utilization.
CPU-Scheduling Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. The short term scheduler.
Chapter 6: CPU Scheduling
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Chapter 6 CPU SCHEDULING.
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.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
Alternating Sequence of CPU And I/O Bursts. Histogram of CPU-burst Times.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
CPU Scheduling Basic Concepts. Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor.
Chapter 5 CPU Scheduling Bernard Chen Spring 2007.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 7: CPU Scheduling Chapter 5.
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.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling Basic.
Operating Systems CMPSC 473 CPU Scheduling September 07, Lecture 5 Instructor: Bhuvan Urgaonkar.
Operating Systems CSE 411 CPU Management Sept Lecture 6 Instructor: Bhuvan Urgaonkar.
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.
Purpose of Operating System Part 2 Monil Adhikari.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 6: CPU Scheduling.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Scheduling (Priority Based)
CPU Scheduling.
Chapter 6: CPU Scheduling
Operating System Concepts
Chapter5: CPU Scheduling
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
CPU Scheduling.
Chapter 5: CPU Scheduling
Presentation transcript:

Operating Systems CMPSC 473 Processes (contd.) September 01, Lecture 4 Instructor: Bhuvan Urgaonkar

Process Switch Suspend the current process and resume a previously suspended process –Also called context switch or task switch

Process Switch Process 0 Process 1 A1 A2 B1 B2 B3 B4 Context_switch() { } Involuntary/Voluntary

Process Switch What does the kernel need to save when suspending a process? –Hint: The entire address space is already saved (either in memory or on swap space). What else would the process need when it has to be resumed? –CPU registers This is called the hardware context of the process Execution context, PC, pointers to elements within address space, page table, etc.

Context_switch() { push R0, R1, …// save regs on its stack PCB[curr].SP = SP // save stack pointer PCB[curr].PT = PT // save ptr(s) to address space next = schedule() // find next process to run PT = PCB[next].PT SP = PCB[next].SP pop Rn, … R0 return// NOTE: Ctrl returns to another process }

Overheads of Process Switch Direct –The time spent switching context Indirect –Cache pollution –TLB flush

CPU Scheduling

Ready Waiting Running Disk Lock OS (scheduler) Hmm.. Who should I pick to run? Process Scheduling

When is the scheduler invoked? 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 only under 1 and 4: nonpreemptive scheduling –E.g., FCFS and SJF All other scheduling is preemptive

First-Come, First-Served Scheduling (FCFS) Process Run Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: ( )/3 = 17 P1P1 P2P2 P3P

FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P 2, P 3, P 1 The Gantt chart for the schedule is: Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: ( )/3 = 3 Much better than previous case Convoy effect short process behind long process P1P1 P3P3 P2P

Choosing the Right Scheduling Algorithm/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) Fairness

Shortest-Job-First (SJF) Scheduling Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time SJF is optimal for avg. waiting time – gives minimum average waiting time for a given set of processes –In class: Compute average waiting time for the previous example with SJF –Exercise: Prove the optimality claimed above

Why Pre-emption is Necessary To improve CPU utilization –Most processes are not ready at all times during their lifetimes –E.g., think of a text editor waiting for input from the keyboard –Also improves I/O utilization To improve responsiveness –Many processes would prefer “slow but steady progress” over “long wait followed by fast process” Most modern CPU schedulers are pre-emptive

SJF: Variations on the theme Non-preemptive: once CPU given to the process it cannot be preempted until completes its CPU burst - the SJF we already saw Preemptive: if a new process arrives with CPU length less than remaining time of current executing process, preempt. This scheme is know as Shortest-Remaining-Time-First (SRTF)  Also called Shortest Remaining Processing Time (SRPT) Why SJF/SRTF may not be practical  CPU requirement of a process rarely known in advance

Round Robin (RR) Each process gets a small unit of CPU time (time quantum), usually 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 => FCFS –q small => q must be large with respect to context switch, otherwise overhead is too high

Example of RR with Time Quantum = 20 ProcessCPU Time P 1 53 P 2 17 P 3 68 P 4 24 The Gantt chart is: Typically, higher average turnaround than SJF, but better response P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P

Time Quantum and Context Switch Time

Turnaround Time Varies With Time Quantum

Proportional-Share Schedulers A generalization of round robin Process P i given a CPU weight w i > 0 The scheduler needs to ensure the following –forall i, j, |T i (t 1, t 2 )/T j (t 1,t 2 ) - w i /w j | ≤ e –Given P i and P j were backlogged during [t 1,t 2 ] Who chooses the weights and how? Application modeling problem: non-trivial Many PS schedulers developed in the 90s –E.g., Start-time Fair Queueing (Qlinux UT-Austin/Umass-Amherst)

Lottery Scheduling [Carl Waldspurger, MIT, ~1995] Perhaps the simplest proportional-share scheduler Create lottery tickets equal to the sum of the weights of all processes –What if the weights are non-integral? Draw a lottery ticket and schedule the process that owns that ticket –What if the process is not ready? Draw tickets only for ready processes –Exercise: Calculate the time/space complexity of the operations Lottery scheduling will involve

Lottery Scheduling Example P1=6P2=9 Schedule P2

P1=6P2=9 Schedule P1 Lottery Scheduling Example

As t ∞, processes will get their share (unless they were blocked a lot) Problem with Lottery scheduling: Only probabilistic guarantee What does the scheduler have to do –When a new process arrives? –When a process terminates? P1=6P2=9 Schedule P2 Lottery Scheduling Example