CPU Scheduling CS 537 - Introduction to Operating Systems.

Slides:



Advertisements
Similar presentations
Scheduling Criteria CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – # of processes that complete their execution per.
Advertisements

Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana.
CPU Scheduling Questions answered in this lecture: What is scheduling vs. allocation? What is preemptive vs. non-preemptive scheduling? What are FCFS,
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 17 Scheduling III.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling.
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
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.
CPU Scheduling Algorithms
Chapter 3: CPU Scheduling
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Operating Systems 1 K. Salah Module 2.1: CPU Scheduling Scheduling Types Scheduling Criteria Scheduling Algorithms Performance Evaluation.
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.
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
A. Frank - P. Weisberg Operating Systems 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.
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
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 Chapter 6 Chapter 6.
Chapter 6: CPU Scheduling
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
Chapter 6 CPU SCHEDULING.
Operating Systems Lecture Notes CPU Scheduling Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
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.
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.
1 Our focus  scheduling a single CPU among all the processes in the system  Key Criteria: Maximize CPU utilization Maximize throughput Minimize waiting.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
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.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
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.
Processor Scheduling Hank Levy. 22/4/2016 Goals for Multiprogramming In a multiprogramming system, we try to increase utilization and thruput by overlapping.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Introduction to Operating System Created by : Zahid Javed CPU Scheduling Fifth Lecture.
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.
 In a single-processor system, only one process can run at a time; any others must wait until the CPU is free and can be rescheduled.  The objective.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
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.
Chapter 5a: CPU Scheduling
Operating Systems Processes Scheduling.
CPU Scheduling Basic Concepts Scheduling Criteria
Chapter 6: CPU Scheduling
Presentation transcript:

CPU Scheduling CS Introduction to Operating Systems

Objectives High throughput Low response time Good utilization of system resources –low waiting time in system Avoid starvation Fairness Be efficient in scheduling - it’s done often

Bursts CPU burst –interval of time a process would run before blocking if not preempted I/O burst –time process spends doing a single I/O operation Burst times do not include waiting times

CPU and I/O Bounded Processes CPU bound process –process spends most of its time using processor –very long CPU bursts –compiler, simulator, scientific application I/O bound process –process spends most of its time using I/O –very short CPU bursts –word processors, database applications Processes usually either CPU or I/O bound –behavior may change over time (drastically)

Schedulers Short-term scheduler –pick best job from those currently in memory –pick a currently active process –this is what we will be concerned with Long-term scheduler –pick best jobs to place in memory –batch system (CONDOR) –need to pick jobs that will run well together want a good mix of CPU bound and I/O bound jobs

Invoking Scheduler 4 situations that could lead to scheduling a new process 1.running process blocks 2.running process terminates 3.running process switches to ready state timer interrupt 4.blocked process switches to ready state finish I/O operation if first 2 only, non-preemptive scheduler if 3 or 4, preemptive scheduler Notice that all 4 do involve interrupts –either software or hardware –no interrupts, no context switches

Analyzing Schedulers Many possible parameters to measure –throughput, avg waiting time, utilization, etc. Must pick important parameters –system dependant –example maximize throughput with all waiting times < 1 sec Various methods to analyze algorithm –deteministic, queueing theory, simulation –will examine these at end of lecture

Analysis Consider following system ProcessBurst Time A 5 B 20 C 12 Gantt chart Calculations –avg waiting time =  (start times) / # of procs –throughput = # of finished jobs / time period –utilization = time busy / total time ABC 52012

Scheduling Policies First-Come, First Serve (FCFS) Shortest Job First (SJF) –non-preemptive and preemptive Priority Round-Robin Multi-Level Feedback Queue

FCFS Processes get processor in order they arrive to ready queue Very easy to manage –new job goes to tail of queue –next job to run is removed from the head Poor policy for CPU scheduling –very sensitive to the order in which jobs arrive

FCFS Example ProcessBurst A 24 B 3 C 3 W = ( ) / 3 = 17 ms now switch processes A and C W = ( ) / 3 = 3 ms ABC 2433

Convoy Effect I/O bound jobs have short CPU bursts CPU bound jobs have long CPU bursts Once CPU bound job does go to I/O, all of the I/O bound jobs will rush through CPU and group behind the CPU bound job Leads to poor utilization Leads to poor response time

Convoy Effect ProcessBurst A 3 B 3 C1000 D 3 ABC A and B finish I/O and get in line behind D 1000 D 33 ABC < 1000 D Disk is now Idle as all jobs wait on CPU Process C finishes and goes to I/O D, A, and B all finish quickly and go to I/O CPU sits idle while all jobs at Disk

SJF non-Preemptive Schedule the job with the shortest burst –better titled Shortest Burst First Provably the lowest response time (highest throughput) a < b < c < d < … R = [0 + a + (a+b) + (a+b+c) + …] / n now switch any 2, for example b and c R’ = [0 + a + (a+c) + (a+c+b) + …] / n (a+c) > (a+b) and all other terms are the same R < R’ ABCD...

SJF non-Preemptive Requires knowledge of future –IMPOSSIBLE! So why study this –if we can analyze after the fact, can compare to ideal –fortunately, consecutive bursts tend to be similar if B n = X, then B n+1  X this allows us to predict the future

SJF non-Preemptive How do we do prediction of future? –could just use the time of the last burst Shortest Last Burst First anomalous burst will give bad prediction –use an exponential average consider all past bursts smooth out anomalous bursts give less weight to bursts that happened longer ago

Exponential Averaging Equation:  n+1 =  t n + (1-  )  n 0    1eqt. 1 t n = time of burst just finished  n = predicted time of burst just finished  n+1 = predicted time of the next burst  = weight to give past events if  = 1, just consider the last burst if  = 0, just use a default prediction Let’s expand out the above function  n =  t n-1 + (1-  )  n-1 eqt. 2 combine equations 1 and 2 to get:  n+1 =  t n + … + (1-  ) j  t n-j + … + (1-  ) n+1  0  0 = arbitrary value (perhaps a system wide average burst time) For scheduling, pick the job with the lowest  value

SJF Preemptive Identical to SJF non-Preemptive except: –if new job has shorter burst than current job has left to run, stop the current job and run the new job Often called Shortest Remaining Time First

SJF Algorithm Problems Starvation –long burst never gets to run because lots of short jobs in the system Fairness –long jobs get to run very infrequently because of lots of short jobs in the system

Aging Common solution to starvation / fairness problem –when job enters queue, give it a value of 0 –after every scheduling decision it loses, increase its value by 1 –if the value become greater than some threshold, it becomes the next job scheduled no matter what –if multiple jobs above threshold, pick the one with the highest value

Priority Scheduling Each job has a priority associated with it Run the job with the highest priority –ties can be broken arbitrarily (FCFS, perhaps) How do priorities get set? –externally programmer administrator –internally OS makes decision avg size of burst, memory requirements, etc. Starvation and Fairness are still issues –use priority aging (increase priority over time)

Round-Robin Give each burst a set time to run If burst not finished after time, preempt and start the next job (head of the ready queue) –preempted process goes to back of ready queue If burst does finish, start the next job at the head of the ready queue New jobs go to the back of the ready queue Similar to FCFS except time limits on running Time a burst gets to run before preemption is called a Quantum

Round-Robin Need hardware timer interrupts Very fair policy –everyone gets an equal shot at processor Fairly simple to implement If quantum is large enough to let most short bursts finish, short jobs get through quickly Must consider overhead of switching processes –if quantum is too small, overhead hurts performance –if quantum is too large, RR becomes like FCFS

Round-Robin ProcessBurst A 6 B 10 C 7 quantum = 3 ABC 333 ABC 333 BCB 131

Multilevel Queue Scheduling Maintain multiple queues Each queue can have a different scheduling policy Or maybe same policy but different parameters –All are Round-Robin with different quantums

Multilevel Feedback Queue Multiple queues for jobs depending on how long they have been running (current burst) All jobs enter at queue 0 –these jobs run for some quantum, n If jobs do not complete in n, they move to queue 1 –these jobs run for some quantum, m (m > n) If these jobs do not complete in time, they are moved to yet another queue A job can only be selected to run from a queue if all queues above it are empty Jobs higher up, preempt jobs lower down

Multilevel Feedback Queue Queue 0 Queue 1 Queue 2 CPU quantum 8 quantum 16 quantum 32 new bursts

Multilevel Feedback Queue Longer a job is in the system, the longer it can be expected to stay Let long jobs run only when there are no short jobs around Different levels of long jobs Can using aging to prevent starvation –if a job sits in a low level queue for too long, move it up one or more levels

Multilevel Feedback Queue Important issues in a multilevel queue 1.number of queues 2.scheduling algorithm at each queue 3.method for upgrading a job to higher level 4.method used for demoting a job to lower level 5.which queue does a process enter on arrival