Chapter 5: CPU Scheduling

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

CPU Scheduling Algorithms

Properties of Processes

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

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

Chapter 6: CPU Scheduling

CS370 Operating Systems

Ch 4 : CPU scheduling

LECTURE 3:CPU SCHEDULING

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

CS370 Operating Systems

Chapter 5 CPU scheduling

Chapter 6: CPU Scheduling

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

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

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

CHAPTER 2: PROCESS MANAGEMENT

Chapter 5: CPU Scheduling

CPU Scheduling: Objectives

Chapter 5: CPU Scheduling

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

Operating System Concepts Ch. 5: Scheduling

CS307: Operating Systems

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

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

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

Lecture 2 Process Management

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

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

CSE 4/521 Introduction to Operating Systems

Operating Systems CS 323 Ms. Ines Abbes

CS3733: Operating Systems

CS370 Operating Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

COSC243 Part 2: Operating Systems

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

Scheduling of processes

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Last Class: Processes

CS370 Operating Systems

1.1 CPU I/O Burst Cycle

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

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

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

Chapter 5: Process Scheduling

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

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

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

Course Syllabus. Operating Systems

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

Operating Systems Unit 3

Process- Concept &Process Scheduling OPERATING SYSTEMS

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

Job Scheduling. CS170 Fall 2018

Scheduling. The Basics

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

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.

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

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

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

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

Uniprocessor Scheduling. Aim of Scheduling

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

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

Unit 3 : Process Management

8: Scheduling. Scheduling. Mark Handley

Chapter 9 Uniprocessor Scheduling

A COMPARATIVE STUDY OF CPU SCHEDULING POLICIES IN OPERATING SYSTEMS

Chapter 9. Uniprocessor Scheduling

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

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

Chapter 5 Process Scheduling

Operating Systems. Scheduling

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

Chapter 5: Process Scheduling

Start of Lecture: February 10, Chapter 6: Scheduling

Operating Systems ECE344. Ding Yuan

Uniprocessor Scheduling

Uniprocessor Scheduling. Chapter 9

Practice Exercises 305

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

CSE 120 Principles of Operating Systems Spring 2017

Frequently asked questions from the previous class survey

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

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

Process Scheduling. Copyright : University of Illinois CS 241 Staff

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

Chapter 6: CPU Scheduling

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

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

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)

Operating Systems. Figure: Process States. 1 P a g e

Advanced Operating Systems (CS 202) Scheduling (1)

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)

Chapter 6: CPU Scheduling

Chapter 5 Scheduling

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

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

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

CSL373: Lecture 6 CPU Scheduling

Transcription:

Chapter 5: CPU Scheduling

Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm Evaluation Chapter 5: CPU Scheduling

Basic Concepts The CPU is one of the primary computer resources, its scheduling is central to operating-system design. In a single-processor system: only one process can run at a time; any others must wait until the CPU is free and can be rescheduled. Maximum CPU utilization obtained with multiprogramming A process is executed until it must wait, typically for the completion of some I/O request. Several processes are kept in memory at one time. When one process has to wait, the operating system takes the CPU away from that process and gives the CPU to another process. This pattern continues. Every time one process has to wait, another process can take over use of the CPU.

Process execution consists of a cycle of CPU execution and I/O wait. Processes alternate between these two states. Process execution begins with a CPU burst, followed by an I/O burst, which is followed by another CPU burst, then another I/O burst, and so on. The final CPU burst ends with a system request to terminate execution. The durations of CPU bursts have been measured. An I/O-bound program typically has many short CPU bursts. A CPU-bound program might have a few long CPU bursts. CPU I/O Burst Cycle

CPU Scheduler Selects from among the processes in ready queue, and allocates the CPU to one of them Queue may be ordered in various ways CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state (the result of an I/O request or an invocation of wait for the termination of one of the child processes (non preemptive scheduling ) 2. Switches from running to ready state (an Interrupt occurs) (preemptive scheduling ) 3. Switches from waiting to ready (I/O Terminates)(preemptive scheduling ) 4. Terminates(non preemptive scheduling ) Under non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU, either by terminating or by switching to the waiting state. All other scheduling is preemptive Consider access to shared data Consider preemption while in kernel mode Consider interrupts occurring during crucial OS activities

Dispatcher Dispatcher module gives control of the CPU to the process selected by the shortterm scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency time it takes for the dispatcher to stop one process and start another running

Scheduling Criteria Many criteria have been suggested for comparing CPU-scheduling algorithms. CPU utilization: keep the CPU as busy as possible ( rang from 0% to 100%). Throughput: # of processes that complete their execution per time unit Turnaround time: amount of time to execute a particular process (Turnaround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O). Waiting time amount of time a process has been waiting in the ready queue (the sum of the periods spent 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) Scheduling Requirements: Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time

Scheduling Algorithms 1. First-Come, First-Served Scheduling (FCFS) The process that requests the CPU first is allocated the CPU first. Can be Implemented using a FIFO queue. When a process enters the ready queue, its PCB is placed on the tail of the queue. CPU is allocated to the process at the head of the queue. The running process is then removed from the queue. The code for FCFS scheduling is simple to write and understand. Disadvantages: The average waiting time is often quite long. There is a convoy effect as all the other processes wait for the one big process to get off the CPU. This effect results in lower CPU and device utilization than might be possible if the shorter processes were allowed to go first.

Scheduling Algorithms 1. First-Come, First-Served Scheduling (FCFS)

Scheduling Algorithms 2. Shortest Job First (SJF) Associate with each process the length of its next CPU burst Use these lengths to schedule the process with the shortest time SJF is optimal gives minimum average waiting time for a given set of processes The difficulty is knowing the length of the next CPU request Could ask the user Disadvantage: How to know the length of the next CPU request. For long-term (job) scheduling in a batch system, we can use as the length the process time limit that a user specifies when he submits the job. Users must estimate the process time limit accurately, since a lower value may mean faster response. SJF scheduling is used frequently in long-term scheduling.

Determining Length of Next CPU Burst We may not know the length of the next CPU burst, but we may be able to predict its value. the next CPU burst will be similar in length to the previous ones. Computing an approximation of the length of the next CPU burst, we can pick the process with the shortest predicted CPU burst. an exponential average of the measured lengths of previous CPU bursts. Let t n be the length of the n th CPU burst, and let n+1 be our predicted value for the next CPU burst. Then, for, 0 1, define

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

Example of Shortest-remaining-time-first

Priority Scheduling A priority number (integer) is associated with each process Equal Priorities are served using FCFS algorithm The CPU is allocated to the process with the highest priority (smallest integer) SJF is priority scheduling, 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 [P1(6)+P2(0)+P3(16)+P4(18)+P5(1)]/5=41/5=8.2

Round Robin (RR) Each process gets a small unit of CPU time (time quantum q), usually 10-100ms. 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. Timer interrupts every quantum to schedule next process Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high

Time Quantum and Context Switch Time 80% of CPU bursts should be shorter than q Turnaround Time Varies With The Time Quantum

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; i.e., 80% to foreground in RR 20% to background in FCFS

Multilevel Queue Scheduling

Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service

Example of Multilevel Feedback Queue Three queues: Q 0 RR with time quantum 8 milliseconds Q 1 RR time quantum 16 milliseconds Q 2 FCFS Scheduling A new job enters queue Q 0 which is served FCFS 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 is again served FCFS and receives 16 additional milliseconds If it still does not complete, it is preempted and moved to queue Q 2