Operating Systems Concepts: Chapter 7: Scheduling Strategies



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

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

Operating Systems. III. Scheduling.

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

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

Processor Scheduling. Queues Recall OS maintains various queues

CPU Scheduling. CPU Scheduling

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

W4118 Operating Systems. Instructor: Junfeng Yang

ICS Principles of Operating Systems

OPERATING SYSTEMS SCHEDULING

CPU Scheduling Outline

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

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

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

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

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

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

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

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

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

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

Linux Process Scheduling Policy

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

Chapter 5 Process Scheduling

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

Scheduling. Monday, November 22, 2004

CPU Scheduling. Core Definitions

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

Operating Systems Lecture #6: Process Management

Real-Time Scheduling 1 / 39

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

Introduction. Scheduling. Types of scheduling. The basics

Job Scheduling Model

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

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

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

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

Operating System: Scheduling

Operating Systems, 6 th ed. Test Bank Chapter 7

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

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

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

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

W4118 Operating Systems. Instructor: Junfeng Yang

Processes and Non-Preemptive Scheduling. Otto J. Anshus

UNIVERSITY OF WISCONSIN-MADISON Computer Sciences Department A. Arpaci-Dusseau

Linux Scheduler. Linux Scheduler

A Comparative Study of CPU Scheduling Algorithms

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

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

REAL TIME OPERATING SYSTEMS. Lesson-10:

Operating System Tutorial

OS OBJECTIVE QUESTIONS

Chapter 3. Operating Systems

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

Completely Fair Scheduler and its tuning 1

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

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

Predictable response times in event-driven real-time systems

ò Scheduling overview, key trade-offs, etc. ò O(1) scheduler older Linux scheduler ò Today: Completely Fair Scheduler (CFS) new hotness

Analysis and Comparison of CPU Scheduling Algorithms

SYSTEM ecos Embedded Configurable Operating System

First-class User Level Threads

Overview and History of Operating Systems

Lecture 3 Theoretical Foundations of RTOS

PROCESS SCHEDULING ALGORITHMS: A REVIEW

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

Scheduling Algorithms

Operating Systems 4 th Class

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

Chapter 2: OS Overview

Process Scheduling II

Introduction. What is an Operating System?

Syllabus MCA-404 Operating System - II

4. Fixed-Priority Scheduling

Chapter 1: Introduction. What is an Operating System?

These sub-systems are all highly dependent on each other. Any one of them with high utilization can easily cause problems in the other.

Chapter 6, The Operating System Machine Level

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

Module 6. Embedded System Software. Version 2 EE IIT, Kharagpur 1

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

Process Scheduling in Linux

Tasks Schedule Analysis in RTAI/Linux-GPL

CS414 SP 2007 Assignment 1

Real Time Programming: Concepts

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

Process Scheduling in Linux

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

Threads Scheduling on Linux Operating Systems

STEPPING TOWARDS A NOISELESS LINUX ENVIRONMENT

Project No. 2: Process Scheduling in Linux Submission due: April 28, 2014, 11:59pm

Final Report. Cluster Scheduling. Submitted by: Priti Lohani

CHAPTER 15: Operating Systems: An Overview

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

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

Understanding Linux on z/vm Steal Time

Comparison between scheduling algorithms in RTLinux and VxWorks

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

Overview of the Linux Scheduler Framework

Transcription:

Operating Systems Concepts: Chapter 7: Scheduling Strategies Olav Beckmann Huxley 449 http://www.doc.ic.ac.uk/~ob3 Acknowledgements: There are lots. See end of Chapter 1. Home Page for the course: http://www.doc.ic.ac.uk/~ob3/teaching/operatingsystemsconcepts/ This is only up-to-date after I have issued printed versions of the notes, tutorials, solutions etc. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 1

Scheduling On most systems, there will be many more processes running than there are CPUs. The scheduler determines which job gets to use the CPU at what time. PCs are very different from mainframes Many machines are limited by the rate of input rather than the speed of the CPU IO bound On high-end networked workstations and servers, scheduling is very important. Must pick right process to run Make efficient use of CPU, but also minimise process switching, which has a cost in itself: State has to be saved registers and memory map Specifically, TLB has to be flushed (see Ch 8). New process state has to be loaded Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 2

Scheduling Scheduling happens when A new process is created, A process exits or blocks (IO/semaphore etc), A blocked process resumes (after IO interrupt) Non pre-emptive scheduling processes run until they block or release the CPU Pre-emptive scheduling the scheduler, via the clock interrupt to the CPU, may de-schedule (stop from running) a process before it has blocked or exited. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 3

Scheduling Categories Goals: fairness, policy enforcement, balance Depends on the OS and environment (even system/user pt of view) Batch systems throughput, turnaround time, CPU utilisation Interactive response time, proportionality (users expectations) Real-time meeting deadlines, predictability Batch algorithms first-come-first-served next on queue is served (simple) (FIFO) Shortest-Job-first well known times, only good if 0 interarrival time Shortest-remaining-time for pre-emptive jobs (new short jobs get good service) Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 4

Three level Scheduling CPU Scheduler CPU Admission Scheduler Main Memory Memory Scheduler disk Jobs arrive at system, placed in input queue stored on disk Admission scheduler decided which to admit to system Job enters system and process created -- competes for CPU If memory can t hold processes swapped to disk Memory scheduler determines which kept in memory which on disk Remember swapping to and from disk costs (disk IO bw goes down) Degree of multi-programming = no processes wanted in mem CPU scheduler decides on which ready process to run Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 5

Round-Robin Process assigned time interval (quantum) If process is running at end of quantum then CPU pre-empted and given to another process Simple algorithm list of runnable process, end of quantum process moves to end of list. Length of quantum affects performance, Why? E.g. context switch = 1msec, quantum = 4 msec CPU spend 20% on admin Quantum = 100 msec =? % Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 6

Round-Robin cont. Performance cont. If 10 users hit <return> same time 10 processes on queue CPU idle therefore starts first one Next don t get CPU until 100 msec later! Last key = 1sec!!! 1 1 second response time for <return> NO THANKYOU! Good to have quantum > mean CPU burst pre-emption rarely will happen Why is this good? Recommendation is around 20-50 msec [Tanenbaum] Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 7

Priority Scheduling all processes are equal but some are more equal than others RR= all processes are equal Pecking order (deans, profs, SLs, janitors and then students ;-) Assigned a priority and highest runs Even PC (single user) multiple processes e.g. mail daemon vs. video player Prevent greedy processes by reducing their priority at clock ticks Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 8

Priority Scheduling cont. Can assign costs to priority. E.g. my fab research job on a supercomputer gets 100 and I pay for it, whereas student compile gets 10 for free! ;-) Nice user reduces priority to be real nice to others (ask about the dept, has anyone ever ever used it?) Dynamic allocation IO bound job gets higher CPU priority, why? Combine RR and Priority (RR within a class of application) During IO, the Io-Process waits until finished Gets CPU immediately so it can get out of the way Out of the way = out of memory and let CPU bound on for longer in parallel Beware of Starvation Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 9

Multiple Queues Large quantum = poor response time Processes divided into priority classes Processes in highest class run for 1 quantum Process in next highest run for 2 quanta next 4 etc Whenever a process has used its quantum, it is moved down a class E.g. Process requires 100 quanta Gets 1 quantum then swaps out, then 2 quanta, 4, 8 16, 32, 64 (37) 7 Swaps in total, how many for RR? 100 Scheduling algorithm with 4 priority Qs Q headers Pri 4 Pri 3 Pri 2 Pri 1 Runnable processes Highest Pri. Lowest Pri. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 10

Policy Vs Mechanism Large apps like DBMS have many child processes DBMS knows how to schedule better than OS Therefore is OS separates mechanism from polity DBMS can communicate (via parameters) to OS Threads User level - use RR and Pri to schedule them won t have interrupt for long threads hogging time, context switch is lightweight Kernel context switch is full state save (heavy/slow) Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 11

(1) Priority - Pre-emption Each process is assigned a priority. A process runs until it suspends itself or it is interrupted. If the interrupt makes a higher priority process ready the high priority process will be run. i.e. the lower priority process is pre-empted. Interrupt handler used in Simple Kernel P low P high Time Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 12

(2) Run-to-completion Scheduling (Natural Break) Process runs until it suspends itself. Suspending itself could be (in the case of Simple Kernel) P() on a semaphore delay() The same process will run after an interrupt has occurred as was running before. Interrupt handler P high P low P low delay Time Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 13

Example: Interrupt Latency with Natural Break. Ready-Queue State: - P1, P2 Clock Interrupt at time T puts P3 on readyq. Ready-Queue State: - P1, P2, P3 P1 then runs for 2 milliseconds before suspending itself. P2 runs for 3 milliseconds before suspending itself. Thus the latency between the clock interrupt occurring and P3 being run on the processor is 5 milliseconds. Advantages: Simple to implement Efficient implementation of mutual exclusion Disadvantages: Assumes well-behaved user processes. no Loops without breaks (delay/p) short time between breaks Response time depends on run-times of user programs. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 14

Exercise: What transition in the Simple Kernel must be disallowed if it is to be modified to a Natural Break Scheduling Strategy? delay(t) running P(s) clock V(s) dispatch ready delayed clock create V(s) suspended Which Kernel procedures must be modified and how? Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 15

(3) Time Sliced Scheduling Each process is run until its time slice expires or until it suspends itself. Used in time sharing systems to share processor among multiple users. P 2 P 3 P 1 timer P(s) P 1 0 100 160 260 Time Large real-time systems can use a mixture of Time-sliced scheduling and priority pre-emption. e.g. VAX/VMS High-priority real-time processes are scheduled by priority pre-emption. Processes with priorities <16 scheduled by time-slicing. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 16

(4) Multi-Level Queues - Dynamic Priority Assignment Unblocked processes CPU Completion 100ms pre-emption CPU Completion 500ms pre-emption Increasing Priority pre-emption CPU Completion 2 secs Increasing Time-slice Size Favours interactive jobs they get a good response time. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 17

disk In real life: Scheduling in UNIX memory low-level scheduling CPU high-level scheduling multiple priority queues Low-level scheduling algorithm is a dynamic priority scheduling algorithm See Tanenbaum Ch 10. There are many different kinds of Unix; the scheduling I describe here is designed to be consistent and a good representation of Unix scheduling, but may not completely correspond to any one particular instance of Unix. Each process is assigned a base priority by the OS. Depends on the type of process (kernel vs. user mode, etc.) Range: -20 <= base <= 20. 20 is the highest base priority! Users can assign a lower priority to their own processes Represented by a value nice : -20 <= nice <= 20. Only root can set negative. Initial priority of a process: priority = base + nice (within [-20,20]). One ready queue per priority Basic scheduling algorithm then selects first process from highest non-empty ready queue (this part is like Simple Kernel). Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 18

UNIX Scheduling Continued A process that is selected to run is assigned a quantum, typically 100ms. After a process uses up its quantum, rejoins its own priority queue -> round-robin scheduling for processed with equal priorities. Priorities are re-calculated once per second, based on recent CPU utilisation Q: number of time slices a process ran during the last second. Penalty: CPUutilisation i = Q + (CPUutilisation (i 1) / 2) Note that this penalty decays exponentially Priorities are re-calculated: priority = CPUutilisation i + nice + base Example: Process with base priority 0, nice 0. Runs for one full second. What is its priority for the next 5 seconds, assuming it does not run again? The effect is a scheduling system that favours interactive processes. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 19

In real life: Linux Scheduling Linux scheduling is different from UNIX. Three classes: real-time FIFO real-time round-robin Timesharing See Tanenbaum Section 10.3; same caveat as UNIX scheduling. Each process has a static priority and a niceness, with a fixed relationship priority = 20 nice. Valid range [1,40]. 40 is highest. Default static priority for user processes is 20 (niceness 0). Adjust the static priority of a process when it starts: /bin/nice n <niceness> <command> Only root can invoke /bin/nice with a negative niceness. In addition to its static priority, each process has a dynamic priority known as its quantum. quantum is initialised to priority. Clock tick every 10msec, 10ms interval known as a jiffy quantum of running process is decremented by 1 at every clock tick. We define goodness = quantum + priority if quantum > 0, else 0. When the scheduler is called, the process with the highest goodness greater than zero is selected to run. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 20

Linux Scheduling Continued The scheduler is not run every 10ms too expensive. Instead, the scheduler runs when the current process becomes ineligible to run (because its goodness becomes 0, or it blocks, etc.) Eventually, the goodness of all ready processes becomes zero Question: which processes do not have goodness zero? When that happens, we recalculate the dynamic priority (quantum) of all processes based on quantum = (quantum / 2) + priority The effect is that processes that did not utilise their full quantum start with higher quantum after recalculation. The time period between re-calculations of dynamic priority is called an epoch. Example: Two processes, CPU intensive, assume no semaphores. A is started normally, B is started with /bin/nice n 15 B. Question: What percentage of CPU do A and B receive, respectively? Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 21

In real Life: Windows 2000 Scheduling See Tanenbaum book. Windows 2000 has processes and (within each process), threads. Two API functions to interact with scheduler: SetPriorityClass (process) and SetThreadPriority. System has 32 priorities (0 to 31) Combination of priority class and thread priority is mapped to priority number via table below. Each thread has a base priority. Current priority can be higher (see next slide) Tanenbaum Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 22

Windows 2000 Scheduling Continued 32-level ready queue (see picture) Scheduler selects first thread from highest non-empty ready queue. Tanenbaum Scheduling is done on a thread basis, independent of process membership. Modifications to this basic system to improve interactive performance: I/O completes and releases waiting thread: current priority boosted depending on device (e.g. 1 for disk, 8 for sound!) Thread waiting on semaphore (etc.) released: boosted by 2 if active window, 1 otherwise. To deal with priority inversion These boosts are not forever, decay by 1 on each quantum where thread is active. Default quantum is 20ms. Windows that become active get more time. Department of Computing, Imperial College London. Operating Systems Concepts (MSc Computing / JMC2) 2005/ 06 Chapter 7 23