Chapter 5: CPU Scheduling. Operating System Concepts 7 th Edition, Jan 14, 2005

Similar documents
Objectives. Chapter 5: Process Scheduling. Chapter 5: Process Scheduling. 5.1 Basic Concepts. To introduce CPU scheduling

Objectives. Chapter 5: CPU Scheduling. CPU Scheduler. Non-preemptive and preemptive. Dispatcher. Alternating Sequence of CPU And I/O Bursts

Chapter 5 Process Scheduling

CPU Scheduling. Basic Concepts. Basic Concepts (2) Basic Concepts Scheduling Criteria Scheduling Algorithms Batch systems Interactive systems

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

CPU Scheduling. CPU Scheduling

CPU Scheduling Outline

CPU Scheduling. Core Definitions

Announcements. Basic Concepts. Histogram of Typical CPU- Burst Times. Dispatcher. CPU Scheduler. Burst Cycle. Reading

2. is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput

ICS Principles of Operating Systems

Scheduling. Scheduling. Scheduling levels. Decision to switch the running process can take place under the following circumstances:

W4118 Operating Systems. Instructor: Junfeng Yang

Comp 204: Computer Systems and Their Implementation. Lecture 12: Scheduling Algorithms cont d

Operating System: Scheduling

/ Operating Systems I. Process Scheduling. Warren R. Carithers Rob Duncan

Deciding which process to run. (Deciding which thread to run) Deciding how long the chosen process can run

OPERATING SYSTEMS SCHEDULING

CPU Scheduling. CSC 256/456 - Operating Systems Fall TA: Mohammad Hedayati

Process Scheduling CS 241. February 24, Copyright University of Illinois CS 241 Staff

Main Points. Scheduling policy: what to do next, when there are multiple threads ready to run. Definitions. Uniprocessor policies

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

Introduction. Scheduling. Types of scheduling. The basics

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

Operating Systems. III. Scheduling.

Processor Scheduling. Queues Recall OS maintains various queues

Scheduling. Yücel Saygın. These slides are based on your text book and on the slides prepared by Andrew S. Tanenbaum

PROCESS SCHEDULING ALGORITHMS: A REVIEW

Job Scheduling Model

OS OBJECTIVE QUESTIONS

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Real-Time Scheduling 1 / 39

Operating Systems, 6 th ed. Test Bank Chapter 7

A Group based Time Quantum Round Robin Algorithm using Min-Max Spread Measure

Process Scheduling. Process Scheduler. Chapter 7. Context Switch. Scheduler. Selection Strategies

A Comparative Study of CPU Scheduling Algorithms

Analysis and Comparison of CPU Scheduling Algorithms

CPU Scheduling. Multitasking operating systems come in two flavours: cooperative multitasking and preemptive multitasking.

Scheduling 0 : Levels. High level scheduling: Medium level scheduling: Low level scheduling

W4118 Operating Systems. Instructor: Junfeng Yang

A Review on Load Balancing In Cloud Computing 1

Operating Systems Lecture #6: Process Management

Scheduling Algorithms

Operating Systems Concepts: Chapter 7: Scheduling Strategies

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

EECS 750: Advanced Operating Systems. 01/28 /2015 Heechul Yun

Operating System Tutorial

CPU Scheduling 101. The CPU scheduler makes a sequence of moves that determines the interleaving of threads.

This tutorial will take you through step by step approach while learning Operating System concepts.

REDUCING TIME: SCHEDULING JOB. Nisha Yadav, Nikita Chhillar, Neha jaiswal

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

Chapter 19: Real-Time Systems. Overview of Real-Time Systems. Objectives. System Characteristics. Features of Real-Time Systems

Linux Process Scheduling Policy

Lecture Outline Overview of real-time scheduling algorithms Outline relative strengths, weaknesses

Real-Time Scheduling (Part 1) (Working Draft) Real-Time System Example

Chapter 2: OS Overview

Final Report. Cluster Scheduling. Submitted by: Priti Lohani

A Priority based Round Robin CPU Scheduling Algorithm for Real Time Systems

Konzepte von Betriebssystem-Komponenten. Linux Scheduler. Valderine Kom Kenmegne Proseminar KVBK Linux Scheduler Valderine Kom

Linux O(1) CPU Scheduler. Amit Gud amit (dot) gud (at) veritas (dot) com

Scheduling. Monday, November 22, 2004

Linux scheduler history. We will be talking about the O(1) scheduler

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

Performance Comparison of RTOS

Overview of Presentation. (Greek to English dictionary) Different systems have different goals. What should CPU scheduling optimize?

A LECTURE NOTE ON CSC 322 OPERATING SYSTEM I DR. S. A. SODIYA

Types Of Operating Systems

Chapter 5 Linux Load Balancing Mechanisms

Syllabus MCA-404 Operating System - II

CS Fall 2008 Homework 2 Solution Due September 23, 11:59PM

Readings for this topic: Silberschatz/Galvin/Gagne Chapter 5

Web Server Software Architectures

Chapter 1: Introduction. What is an Operating System?

Real-Time Software. Basic Scheduling and Response-Time Analysis. René Rydhof Hansen. 21. september 2010

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Advanced topics: reentrant function

Multilevel Load Balancing in NUMA Computers

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

4. Fixed-Priority Scheduling

Convenience: An OS makes a computer more convenient to use. Efficiency: An OS allows the computer system resources to be used in an efficient manner.

Load Balancing Scheduling with Shortest Load First

Multi-core architectures. Jernej Barbic , Spring 2007 May 3, 2007

Task Scheduling for Multicore Embedded Devices

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

Process Scheduling II

Lecture 3 Theoretical Foundations of RTOS

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

Operating Systems. Rafael Ramirez (T, S)

Efficiency of Batch Operating Systems

Linux Block I/O Scheduling. Aaron Carroll December 22, 2007

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 1 8 Essay Question Review

Linux Process Scheduling. sched.c. schedule() scheduler_tick() hooks. try_to_wake_up() ... CFS CPU 0 CPU 1 CPU 2 CPU 3

Design and performance evaluation of Advanced Priority Based Dynamic Round Robin Scheduling Algorithm (APBDRR)

How To Understand And Understand An Operating System In C Programming

Operating Systems 4 th Class

Chapter 1 13 Essay Question Review

CHAPTER 15: Operating Systems: An Overview

Scheduling policy. ULK3e 7.1. Operating Systems: Scheduling in Linux p. 1

Comparison between scheduling algorithms in RTLinux and VxWorks

Transcription:

Chapter 5: CPU Scheduling Operating System Concepts 7 th Edition, Jan 14, 2005 Silberschatz, Galvin and Gagne 2005

Outline Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Thread Scheduling Operating Systems Examples Java Thread Scheduling Algorithm Evaluation

Basic Concepts Operating System Concepts 7 th Edition, Jan 14, 2005 Silberschatz, Galvin and Gagne 2005

Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU scheduling is the basis of multiprogramming Key to the success of CPU scheduling CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait CPU burst, I/O burst, CPU burst, I/O burst CPU burst distribution usually a large number of short CPU bursts and a small number of long CPU bursts I/O bound: has many short CPU bursts CPU-bound: have a few long CPU burst

Alternating Sequence of CPU And I/O Bursts

Histogram of CPU-burst Times

CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them CPU scheduling decisions may take place when a process: Switches from running to waiting state Switches from running to ready state Switches from waiting to ready state Terminates Nonpreemptive or cooperative scheduling When scheduling takes place only under 1 and 4 Process keeps the CPU until it releases the CPU Preemptive scheduling All others are preemptive A process having obtained the CPU may be forced to release the CPU

Dispatcher Dispatcher module gives control of the CPU to the process selected by the CPU 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 Should be as fast as possible

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 For interactive processes, we may not care the turnaround time

Scheduling Criteria (Cont.) Optimization Criteria -- may be conflict Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time In real cases Minimize the variance in the response time (predictable) Minimize the average waiting time

Scheduling Algorithms Operating System Concepts 7 th Edition, Jan 14, 2005 Silberschatz, Galvin and Gagne 2005

First-Come, First-Served (FCFS) Ready queue is a FIFO queue Example: Process CPU Burst Time Scheduling 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: Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 P 1 P 2 P 3 0 24 27 30

First-Come, First-Served (FCFS) Scheduling (Cont.) Suppose that the processes arrive in the order: P 2, P 3, P 1 The Gantt chart for the schedule is: Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case P 2 P 3 P 1 0 3 6 30 Convoy effect: all the other processes wait for the one big process to get off the CPU Result in lower CPU and device utilization FCFS scheduling is nonpreemptive Unsuitable for time-sharing systems

Shortest-Job Job-First (SJF) Scheduling Use the of next CPU burst lengths to schedule the process with the shortest CPU burst time Should be termed as: shortest-next-cpu-burst algorithm Depend on the length of next CPU burst of a process, not total length Two schemes: nonpreemptive once CPU given to the process it cannot be preempted until completes its CPU burst preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. Sometimes called the Shortest-Remaining-Time-First (SRTF)

Example of Non-Preemptive SJF

Example of Preemptive SJF

Shortest-Job Job-First (SJF) Scheduling (Cont.) SJF is optimal gives minimum average waiting time for a given set of processes Problem: cannot be implemented in CPU scheduler No way to know the length of the next CPU burst Sol.: predict by using the length of previous CPU bursts, using exponential averaging 1. 2. 3. 4. t n actual lenght of n n 1 predicted value for the next, 0 1 Define : th CPU burst CPU burst

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

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 Problem: starvation Low priority processes may never execute Solution : aging As time progresses increase the priority of the process

Example of Priority Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 P 2 P 5 P 1 P 3 P 4 0 1 6 16 18 19 Average Waiting Time = 8.2

Round Robin (RR) Each process gets a small unit of CPU time (time quantum) Usually 10-100 milliseconds. After this time has elapsed, the process is preempted. If there are n processes in the ready queue and the time quantum is q, 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 Rule of thumb: 80% of CPU bursts should be shorter than the time quantum

Example: RR with Time Quantum = 20

How a Smaller Time Quantum Increases Context Switches

Turnaround Time Varies With The Time Quantum

Multilevel Queue Scheduling Ready queue is partitioned into separate queues: According to process properties and scheduling needs foreground (interactive) and background (batch) Normally, processes are permanently assigned to one queue Each queue has its own scheduling algorithm, for example foreground RR background FCFS Scheduling must be done between the queues Fixed priority scheduling: 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 Example: 80% to foreground in RR and 20% to background in FCFS

Multilevel Queue Scheduling

Multilevel Feedback Queue A process can move between the various queues Idea Separate processes with different CPU-burst characteristics A process waiting too long in a lower-priority queue may be moved to a higher-priority queue Thus Leave I/O-bound and interactive processes in the higherpriority queues

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 RR. 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 RR and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q 2.

Multilevel Feedback Queues

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available Separate vs. common ready queue Load sharing Asymmetric multiprocessing only the master process handle the scheduling algorithm and accesses the system data structures Symmetric Multiprocessing (SMP) each processor makes its own scheduling decisions Access and update a common data structure Must ensure two processors do not choose the same process Windows, Linux, Mac OS

Processor Affinity Processor Affinity When process migrates to another processor Cache memory must be invalidated and re-populated Most SMP systems avoid migration of process from one processor to another Attempt to keep a process running on the same processor

Load Balancing Keep the workload evenly distributed across all processors Two approaches Push migration A specific task periodically checks the load on each processor If imbalance, push processes from overloaded to idle or less-busy processor Pull migration An idle process pulls a waiting task from a busy processor Can be implemented in parallel But loading balancing counteracts the benefits of processor affinity

Symmetric Multithreading Symmetric multithreading Create multiple logical processors on the same physical processor A feature provided in architecture, not software Hyperthreading technology on Intel processor

A SMT Architecture To the OS, four processors are available

Thread Scheduling Process-contention scope Local Scheduling How the threads library decides which thread to put onto an available LWP System-contention scope Global Scheduling How the kernel decides which kernel thread to run next

Operating System Examples Solaris scheduling Windows XP scheduling Linux scheduling Operating System Concepts 7 th Edition, Jan 14, 2005 Silberschatz, Galvin and Gagne 2005

Solaris Scheduling Priority-based process scheduling Classes: real time, system, time sharing, interactive Each class has different priority and scheduling algorithm

Solaris Scheduling

Windows XP Scheduling Priority-based preemptive scheduling 32-level priority scheme Variable (1-15) and real-time (16-31) classes, 0 (memory manage) A queue for each priority. Traverses the set of queues from highest to lowest until it finds a thread that is ready to run Run the idle thread when no ready thread Base priority of each priority class Initial priority for a thread belonging to that class

Windows XP Priorities Priority class Base priority Relative priority

Linux Scheduling Preemptive, priority-based scheduling with two priority ranges Real-time: 0~99 Nice (for time-sharing): 100~140 Time-sharing: dynamic priority-based The runqueue consists of tasks that are ready to run Consists of active array and expired array Priority is changed depends on task s interactivity Real-time: static priority-based FCFS and RR Highest priority process always runs first

The Relationship Between Priorities and Time-slice length

List of Tasks Indexed According to Priorities

Algorithm Evaluation Operating System Concepts 7 th Edition, Jan 14, 2005 Silberschatz, Galvin and Gagne 2005

Algorithm Evaluation Define the criteria for evaluation and comparison Ex. Maximize CPU utilization under the constraint that the maximum response time is 1 second Evaluation methods Deterministic modeling Queuing models Simulations Implementation Environment in which the scheduling algorithm is used will change Your algorithm is good today, but still good tomorrow?

Deterministic Modeling Analytic evaluation (algorithm) + (workload) = (number of formula) This number is used to evaluate the performance of the algorithm for that workload Deterministic modeling is one analytic evaluation Deterministic modeling Takes a particular predetermined workload and defines the performance of each algorithm for that workload Require exact numbers for input, and answers apply only to the input

Example of Deterministic Modeling Example: CPU burst time: P1 = 10, P2 = 29, P3 = 3, P4 = 7, P5 = 12 Algorithm evaluations If FCFS, average waiting time = 28 If nonpreemptive SJF, average waiting time = 13 If RR, average waiting time = 23 In this case, nonpreemptive SJF is the best Similar to what we have done in this Chapter Simple, fast, and give exact numbers

Gantt Chart FCFS Nonpreemptive SJF RR

Queueing Models Input: Distribution of CPU and I/O bursts Distribution of process arrival time Output: compute the average throughput, utilization, waiting time Mathematical and statistical analysis Approximation of a real system accuracy may be questionable

Simulations Programming a model of the computer system Use software data structure to model queues, CPU, devices, timers Data to drive the simulation Random-number generator according to probability distributions Processes, CPU- and I/O-burst times, arrivals/departures Trace tape the usage logs of a real system Disadvantage expensive

Evaluation of CPU Scheduler by Simulation

Implementation Code a scheduling algorithm, put it in OS, and see Put the actual algorithm in the real system for evaluation under real operating conditions Difficulty High cost Coding the algorithm and modifying the OS Reaction of the users to a constantly changing OS Environment in which the algorithm is used will change Good solutions Flexible scheduling algorithm that can be altered by the system managers or users to tune Use APIs that modify the priority of a process or thread