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

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

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

CPU Scheduling Algorithms

Properties of Processes

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

CPU Scheduling: Objectives

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

CS370 Operating Systems

CS370 Operating Systems

Chapter 5: CPU Scheduling

Chapter 6: CPU Scheduling

Chapter 5: CPU Scheduling

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

CS307: Operating Systems

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

Chapter 6: CPU Scheduling

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

Chapter 6: CPU Scheduling

LECTURE 3:CPU SCHEDULING

Operating Systems CS 323 Ms. Ines Abbes

Chapter 5 CPU scheduling

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

Chapter 5: Process Scheduling

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

CSE 4/521 Introduction to Operating Systems

Chapter 5: Process Scheduling

Chapter 5: CPU Scheduling

Practice Exercises 305

CS370 Operating Systems

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

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

Operating System Concepts Ch. 5: Scheduling

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Chapter 6: CPU Scheduling

Chapter 5 Process Scheduling

CS370 Operating Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

CHAPTER 2: PROCESS MANAGEMENT

TDIU25: Operating Systems II. Processes, Threads and Scheduling

CS370 Operating Systems

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

Course Syllabus. Operating Systems

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

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

Job Scheduling. CS170 Fall 2018

Ch 4 : CPU scheduling

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

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

COSC243 Part 2: Operating Systems

CS3733: Operating Systems

So far. Next: scheduling next process from Wait to Run. 1/31/08 CSE 30341: Operating Systems Principles

Round Robin (RR) ACSC 271 Operating Systems. RR Example. RR Scheduling. Lecture 9: Scheduling Algorithms

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

Lecture 2 Process Management

Scheduling of processes

Last Class: Processes

Chapter 5 Scheduling

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

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

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

Operating Systems. Scheduling

Operating Systems Unit 3

Process- Concept &Process Scheduling OPERATING SYSTEMS

Scheduling. Today. Next Time Process interaction & communication

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

Scheduling. Scheduling 1/51

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

by Maria Lima Term Paper for Professor Barrymore Warren Mercy College Division of Mathematics and Computer Information Science

Scheduling in the Supermarket

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

Chapter 19: Real-Time Systems. Operating System Concepts 8 th Edition,

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

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.

1.1 CPU I/O Burst Cycle

CPU Scheduling: Part I ( 5, SGG) Operating Systems. Autumn CS4023

Scheduling. Scheduling 1/51

Operating Systems. Process scheduling. Thomas Ropars.

Scheduling. The Basics

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

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

Operating Systems ECE344. Ding Yuan

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Frequently asked questions from the previous class survey

Uniprocessor Scheduling. Aim of Scheduling

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

Chapter 9. Uniprocessor Scheduling

Frequently asked questions from the previous class survey

Start of Lecture: February 10, Chapter 6: Scheduling

Recap. Run to completion in order of arrival Pros: simple, low overhead, good for batch jobs Cons: short jobs can stuck behind the long ones

Unit 3 : Process Management

TDDD82 Secure Mobile Systems Lecture 6: Quality of Service

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait

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

Chapter 9 Uniprocessor Scheduling

A COMPARATIVE STUDY OF CPU SCHEDULING POLICIES IN OPERATING SYSTEMS

OS Assignment II. The process of executing multiple threads simultaneously is known as multithreading.

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Transcription:

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

Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait CPU burst followed by I/O burst CPU burst distribution is of main concern load store add store read from file wait for I/O store increment index write to file wait for I/O load store add store read from file CPU burst I/O burst CPU burst I/O burst CPU burst wait for I/O I/O burst Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 2

Histogram of CPU-burst Times Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 3

Scheduling Criteria CPU utilization keep the CPU as busy as possible Throughput # of processes that complete their execution per time unit Turnaround time amount of time to execute a particular process Waiting time amount of time a process has been waiting in the ready queue Response time amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 4

First- Come, First-Served (FCFS) Scheduling Process Burst Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: P P P 1 2 3 0 24 27 30 Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 5

Determining Length of Next CPU Burst Can only estimate the length should be similar to the previous one Then pick process with shortest predicted next CPU burst Can be done by using the length of previous CPU bursts, using exponential averaging 1. 2. t n = actual length of n τ n+ 1 3. α, 0 α 1 4. Define : th CPU burst = predicted value for the next CPU burst ( 1 α ). τ = α t + τ n= 1 n n Commonly, α set to ½ Preemptive version called shortest-remaining-timefirst Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 6

Prediction of the Length of the Next CPU Burst 12 τ i 10 8 t i 6 4 2 time CPU burst (t i ) 6 4 6 4 13 13 13 "guess" (τ i ) 10 8 6 6 5 9 11 12 Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 7

Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority) Preemptive Nonpreemptive SJF is priority scheduling where priority is the inverse of predicted next CPU burst time Problem Starvation low priority processes may never execute Solution Aging as time progresses increase the priority of the process Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 8

Round Robin (RR) Each process gets a small unit of CPU time (time quantum q), usually 4-10 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 9

Multilevel Queue Ready queue is partitioned into separate queues, eg: foreground (interactive) background (batch) Process permanently in a given queue Each queue has its own scheduling algorithm: foreground RR background FCFS Scheduling must be done between the queues: Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. Time slice each queue gets a certain amount of CPU time which it can schedule amongst its processes; 80% to foreground in RR 20% to background in FCFS Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 10

Multilevel Feedback Queue (by example) Three queues: Q 0 RR; quantum 8 milliseconds Q 1 RR; quantum 16 milliseconds Q 2 FCFS Scheduling A new job enters queue Q 0 When it gains CPU, job receives 8 milliseconds If it does not finish in 8 milliseconds, job is moved to queue Q 1 At Q 1 job receives 16 additional milliseconds If it still does not complete, it is preempted and moved to queue Q 2 Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 11

NUMA Multiple-Processor Scheduling CPU CPU fast access slow access fast access memory memory computer Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 12

Multiple-Processor Scheduling Symmetric multiprocessing (SMP) each processor is self-scheduling, all processes in common ready queue, or each has its own private queue of ready processes Currently, most common Processor affinity process has affinity for processor on which it is currently running soft affinity hard affinity Load balancing Contradicts affinity? Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 13

Multithreaded Multicore System Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 14

Real-Time CPU Scheduling Conflict event phase of dispatch latency: response to event 1. Preemption of any process response running interval in kernel mode process made 2. Release interrupt by low-priority available process of resources needed by high-priority processingprocesses dispatch latency real-time process execution conflicts dispatch time Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 15

Rate Montonic Scheduling A priority is assigned based on the inverse of its period Shorter periods = higher priority; Longer periods = lower priority P 1 is assigned a higher priority than P 2. Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 16

Earliest Deadline First Scheduling (EDF) Priorities are assigned according to deadlines: the earlier the deadline, the higher the priority Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 17

Operating System Examples Linux scheduling Windows scheduling Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 18

Linux Scheduling in Version 2.6.23 + Scheduling classes default: Completely Fair Scheduler (CFS) real-time scheduling class (highest priority tasks) CFS Quantum based on proportion of CPU time per-task virtual run time in variable vruntime vruntime += t, t is the amount of time it ran Choose the task with the lowest vruntime Normal default priority è virtual run time = actual run time decay factor based on priority of task lower priority is higher decay rate ( bonus ) To decide next task to run, scheduler picks task with lowest virtual run time Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 19

(Red-Black) Binary Search Tree, not queue CFS Performance Insert finishing process into queue (n log n) Pointer the lowest: faster RB tree is self-balancing Vruntime calculated based on nice value from -20 to +19 Lower value is higher priority; nice is static value What happens to I/O bound processes? Initialization value? vruntime = min_vruntime Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 20

User Mode Scheduling Windows 7 added user-mode scheduling (UMS) Applications create and manage threads independent of kernel For large number of threads, much more efficient UMS schedulers come from programming language libraries like C++ Concurrent Runtime (ConcRT) framework Linux has P-threads (and other thread packages) What happens when one thread blocks? Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 21

Algorithm Evaluation How to select CPU-scheduling algorithm for an OS? Deterministic Proofs queuing models simulation implementation Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 22

Deterministic Evaluation Group activity: calculate minimum average waiting time FCFS non-preemptive SJF RR with quantum=10 Multilevel Feedback Queue (q0: 8; q1: 16; q2: FCFS) Simple and fast, but requires exact numbers for input, applies only to those inputs Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 23

FCFS is 28ms: Non-preemptive SJF is 13ms: RR is 23ms: FCFS is 28ms: Non-preemptive SJF is 13ms: RR is 23ms: Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 24

Proofs Mathematical functions that you want to optimize Metrics: response time, average response time, maximum response time, throughput, Optimize: minimize, maximize, Assumptions: very important; realistic? Eg, all jobs available at time t=0 Example: prove that SJF is optimal with respect to minimizing average response time Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 25

Queueing Models Describes the arrival of processes, and CPU and I/O bursts probabilistically Commonly exponential, and described by mean Computes average throughput, utilization, waiting time, etc Computer system described as network of servers, each with queue of waiting processes Knowing arrival rates and service rates Computes utilization, average queue length, average wait time, etc Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 26

Little s Formula n = average queue length W = average waiting time in queue λ = average arrival rate into queue Little s law in steady state, processes leaving queue must equal processes arriving, thus: n = λ x W Valid for any scheduling algorithm and arrival distribution For example, if on average 7 processes arrive per second, and normally 14 processes in queue, then average wait time per process = 2 seconds Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 27

Simulations Queueing models limited Simulations more accurate Programmed model of computer system Clock is a variable Gather statistics indicating algorithm performance Data to drive simulation gathered via Random number generator according to probabilities Distributions defined mathematically or empirically Trace tapes record sequences of real events in real systems Event-driven or Time-Driven simulations Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 28

Implementation Even simulations have limited accuracy Just implement new scheduler and test in real systems High cost, high risk Environments vary Most flexible schedulers can be modified per-site or per-system Or APIs to modify priorities But (again) environments vary and can be modified does not mean it s easy J Spring 2018 CS/COE 1550 Operating Systems Sherif Khattab 29