Operating System Concepts Ch. 5: Scheduling

Similar documents
CPU Scheduling Algorithms

Properties of Processes

Chapter 5: CPU Scheduling

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

Chapter 6: CPU Scheduling

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

CS370 Operating Systems

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

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

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

COSC243 Part 2: Operating Systems

CS370 Operating Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

Chapter 5: CPU Scheduling

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

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

Chapter 6: CPU Scheduling

CHAPTER 2: PROCESS MANAGEMENT

CPU Scheduling: Objectives

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

CS370 Operating Systems

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

Chapter 5 CPU scheduling

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

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

Ch 4 : CPU scheduling

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

Last Class: Processes

CSE 4/521 Introduction to Operating Systems

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

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

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

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

CS370 Operating Systems

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

CSE 120 Principles of Operating Systems Spring 2017

Lecture 2 Process Management

LECTURE 3:CPU SCHEDULING

CPU scheduling. Alternating sequence of CPU and I/O bursts. P a g e 31

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

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Frequently asked questions from the previous class survey

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

Job Scheduling. CS170 Fall 2018

Unit 3 : Process Management

Chapter 5: CPU Scheduling

Chapter 5: Process Scheduling

CS3733: Operating Systems

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

A COMPARATIVE STUDY OF CPU SCHEDULING POLICIES IN OPERATING SYSTEMS

Scheduling of processes

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

Process- Concept &Process Scheduling OPERATING SYSTEMS

CS307: Operating Systems

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

Scheduling. The Basics

Operating Systems. Process scheduling. Thomas Ropars.

8th Slide Set Operating Systems

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

Operating Systems CS 323 Ms. Ines Abbes

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

Uniprocessor Scheduling

1.1 CPU I/O Burst Cycle

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.

Scheduling. Scheduling 1/51

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

Operating Systems Unit 3

Operating Systems. Scheduling

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

Chapter 5 Process Scheduling

Course Syllabus. Operating Systems

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Chapter 5: Process Scheduling

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

CSE 120 Principles of Operating Systems

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

Scheduling. Scheduling 1/51

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

Operating Systems ECE344. Ding Yuan

Advanced Operating Systems (CS 202) Scheduling (1)

Titolo presentazione. Scheduling. sottotitolo A.Y Milano, XX mese 20XX ACSO Tutoring MSc Eng. Michele Zanella

Practice Exercises 305

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)

Frequently asked questions from the previous class survey

Scheduling - Overview

Uniprocessor Scheduling. Aim of Scheduling

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

Start of Lecture: February 10, Chapter 6: Scheduling

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

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

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

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

OPERATING SYSTEMS: Lesson 4: Process Scheduling

TDDD82 Secure Mobile Systems Lecture 6: Quality of Service

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

SMD149 - Operating Systems

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)

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)

Transcription:

Operating System Concepts Ch. 5: Scheduling Silberschatz, Galvin & Gagne

Scheduling In a multi-programmed system, multiple processes may be loaded into memory at the same time. We need a procedure, or rather algorithm, to decide what process is assigned to the CPU. - This algorithm is the scheduling algorithm. - Various algorithms exist which tune for different criteria. Remember an OS serves as resource allocator; the CPU scheduler is the allocator for the CPU cycles resource.

Bursts The execution of a process can be seen as a sequence of alternating CPU and I/O bursts. In an I/O burst the process blocks waiting on I/O, it cannot make further progress until the I/O operation is completed. With multi-programming the CPU does not have to sit idle during I/O, we can assign another process to the CPU. - CPU utilization is maximized. Source: Silberschatz et al., Operating System Concepts, 9 th Edition

Process context switch Recall: the switch from one process to another is referred to as a context switch. Source: Silberschatz et al., Operating System Concepts, 9 th Edition

CPU burst time histogram When a CPU to I/O burst transition (system call involving blocking I/O) is encountered, we need to invoke the scheduler. The typical length of a CPU burst tells us how often scheduler invocations need to take place. Source: Silberschatz et al., Operating System Concepts, 9 th Edition

The CPU scheduler (short-term scheduler) Short bursts (< 8 ms) most frequent; we need a scheduler that is invoked (very) often and makes quick decisions. - This is the task of the short-term scheduler. - Typically a ready queue is maintained of processes that are ready to run (and don't block on e.g. I/O). - Any process from this queue may be assigned to the CPU. Which is chosen exactly depends on the scheduling algorithm that is in use.

The CPU scheduler (2) In the simple case, a scheduling decision is only made when: - A process terminates itself (exit() system call). - A process calls a blocking system call (transition running -> waiting), relinquishing the CPU. If the scheduler is only invoked in these cases, the scheduler is called non-preemptive. Non-preemptive systems are also known as cooperative systems. - The context switches that are triggered are voluntary. - Note that a malicious process may choose to never terminate itself or call a system call (infinite loop). - Only works if everybody plays by the rules. - Used in past systems, e.g. classic Mac OS (before Mac OS X).

The CPU scheduler (3) Now, it is clear there also is a category of schedulers known as preemptive schedulers. These additionally invoke the scheduler in these cases: - A process' state changes from waiting to ready, so no longer blocks and is put back in the run queue. Note that this may cause the currently running process to be interrupted and exchanged for another. - A process' state changes from running to ready, so it could have continued to run (no blockade) but its assignment of the CPU is revoked. Note that these additions concern involuntary context switches, or process preemptions.

The CPU scheduler (4) Our OS model of having a timer interrupt handler that periodically invokes the scheduler is dependent on preemptive scheduling. - Recall we could terminate infinite loop processes this way as a kernel always regain control of the system. Most modern OS kernels implement preemptive scheduling. This is not without problems however: - What if a process is involuntarily interrupted while manipulating shared data structures? - What if a process is involuntarily interrupted while manipulating (shared) kernel data structures from a system call? - This, and similar, problems need a solution when we want to enable preemptive scheduling.

The dispatcher The task of the CPU scheduler is clear: given a ready queue, give us the next process to run. Now another routine is necessary which replaces the currently running process with the next process to run. - This is the task of the dispatcher. - It handles, amongst others: State saving (register state) Switching context / address space Resuming next process at the right location and switch back to user mode. - The time required to perform this switch is referred to as the dispatch latency (and is pure overhead).

Scheduling Algorithms We are now ready to see some scheduling algorithms. An important question first: what to optimize for? Common scheduling criteria: - CPU utilization: maximize use of the CPU. - Throughput: maximize tasks that complete per time unit (e.g. requests or transactions per second). - Turnaround time: minimize time it takes to complete a process from start to finish. - Wait time: minimize time that processes spend waiting in queues. - Response time: minimize time between request submission (or device input) and first response of the system.

Scheduling Algorithms (2) We will now discuss a number of (simple) scheduling algorithms. - To keep things simple and manageable a single CPU burst (in milliseconds) per process is considered. - We optimize for average waiting time. - We chart the schedules using a Gantt chart. - The algorithms are non-preemptive unless otherwise noted.

FCFS: First-come First-Serve Process P1 24 P2 3 P3 3 Burst time Given is that all processes are present in the ready queue at time 0 in the order: P1, P2, P3. This results in the following Gantt chart: Compute waiting times for each process: P1 = 0; P2 = 24; P3 = 27. This gives as average waiting time (0+24+27)/3 = 17 Example taken from: Silberschatz et al., Operating System Concepts, 9 th Edition

FCFS: First-come First-Serve (2) Now, assume the processes are present in the ready queue at time 0 in a different order: P2, P3, P1. The schedule changes and we obtain a different Gantt chart: New average waiting time: (0+3+6)/3=3 - Much better result. We see here that the achieved performance of the algorithm depends on the order of the processes in the run queue. - Convoy effect: short processes waiting behind a long process. - For example consider a (long) CPU bound processes and many (interactive) I/O bound processes. Example taken from: Silberschatz et al., Operating System Concepts, 9 th Edition

SJF: Shortest Job First Process Burst time P1 6 P2 8 P3 7 P4 3 Idea: select the process with the shortest CPU burst. All processes present in the ready queue at time 0. Average waiting time: (3+16+9+0)/4 = 7 Example taken from: Silberschatz et al., Operating System Concepts, 9 th Edition

SJF: Shortest Job First (2) The good news: SJF is proven optimal! It results in the minimum average waiting time for any set of processes. Now the bad news: We usually don't know the length of the CPU burst beforehand. - Except in batch scheduling systems where you could ask the user. - Or if you design a system such that a prediction for the length of the CPU burst must be given when entering the ready queue: difficult!

SJF: Shortest Job First (3) A way out is to estimate the length and use these predictions to select the (predicted) shortest job. For instance, this can be achieved by recording the length of previous CPU bursts and using exponential averaging. 1. t n =actual length of n th CPU burst 2. τ n+1 = predicted value for the next CPU burst 3. α, 0 α 1 4. Define: τ n+1 =α t n +(1 α )τ n. Alpha is commonly set to 0.5.

SRTF: Shortest Remaining Time First SRTF is the preemptive version of SJF. We now also take the arrival times of processes into the ready queue into account. When a process arrives in the ready queue the scheduler is invoked. Process Arrival Time Burst time P1 0 8 P2 1 4 P3 2 9 P4 3 5 The following Gantt chart is obtained: Note the process preemption at time 1. Average waiting time: ((10-1)+(1-1)+(17-2)+5-3))/4 = 26/4 = 6.5 Example taken from: Silberschatz et al., Operating System Concepts, 9 th Edition

Priority Scheduling In fact, SJF and STRF are instances of a priority scheduling algorithm. In a priority scheduling algorithm, a priority must be computed for each process. The process with the highest priority is scheduled first. - The priority is often an integer number. - For SJF the priority is the inverse of the predicted duration of the next CPU burst. Priority scheduling algorithms suffer from starvation. Low priority processes may never execute. - A solution is to implement aging, in which the priority of a process is gradually increased as it ages (spends more time waiting).

Priority Scheduling (2) Process Priority Burst time P1 3 10 P2 1 1 P3 4 2 P4 5 1 P5 2 5 Average waiting time: (0+1+6+16+18)/5 = 8.2 Example taken from: Silberschatz et al., Operating System Concepts, 9 th Edition

RR: Round Robin A preemptive scheduling algorithm devised for interactive systems is Round Robin scheduling. Idea: give each process a small time slice (or time quantum). If the process still runs when the time quantum expires, it is preempted and put at the end of the ready queue. - (Otherwise the process performed a blocking system call within its time quantum causing it to be replaced). Time quantum length typically 10 100 milliseconds. - 1o ms: compare with histogram of CPU bursts.

RR: Round Robin (2) Given n processes in the ready queue with time quantum is q, then each process gets 1/n of the CPU time in slices of (at most) q time units. Because processes rotate, no process waits longer than (n-1)q time units for its turn. How are the processes interrupted? We need to program the timer interrupt for this. The timer interrupt handler must call a function which checks whether the time quantum of the currently running process has expired.

RR: Round Robin (3) Process P1 24 P2 3 P3 3 Burst time We apply Round Robin scheduling with a time quantum of 4. All processes are in the ready queue at time 0. Average waiting time: ((0+(10-4))+4+7)/3 = 5 2/3 Higher average waiting time than SJF. This is typical and to be expected. However, for RR response time is the optimization objective. Example taken from: Silberschatz et al., Operating System Concepts, 9 th Edition

RR: Round Robin (4) Tuning the time quantum is important. - Large quantum: many processes may run until their next voluntary context switch, so the scheduler behaves like a FIFO. - Small quantum: processes are always preempted and many more context switches are required to get the work done. Recall that context switches are pure overhead. Naturally, time quantum should be larger than the context switch time. Source: Silberschatz et al., Operating System Concepts, 9 th Edition

Continue with the slides provided by the textbook, Chapter 6 (CPU Scheduling), starting at topic Multilevel Queue : http://codex.cs.yale.edu/avi/os-book/os9/slide-dir/index.html

End of Chapter 5.