IT 344: Operating Systems Winter 2010 Module 9 Scheduling Chia-Chi Teng 265 CTB.

Slides:



Advertisements
Similar presentations
CSE 451: Operating Systems Winter 2010 Module 6 Scheduling Mark Zbikowski Gary Kimura.
Advertisements

IT 344: Operating Systems Module 9 Scheduling Chia-Chi Teng 265 CTB.
CSE 451: Operating Systems Spring 2012 Module 10 Scheduling Ed Lazowska Allen Center 570.
Operating Systems ECE344 Ding Yuan Scheduling Lecture 10: 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
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
Scheduling in Batch Systems
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
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.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
Chapter 5-CPU Scheduling
Job scheduling Queue discipline.
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 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.
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.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
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.
1 CSE451 Scheduling Autumn 2002 Gary Kimura Lecture #6 October 11, 2002.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Thread Implementation and Scheduling CSE451 Andrew Whitaker.
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.
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.
6.1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Scheduling Algorithms : Important Aspects Minimize Response Time –Elapsed time to do an operation (job) –Response time is what the user sees Time to echo.
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.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
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.
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
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
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
1 Chapter 5: CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU Scheduling Andy Wang Operating Systems COP 4610 / CGS 5765.
CSE 451: Operating Systems Spring 2010 Module 6 Scheduling John Zahorjan Allen Center 534.
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
CSE 451: Operating Systems Spring 2013 Module 10 Scheduling
Chapter 5a: CPU Scheduling
Chapter 6: CPU Scheduling
Andy Wang Operating Systems COP 4610 / CGS 5765
Operating System Concepts
CSE 451: Operating Systems Winter 2007 Module 9 Scheduling
CSE 451: Operating Systems Winter 2006 Module 9 Scheduling
CSE 451: Operating Systems Winter 2009 Module 6 Scheduling
CSE 451: Operating Systems Autumn 2009 Module 6 Scheduling
CSE 451: Operating Systems Spring 2007 Module 6 Scheduling
CSE 451: Operating Systems Winter 2003 Lecture 6 Scheduling
CSE 451: Operating Systems Spring 2006 Module 9 Scheduling
CSE 451: Operating Systems Autumn 2010 Module 6 Scheduling
CSE 451: Operating Systems Winter 2012 Scheduling
CSE 451: Operating Systems Winter 2007 Module 9 Scheduling
CSE 451: Operating Systems Winter 2004 Module 9 Scheduling
CSE 451: Operating Systems Winter 2001 Lecture 6 Scheduling
Presentation transcript:

IT 344: Operating Systems Winter 2010 Module 9 Scheduling Chia-Chi Teng 265 CTB

3/21/20162 Review: semaphores (blocking lock) Each semaphore has an associated queue of threads –when wait(sem) is called by a thread, if sem was “available” (>0), decrement sem and let thread continue if sem was “unavailable” (<=0), place thread on associated queue; run some other thread –when signal(sem) is called by a thread if thread(s) are waiting on the associated queue, unblock one –place it on the ready queue –might as well let the “signaling” thread continue execution otherwise (when no threads are waiting on the sem), increment sem –the signal is “remembered” for next time wait(sem) is called Semaphores thus have history

3/21/20163 Usage From the programmer’s perspective, wait and signal on a binary semaphore are just like Acquire and Release on a lock wait(sem). do whatever stuff requires mutual exclusion; could conceivably be a lot of code. signal(sem) –same lack of programming language support for correct usage Important differences in the underlying implementation, however

3/21/20164 Problems with semaphores (and locks) They can be used to solve any of the traditional synchronization problems, but: –semaphores are essentially shared global variables can be accessed from anywhere (bad software engineering) –there is no connection between the semaphore and the data being controlled by it –used for both critical sections (mutual exclusion) and for coordination (scheduling) –no control over their use, no guarantee of proper usage Thus, they are prone to bugs –another (better?) approach: use programming language support

3/21/20165 One More Approach: Monitors A monitor is a programming language construct that supports controlled access to shared data –synchronization code is added by the compiler why does this help? A monitor encapsulates: –shared data structures –procedures that operate on the shared data –synchronization between concurrent threads that invoke those procedures Data can only be accessed from within the monitor, using the provided procedures –protects the data from unstructured access Addresses the key usability issues that arise with semaphores

Administrivia HW this week Lectures –This week: scheduling –Next week: memory management Quiz 2 next Tuesday: scheduling Quiz 3 the following week: memory management Midterm: tentatively Feb 18, take home, open book 3/21/20166

7 Scheduling In discussing processes and threads, we talked about context switching –an interrupt occurs (device completion, timer interrupt) –a thread causes an exception (a trap or a fault) We glossed over the choice of which process or thread is chosen to be run next –“some thread from the ready queue” This decision is called scheduling –scheduling is policy –context switching is mechanism

3/21/20168 Classes of Schedulers Batch –Throughput / utilization oriented –Example: audit inter-bank funds transfers each night Interactive –Response time oriented –Example: Windows GUI, X host – X client Real time –Deadline driven –Example: embedded systems (cars, airplanes, etc.) Parallel –Speedup driven –Example: “space-shared” use of a 1000-processor machine for large simulations Others… We’ll be talking primarily about interactive schedulers for now.

3/21/20169 Multiple levels of scheduling decisions Long term –Should a new “job” be “initiated,” or should it be held? –typical of batch systems –what might cause you to make a “hold” decision? Medium term –Should a running program be temporarily marked as non- runnable (e.g., swapped out)? Short term –Which thread should be given the CPU next? For how long? –Which I/O operation should be sent to the disk next? –On a multiprocessor: should we attempt to coordinate the running of threads from the same address space in some way? should we worry about cache state (processor affinity)?

3/21/ Scheduling Goals I: Performance Many possible metrics / performance goals (which sometimes conflict) –maximize CPU utilization –maximize throughput ( requests completed / s ) –minimize average response (turn-around) time ( average time from submission of request to completion of response ) –minimize average waiting time ( average time from submission of request to start of execution ) –minimize energy ( joules per instruction ) subject to some constraint

3/21/ Scheduling Goals II: Fairness No single, compelling definition of “fair” –How to measure fairness? Equal CPU consumption? (over what time scale?) –Fair per-user? per-process? per-thread? –What if one process is CPU bound and one is IO bound? Sometimes the goal is to be unfair: –Explicitly favor some particular class of requests ( priority system ), but… –avoid starvation ( be sure everyone gets at least some service )

3/21/ The basic situation  Schedulable units Resources Scheduling: -Who to assign each resource to -When to re-evaluate your decisions

3/21/ When to assign? Pre-emptive vs. non-preemptive schedulers –Non-preemptive once you give somebody the green light, they’ve got it until they relinquish it –an I/O operation –allocation of memory in a system without swapping –Preemptive you can re-visit a decision –setting the timer allows you to preempt the CPU from a thread even if it doesn’t relinquish it voluntarily –in any modern system, if you mark a program as non-runnable, its memory resources will eventually be re-allocated to others Re-assignment always involves some overhead –Overhead doesn’t contribute to the goal of any scheduler We’ll assume “work conserving” policies –Never leave a resource idle when someone wants it Why even mention this? When might it be useful to do something else?

3/21/ Algorithm #1: FCFS/FIFO First-come first-served / First-in first-out (FCFS/FIFO) –schedule in the order that they arrive –“real-world” scheduling of people in (single) lines supermarkets, bank tellers, McD’s, Starbucks … –typically non-preemptive no context switching at supermarket! –jobs treated equally, no starvation In what sense is this “fair”? Sounds perfect! –in the real world, when does FCFS/FIFO work well? even then, what’s it’s limitation? –and when does it work badly?

3/21/ FCFS/FIFO example Suppose the duration of A is 5 time unit, and the durations of B and C are each 1 What are the average response (turn around) time? Job A B C CB time 1 2

3/21/ FCFS/FIFO example Suppose the duration of A is 5 time unit, and the durations of B and C are each 1 –average response time for schedule 1 (assuming A, B, and C all arrive at about time 0) is (5+6+7)/3 = 18/3 = 6 –average response time for schedule 2 is (1+2+7)/3 = 10/3 = 3.3 –consider also “elongation factor” – a “perceptual” measure: Schedule 1: A is 5/5, B is 6/1, C is 7/1 (worst is 7, ave is 4.7) Schedule 2: A is 7/5, B is 1/1, C is 2/1 (worst is 2, ave is 1.5) Job A B C CB time 1 2

3/21/ Average response time can be lousy –small requests wait behind big ones May lead to poor utilization of other resources –if you send me on my way, I can go keep another resource busy –FCFS may result in poor overlap of CPU and I/O activity FCFS/FIFO drawbacks

3/21/ Algorithm #2: SPT/SJF/SPN Shortest processing time first / Shortest job first / Shortest process next (SPT/SJF/SPN) –choose the request with the smallest service requirement Provably optimal with respect to average response time

3/21/ SPT/SJF/SPN optimality tktk sfsf sgsg t k +s f t k +s f +s g In any schedule that is not SPT/SJF/SPN, there is some adjacent pair of requests f and g where the service time (duration) of f, s f, exceeds that of g, s g The total contribution to average response time of f and g is (t k +s f ) + (t k +s f +s g ) = 2t k +2s f +s g If you interchange f and g, their total contribution will be 2t k +2s g +s f, which is smaller because s g < s f If the variability among request durations is zero, how does FCFS compare to SPT for average response time?

3/21/ It’s non-preemptive –So? … but there’s a preemptive version – SRPT (Shortest Remaining Processing Time first) – that accommodates arrivals (rather than assuming all requests are initially available) Sounds perfect! –what about starvation? –can you know the processing time of a request? –can you guess/approximate? How? SPT/SJF/SPN drawbacks

3/21/ Algorithm #3: RR Round Robin scheduling (RR) –ready queue is treated as a circular FIFO queue –each request is given a time slice, called a quantum request executes for duration of quantum, or until it blocks –what signifies the end of a quantum? time-division multiplexing (time-slicing) –great for timesharing no starvation Sounds perfect! –how is RR an improvement over FCFS? –how is RR an improvement over SPT? –how is RR an approximation to SPT? –what are the warts?

Example of RR with Time Quantum = 20 Example: ProcessBurst Time P 1 53 P 2 8 P 3 68 P 4 24 –The Gantt chart is: –Waiting time for P 1 =(68-20)+(112-88)=72 P 2 =(20-0)=20 P 3 =(28-0)+(88-48)+( )=85 P 4 =(48-0)+(108-68)=88 –Average waiting time = ( )/4=66¼ –Average completion time = ( )/4 = 104½ Thus, Round-Robin Pros and Cons: –Better for short jobs, Fair (+) –Context-switching time adds up for long jobs (-) P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P

Round-Robin Discussion How do you choose time slice? –What if too big? Response time suffers –What if infinite (  )? Get back FIFO –What if time slice too small? Throughput suffers! Actual choices of timeslice: –Initially, UNIX timeslice one second: Worked ok when UNIX was used by one or two people. What if three compilations going on? 3 seconds to echo each keystroke! –In practice, need to balance short-job performance and long-job throughput: Typical time slice today is between 10ms – 100ms Typical context-switching overhead is 0.1ms – 1ms Roughly 1% overhead due to context-switching

Comparisons between FCFS and RR Assuming zero-cost context-switching time, is RR always better than FCFS? Simple example: 10 jobs, each take 100s of CPU time RR scheduler quantum of 1s All jobs start at the same time Completion Times: –Both RR and FCFS finish at the same time –Average response time is much worse under RR! Bad when all jobs same length Also: Cache state must be shared between all jobs with RR but can be devoted to each job with FIFO –Total time for RR longer even for zero-cost switch! Job #FIFORR ………

3/21/ RR drawbacks What if all jobs are exactly the same length? –What would the pessimal schedule be? What do you set the quantum to be? –no value is “correct” if small, then context switch often, incurring high overhead if large, then response time degrades –treats all jobs equally if I run 100 copies of it degrades your service how might I fix this?

3/21/ Algorithm #4: Priority Assign priorities to requests –choose request with highest priority to run next if tie, use another scheduling algorithm to break (e.g., RR) –to implement SJF, priority = expected length of CPU burst Abstractly modeled (and usually implemented) as multiple “priority queues” –put a ready request on the queue associated with its priority Sounds perfect!

3/21/ Priority drawbacks How are you going to assign priorities? Starvation –if there is an endless supply of high priority jobs, no low- priority job will ever run Solution: “age” threads over time –increase priority as a function of accumulated wait time –decrease priority as a function of accumulated processing time –many ugly heuristics have been explored in this space

3/21/ Combining algorithms In practice, any real system uses some sort of hybrid approach, with elements of FCFS, SPT, RR, and Priority Example: multi-level feedback queues (MLFQ) –there is a hierarchy of queues –there is a priority ordering among the queues –new requests enter the highest priority queue –each queue is scheduled RR –queues have different quanta –requests/jobs move between queues based on execution history –in what situations might this approximate SJF?

3/21/ UNIX/Linux scheduling Canonical scheduler is pretty much MLFQ –3-4 classes spanning ~170 priority levels timesharing: lowest 60 priorities system: middle 40 priorities real-time: highest 60 priorities –priority scheduling across queues, RR within process with highest priority always run first processes with same priority scheduled RR –processes dynamically change priority increases over time if process blocks before end of quantum decreases if process uses entire quantum Goals: –reward interactive behavior over CPU hogs interactive jobs typically have short bursts of CPU

3/21/ Scheduling the Apache web server SRPT What does a web request consist of? (What’s it trying to get done?) How are incoming web requests scheduled, in practice? How might you estimate the service time of an incoming request? Starvation under SRPT is a problem in theory – is it a problem in practice? –“Kleinrock’s conservation law” (Recent work by Bianca Schroeder and Mor Harchol-Balter at CMU)

3/21/ © 2003 Bianca Schroeder & Mor Harchol-Balter, CMU

3/21/ Summary Scheduling takes place at many levels It can make a huge difference in performance –this difference increases with the variability in service requirements Multiple goals, sometimes conflicting There are many “pure” algorithms, most with some drawbacks in practice – FCFS, SPT, RR, Priority Real systems use hybrids Recent work has shown that SPT/SRPT – always known to be beneficial in principle – may be more practical in some settings than long thought

Administrivia Quiz 2 on blackboard today, –Grade in class on Thursday Project 1 –Demo in lab section this week –Write up due Tuesday March 2 No lab next week Project 2 –Begin this week with Part 1 –Your project needs to be approved by me –Site references, including distribution/location of the source code you’re using to build –Full write up (with approval) due next week, Friday Feb 19 3/21/201633