Operating Systems. Scheduling

Similar documents
CSE 451: Operating Systems Spring Module 8 Scheduling

CPU Scheduling. Jo, Heeseung

Scheduling I. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Advanced topics on scheduling

CPU Scheduling. Jo, Heeseung

SE350: Operating Systems. Lecture 6: Scheduling

CPU scheduling. CPU Scheduling

CPU Scheduling. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Scheduling. CSE Computer Systems November 19, 2001

CPU Scheduling. Chapter 9

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Scheduling Processes 11/6/16. Processes (refresher) Scheduling Processes The OS has to decide: Scheduler. Scheduling Policies

CPU Scheduling (Chapters 7-11)

CPU SCHEDULING. Scheduling Objectives. Outline. Basic Concepts. Enforcement of fairness in allocating resources to processes

Principles of Operating Systems

Chapter 6: CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. CPU Scheduler. Dispatcher. Alternating Sequence of CPU And I/O Bursts

א א א א א א א א

CS 111. Operating Systems Peter Reiher

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

CS 143A - Principles of Operating Systems

CSC 1600: Chapter 5. CPU Scheduling. Review of Process States

Scheduling Algorithms. Jay Kothari CS 370: Operating Systems July 9, 2008

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Advanced Types Of Scheduling

Reading Reference: Textbook: Chapter 7. UNIX PROCESS SCHEDULING Tanzir Ahmed CSCE 313 Fall 2018

CS 153 Design of Operating Systems Winter 2016

FIFO SJF STCF RR. Operating Systems. Minati De. Department of Mathematics, Indian Institute of Technology Delhi, India. Lecture 6: Scheduling

CSC 553 Operating Systems

Introduction to Operating Systems. Process Scheduling. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati

Comp 204: Computer Systems and Their Implementation. Lecture 10: Process Scheduling

Motivation. Types of Scheduling

TABLE OF CONTENTS CHAPTER NO. TITLE PAGE NO. ABSTRACT LIST OF TABLES LIST OF FIGURES LIST OF SYMBOLS AND ABBREVIATIONS

Lecture 11: CPU Scheduling

CPU Scheduling Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University

CPU Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Unix Scheduler

CPU Scheduling. Disclaimer: some slides are adopted from book authors and Dr. Kulkarni s slides with permission

Intro to O/S Scheduling. Intro to O/S Scheduling (continued)

CPU Scheduling CPU. Basic Concepts. Basic Concepts. CPU Scheduler. Histogram of CPU-burst Times. Alternating Sequence of CPU and I/O Bursts

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - V CPU Scheduling - I. University at Buffalo.

Announcements. Program #1. Reading. Is on the web Additional info on elf file format is on the web. Chapter 6. CMSC 412 S02 (lect 5)

CS510 Operating System Foundations. Jonathan Walpole

Scheduling II. To do. q Proportional-share scheduling q Multilevel-feedback queue q Multiprocessor scheduling q Next Time: Memory management

Chapter 9 Uniprocessor Scheduling

CSE 5343/7343 Fall 2006 PROCESS SCHEDULING

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - V CPU Scheduling - I. Louisiana State University.

Lecture 3. Questions? Friday, January 14 CS 470 Operating Systems - Lecture 3 1

Salisu Aliyu Department of Mathematics, Ahmadu Bello University, Zaria, Nigeria

Uniprocessor Scheduling

Project 2 solution code

Journal of Global Research in Computer Science

Simulation of Process Scheduling Algorithms

September 30 th, 2015 Prof. John Kubiatowicz

Example. You manage a web site, that suddenly becomes wildly popular. Performance starts to degrade. Do you?

Recall: FCFS Scheduling (Cont.) Example continued: Suppose that processes arrive in order: P 2, P 3, P 1 Now, the Gantt chart for the schedule is:

Process Scheduling Course Notes in Operating Systems 1 (OPESYS1) Justin David Pineda

Process Scheduling I. COMS W4118 Prof. Kaustubh R. Joshi hdp://

IJCSC VOLUME 5 NUMBER 2 JULY-SEPT 2014 PP ISSN

A COMPARATIVE ANALYSIS OF SCHEDULING ALGORITHMS

ELC 4438: Embedded System Design Real-Time Scheduling

CPU scheduling CPU 1. P k P 3 P 2 P 1 CPU 2. CPU n. The scheduling problem: Which jobs should we assign to which CPU(s)?

Lecture Note #4: Task Scheduling (1) EECS 571 Principles of Real-Time Embedded Systems. Kang G. Shin EECS Department University of Michigan

Recall: Example of RR with Time Quantum = 20. Round-Robin Discussion

OPERATING SYSTEMS. Systems and Models. CS 3502 Spring Chapter 03

Improvement of Queue Management for Real Time Task in Operating System

Clock-Driven Scheduling

GENERALIZED TASK SCHEDULER

ENGG4420 CHAPTER 4 LECTURE 3 GENERALIZED TASK SCHEDULER

CPU Scheduling: Part I. Operating Systems. Spring CS5212

Operating System 9 UNIPROCESSOR SCHEDULING

CS162 Operating Systems and Systems Programming Lecture 10. Tips for Handling Group Projects Thread Scheduling

Lecture 6: CPU Scheduling. CMPUT 379, Section A1, Winter 2014 February 5

Motivating Examples of the Power of Analytical Modeling

LOAD SHARING IN HETEROGENEOUS DISTRIBUTED SYSTEMS

Priority-Driven Scheduling of Periodic Tasks. Why Focus on Uniprocessor Scheduling?

A NOVEL METHOD BASED ON PRIORITY FOR ENHANCEMENT ROUND-ROBIN SCHEDULING ALGORITHM

An operating system executes a variety of programs: Batch system - jobs Time-shared systems - user programs or tasks

Scheduling: Introduction

Real Time Scheduling. Real Time Scheduling. Real-Time Scheduling. Scheduling

Operating Systems Process Scheduling Prof. Dr. Armin Lehmann

Tasks or processes attempt to control or react to external events occuring in real time RT processes must be able to keep up events

2. Scheduling issues. Common approaches /2. Common approaches /1. Common approaches / /18 UniPD - T. Vardanega 14/03/2018

Limited-preemptive Earliest Deadline First Scheduling of Real-time Tasks on Multiprocessors

The BEST Desktop Soft Real-Time Scheduler

Efficient Round Robin Scheduling Algorithm with Dynamic Time Slice

A Paper on Modified Round Robin Algorithm

Real-Time and Embedded Systems (M) Lecture 4

CS Advanced Operating Systems Structures and Implementation Lecture 10. Scheduling (Con t) Real-Time Scheduling.

TCSS 422: OPERATING SYSTEMS

3. Scheduling issues. Common approaches /2. Common approaches /1. Common approaches / /17 UniPD / T. Vardanega 06/03/2017

1

LEAST-MEAN DIFFERENCE ROUND ROBIN (LMDRR) CPU SCHEDULING ALGORITHM

Fractal Exercise. Fractals, task farm and load imbalance

Periodic task scheduling

Comparative Analysis of Basic CPU Scheduling Algorithms

Lab: Response Time Analysis using FpsCalc Course: Real-Time Systems Period: Autumn 2015

Lecture 11: Scheduling

Clock-Driven Scheduling

Q1. What is Real time system? Explain the basic model of Real time system. (8)

Transcription:

Operating Systems Fall 2014 Scheduling Myungjin Lee myungjin.lee@ed.ac.uk 1

Scheduling In discussing processes and threads, we talked about context switching an interrupt occurs (device completion, timer interrupt) a thread causes a trap or exception may need to choose a different thread/process to run 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 a policy context switching is a mechanism 2

Classes of Schedulers Batch Throughput / utilization oriented Example: audit inter-bank funds transfers each night, Pixar rendering, Hadoop/MapReduce jobs Interactive Response time oriented 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 We ll be talking primarily about interactive schedulers 3

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)? 4

Scheduling Goals I: Performance Many possible metrics / performance goals (which sometimes conflict) maximize CPU utilization maximize throughput (requests completed / s) minimize average response 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 (e.g., frames/second) 5

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 I/O 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) 6

The basic situation Scheduling: - Who to assign each resource to - When to re-evaluate your decisions Schedulable units Resources 7

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? 8

Before we look at specific policies There are some simple but useful laws to know about The Utilization Law: U = X * S Where U is utilization, X is throughput (requests per second), and S is average service time Obviously true This means that utilization is constant, independent of the schedule, so long as the workload can be processed 9

Little s Law: N = X * R Where N is average number in system, X is throughput, and R is average response time (average time in system) This means that better average response time implies fewer in system, and vice versa Proof: Let W denote the total time-in-system accumulated by all customers during a time interval of length T The average number of requests in the system N = W / T If C customers complete during that time period, then the average contribution of each completing request R = W / C Algebraically, W/T = C/T * W/C. Thus, N = X * R 10

(Not quite a law requires some assumptions) Response Time at a single server under FCFS scheduling: R = S / (1-U) Clearly, when a customer arrives, her response time will be the service time of everyone ahead of her in line, plus her own service time: R = S * (1+A) Assumes everyone has the same average service time Assume that the number you see ahead of you at your instant of arrival is the long-term average number in line; so R = S * (1+N) By Little s Law, N = X * R So R = S * (1 + X*R) = S + S*X*R = S / (1 X*S) By the Utilization Law, U = X*S So R = S / (1-U) And since N = X*R, N = U / (1-U) 11

12

13

Kleinrock s Conservation Law for priority scheduling: Σ p U p * R p = constant Where U p is the utilization by priority level p and R p is the time in system of priority level p This means you can t improve the response time of one class of task by increasing its priority, without hurting the response time of at least one other class 14

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, McD s, Starbucks 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? 15

FCFS/FIFO example 1 time Job A B C 2 B C Job A Suppose the duration of A is 5, 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) 16

FCFS/FIFO drawbacks 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 E.g., a CPU-intensive job prevents an I/O-intensive job from doing a small bit of computation, thus preventing it from going back and keeping the I/O subsystem busy Note: The more copies of the resource there are to be scheduled, the less dramatic the impact of occasional very large jobs (so long as there is a single waiting line) E.g., many cores vs. one core 17

Algorithm #2: SPT/SJF Shortest processing time first / Shortest job first (SPT/SJF) choose the request with the smallest service requirement Provably optimal with respect to average response time Why do we care about provably optimal? 18

SPT/SJF optimality The interchange argument s f s g t k t k +s f t k +s f +s g In any schedule that is not SPT/SJF, 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 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? 19

SPT/SJF drawbacks 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? 20

Algorithm #3: RR Round Robin scheduling (RR) Use preemption to offset lack of information about execution times I don t know which one should run first, so let s run them all! 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? 21

RR drawbacks What if all jobs are exactly the same length? What would the pessimal schedule be (with average response time as the measure)? 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 SETI@home, it degrades your service how might I fix this? 22

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) Goal: non-fairness (favor one group over another) Abstractly modeled (and usually implemented) as multiple priority queues put a ready request on the queue associated with its priority Sounds perfect! 23

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 24

Program behavior and scheduling An analogy: Say you're at the airport waiting for a flight There are two identical ATMs: ATM 1 has 3 people in line ATM 2 has 6 people in line You get into the line for ATM 1 ATM 2's line shrinks to 4 people Why might you now switch lines, preferring 5th in line for ATM 2 over 4th in line for ATM 1? 25

Residual Life Given that a job has already executed for X seconds, how much longer will it execute, on average, before completing? Give priority to new jobs Residual Life Round robin Give priority to old jobs Time Already Executed 26

Multi-level Feedback Queues (MLFQ) It s been observed that workloads tend to have increasing residual life if you don t finish quickly, you re probably a lifer This is exploited in practice by using a policy that discriminates against the old (with apologies to the EEOC) 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 requests move between queues based on execution history 27

UNIX 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 28

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 that exploit observed program behavior Scheduling is still important, and there are still new angles to be explored particularly in large-scale datacenters for reasons of cost and energy 29

Multiprocessor Scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Asymmetric multiprocessing only one processor accesses the system data structures, alleviating the need for data sharing Symmetric multiprocessing (SMP) each processor is selfscheduling, all processes in common ready queue, or each has its own private queue of ready processes Currently, most common Windows, Linux, and MAC OS X support SMP 30

Multiprocessor Scheduling Processor affinity Process has affinity for processor on which it is currently running keep using the same processor to avoid having to repopulate cache soft affinity: not guaranteed the same processor hard affinity: process can specify a subset of processors Variations including processor sets 31

NUMA and CPU Scheduling CPU CPU fast access slow access fast access memory memory computer NUMA: non-uniform memory access 32

Multiprocessor Scheduling Load Balancing If symmetric multiprocessing (SMP), need to keep all CPUs loaded for efficiency Load balancing attempts to keep workload evenly distributed Push migration periodic task checks load on each processor, and if found pushes task from overloaded CPU to other CPUs Pull migration idle processors pull waiting task from busy processor 33

Multicore Processors Recent trend to place multiple processor cores on same physical chip" Faster and consumes less power" Multiple hardware threads per core also growing" Takes advantage of memory stall: progress can run another thread while memory retrieve happens" " 34

Multithreaded Multicore System Single threaded processor core Dual threaded processor core 35