CSE 421/521 - Operating Systems Fall Lecture - VII CPU Scheduling - II. University at Buffalo

Similar documents
CPU Scheduling Algorithms

Operating System Concepts Ch. 5: Scheduling

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - VII CPU Scheduling - II. Louisiana State University

Roadmap. Multilevel Queue Scheduling. Multilevel Queue. Example of Multilevel Feedback Queue. Multilevel Feedback Queue. Tevfik Ko!

Chapter 6: CPU Scheduling

Properties of Processes

Chapter 5: CPU Scheduling

Virtual Memory - I. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XV. University at Buffalo.

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

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo.

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

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

Chapter 6: CPU Scheduling

Virtual Memory - I. Roadmap. Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

COSC243 Part 2: Operating Systems

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

Chapter 5 CPU scheduling

CS 140. Lab 1 - Threads

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

1.1 CPU I/O Burst Cycle

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

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

Midterm Exam. October 20th, Thursday NSC

CS370 Operating Systems

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

CSE 421/521 - Operating Systems Fall Lecture - XII Main Memory Management. Tevfik Koşar. University at Buffalo. October 18 th, 2012.

CS370 Operating Systems

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

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

Chapter 5: CPU Scheduling

Last Class: Processes

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XI Deadlocks - II. University at Buffalo. Deadlocks. October 6 th, 2011

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

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

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

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

CS307: Operating Systems

Job Scheduling. CS170 Fall 2018

CS370 Operating Systems

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

Operating Systems. Process scheduling. Thomas Ropars.

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

CS370 Operating Systems

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 5: CPU Scheduling

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Frequently asked questions from the previous class survey

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

CPU Scheduling: Objectives

CSE 4/521 Introduction to Operating Systems

Chapter 5: Process Scheduling

! The Process Control Block (PCB) " is included in the context,

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)

LECTURE 3:CPU SCHEDULING

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

Operating Systems CS 323 Ms. Ines Abbes

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

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Distributed Systems - II

Roadmap. Deadlock Prevention. Deadlock Prevention (Cont.) Deadlock Detection. Exercise. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

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

Frequently asked questions from the previous class survey

Start of Lecture: February 10, Chapter 6: Scheduling

Chapter 5 Process Scheduling

CS3733: Operating Systems

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

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)

OS Design Approaches. Roadmap. OS Design Approaches. Tevfik Koşar. Operating System Design and Implementation

King Saud University. College of Computer & Information Sciences. Information Technology Department. IT425: Operating Systems.

Chapter 5: Process Scheduling

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - X Deadlocks - II. Louisiana State University. Deadlocks

Process Synchronization - I

CSC 716 Advanced Operating System Fall 2007 Exam 1. Answer all the questions. The maximum credit for each question is as shown.

CSE 120 Principles of Operating Systems Spring 2017

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

Operating Systems. Scheduling

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

Operating Systems ECE344. Ding Yuan

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

Scheduling. Today. Next Time Process interaction & communication

CS630 Operating System Design, First Exam, Spring 2017,

FCM 710: Architecture of Secure Operating Systems

Advanced Operating Systems (CS 202) Scheduling (1)

8: Scheduling. Scheduling. Mark Handley

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

Chapter 6: CPU Scheduling

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

Starting the Threads

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

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - II OS Structures. University at Buffalo. OS Design and Implementation

Chapter 6: CPU Scheduling

OS Design Approaches. Roadmap. System Calls. Tevfik Koşar. Operating System Design and Implementation. CSE 421/521 - Operating Systems Fall 2013

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

Interactive Scheduling

Two Level Scheduling. Interactive Scheduling. Our Earlier Example. Round Robin Scheduling. Round Robin Schedule. Round Robin Schedule

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

CSL373: Lecture 6 CPU Scheduling

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

Transcription:

CSE 421/521 - Operating Systems Fall 2014 Lecture - VII CPU Scheduling - II Tevfik Koşar University at Buffalo September 16 th, 2014 1

Roadmap CPU Scheduling Comparison of CPU Scheduling Algorithms Estimating CPU bursts 4.4BSD SCheduler 2

Comparison of Scheduling Algorithms 3

FCFS PROS: It is a fair algorithm schedule in the order that they arrive CONS: Average response time can be lousy small requests wait behind big ones (convoy effect) May lead to poor utilization of other resources FCFS may result in poor overlap of CPU and I/O activity E.g., a CPU-intensive job prevents an I/O-intensive job from doing a small bit of computation, thus preventing it from going back and keeping the I/O subsystem busy 4

SJF PROS: Provably optimal with respect to average waiting time prevents convoy effect (long delay of short jobs) CONS: Can cause starvation of long jobs Requires advanced knowledge of CPU burst times this can be very hard to predict accurately! 5

Priority Scheduling PROS: Guarantees early completion of high priority jobs CONS: Can cause starvation of low priority jobs How to decide/assign priority numbers? 6

Round Robin PROS: Great for timesharing no starvation Does not require prior knowledge of CPU burst times Generally reduces average response time CONS: What if all jobs are almost time same length? Increases the turnaround time How to set the best time quantum? if small, then context switch often, incurring high overhead if large, then response time degrades 7

How to estimate CPU burst time? 8

Determining Length of Next CPU Burst Can only estimate the length Can be done by using the length of previous CPU bursts, using exponential averaging + 9

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 10

Prediction of the Length of the Next CPU Burst Alpha = 1/2, T0 = 10 11

Exercise 12

4.4 BSD Scheduler 13

4.4BSD Priority Based Scheduling 4.4BSD scheduler has 64 priorities and thus 64 ready queues, numbered 0 (PRI_MIN) through 63 (PRI_MAX). 63 0 14

Calculating Priority NOTE: Lower numbers correspond to lower priorities in 4.4BSD, so that priority 0 is the lowest priority and priority 63 is the highest. priority = PRI_MAX - (recent_cpu / 4) - (nice * 2) (rounded down to the nearest integer) It gives a thread that has received CPU time recently lower priority for being reassigned the CPU the next time the scheduler runs. 15

Nice Value ==> how \nice" the thread should be to other threads. A nice of zero does not affect thread priority. A positive nice, to the maximum of 20, decreases the priority of a thread and causes it to give up some CPU time it would otherwise receive. A negative nice, to the minimum of -20, tends to take away CPU time from other threads. 16

Calculating recent_cpu An array of n elements to track the CPU time received in each of the last n seconds requires O(n) space per thread and O(n) time per calculation of a new weighted average. Instead, we use a exponentially weighted moving average: recent_cpu(0) = 0 // or parent thread s value at each timer interrupt, recent_cpu++ for the running thread. and once per second, for each thread: recent_cpu(t) = a * recent_cpu(t-1) + nice where, a = (2*load_avg)/(2*load_avg + 1) 17

Calculating load_avg Estimates the average number of threads ready to run over the past minute. Like recent_cpu, it is an exponentially weighted moving average. Unlike priority and recent_cpu, load_avg is system-wide, not thread-specific. At system boot, it is initialized to 0. Once per second thereafter, it is updated according to the following formula: load_avg(t) = (59/60)*load_avg(t-1) + (1/60)*ready_threads 18

Functions to implement Skeletons of these functions are provided in threads/threads.c : int thread_get_nice (void) void thread_set_nice (int new_nice) void thread_set_priority (int new_priority) int thread_get_priority (void) int thread_get_recent_cpu (void) int thread_get_load_avg (void) 19

Exercise Draw gantt charts, find average turnaround, waiting, and response times for above processes, considering: 1) First Come First Served Scheduling 2) Shortest Job First Scheduling (non-preemptive) 3) Shortest Job First Scheduling (preemptive) 4) Round-Robin Scheduling 5) Priority Scheduling (non-preemptive) 6) Priority Scheduling (preemptive) 20

Summary CPU Scheduling Comparison of CPU Scheduling Algorithms Estimating CPU bursts 4.4BSD SCheduler Hmm.. Next Lecture: Synchronization 21

Acknowledgements Operating Systems Concepts book and supplementary material by A. Silberschatz, P. Galvin and G. Gagne Operating Systems: Internals and Design Principles book and supplementary material by W. Stallings Modern Operating Systems book and supplementary material by A. Tanenbaum R. Doursat and M. Yuksel from UNR, Ed Lazowska from UWashington 22