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

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

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

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

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

Chapter 5 Process Scheduling

CPU Scheduling. CPU Scheduling

ICS Principles of Operating Systems

Operating System: Scheduling

CPU Scheduling Outline

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

OPERATING SYSTEMS SCHEDULING

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

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

CPU Scheduling. Core Definitions

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

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

PROCESS SCHEDULING ALGORITHMS: A REVIEW

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

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

Operating Systems. III. Scheduling.

A Comparative Study of CPU Scheduling Algorithms

Processor Scheduling. Queues Recall OS maintains various queues

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

Analysis and Comparison of CPU Scheduling Algorithms

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

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

OS OBJECTIVE QUESTIONS

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

Introduction. Scheduling. Types of scheduling. The basics

Job Scheduling Model

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

Real-Time Scheduling 1 / 39

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Operating Systems Lecture #6: Process Management

Scheduling Algorithms

Operating Systems, 6 th ed. Test Bank Chapter 7

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

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

Operating Systems Concepts: Chapter 7: Scheduling Strategies

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

Operating System Tutorial

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

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

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

A Review on Load Balancing In Cloud Computing 1

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

Syllabus MCA-404 Operating System - II

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

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

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

W4118 Operating Systems. Instructor: Junfeng Yang

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

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

Chapter 2: OS Overview

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Performance Comparison of RTOS

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

Efficiency of Batch Operating Systems

218 Chapter 5 CPU Scheduling

CS414 SP 2007 Assignment 1

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.

Introduction. System Calls

Weight-based Starvation-free Improvised Round-Robin (WSIRR) CPU Scheduling Algorithm

CHAPTER 15: Operating Systems: An Overview

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

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

Chapter 1: Introduction. What is an Operating System?

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

CHAPTER 1 INTRODUCTION

Comparison between scheduling algorithms in RTLinux and VxWorks

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

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

Analysis of Job Scheduling Algorithms in Cloud Computing

Chapter 1 8 Essay Question Review

Multi-core Programming System Overview

Chapter 1 13 Essay Question Review

Linux Process Scheduling Policy

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

Final Report. Cluster Scheduling. Submitted by: Priti Lohani

Types Of Operating Systems

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

Operating Systems 4 th Class

How To Understand And Understand An Operating System In C Programming

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

Improving Distributed Workload Performance by Sharing Both CPU and Memory Resources

Overview and History of Operating Systems

Load Balancing Scheduling with Shortest Load First

Final Project Report. Trading Platform Server

Far-western University Central Office, Mahendranagar Operating System

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

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

Undergraduate Course Syllabus

General Overview of Shared-Memory Multiprocessor Systems

Chapter 1 FUNDAMENTALS OF OPERATING SYSTEM

Threads Scheduling on Linux Operating Systems

Ready Time Observations

Transcription:

TDDB3: Concurrent programming and operating systems [SGG7] Chapter 5 Agenda CPU Scheduling Introduce CPU scheduling Describe various CPU scheduling algorithms Discuss evaluation criteria of CPU scheduling algorithms Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Thread Scheduling Operating Systems Examples Algorithm Evaluation Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin s and Gagne s book ( Operating System Concepts, 7 th ed., Wiley, 2005). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Addison-Wesley. These lecture notes should only be used for internal teaching purposes at the Linköping University. Andrzej Bednarski, IDA Linköpings universitet, 2005 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.2 Basic Concepts Alternating Sequence of CPU And I/O Bursts Maximum CPU utilization obtained with multiprogramming CPU I/O Burst Cycle Process execution consists of + cycle of CPU execution, and + I/O wait CPU burst distribution TDDB3, A. Bednarski, IDA, Linköpings universitet 5.3 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.4 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: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready (task arrives). 4. Terminates. Scheduling under 1 and 4 is nonpreemptive. All other scheduling is preemptive. TDDB3, A. Bednarski, IDA, Linköpings universitet 5.5 TDDB3, A. Bednarski, IDA, Linköpings universitet 5. 1

Dispatcher Scheduling Criteria Dispatcher module gives control of the CPU to the process selected by the short-term 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. CPU utilization quotient of time the CPU is busy and the observation period Throughput number of processes that complete their execution per time unit Turnaround time the time between job submit time and job completion time. 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) TDDB3, A. Bednarski, IDA, Linköpings universitet 5.7 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.8 Optimization Criteria First-Come, First-Served (FCFS) Scheduling Maximize CPU utilization Maximize throughput Minimize turnaround time Minimize waiting time Minimize response time Example: Process Burst Time (ms) 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 1 P 2 P 3 0 24 27 30 Waiting time for P 1 = 0; P 2 = 24; P 3 = 27ms Average waiting time: (0 + 24 + 27)/3 = 17ms TDDB3, A. Bednarski, IDA, Linköpings universitet 5.9 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.10 FCFS Scheduling (Cont.) Shortest-Job-First (SJF) Scheduling Suppose that the processes arrive in the order P 2, P 3, P 1. The Gantt chart for the schedule is: P 2 P 3 0 3 30 Waiting time for P 1 = ms;p 2 = 0ms ; P 3 = 3ms Average waiting time: ( + 0 + 3)/3 = 3ms Much better than previous case. Convoy effect: short process behind long process P 1 Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes: + Nonpreemptive once CPU given to the process it cannot be preempted until it completes its CPU burst. + Preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. Shortest-Remaining-Time-First (SRTF). SJF is optimal gives minimum average waiting time for a given set of processes. TDDB3, A. Bednarski, IDA, Linköpings universitet 5.11 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.12 2

SJF (nonpreemptive) Determining Length of Next CPU Burst 0 P 4 3 Process Burst Time (ms) P 1 P 2 8 P 3 7 P 4 3 P 1 P 3 P 2 9 Average waiting time = (3 + 1 + 9 + 0)/4 = 7ms 1 24 Can only estimate the length. Can be done by using the length of previous CPU bursts, using exponential averaging. 1. t n = actual lenght of n 2. τ n + 1 3. α, 0 α 1 4. Define : th CPU burst = predicted value for the next CPU burst ( 1 α ). τ n = α t + τ + 1 n n TDDB3, A. Bednarski, IDA, Linköpings universitet 5.13 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.14 Examples of Exponential Averaging Prediction of Next CPU Burst α =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. 12 10 8 4 2 CPU burst (t i ) - 4 13 13 13 guess (τ i ) 10 8 5 9 11 11 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.15 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.1 SJF (preemptive) Priority Scheduling Process Arrival Time (ms) Burst Time (ms) P 1 0 8 P 2 1 4 P 3 2 9 P 4 3 5 Shortest Remaining Time Process Burst Time (ms) Priority P 1 10 3 P 2 1 1 P 3 2 4 P 4 1 5 P 5 5 2 P 2 P 5 P 1 P 3 P 4 P 1 P 2 P 4 P 1 P 3 0 1 1 18 19 0 1 5 10 17 2 Average waiting time = (9 + 0 + 15 + 2)/4 =.5 calculated as: (10 1) + (1 1) + (17 2) + (5 3) A priority number (integer) is associated with each process Priorities + Internal (time limits, memory requirement,...) + External (process importance, political/economical factors, ) TDDB3, A. Bednarski, IDA, Linköpings universitet 5.17 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.18 3

Priority Scheduling (Cont.) Round Robin (RR) The CPU is allocated to the process with the highest priority (smallest integer highest priority). + Preemptive + Nonpreemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem: Starvation low priority processes may never execute. Solution: Aging as time progresses increase the priority of the process. TDDB3, A. Bednarski, IDA, Linköpings universitet 5.19 Each process gets a small unit of CPU time (time quantum, time slice), usually 10-100 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 Processor sharing (virtually n processes running at the speed of 1/n) Observe that q must be large with respect to context switch, otherwise overhead is too high. TDDB3, A. Bednarski, IDA, Linköpings universitet 5.20 Example of RR with Time Quantum=20 How a Smaller Time Quantum Increases Context Switches The Gantt chart is: Process Burst Time P 1 53 P 2 17 P 3 8 P 4 24 P 1 P 2 P 3 P 4 P 1 P 3 P 4 P 1 P 3 P 3 0 20 37 57 77 97 117 121 134 154 12 RR has typically higher average turnaround than SJF, but better response. TDDB3, A. Bednarski, IDA, Linköpings universitet 5.21 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.22 Turnaround Time Varies with The Time Quantum Multilevel Queue Ready queue is partitioned into separate queues: + foreground (interactive) + background (batch) 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 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.23 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.24 4

Example of Multilevel Queue 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 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.25 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.2 Example of Multilevel Feedback Queue Multiple-Processor Scheduling Three queues: + Q 0 RR with time quantum 8 ms + Q 1 RR time quantum 1 ms + Q 2 FCFS Q 0 Q 1 CPU scheduling more complex when multiple CPUs are available. Homogeneous processors within a multiprocessor. Asymmetric multiprocessing only one processor accesses the system data structures, alleviating the need for data sharing. Scheduling + A new job enters queue Q 0 which is served RR. When it gains CPU, job receives 8 ms. If it does not finish in 8 ms, job is moved to queue Q 1. + At Q 1 job is again served RR and receives 1 additional ms. + If it still does not complete, it is preempted and moved to queue Q 2 served in FCFS. Q 2 Symmetric multiprocessing (SMP) each processor is selfscheduling. Processor affinity Load sharing/balancing Symmetric multithreading (SMT) TDDB3, A. Bednarski, IDA, Linköpings universitet 5.27 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.28 Thread Scheduling Solaris Scheduling User-level and kernel-level threads Contention scope + Process-contention scope (PCS) local The threads library decides which thread to put onto an available LWP + System-contention scope (SCS) global Kernel decides which kernel thread to run next Scheduling Dispatch table for interactive and time-sharing threads TDDB3, A. Bednarski, IDA, Linköpings universitet 5.29 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.30 5

Windows XP: Priority-based Scheduling Linux Scheduling Priority-based + Variable class (priorities 1-15) + Real-time class (priorities 15-32) + Idle thread (priority 0): memory management Preemptive, priority based scheduling with two priority ranges: + Real-time (0-99) + Other (100-140) Complexity: O(1) Active/expired arrays of tasks Priorities/time-slice relation TDDB3, A. Bednarski, IDA, Linköpings universitet 5.31 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.32 Algorithm Evaluation Recommended Reading and Exercises Deterministic modeling: Takes a particular predetermined workload and defines the performance of each algorithm for that workload. Queueing models mathematical formulation Simulation models based on system trace Implementation evaluation in real situation Reading: + Chapter 5 [SGG7] + Chapter (sixth edition) Exercises: + All No project in Chapter 5 Evaluation of CPU schedulers by simulation TDDB3, A. Bednarski, IDA, Linköpings universitet 5.33 TDDB3, A. Bednarski, IDA, Linköpings universitet 5.34