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

Similar documents
CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CPU Scheduling. Jo, Heeseung

CPU Scheduling. Jo, Heeseung

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

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

CPU Scheduling (Chapters 7-11)

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

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

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

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

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

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

CSE 451: Operating Systems Spring Module 8 Scheduling

CS510 Operating System Foundations. Jonathan Walpole

Scheduling. CSE Computer Systems November 19, 2001

CPU scheduling. CPU Scheduling

א א א א א א א א

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

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

CPU Scheduling. Chapter 9

CS 153 Design of Operating Systems Winter 2016

Operating Systems. Scheduling

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

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

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

Project 2 solution code

TCSS 422: OPERATING SYSTEMS

SE350: Operating Systems. Lecture 6: Scheduling

CS 143A - Principles of Operating Systems

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

CSE 5343/7343 Fall 2006 PROCESS SCHEDULING

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

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

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

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

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

Principles of Operating Systems

September 30 th, 2015 Prof. John Kubiatowicz

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)

CS 111. Operating Systems Peter Reiher

Lecture 11: CPU Scheduling

CPU Scheduling: Part I. Operating Systems. Spring CS5212

Motivation. Types of Scheduling

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

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:

CSC 553 Operating Systems

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

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

Scheduling: Introduction

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

Journal of Global Research in Computer Science

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

Operating Systems Process Scheduling Prof. Dr. Armin Lehmann

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

A Paper on Modified Round Robin Algorithm

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

Chapter 9 Uniprocessor Scheduling

Simulation of Process Scheduling Algorithms

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

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

Improvement of Queue Management for Real Time Task in Operating System

A COMPARATIVE ANALYSIS OF SCHEDULING ALGORITHMS

Operating System 9 UNIPROCESSOR SCHEDULING

IJCSC VOLUME 5 NUMBER 2 JULY-SEPT 2014 PP ISSN

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

Review of Round Robin (RR) CPU Scheduling Algorithm on Varying Time Quantum

Uniprocessor Scheduling

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

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

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

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

Asia Pacific Journal of Engineering Science and Technology

ELC 4438: Embedded System Design Real-Time Scheduling

Pallab Banerjee, Probal Banerjee, Shweta Sonali Dhal

Advanced Types Of Scheduling

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

The BEST Desktop Soft Real-Time Scheduler

Queue based Job Scheduling algorithm for Cloud computing

Improvised Optimum Multilevel Dynamic Round Robin Algorithm for Optimizing CPU Scheduling

Comparative Analysis of Basic CPU Scheduling Algorithms

Bhavin Fataniya 1, Manoj Patel 2 1 M.E(I.T) Student, I.T Department, L.D College Of Engineering, Ahmedabad, Gujarat, India ABSTRACT I.

SELF OPTIMIZING KERNEL WITH HYBRID SCHEDULING ALGORITHM

Homework 2: Comparing Scheduling Algorithms

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

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

Mixed Round Robin Scheduling for Real Time Systems

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

Clock-Driven Scheduling

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

Efficient Round Robin Scheduling Algorithm with Dynamic Time Slice

Design and Performance Evaluation of Smart Job First Dynamic Round Robin (SJFDRR) Scheduling Algorithm with Smart Time Quantum

DRR Based Job Scheduling for Computational Grid and its Variants

Operating Systems (234123) Spring 2013 Scheduling Dan Tsafrir (18/3/2013, 8/4/2013)

A SURVEY ON TRADITIONAL AND EARLIER JOB SCHEDULING IN CLOUD ENVIRONMENT

A Survey of Resource Scheduling Algorithms in Green Computing

Analysis of Adaptive Round Robin Algorithm and Proposed Round Robin Remaining Time Algorithm

GENERALIZED TASK SCHEDULER

Improving Throughput and Utilization in Parallel Machines Through Concurrent Gang

Advanced Operating Systems (CS 202) Scheduling (2)

Transcription:

CPU Scheduling Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu

CPU Scheduling policy deciding which process to run next, given a set of runnable processes Happens frequently, hence should be fast Mechanism How to transition? Ready Scheduled Time slice exhausted Running Policy When to transition? I/O or event completion Blocked I/O or event wait 2

Basic pproaches Non-preemptive scheduling The scheduler waits for the running process to voluntarily yield the CPU Processes should be cooperative Preemptive scheduling The scheduler can interrupt a process and force a context switch What happens If a process is preempted in the midst of updating the shared data? If a process in a system call is preempted? 3

Terminologies Workload set of job descriptions e.g. arrival time, run time, etc. Scheduler logic that decides when jobs run Metric Measurement of scheduling quality e.g. turnaround time, response time, fairness, etc. 4

Workload ssumptions 1. Each job runs for the same amount of time 2. ll jobs arrive at the same time 3. Once started, each job runs to completion 4. ll jobs only use the CPU (no I/O) 5. The run time of each job is known Metric: Turnaround time T turnaround = T completion T arrival 5

FIFO First-Come, First-Served Jobs are scheduled in order that they arrive Real-world scheduling of people in lines e.g. supermarket, bank tellers, McDonalds, etc. Non-preemptive Jobs are treated equally: no starvation Problems Convoy effect verage turnaround time can be large if small jobs wait behind long ones 6

SJF Shortest Job First Each job has a variable run time (ssumption 1 relaxed) Choose the job with the smallest run time Can prove that SJF shows the optimal turnaround time under our assumptions Non-preemptive Problems Not optimal when jobs arrive at any time Can potentially starve 7

FIFO vs. SJF FIFO (10), B(10), C(10) (100), B(10), C(10) B C B C 0 20 40 60 80 100 120 T turnaround = (10 + 20 + 30)/3 = 20 SJF (100), B(10), C(10) 0 20 40 60 80 100 120 T turnaround = (100 + 110 + 120)/3 = 110 (100) B(10), C(10) B C B C 0 20 40 60 80 100 120 T turnaround = (10 + 20 + 120)/3 = 50 0 20 40 60 80 100 120 T turnaround = (100 + 90 + 100)/3 = 96. 7 8

STCF Shortest Time-to-Completion First Jobs are not available simultaneously (ssumption 2 relaxed) Preemptive version of SJF (ssumption 3 relaxed) If a new job arrives with the run time less than the remaining time of the current job, preempt it (100) B(10), C(10) (100) B(10), C(10) B C B C 0 20 40 60 80 100 120 T turnaround = (100 + 90 + 100)/3 = 96. 7 SJF 0 20 40 60 80 100 120 T turnaround = (120 + 10 + 20)/3 = 50 STCF 9

RR Round Robin Run queue is treated as a circular FIFO queue Each job is given a time slice (or scheduling quantum) Multiple of the timer-interrupt period or the timer tick Too short higher context switch overhead Too long less responsive Usually 10 ~ 100ms Runs a job for a time slice and then switches to the next job in the run queue Preemptive No starvation Improved response time: Great for time-sharing 10

SJF vs. RR RR focuses on a new metric: response time T response = T firstrun T arrival Typically, RR has higher turnaround time than SJF, but better response time (30), B(30), C(30) (30), B(30), C(30) B C B C B C B C 0 20 40 60 80 100 120 T turnaround = (30 + 60 + 90)/3 = 60 T response = (0 + 30 + 60)/3 = 30 SJF 0 20 40 60 80 100 120 T turnaround = (70 + 80 + 90)/3 = 80 T response = (0 + 10 + 20)/3 = 10 RR 11

(Static) Priority Scheduling Each job has a (static) priority cf.) nice(), renice(), setpriority(), getpriority() Choose the job with the highest priority to run next Round-robin or FIFO within the same priority Can be either preemptive or non-preemptive Starvation problem If there is an endless supply of high priority jobs, no low priority job will ever run 12

Incorporating I/O I/O-aware scheduling ssumption 4 relaxed Overlap computation with I/O Treat each CPU burst as an independent job Example: (interactive) + B (CPU-intensive) CPU burst I/O burst CPU B B B B B B B B Disk 0 20 40 60 80 100 120 STCF 0 20 40 60 80 100 120 I/O-aware STCF 13

Towards a General CPU Scheduler Goals Optimize turnaround time Minimize response time for interactive jobs Challenge: No a priori knowledge on the workloads The run time of each job is known (ssumption 5) How can the scheduler learn the characteristics of the jobs and make better decisions? Learn from the past to predict the future (as in branch predictors or cache algorithms) 14

MLFQ Multi-Level Feedback Queue number of distinct queues for each priority level Priority scheduling b/w queues, round-robin in the same queue Rule 1: If Priority() > Priority(B), runs (B doesn t). Rule 2: If Priority() = Priority(B), & B run in RR. Priority is varied based on its observed behavior 15

Changing Priority Typical workload: a mix of Interactive jobs: short-running, require fast response time CPU-intensive jobs: need a lot of CPU time, don t care about response time ttempt #1: Dynamic Priority Change Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue). Rule 4a: If a job uses up an entire time slice while running, its priority is reduced (i.e. moves down one queue). Rule 4b: If a job gives up the CPU before the time slice is up, it stays at the same priority level. 16

Scheduling Under Rules 1-4 Workload : long-running job, B: short-running job, C: interactive job B C Q2 B B terminated Q1 B Q0 0 20 40 60 80 100 120 140 160 180 200 220 17

Priority Boost Problems in ttempt #1 Long-running jobs can starve due to too many interactive jobs malicious user can game the scheduler by relinquishing the CPU just before the time slice is expired program may change its behavior over time ttempt #2: Priority Boost Rule 5: fter some time period S, move all the jobs in the system to the topmost queue. 18

Boost Boost Boost Scheduling Under Rules 1-5 Q2 Without Priority Boost Q1 Q0 starvation 0 20 40 60 80 100 120 140 160 180 200 220 With Priority Boost Q2 Q1 Q0 0 20 40 60 80 100 120 140 160 180 200 220 19

Better ccounting ttempt #3: Revise Rule 4a/4b for better accounting Rule 4: Once a job uses up its time allotment at a given level (regardless of how many times it has given up the CPU), its priority is reduced. Q2 B B B B B B B B B B Q1 B Q0 B B B B 0 20 40 60 80 100 Without precise accounting 0 20 40 60 80 100 With precise accounting 20

UNIX Scheduler MLFQ Preemptive priority scheduling Time-shared based on time slice Processes dynamically change priority 3~4 classes spanning ~170 priority levels (Solaris 2) Favor interactive processes over CPU-bound processes Use aging: no starvation Increase priority as a function of wait time Decrease priority as a function of CPU time Many ugly heuristics for voo-doo constants 21