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

Similar documents
CPU scheduling. CPU Scheduling

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

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

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

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

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

CPU Scheduling. Jo, Heeseung

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

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

CS510 Operating System Foundations. Jonathan Walpole

SE350: Operating Systems. Lecture 6: Scheduling

א א א א א א א א

Project 2 solution code

CS 143A - Principles of Operating Systems

CPU Scheduling. Chapter 9

Scheduling. CSE Computer Systems November 19, 2001

September 30 th, 2015 Prof. John Kubiatowicz

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

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:

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

CPU Scheduling. Jo, Heeseung

Motivation. Types of Scheduling

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

CPU Scheduling (Chapters 7-11)

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

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

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 11: CPU Scheduling

Principles of Operating Systems

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

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

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

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

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

CS 153 Design of Operating Systems Winter 2016

TCSS 422: OPERATING SYSTEMS

CS 111. Operating Systems Peter Reiher

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

CSE 5343/7343 Fall 2006 PROCESS SCHEDULING

CPU Scheduling: Part I. Operating Systems. Spring CS5212

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

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

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

Advanced Types Of Scheduling

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

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

Journal of Global Research in Computer Science

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

Operating Systems. Scheduling

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

ELC 4438: Embedded System Design Real-Time Scheduling

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

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

CSC 553 Operating Systems

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

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

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)

IJCSC VOLUME 5 NUMBER 2 JULY-SEPT 2014 PP ISSN

Improvement of Queue Management for Real Time Task in Operating System

Uniprocessor Scheduling

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

Operating Systems Process Scheduling Prof. Dr. Armin Lehmann

Periodic task scheduling

Advanced Operating Systems (CS 202) Scheduling (2)

CSE 451: Operating Systems Spring Module 8 Scheduling

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

Asia Pacific Journal of Engineering Science and Technology

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

Chapter 9 Uniprocessor Scheduling

Simulation of Process Scheduling Algorithms

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

GENERALIZED TASK SCHEDULER

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

Operating System 9 UNIPROCESSOR SCHEDULING

An Optimized Task Scheduling Algorithm in Cloud Computing Environment

Design and Implementation of LST Based Dynamic Scheduler on Real Time OS

A Paper on Modified Round Robin Algorithm

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

A COMPARATIVE ANALYSIS OF SCHEDULING ALGORITHMS

The BEST Desktop Soft Real-Time Scheduler

Lecture 11: Scheduling

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

Comparative Analysis of Basic CPU Scheduling Algorithms

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

Pallab Banerjee, Probal Banerjee, Shweta Sonali Dhal

Real-Time and Embedded Systems (M) Lecture 4

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

SELF OPTIMIZING KERNEL WITH HYBRID SCHEDULING ALGORITHM

Lecture 6: Scheduling. Michael O Boyle Embedded Software

Resource Utilization & Execution Time Enhancement by Priority Based Preemptable Shortest Job Next Scheduling In Private Cloud Computing

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

CS 425 / ECE 428 Distributed Systems Fall 2018

CS 425 / ECE 428 Distributed Systems Fall 2017

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

ENGG4420 CHAPTER 4 LECTURE 3 GENERALIZED TASK SCHEDULER

MAX PLANCK INSTITUTE FOR SOFTWARE SYSTEMS. Max Planck Institute for Software Systems (MPI-SWS) Germany

Graph Optimization Algorithms for Sun Grid Engine. Lev Markov

Limited Preemptive Real-time Scheduling on Multiprocessors. Abhilash Thekkilakattil

Transcription:

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

Recap Deadlock prevention Break any of four deadlock conditions Mutual exclusion, no preemption, hold & wait, circular dependency Banker s algorithm If a request is granted, can it lead to a deadlock? CPU Scheduling Decides: which thread, when, and how long? 2

FIFO SJF In the order of arrival Non-preemptive Shortest job first. Non preemptive SRTF Recap Preemptive version of SJF 3

Average waiting time? (9 + 0 + 15 + 2 ) / 4 = 6.5 Quiz: SRTF Process Arrival Time Burst Time P1 0 8 P2 1 4 P3 2 9 P4 3 5 P1 P2 P3 P4 P P 2 P 4 P 1 P 3 1 0 1 5 10 17 26 4

FIFO Issues Bad average turn-around time SJF/SRTF Good average turn-around time IF you know or can predict the future Time-sharing systems Multiple users share a machine Need high interactivity low response time 5

FIFO with preemption Round-Robin (RR) Each job executes for a fixed time slice: quantum When quantum expires, the scheduler preempts the task Schedule the next job and continue... Simple, fair, and easy to implement 6

Round-Robin (RR) Example Quantum size = 4 Gantt chart Process Burst Times P1 24 P2 3 P3 3 Response time (between ready to first schedule) P1: 0, P2: 4, P3: 7. average response time = (0+4+7)/3 = 3.67 Waiting time P 1 P 2 P 3 P 1 P 1 P 1 P 1 P 1 0 4 7 10 14 18 22 26 30 P1: 6, P2: 4, P3: 7. average waiting time = (6+4+7)/3 = 5.67 7

How To Choose Quantum Size? Quantum length Too short high overhead (why?) Too long bad response time Very long quantum FIFO 8

Round-Robin (RR) Example Quantum size = 2 Gantt chart Process Burst Times P1 24 P2 3 P3 3 P 1 P 2 P 3 P 1 P 2 P 3 P 1 P 1 P 1 0 2 4 6 8 9 10 12 14 30 Response time (between ready to first schedule) P1: 0, P2: 2, P3: 4. average response time = (0+2+4)/3 = 2 Waiting time P1: 6, P2: 6, P3: 7. average waiting time = (6+6+7)/3 = 6.33 9

Discussion Comparison between FCFS, SRTF(SJF), and RR What to choose for smallest average waiting time? SRTF (SFJ) is the optimal What to choose for better interactivity? RR with small time quantum (or SRTF) What to choose to minimize scheduling overhead? FCFS 10

Example A or B C Compute I/O I/O Task A and B CPU bound, run an hour Task C I/O bound, repeat(1ms CPU, 9ms disk I/O) FCFS? If A or B is scheduled first, C can begins an hour later RR and SRTF? 11

Example Timeline C A B I/O RR with 100ms time quantum C A B A B C A B A B C A B I/O I/O RR with 1ms time quantum C A C A C A I/O I/O SRTF 12

Summary First-Come, First-Served (FCFS) Run to completion in order of arrival Pros: simple, low overhead, good for batch jobs Cons: short jobs can stuck behind the long ones Round-Robin (RR) FCFS with preemption. Cycle after a fixed time quantum Pros: better interactivity (optimize response time) Cons: performance is dependent on the quantum size Shortest Job First (SJF)/ Shorted Remaining Time First (SRTF) Shorted job (or shortest remaining job) first Pros: optimal average waiting time (turn-around time) Cons: you need to know the future, long jobs can be starved by short jobs 13

Agenda Multi-level queue scheduling Fair scheduling Real-time scheduling Multicore scheduling 14

Multiple Scheduling Goals Optimize for interactive applications Round-robin Optimize for batch jobs FCFS Can we do both? 15

Multi-level Queue Ready queue is partitioned into separate queues Foreground: interactive jobs Background: batch jobs Each queue has its own scheduling algorithm Foreground : RR Background: FCFS Between the queue? 16

Multi-level Queue Scheduling Scheduling between the queues Fixed priority Foreground first; schedule background only when no tasks in foreground Possible starvation Time slicing Assign fraction of CPU time for each queue 80% time for foreground; 20% time for background 17

Multi-level Feedback Queue Each queue has a priority Tasks migrate across queues Each job starts at the highest priority queue If it uses up an entire quantum, drop one-level If it finishes early, move up one-level (or stay at top) Benefits Interactive jobs stay at high priority queues Batch jobs will be at the low priority queue Automatically! 18

Completely Fair Scheduler (CFS) Linux default scheduler, focusing on fairness Each task owns a fraction of CPU time share E.g.,) A=10%, B=30%, C=60% Scheduling algorithm Each task maintains its virtual runtime Virtual runtime = executed time (x weight) Pick the task with the smallest virtual runtime Tasks are sorted according to their virtual times 19

CFS Example 5 Scheduled the neediest task 6 8 10 Tasks are sorted according to their virtual times 20

CFS Example 6 8 9 On a next scheduler event re-sort the list 10 But list is inefficient. Tasks are sorted according to their virtual times 21

Red-black Tree Figure source: M. Tim Jones, Inside the Linux 2.6 Completely Fair Scheduler, IBM developerworks Self-balancing binary search tree Insert: O(log N), Remove: O(1) 22

Weighed Fair Sharing: Example Weights: gcc = 2/3, bigsim=1/3 X-axis: mcu (tick), Y-axis: virtual time Fair in the long run 23

Real-Time Scheduling Goal: meet the deadlines of important tasks Soft deadline: game, video decoding, Hard deadline: engine control, anti-lock break (ABS) 100 ECUs (processors) in BMW i3 [*] Priority scheduling A high priority task preempts lower priority tasks Static priority scheduling Dynamic priority scheduling [*] Robert Leibinger, Software Architectures for Advanced Driver Assistance Systems (ADAS), OSPERT 15 keynote 24

Rate Monotonic (RM) Priority is assigned based on periods Shorter period -> higher priority Longer period -> lower priority Optimal static-priority scheduling (3,1) (4,1) 25

Earliest Deadline First (EDF) Priority is assigned based on deadline Shorter deadline higher priority Longer deadline lower priority Optimal dynamic priority scheduling (3,1) (4,1) (5,2) 26

Real-Time Schedulers in Linux SCHED_FIFO Static priority scheduler SCHED_RR Same as SCHED_FIFO except using RR for tasks with the same priority SCHED_DEADLINE EDF scheduler Recently merged in the Linux mainline (v3.14) 27

Linux Scheduling Framework Real-time (sched/rt.c) CFS (sched/fair.c) First, schedule real-time tasks Real-time schedulers: (1) Priority based, (2) deadline based Then schedule normal tasks Completely Fair Scheduler (CFS) Two-level queue scheduling Between queues? 28

Multiprocessor Scheduling Core1 Core2 Core3 Core4 DRAM How many scheduling queues are needed? Global shared queue: all tasks are placed in a single shared queue (global scheduling) Per-core queue: each core has its own scheduling queue (partitioned scheduling) 29

Global Scheduling tasks OS RunQueue HW CPU1 CPU2 CPU3 CPU4 30

Partitioned Scheduling tasks tasks tasks tasks OS RunQueue RunQueue RunQueue RunQueue HW CPU1 CPU2 CPU3 CPU4 Linux s basic design. Why? 31

Undesirable situation Load Balancing Core 1 s queue: 40 tasks Core 2 s queue: 0 task Load balancing Tries to balance load across all cores. Not so simple, why? Migration overhead: cache warmup 32

More considerations Load Balancing What if certain cores are more powerful than others? E.g., ARM biglittle (4 big cores, 4 small cores) What if certain cores share caches while others don t? Which tasks to migrate? Core1 Core2 Core3 Core4 LLC LLC Some tasks may compete for limited shared resources 33

Summary Multi-level queue scheduling Each queue has its own scheduler Scheduling between the queues Fair scheduling (CFS) Fairly allocate CPU time across all tasks Pick the task with the smallest virtual time Guarantee fairness and bounded response time Real-time scheduling Static priority scheduling Dynamic priority scheduling 34

Multicore scheduling Summary Global queue vs. per-core queue Mostly per-core queue due to scalability Load balancing Balance load across all cores Is complicated due to Migration overhead Shared hardware resources (cache, dram, etc) Core architecture heterogeneity (big cores vs. small cores) 35

Some Edge Cases How to set the virtual time of a new task? Can t set as zero. Why? System virtual time (SVT) The minimum virtual time among all active tasks cfs_rq->min_vruntime The new task can catch-up tasks by setting its virtual time with SVT 36

Weighed Fair Sharing: Example 2 Weights: gcc = 2/3, bigsim=1/3 X-axis: mcu (tick), Y-axis: virtual time gcc slept 15 mcu 37