CPU Scheduling Yi Shi Fall 2015 Xi an Jiaotong University

Similar documents
CPU Scheduling Outline

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

Chapter 5 Process Scheduling

CPU Scheduling. Core Definitions

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

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

ICS Principles of Operating Systems

CPU Scheduling. CPU Scheduling

W4118 Operating Systems. Instructor: Junfeng Yang

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

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

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

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

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

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

OPERATING SYSTEMS SCHEDULING

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

Operating Systems. III. Scheduling.

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

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

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

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

Processor Scheduling. Queues Recall OS maintains various queues

Job Scheduling Model

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

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

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

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

Introduction. Scheduling. Types of scheduling. The basics

OS OBJECTIVE QUESTIONS

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

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

Operating System: Scheduling

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

Scheduling Algorithms

Operating Systems Lecture #6: Process Management

Real-Time Scheduling 1 / 39

Overview of Presentation. (Greek to English dictionary) Different systems have different goals. What should CPU scheduling optimize?

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Operating Systems, 6 th ed. Test Bank Chapter 7

PROCESS SCHEDULING ALGORITHMS: A REVIEW

A Comparative Study of CPU Scheduling Algorithms

W4118 Operating Systems. Instructor: Junfeng Yang

Analysis and Comparison of CPU Scheduling Algorithms

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

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

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

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

Linux Process Scheduling Policy

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

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

Scheduling. Monday, November 22, 2004

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

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

EECS 750: Advanced Operating Systems. 01/28 /2015 Heechul Yun

Syllabus MCA-404 Operating System - II

CHAPTER 1 INTRODUCTION

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

Completely Fair Scheduler and its tuning 1

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

A Review on Load Balancing In Cloud Computing 1

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

Lecture 3 Theoretical Foundations of RTOS

Operating System Tutorial

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

Exercises : Real-time Scheduling analysis

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

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

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

Why Relative Share Does Not Work

Final Report. Cluster Scheduling. Submitted by: Priti Lohani

3 - Introduction to Operating Systems

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

Performance Comparison of RTOS

Comparison between scheduling algorithms in RTLinux and VxWorks

4. Fixed-Priority Scheduling

Real- Time Scheduling

REAL TIME OPERATING SYSTEMS. Lesson-18:

Chapter 5 Linux Load Balancing Mechanisms

Chapter 2: OS Overview

Dispatching Domains for Multiprocessor Platforms and their Representation in Ada

Threads Scheduling on Linux Operating Systems


Analysis of Job Scheduling Algorithms in Cloud Computing

Weight-based Starvation-free Improvised Round-Robin (WSIRR) CPU Scheduling Algorithm

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

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

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

Principles of Operating Systems CS 446/646

Scaling Networking Applications to Multiple Cores

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

Common Approaches to Real-Time Scheduling

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

Process Scheduling II

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

Real-Time Operating Systems for MPSoCs

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

Aperiodic Task Scheduling

218 Chapter 5 CPU Scheduling

Overview and History of Operating Systems

Transcription:

CPU Scheduling Yi Shi Fall 2015 Xi an Jiaotong University

Goals for Today CPU Schedulers Scheduling Algorithms Algorithm Evaluation Metrics Algorithm details Thread Scheduling Multiple-Processor Scheduling Real-Time Scheduling

Schedulers Process migrates among several queues Device queue, job queue, ready queue Scheduler selects a process to run from these queues Long-term scheduler: load a job in memory Runs infrequently Short-term scheduler: Select ready process to run on CPU Should be fast Middle-term scheduler (aka swapper) Reduce multiprogramming or memory consumption

Process Scheduling process and thread used interchangeably Which process to run next Many processes in ready state Which ready process to pick to run on the CPU? 0 ready processes: run idle loop 1 ready process: easy! > 1 ready process: what to do? New Ready Running Exit Waiting

When does scheduler run? Non-preemptive minimum Process runs until voluntarily relinquish CPU process blocks on an event (e.g., I/O or synchronization) process terminates process yields Preemptive minimum All of the above, plus: Event completes: process moves from blocked to ready Timer interrupts Implementation: process can be interrupted in favor of another New Ready Running Exit Waiting

Process Model 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 Problem: don t know job s type before running

Scheduling Evaluation Metrics Many quantitative criteria for evaluating scheduling 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 An underlying assumption: response time most important for interactive jobs (I/O bound)

The perfect CPU scheduler Minimize latency: response or job completion time Maximize throughput: Maximize jobs / time. Maximize utilization: keep CPU and I/O devices busy. Fairness: everyone makes progress, no one starves

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 P 1 P 2 P 3 time 0 16 20 24 P 2 P 3 P 1 0 4 8 24 Advantage: really simple!

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) I/O bound jobs waiting for CPU CPU bound I/O I/O bound job(s) run, quickly block on I/O (CPU idle) CPU bound runs again I/O completes CPU bound still runs while I/O devices idle (continues )

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

Problem 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 the 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 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

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

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

Prediction of the Length of the Next CPU Burst

Examples of Exponential Averaging =0 n+1 = n Recent history does not count =1 n+1 = t n Only the actual last CPU burst counts If we expand the formula, we get: n+1 = t n +(1 - ) t n -1 + +(1 - ) j t n -j + +(1 - ) n +1 0 Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor

Priority Scheduling Priority Scheduling Choose next job based on priority For SJF, priority = expected CPU burst Can be either preemptive or non-preemptive Problem: Starvation: jobs can wait indefinitely Solution to starvation Age processes: increase priority as a function of waiting time

Round Robin Round Robin (RR) 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 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 Higher average turnaround than SJF, But better response time

Turnaround Time w/ Time Quanta

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 10~100 milliseconds Context switches typically cost < 1 millisecond Moral: Context switch is usually negligible (< 1% per timeslice) otherwise you context switch too frequently and lose all productivity

Multi-level 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

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

Multi-level 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

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

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

Multiple-Processor 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 Processor affinity process has affinity for processor on which it is currently running soft affinity hard affinity Load Balancing push migration pull migration

NUMA and CPU Scheduling

Multicore Processors Recent trend to place multiple processor cores on same physical chip Faster and consume less power Multiple threads per core also growing Takes advantage of memory stall to make progress on another thread while memory retrieve happens

Multithreaded Multicore System

Thread Scheduling Since all threads share code & data segments Option 1: Ignore this fact Option 2: Gang scheduling run all threads belonging to a process together (multiprocessor only) if a thread needs to synchronize with another thread the other one is available and active Option 3: Two-level scheduling: Medium level scheduler schedule processes, and within each process, schedule threads reduce context switching overhead and improve cache hit ratio

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

Operating System Examples Solaris scheduling Windows XP scheduling Linux scheduling

Solaris Dispatch Table

Solaris Scheduling

Windows XP Priorities

Linux Scheduling Constant order O(1) scheduling time Two priority ranges: time-sharing and real-time Real-time range from 0 to 99 and nice value from 100 to 140

Priorities and Time-slice length

List of Tasks Indexed According to Priorities

Summary Scheduling problem Given a set of processes that are ready to run Which one to select next Scheduling criteria CPU utilization, Throughput, Turnaround, Waiting, Response Predictability: variance in any of these measures Scheduling algorithms FCFS, SJF, SRTF, RR Multilevel (Feedback-)Queue Scheduling The best schemes are adaptive. To do absolutely best we d have to predict the future. Most current algorithms give highest priority to those that need the least! Scheduling become increasingly ad hoc over the years. 1960s papers very math heavy, now mostly tweak and see