COS 318: Operating Systems. CPU Scheduling. (http://www.cs.princeton.edu/courses/cos318/)

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

W4118 Operating Systems. Instructor: Junfeng Yang

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

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

CPU Scheduling Outline

Operating Systems. III. Scheduling.

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

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

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

ICS Principles of Operating Systems

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

OPERATING SYSTEMS SCHEDULING

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

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

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

Chapter 5 Process Scheduling

CPU Scheduling. CPU Scheduling

Real-Time Scheduling 1 / 39

Operating Systems Concepts: Chapter 7: Scheduling Strategies

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

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

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

Job Scheduling Model

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

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.

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Processor Scheduling. Queues Recall OS maintains various queues

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

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

OS OBJECTIVE QUESTIONS

Operating Systems, 6 th ed. Test Bank Chapter 7

Lecture 3 Theoretical Foundations of RTOS

Introduction. Scheduling. Types of scheduling. The basics

CPU Scheduling. Core Definitions

Operating Systems Lecture #6: Process Management

A Comparative Study of CPU Scheduling Algorithms

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

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

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

REAL TIME OPERATING SYSTEMS. Lesson-10:

Scheduling Algorithms

PROCESS SCHEDULING ALGORITHMS: A REVIEW

Operating System: Scheduling

W4118 Operating Systems. Instructor: Junfeng Yang

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

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

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

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

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

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

Linux Process Scheduling Policy

Analysis and Comparison of CPU Scheduling Algorithms

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

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

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

Aperiodic Task Scheduling

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

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

Operating System Aspects. Real-Time Systems. Resource Management Tasks

Today. Intro to real-time scheduling Cyclic executives. Scheduling tables Frames Frame size constraints. Non-independent tasks Pros and cons

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

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

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

Final Report. Cluster Scheduling. Submitted by: Priti Lohani

A Review on Load Balancing In Cloud Computing 1

Threads Scheduling on Linux Operating Systems

3. Scheduling issues. Common approaches /1. Common approaches /2. Common approaches / /13 UniPD / T. Vardanega 23/01/2013. Real-Time Systems 1

Real- Time Scheduling

Operating System Tutorial

Modular Real-Time Linux

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

Factors to Describe Job Shop Scheduling Problem

Processes and Non-Preemptive Scheduling. Otto J. Anshus

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

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

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

Performance Comparison of RTOS

Common Approaches to Real-Time Scheduling

Syllabus MCA-404 Operating System - II

Scheduling in Distributed Systems

Operating Systems 4 th Class

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

LAB 5: Scheduling Algorithms for Embedded Systems

Why Relative Share Does Not Work

Completely Fair Scheduler and its tuning 1

The International Journal Of Science & Technoledge (ISSN X)

Understanding Linux on z/vm Steal Time

Chapter 2: OS Overview

A Survey of Fitting Device-Driver Implementations into Real-Time Theoretical Schedulability Analysis

Real-Time Operating Systems for MPSoCs

Predictable response times in event-driven real-time systems

CHAPTER 15: Operating Systems: An Overview

Efficient Parallel Processing on Public Cloud Servers Using Load Balancing

Linux Scheduler. Linux Scheduler

Chapter 1: Introduction. What is an Operating System?

Transcription:

COS 318: Operating Systems CPU Scheduling (http://www.cs.princeton.edu/courses/cos318/)

Today s Topics! CPU scheduling! CPU Scheduling algorithms 2

When to Schedule?! Process/thread creation! Process/thread exit! Blocking on I/O or synchronization! I/O interrupt! Clock interrupt (pre-emptive scheduling) 3

Preemptive vs. Non-Preemptive Scheduling! Preemptive scheduling " Running! ready " Blocked! ready " Running! blocked " Terminate! Non-preemptive scheduling " Running! blocked " Terminate! Batch vs interactive vs real-time Create Scheduler dispatch Ready Terminate (call scheduler) Running Yield, Interrupt (call scheduler) Resource free, I/O completion interrupt (move to ready queue) Block for resource (call scheduler) Blocked Exited 4

Scheduling Criteria! Assumptions " One program per user and one thread per program " Programs are independent! Goals for batch and interactive systems " Provide fairness " Everyone makes some progress; no one starves " Maximize CPU utilization Not including idle process " Maximize throughput Operations/second (min overhead, max resource utilization) " Minimize turnaround time Batch jobs: time to execute (from submission to completion) " Shorten response time Interactive jobs: time response (e.g. typing on a keyboard) " Proportionality Meets user s expectations " Achieve fairness

Scheduling Criteria! Questions: " What are the goals for PCs versus servers? " Average response time vs. throughput " Average response time vs. fairness

Problem Cases! Completely blind about job types " No CPU and I/O overlap.! Optimization involves favoring jobs of type A over B " Lots of A s? B s starve.! Interactive process trapped behind others " Response time bad for no good reason.! Priorities: A depends on B and A s priority > B s " B never runs. 7

First-Come-First-Serve (FCFS) Policy! What does it mean? " Run to completion (old days) " Run until blocked or yield! Example 1 " P1 = 24sec, P2 = 3sec, and P3 = 3sec, submitted together " Average response time = (24 + 27 + 30) / 3 = 27! Example 2 P1 P2 P3 " Same jobs but come in different order: P2, P3 and P1 " Average response time = (3 + 6 + 30) / 3 = 13 P2 P3 P1 (Gantt Graph)

STCF and SRTCF! Shortest Time to Completion First " Non-preemptive! Shortest Remaining Time to Completion First " Preemptive version! Example " P1 = 6sec, P2 = 8sec, P3 = 7sec, P4 = 3sec " All arrive at the same time P4 P1 P3 P2! Can you do better than SRTCF in terms of average response time?! Issues with this approach?

Round Robin! Similar to FCFS, but add a time slice for timer interrupt! FCFS for preemptive scheduling! Real systems also have I/O interrupts in the mix Current process! How do you choose time slice?

FCFS vs. Round Robin! Example " 10 jobs and each takes 100 seconds! FCFS (non-preemptive scheduling) " job 1: 100s, job2: 200s,..., job10: 1000s! Round Robin (preemptive scheduling) " time slice 1sec and no overhead " job1: 991s, job2: 992s,..., job10: 1000s! Comparisons " Round robin is much worse (turnaround time) for jobs about the same length " Round robin is better for short jobs

Resource Utilization Example! A, B, and C run forever (in this order) " A and B each uses 100% CPU forever " C is a CPU plus I/O job (1ms CPU + 10ms disk I/O)! Time slice 100ms " A (100ms CPU), B (100ms CPU), C (1ms CPU + 10ms I/O),! Time slice 1ms " A (1ms CPU), B (1ms CPU), C (1ms CPU), A (1ms CPU), B (1ms CPU), C(10ms I/O) A, B,, A, B! What do we learn from this example?

Virtual Round Robin! Aux queue is FIFO! I/O bound processes go to aux queue (instead of ready queue) to get scheduled! Aux queue has preference over ready queue Admit I/O completion Timeout Dispatch CPU Aux queue I/O wait I/O wait I/O wait 13

Priority Scheduling! Obvious " Not all processes are equal, so rank them! The method " Assign each process a priority " Run the process with highest priority in the ready queue first " Adjust priority dynamically (I/O wait raises the priority, reduce priority as process runs)! Why adjusting priorities dynamically " T1 at priority 4, T2 at priority 1 and T2 holds lock L " Scenario T1 tries to acquire L, fails, blocks. T3 enters system at priority 3. T2 never gets to run! 14

Multiple Queues Priority 4 3 2 1 Time slices 1 2 4 8! Jobs start at highest priority queue! If timeout expires, drop one level! If timeout doesn t expires, stay or pushup one level! What does this method do?

Lottery Scheduling! Motivations " SRTCF does well with average response time, but unfair! Lottery method " Give each job a number of tickets " Randomly pick a winning tickets " To approximate SRTCF, give short jobs more tickets " To avoid starvation, give each job at least one ticket " Cooperative processes can exchange tickets! Question " How do you compare this method with priority scheduling?

Multiprocessor and Cluster CPU L1 $ CPU L1 $ L2 $ L2 $ Memory Network Multiprocessor architecture! Cache coherence! Single OS Cluster or multicomputer! Distributed memory! An OS in each box 17

Multiprocessor/Cluster Scheduling! Design issue " Process/thread to processor assignment! Gang scheduling (co-scheduling) " Threads of the same process will run together " Processes of the same application run together! Dedicated processor assignment " Threads will be running on specific processors to completion " Is this a good idea? 18

Real-Time Scheduling! Two types of real-time " Hard deadline Must meet, otherwise can cause fatal error " Soft Deadline Meet most of the time, but not mandatory! Admission control " Take a real-time process only if the system can guarantee the real-time behavior of all processes " The jobs are schedulable, if the following holds: " C i T i # 1 where C i = computation time, and T i = period 19

Rate Monotonic Scheduling (Liu & Layland 73)! Assumptions " Each periodic process must complete within its period " No process is dependent on any other process " Each process needs the same amount of CPU time on each burst " Non-periodic processes have no deadlines " Process preemption occurs instantaneously (no overhead)! Main ideas of RMS " Assign each process a fixed priority = frequency of occurrence " Run the process with highest priority " Prove to be optimal! Example " P1 runs every 30ms gets priority 33 (33 times/sec) " P2 runs every 50ms gets priority 20 (20 times/sec) 20

Earliest Deadline Scheduling! Assumptions " When a process needs CPU time, it announces its deadline " No need to be periodic process " CPU time needed may vary! Main idea of EDS " Sort ready processes by their deadlines " Run the first process on the list (earliest deadline first) " When a new process is ready, it preempts the current one if its deadline is closer! Example " P1 needs to finish by 30sec, P2 by 40sec and P3 by 50sec " P1 goes first " More in MOS 7.4.4 21

4.3 BSD Scheduling with Multi-Queue! 1 sec preemption " Preempt if a process doesn t block or complete within 1 second! Priority is recomputed every second " P i = base + (CPU i -1) / 2 + nice, where CPU i = (U i + CPU i -1) / 2 " Base is the base priority of the process " U i is process utilization in interval i! Priorities " Swapper " Block I/O device control " File operations " Character I/O device control " User processes 22

Linux Scheduling! Time-sharing scheduling " Each process has a priority and # of credits " I/O event will raise the priority " Process with the most credits will run next " A timer interrupt causes a process to lose a credit " If no process has credits, then the kernel issues credits to all processes: credits = credits/2 + priority! Real-time scheduling " Soft real-time " Kernel cannot be preempted by user code 23

Windows Scheduling! Classes and priorities " Real time: 16 static priorities " Variable: 16 variable priorities, start at a base priority If a process has used up its quantum, lower its priority If a process waits for an I/O event, raise its priority! Priority-driven scheduler " For real-time class, do round robin within each priority " For variable class, do multiple queue! Multiprocessor scheduling " For N processors, run N-1 highest priority threads on N-1 processors and run remaining threads on a single processor " A thread will wait for processors in its affinity set, if there are other threads available (for variable priorities) 24

Summary! Different scheduling goals " Depend on what systems you build! Scheduling algorithms " Small time slice is important for improving I/O utilization " STCF and SRTCF give the minimal average response time " Priority and its variations are in most systems " Lottery is flexible " Real-time depends on admission control 25