CS 4410 Operating Systems. CPU Scheduling. Summer 2011 Cornell University

Similar documents
W4118 Operating Systems. Instructor: Junfeng Yang

Chapter 5 Process Scheduling

CPU Scheduling Outline

CPU Scheduling. CPU Scheduling

Announcements. Basic Concepts. Histogram of Typical CPU- Burst Times. Dispatcher. CPU Scheduler. Burst Cycle. Reading

Objectives. Chapter 5: CPU Scheduling. CPU Scheduler. Non-preemptive and preemptive. Dispatcher. Alternating Sequence of CPU And I/O Bursts

Objectives. Chapter 5: Process Scheduling. Chapter 5: Process Scheduling. 5.1 Basic Concepts. To introduce CPU scheduling

ICS Principles of Operating Systems

CPU Scheduling. Basic Concepts. Basic Concepts (2) Basic Concepts Scheduling Criteria Scheduling Algorithms Batch systems Interactive systems

Operating Systems. III. Scheduling.

CPU Scheduling. Core Definitions

Scheduling. Yücel Saygın. These slides are based on your text book and on the slides prepared by Andrew S. Tanenbaum

Comp 204: Computer Systems and Their Implementation. Lecture 12: Scheduling Algorithms cont d

Main Points. Scheduling policy: what to do next, when there are multiple threads ready to run. Definitions. Uniprocessor policies

/ Operating Systems I. Process Scheduling. Warren R. Carithers Rob Duncan

Process Scheduling CS 241. February 24, Copyright University of Illinois CS 241 Staff

Process Scheduling. Process Scheduler. Chapter 7. Context Switch. Scheduler. Selection Strategies

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

Deciding which process to run. (Deciding which thread to run) Deciding how long the chosen process can run

CPU Scheduling 101. The CPU scheduler makes a sequence of moves that determines the interleaving of threads.

Operating System: Scheduling

Job Scheduling Model

Scheduling 0 : Levels. High level scheduling: Medium level scheduling: Low level scheduling

Scheduling Algorithms

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

OPERATING SYSTEMS SCHEDULING

Introduction. Scheduling. Types of scheduling. The basics

Processor Scheduling. Queues Recall OS maintains various queues

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition

CPU Scheduling. CSC 256/456 - Operating Systems Fall TA: Mohammad Hedayati

CPU Scheduling. Multitasking operating systems come in two flavours: cooperative multitasking and preemptive multitasking.

2. is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput

OS OBJECTIVE QUESTIONS

Scheduling. Scheduling. Scheduling levels. Decision to switch the running process can take place under the following circumstances:

Operating Systems Lecture #6: Process Management

A Group based Time Quantum Round Robin Algorithm using Min-Max Spread Measure

Operating Systems Concepts: Chapter 7: Scheduling Strategies

CS Fall 2008 Homework 2 Solution Due September 23, 11:59PM

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

PROCESS SCHEDULING ALGORITHMS: A REVIEW

Operating Systems, 6 th ed. Test Bank Chapter 7

A Comparative Study of CPU Scheduling Algorithms

Real-Time Scheduling 1 / 39

Analysis and Comparison of CPU Scheduling Algorithms

Readings for this topic: Silberschatz/Galvin/Gagne Chapter 5

Lecture Outline Overview of real-time scheduling algorithms Outline relative strengths, weaknesses

W4118 Operating Systems. Instructor: Junfeng Yang

Linux Process Scheduling Policy

Syllabus MCA-404 Operating System - II

REDUCING TIME: SCHEDULING JOB. Nisha Yadav, Nikita Chhillar, Neha jaiswal

Completely Fair Scheduler and its tuning 1

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

Linux scheduler history. We will be talking about the O(1) scheduler

4. Fixed-Priority Scheduling

A Review on Load Balancing In Cloud Computing 1

REAL TIME OPERATING SYSTEMS. Lesson-18:

A LECTURE NOTE ON CSC 322 OPERATING SYSTEM I DR. S. A. SODIYA

Common Approaches to Real-Time Scheduling

Chapter 19: Real-Time Systems. Overview of Real-Time Systems. Objectives. System Characteristics. Features of Real-Time Systems

A Priority based Round Robin CPU Scheduling Algorithm for Real Time Systems

Lecture 3 Theoretical Foundations of RTOS

CS414 SP 2007 Assignment 1

Module 6. Embedded System Software. Version 2 EE IIT, Kharagpur 1

Scheduling policy. ULK3e 7.1. Operating Systems: Scheduling in Linux p. 1

Real-Time Scheduling (Part 1) (Working Draft) Real-Time System Example

Operating System Aspects. Real-Time Systems. Resource Management Tasks

Performance Comparison of RTOS

Real-time scheduling algorithms, task visualization

Konzepte von Betriebssystem-Komponenten. Linux Scheduler. Valderine Kom Kenmegne Proseminar KVBK Linux Scheduler Valderine Kom

Real Time Scheduling Basic Concepts. Radek Pelánek

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

Aperiodic Task Scheduling

Analysis of Job Scheduling Algorithms in Cloud Computing

Linux Block I/O Scheduling. Aaron Carroll December 22, 2007

This tutorial will take you through step by step approach while learning Operating System concepts.

Real- Time Scheduling

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

Exercises : Real-time Scheduling analysis

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Comparison between scheduling algorithms in RTLinux and VxWorks

ò Scheduling overview, key trade-offs, etc. ò O(1) scheduler older Linux scheduler ò Today: Completely Fair Scheduler (CFS) new hotness

Processes and Non-Preemptive Scheduling. Otto J. Anshus

REAL TIME OPERATING SYSTEMS. Lesson-10:

3. Scheduling issues. Common approaches /1. Common approaches /2. Common approaches / /13 UniPD / T. Vardanega 23/01/2013. Real-Time Systems 1

Final Report. Cluster Scheduling. Submitted by: Priti Lohani

Resource Models: Batch Scheduling

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

Real-Time Software. Basic Scheduling and Response-Time Analysis. René Rydhof Hansen. 21. september 2010

Predictable response times in event-driven real-time systems

Linux O(1) CPU Scheduler. Amit Gud amit (dot) gud (at) veritas (dot) com

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

Operating System Tutorial

Commonly Used Approaches to Real-Time Scheduling

Load Balancing Scheduling with Shortest Load First

Transcription:

CS 4410 Operating Systems CPU Scheduling Summer 2011 Cornell University

Today How does CPU manage the execution of simultaneously ready processes? Example Multitasking - Scheduling Scheduling Metrics Scheduling Algorithms Real-time Scheduling Thread Scheduling Multiprocessor Scheduling 2

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

Correspondence Dinner - Multitasking Operating System Ordering Manager CPU Scheduler Cook CPU Client User Order Process Dish category CPU/I-O Burst 4

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

CPU Scheduler Processes and threads migrate among queues Ready queue, device wait queues, Scheduler selects one from ready queue to run Which one? When? New Ready Running Exit Waiting 6

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 7

Scheduling Metrics 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 8

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 The right metric depends on the context 9

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 10

Scheduling Algorithms FCFS First-come First-served Jobs are scheduled in order of arrival Non-preemptive Problem: Average waiting time depends on arrival order P 1 P 2 P 3 time 0 16 20 24 P 2 P 3 P 1 0 4 8 24 Advantage: really simple! 11

Scheduling Algorithms LIFO Last-In First-out 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 12

Scheduling Algorithms 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 runs 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 13

RR with Time Quantum = 20 Process Burst Time P 1 53 P 2 17 P 3 68 P 4 24 The Gantt chart is: P 1 P 2 P 3 P 4 P 1 P 3 P 4 P 1 P 3 P 3 0 20 37 57 77 97 117 121 134 154 162 14

RR: Choice of Time Quantum Performance depends on length of the time-slice Context switching isn t a free operation. If time-slice 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. Time-slice frequently set to ~100 milliseconds Context switches typically cost < 1 millisecond Moral: Context switch is usually negligible (< 1% per time-slice) unless you context switch too frequently and lose all productivity 15

Turnaround Time w/ Time Quanta 16

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. 17

Scheduling Algorithms SJF Shortest Job First Choose the job with the shortest next CPU burst Provably optimal for minimizing average waiting time P 1 P 3 P 2 0 15 21 24 P 2 2 P 3 3 P 1 0 3 9 24 Problem: Impossible to know the length of the next CPU burst 18

Shortest Job First Prediction 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 nth 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 19

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 P 2 P 3 P 1 0 6 21 10 P 3 P 1 P 2 P 1 0 6 10 13 24 20

Priority Scheduling 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 21

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

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 23

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

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 25

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

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! 27

Thread Scheduling All threads share code & data segment 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 28

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) 29

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

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 31

Today How does CPU manage the execution of simultaneously ready processes? Example Multitasking - Scheduling Scheduling Metrics Scheduling Algorithms Real-time Scheduling Thread Scheduling Multiprocessor Scheduling 32