CPU Scheduling Prof. Sirer (dr. Willem de Bruijn) CS 4410 Cornell University.

Slides:



Advertisements
Similar presentations
Scheduling Algorithms. Announcements Homework 1 is graded Homework 2 is on CMS Prelim is in class on 14 th March.
Advertisements

CPU Scheduling.
CPU Scheduling Questions answered in this lecture: What is scheduling vs. allocation? What is preemptive vs. non-preemptive scheduling? What are FCFS,
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.
CPU Scheduling CS 3100 CPU Scheduling1. Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various.
CPU Scheduling Algorithms
Chapter 3: CPU Scheduling
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
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.
CPU Scheduling. Schedulers Process migrates among several queues –Device queue, job queue, ready queue Scheduler selects a process to run from these queues.
CPU Scheduling. Schedulers Process migrates among several queues –Device queue, job queue, ready queue Scheduler selects a process to run from these queues.
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.
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
CPU Scheduling. Announcements CS 4410 was due two days ago! CS 4411 projects due next Wednesday, September 17 th Everyone should have access to CMS (
CPU Scheduling. Announcements CS 414 Homework next Wednesday, Feb 7th CS 415 initial design documents due TODAY, Friday, Feb 2nd –Project due following.
Job scheduling Queue discipline.
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.
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.
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.
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.
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.
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.
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.
CPU Scheduling G.Anuradha Reference : Galvin. CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time.
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.
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.
CPU SCHEDULING.
Module 5: CPU Scheduling
Chapter5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Module 5: CPU Scheduling
Module 5: CPU Scheduling
Presentation transcript:

CPU Scheduling Prof. Sirer (dr. Willem de Bruijn) CS 4410 Cornell University

Problem You are the cook at the state st. diner customers continually enter and place their orders Dishes take varying amounts of time to prepare What is your goal ? Which strategy achieves this goal?

Multitasking Operating Systems time sharing the cpu among processes

Process Model Process alternates between CPU and I/O bursts CPU-bound jobs: Long CPU bursts I/O-bound: Short CPU bursts I/O burst = process idle, switch to another “for free” Matrix multiply emacs

CPU Scheduler Processes and threads migrate among queues Ready queue, device wait queues,... Scheduler selects one from ready queue to run Which one? 0 ready processes: run idle loop 1 ready process: easy! > 1 ready process: what to do? NewReadyRunningExit Waiting

multitasking design decisions algorithms advanced topics

Goals What are metrics that schedulers should optimize for ? There are many, the right choice depends on the context Suppose: You own an (expensive) container ship and have cargo across the world You own a sweatshop, and need to evaluate workers You own a diner and have customers queuing You are a nurse and have to combine care and administration

Scheduling Metrics Many quantitative criteria for evaluating scheduler algorithm: CPU utilization: percentage of time the CPU is not idle Throughput: completed processes per time unit Turnaround time: submission to completion Waiting time: time spent on the ready queue Response time: response latency Predictability: variance in any of these measures The right metric depends on the context

“The perfect scheduler” Minimize latency: response or job completion time Maximize throughput: Maximize jobs / time Maximize utilization: keep all devices busy Fairness: everyone makes progress, no one starves

Task Preemption Non-preemptive Process runs until voluntarily relinquish CPU  process blocks on an event (e.g., I/O or synchronization)  process terminates  Process periodically calls the yield() system call to give up the CPU Only suitable for domains where processes can be trusted to relinquish the CPU Preemptive The scheduler actively interrupts and deschedules an executing process Required when applications cannot be trusted to yield Incurs some overhead

Other considerations

Uni vs. Multiprocessor Uniprocessor scheduling concerns itself with the selection of processes on a single processor or core Multiprocessor scheduling concerns itself with the partitioning of jobs across multiple CPUs or multiple cores

Best Effort vs. Real Time Predictability: ABS in your car vs. navigation software heart rate monitor Real time schedulers give strong predictability guarantee Best effort schedulers provide no such guarantees Most desktop Oses use best effort schedulers, as do all of the following algorithms

multitasking design decisions algorithms advanced topics

Scheduling Algorithms FCFS First-come First-served (FCFS) (FIFO) Jobs are scheduled in order of arrival Non-preemptive Problem: Average waiting time depends on arrival order Advantage: really simple! time P1P1 P2P2 P3P P1P1 P2P2 P3P3 048

Scheduling Algorithms LIFO Last-In First-out (LIFO) Newly arrived jobs are placed at head of ready queue Improves response time for newly created threads Problem: May lead to starvation – early processes may never get CPU

Round Robin FCFS with preemption Often used for timesharing Ready queue is treated as a circular queue (FIFO) Each process is given a time slice called a quantum It is run for the quantum or until it blocks RR allocates the CPU uniformly (fairly) across participants. If average queue length is n, each participant gets 1/n

RR with Time Quantum = 20 ProcessBurst Time P 1 53 P 2 17 P 3 68 P 4 24  The Gantt chart is: P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P

RR: Choice of Time Quantum Performance depends on length of the timeslice Context switching isn’t a free operation. If timeslice time is set too high  attempting to amortize context switch cost, you get FCFS.  i.e. processes will finish or block before their slice is up anyway If it’s set too low  you’re spending all of your time context switching between threads. Timeslice frequently set to ~100 milliseconds Context switches typically cost < 1 millisecond Moral: Context switch is usually negligible (< 1% per timeslice) unless you context switch too frequently and lose all productivity

Turnaround Time w/ Time Quanta

Problem Revisited You work as a short-order cook Customers come in and specify which dish they want Each dish takes a different amount of time to prepare Your goal: minimize average time customers wait for their food What strategy would you use ? Note: most restaurants use FCFS.

Scheduling Algorithms: SJF Shortest Job First (SJF) Choose the job with the shortest next CPU burst Provably optimal for minimizing average waiting time Problem: Impossible to know the length of the next CPU burst P1P1 P2P2 P3P P1P1 P2P2 P3P3 039 P2P2 P3P3

Approximate next CPU-burst duration from the durations of the previous bursts  The past can be a good predictor of the future No need to remember entire past history Use exponential average: t n duration of the n th CPU burst  n+1 predicted duration of the (n+1) st CPU burst  n+1 =  t n + (1-  )  n where 0    1  determines the weight placed on past behavior Shortest Job First Prediction

Scheduling Algorithms SRTF SJF can be either preemptive or non-preemptive New, short job arrives; current process has long time to execute Preemptive SJF is called shortest remaining time first P1P1 P2P2 P3P P1P1 P3P3 P1P1 P2P

Priority Scheduling Choose next job based on priority For SJF, priority = expected CPU burst Can be either preemptive or non-preemptive Priority schedulers can approximate other scheduling algorithms P = arrival time => FIFO P = now - arrival time =>LIFO P = job length => SJF Problem: Starvation: jobs can wait indefinitely Solution to starvation Age processes: increase priority as a function of waiting time

Multilevel Queue Scheduling System Processes Interactive Processes Batch Processes Student Processes Lowest priority Highest priority

Multilevel Queue Scheduling Implement multiple ready queues based on job “type” interactive processes CPU-bound processes batch jobs system processes student programs Different queues may be scheduled using different algorithms Intra-queue CPU allocation is either strict or proportional Problem: Classifying jobs into queues is difficult A process may have CPU-bound phases as well as interactive ones

Quantum = 2 Quantum = 4 Quantum = 8 FCFS Lowest priority Highest priority Multilevel Feedback Queues

Implement multiple ready queues Different queues may be scheduled using different algorithms Just like multilevel queue scheduling, but assignments are not static Jobs move from queue to queue based on feedback Feedback = The behavior of the job,  e.g. does it require the full quantum for computation, or  does it perform frequent I/O ? Very general algorithm Need to select parameters for: Number of queues Scheduling algorithm within each queue When to upgrade and downgrade a job

A Multi-level System priority timeslice I/O bound jobs CPU bound jobs

Algorithm Summary FIFO LIFO RR SJF SRTF Priority-based Multilevel queue Multilevel feedback queue

multitasking design decisions algorithms advanced topics real-time, threads, multiprocessor

Real-time Scheduling Real-time processes have timing constraints Expressed as deadlines or rate requirements Common RT scheduling policies Rate monotonic  Just one scalar priority related to the periodicity of the job  Priority = 1/rate  Static Earliest deadline first (EDF)  Dynamic but more complex  Priority = deadline Both require admission control to provide guarantees Common misconception: real time does not mean fast!

Thread Scheduling all threads share code & data segments Option 1: Ignore this fact Option 2: Two-level scheduling: user-level scheduler schedule processes, and within each process, schedule threads reduce context switching overhead and improve cache hit ratio

Multiprocessor Scheduling Option 1. Ignore this fact random in time and space Option 2. Space-based affinity: assign threads to processors + control resource sharing: sharing/interference - possibly poor load balancing Option 3. Gang scheduling run all threads belonging to a process at the same time + low-latency communication - greater distance (cache)

Postscript To do absolutely best we’d have to predict the future. Most current algorithms give highest priority to those that need the least! Scheduling has become increasingly ad hoc over the years. 1960s papers very math heavy, now mostly “tweak and see ”

Convoy Effect A CPU bound job will hold CPU until done, or it causes an I/O burst  rare occurrence, since the thread is CPU-bound  long periods where no I/O requests issued, and CPU held Result: poor I/O device utilization Example: one CPU bound job, many I/O bound  CPU bound runs (I/O devices idle)  CPU bound blocks  I/O bound job(s) run, quickly block on I/O  CPU bound runs again  I/O completes  CPU bound still runs while I/O devices idle (continues…) Simple hack: run process whose I/O completed?  What is a potential problem?

Problem Cases Blindness about job types I/O goes idle Optimization involves favoring jobs of type “A” over “B”. Lots of A’s? B’s starve Interactive process trapped behind others. Response time suffers for no reason Priorities: A depends on B. A’s priority > B’s. B never runs