CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

Similar documents
Operating Systems ECE344. Ding Yuan

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

Opera&ng Systems ECE344

CSE 120 Principles of Operating Systems Spring 2017

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

CSE 120. Fall Lecture 8: Scheduling and Deadlock. Keith Marzullo

CSE 120 Principles of Operating Systems

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Chapter 5: CPU Scheduling

Last Class: Processes

Scheduling of processes

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

CS3733: Operating Systems

Advanced Operating Systems (CS 202) Scheduling (1)

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

CPU Scheduling Algorithms

Operating Systems. Scheduling

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

Course Syllabus. Operating Systems

CS 153 Design of Operating Systems Winter 2016

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Properties of Processes

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

COSC243 Part 2: Operating Systems

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

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

Computer Systems Laboratory Sungkyunkwan University

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

8: Scheduling. Scheduling. Mark Handley

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

CS370 Operating Systems

Chapter 6: CPU Scheduling

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

1.1 CPU I/O Burst Cycle

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Unit 3 : Process Management

Scheduling. Multiple levels of scheduling decisions. Classes of Schedulers. Scheduling Goals II: Fairness. Scheduling Goals I: Performance

Scheduling. Scheduling. Scheduling. Scheduling Criteria. Priorities. Scheduling

Operating System Concepts Ch. 5: Scheduling

CSE 451: Operating Systems Winter Module 10 Scheduling

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Chapter 9. Uniprocessor Scheduling

Chapter 5: CPU Scheduling

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Uniprocessor Scheduling. Chapter 9

LECTURE 3:CPU SCHEDULING

Operating Systems. Process scheduling. Thomas Ropars.

CPU Scheduling (1) CPU Scheduling (Topic 3) CPU Scheduling (2) CPU Scheduling (3) Resources fall into two classes:

CHAPTER 2: PROCESS MANAGEMENT

Job Scheduling. CS170 Fall 2018

Uniprocessor Scheduling

Scheduling. The Basics

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

Operating Systems: Quiz2 December 15, Class: No. Name:

CPU Scheduling: Objectives

Chapter 9 Uniprocessor Scheduling

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

CS 318 Principles of Operating Systems

CS370 Operating Systems

Announcements/Reminders

Chapter 5 CPU scheduling

Ch 4 : CPU scheduling

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

CSL373: Lecture 6 CPU Scheduling

Operating System Review Part

Advanced Operating Systems (CS 202) Scheduling (1) Jan, 23, 2017

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

CSCE Operating Systems Scheduling. Qiang Zeng, Ph.D. Fall 2018

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Operating Systems. CPU Scheduling ENCE 360

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

3. CPU Scheduling. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Lecture 2 Process Management

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

Frequently asked questions from the previous class survey

Chapter 6: CPU Scheduling

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

Chapter 5: CPU Scheduling

CS307: Operating Systems

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

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

CS370 Operating Systems

OPERATING SYSTEMS: Lesson 4: Process Scheduling

Subject Name: OPERATING SYSTEMS. Subject Code: 10EC65. Prepared By: Kala H S and Remya R. Department: ECE. Date:

Lecture 7: CVs & Scheduling

Scheduling in the Supermarket

Chapter 5: Process Scheduling

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

CSE 4/521 Introduction to Operating Systems

Process Scheduling Part 2

Transcription:

CSE120 Principles of Operating Systems Prof Yuanyuan (YY) Zhou Scheduling

Announcement l Homework 2 due on October 26th l Project 1 due on October 27th 2

Scheduling Overview l In discussing process management and synchronization, we talked about context switching among processes/threads on the ready queue l But we have glossed over the details of exactly which thread is chosen from the ready queue l Making this decision is called scheduling l In this lecture, we ll look at: The goals of scheduling Starvation Various well-known scheduling algorithms Standard Unix scheduling algorithm 3

Multiprogramming l In a multiprogramming system, we try to increase CPU utilization and job throughput by overlapping I/ O and CPU activities Doing this requires a combination of mechanisms and policy l We have covered the mechanisms Context switching, how and when it happens Process queues and process states l Now we ll look at the policies Which process (thread) to run, for how long, etc. l We ll refer to schedulable entities as jobs (standard usage) could be processes, threads, etc. 4

Scheduling l Deciding which process/thread should occupy the resource (CPU, disk, etc) (CPU) I want to play it Whose turn is it? Process 1 Process 2 Process 3 5

When does OS need to do schedule? l A new process starts l A running process exits l A running process is blocked l I/O interrupt (some processes will be ready) l Clock interrupt (every 10 milliseconds) 6

Preemptive vs. Non-preemptive l Non-preemptive scheduling: The running process keeps the CPU until it voluntarily gives up the CPU Running l process exits l switches to blocked state l 1and 4 only (no 3) l Preemptive scheduling: The running process can be interrupted and must release the CPU (can be forced to give up CPU) 3 Ready 4 1 Terminated Blocked 7

What are the scheduling objectives? l Anyone? CPU I want to play Whose turn is it? Process 1 Process 2 Process 3 8

Scheduling Objectives l l l l l l Fair (nobody cries) Priority (lady first) Efficiency (make best use of equipment) Encourage good behavior (good boy/girl) Support heavy loads (degrade gracefully) Adapt to different environments (interactive, real-time, multi-media) 9

Performance Criteria l l l l l l l Fairness Efficiency: keep resources as busy as possible Throughput: # of processes that completes in unit time Turnaround Time (also called elapse time) amount of time to execute a particular process from the time its entered Waiting Time amount of time process has been waiting in ready queue Response Time amount of time from when a request was first submitted until first response is produced. predictability and variance Meeting Deadlines: avoid losing data 10

Different Systems, Different Focuses l For all Fairness, policy enforcement, resource balance l Batch Systems Max throughput, min turnaround time, max CPU utilization l Interactive Systems Min Response time, best proportionality l Real-Time Systems predictability, meeting deadlines 11

Program Behaviors Considered in Scheduling l Is it I/O bound? Example? I/O I/O l Is it CPU bound? Example? compute I/O compute l Batch or interactive environment l Urgency l Priority l Frequency of page faults l Frequency of preemption l How much execution time it has already received l How much execution time it needs to complete 12

Single Processor Scheduling Algorithms l Batch systems First Come First Serve (FCFS) Short Job First l Interactive Systems Round Robin Priority Scheduling Multi Queue & Multi-level Feedback Shortest process time Guaranteed Scheduling Lottery Scheduling Fair Sharing Scheduling 13

First Come First Serve (FCFS) l Process that requests the CPU FIRST is allocated the CPU FIRST. Also called FIFO l Non-preemptive l Used in Batch Systems l Real life analogy: Fast food restaurant l Implementation: FIFO queues A new process enters the tail of the queue The schedule selects from the head of the queue. l Performance Metric: Average Waiting Time. l Given Parameters: Duration(in ms), Arrival Time and Order 14

FCFS Example Process Duration Order Arrival Time P1 24 1 0 P2 3 2 0 P3 4 3 0 The final schedule: 0 P1 (24) P2 (3) P3 (4) 24 27 P1 waiting time: 0 P2 waiting time: 24 P3 waiting time: 27 The average waiting time: (0+24+27)/3 = 17 15

Problems with FCFS l Non-preemptive l Not optimal AWT Average waiting time can be large if small jobs wait behind long ones l Solution? l You have a basket, but you re stuck behind someone with a full shopping cart at Von s. Express lane (12 items or less) 16

Shortest Job First (SJF) 17 l Schedule the job with the shortest elapse time(duration) first l Scheduling used in Batch Systems l Two types: Non-preemptive & Preemptive l Requirement: the elapse time needs to know in advance l Optimal if all the jobs are available simultaneously (provable). Gives the best possible AWT (average waiting time) l Real life analogy? Express lane in supermarket Shortest important task first --The 7 Habits of Highly Effective People

Non-preemptive SJF: Example Process Duration Order Arrival Time P1 6 1 0 P2 8 2 0 P3 7 3 0 P4 3 4 0 P4 (3) P1 (6) P3 (7) P2 (8) 0 3 9 16 24 18 P4 waiting time: 0 P1 waiting time: 3 P3 waiting time: 9 P2 waiting time: 16 The total time is: 24 The average waiting time (AWT): (0+3+9+16)/4 = 7

Comparing to FCFS Process Duration Order Arrival Time P1 6 1 0 P2 8 2 0 P3 7 3 0 P4 3 4 0 P1 (6) P2 (8) P3 (7) P4 (3) 19 0 6 P1 waiting time: 0 P2 waiting time: 6 P3 waiting time: 14 P4 waiting time: 21 14 21 The total time is the same (why?) The average waiting time (AWT): (0+6+14+21)/4 = 10.25 (comparing to 7) 24

SJF is not always optimal l Is SJF optimal if all the jobs are not available simultaneously? Process Duration Order Arrival Time P1 10 1 0 P2 2 2 2 P1 (10) P2 (2) 0 2 (p2 arrives) 10 12 P1 waiting time: 0 P2 waiting time: 8 The average waiting time (AWT): (0+8)/2 = 4 20

Preemptive SJF l Also called Shortest Remaining Time First Schedule the job with the shortest remaining time required to complete l Requirement: the elapse time needs to be known in advance 21

Preemptive SJF: Same Example Process Duration Order Arrival Time P1 10 1 0 P2 2 2 2 P1 (2) P2 (2) P1 (8) 0 2 4 12 P1 waiting time: 4-2 =2 P2 waiting time: 0 The average waiting time (AWT): (0+2)/2 = 1 22 No CPU waste!!!

A Problem with SJF l Starvation In some condition, a job is waiting for ever Example: SJF l Process A with elapse time of 1 hour arrives at time 0 l But every 1 minute, a short process with elapse time of 2 minutes arrive l Result of SJF: A never gets to run 23

Interactive Scheduling Algorithms 24 l Usually preemptive Time is sliced into quantum (time intervals) Scheduling decision is also made at the beginning of each quantum l Performance Criteria Min Response time best proportionality l Representative algorithms: Priority-based Round-robin Multi Queue & Multi-level Feedback Shortest process time Guaranteed Scheduling Lottery Scheduling Fair Sharing Scheduling

Priority Scheduling 25 l Each job is assigned a priority. l FCFS within each priority level. l Select highest priority job over lower ones. l Rational: higher priority jobs are more mission-critical Example: DVD movie player vs. send email l Real life analogy? Boarding at airports l Problems: May not give the best AWT indefinite blocking or starvation a process

Set Priority l Two approaches Static (for system with well known and regular application behaviors) Dynamic (otherwise) l Priority may be based on: Cost to user. Importance of user. Aging Percentage of CPU time used in last X hours. 26

Priority Scheduling: Example Process Duration Priority Arrival Time P1 6 4 0 P2 8 1 0 P3 7 3 0 P4 3 2 0 P2 (8) P4 (3) P3 (7) P1 (6) 0 8 11 18 24 27 P2 waiting time: 0 P4 waiting time: 8 P3 waiting time: 11 P1 waiting time: 18 The average waiting time (AWT): (0+8+11+18)/4 = 9.25 (worse than SJF)

Priority in Unix 28

Nobody wants to Be nice in Unix 29

priority priority More on Priority Scheduling l For real-time (predictable) systems, priority is often used to isolate a process from those with lower priority. Priority inversion is a risk unless all resources are jointly scheduled A solution: priority inheritance x->acquire() x->acquire() x->release() time x->acquire() How can this be avoided? x->acquire() 30 time

Round-robin l One of the oldest, simplest, most commonly used scheduling algorithm l Select process/thread from ready queue in a round-robin fashion (take turns) l Real life analogy? Problem: Do not consider priority Context switch overhead 31

Round-robin: Example Process Duration Order Arrival Time P1 3 1 0 P2 4 2 0 P3 3 3 0 Suppose time quantum is: 1 unit, P1, P2 & P3 never block P1 P2 P3 P1 P2 P3 P1 P2 P3 P2 0 P1 waiting time: 4 P2 waiting time: 6 P3 waiting time: 6 10 The average waiting time (AWT): (4+6+6)/3 = 5.33 32

l Time slice too large FIFO behavior Poor response time l Time slice too small Time Quantum Too many context switches (overheads) Inefficient CPU utilization l Heuristic: 70-80% of jobs block within timeslice l Typical time-slice 10 to 100 ms l Time spent in system depends on size of job. 33

Combining Algorithms l Scheduling algorithms can be combined Have multiple queues Use a different algorithm for each queue Move processes among queues l Example: Multiple-level feedback queues (MLFQ) Multiple queues representing different job types l Interactive, CPU-bound, batch, system, etc. Queues have priorities, jobs on same queue scheduled RR Jobs can move among queues based upon execution history l Feedback: Switch from interactive to CPU-bound behavior 34

Multi-level Feedback Algorithm: Example 35

Unix Scheduler l The canonical Unix scheduler uses a MLFQ 3-4 classes spanning ~170 priority levels (the higher the better) l Timesharing: first 60 priorities l System: next 40 priorities l Real-time: next 60 priorities l Interrupt: next 10 (Solaris) l Priority scheduling across queues, RR within a queue The process with the highest priority always runs Processes with the same priority are scheduled RR l Processes dynamically change priority Increases over time if process blocks before end of quantum Decreases over time if process uses entire quantum 36

Motivation of Unix Scheduler l The idea behind the Unix scheduler is to reward interactive processes over CPU hogs l Interactive processes (shell, editor, etc.) typically run using short CPU bursts They do not finish quantum before waiting for more input l Want to minimize response time Time from keystroke (putting process on ready queue) to executing keystroke handler (process running) Don t want editor to wait until CPU hog finishes quantum l This policy delays execution of CPU-bound jobs But that s ok 37

Scheduling Summary l Scheduler (dispatcher) is the module that gets invoked when a context switch needs to happen l Scheduling algorithm determines which process runs, where processes are placed on queues l Many potential goals of scheduling algorithms Utilization, throughput, wait time, response time, etc. l Various algorithms to meet these goals FCFS/FIFO, SJF, Priority, RR l Can combine algorithms Multiple-level feedback queues Unix example 38