Operating Systems Lecture Notes CPU Scheduling Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.

Slides:



Advertisements
Similar presentations
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 17 Scheduling III.
Advertisements

Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling.
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Chap 5 Process Scheduling. Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Operating Systems CPU Scheduling. Agenda for Today What is Scheduler and its types Short-term scheduler Dispatcher Reasons for invoking scheduler Optimization.
Chapter 3: CPU Scheduling
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Operating Systems 1 K. Salah Module 2.1: CPU Scheduling Scheduling Types Scheduling Criteria Scheduling Algorithms Performance Evaluation.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
02/06/2008CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Scheduling in Batch Systems
Chapter 6: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 6: CPU Scheduling Basic.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5-CPU Scheduling
Job scheduling Queue discipline.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Basic Concepts Maximum CPU utilization.
Operating Systems Part III: Process Management (CPU Scheduling)
Chapter 6: CPU Scheduling
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
Chapter 6 CPU SCHEDULING.
Chapter 6 Scheduling. Basic concepts Goal is maximum utilization –what does this mean? –cpu pegged at 100% ?? Most programs are I/O bound Thus some other.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
Alternating Sequence of CPU And I/O Bursts. Histogram of CPU-burst Times.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Chapter 5 CPU Scheduling Bernard Chen Spring 2007.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 11/29/2015 Chapter 6: CPU Scheduling l Basic Concepts l Scheduling Criteria l Scheduling Algorithms l Multiple-Processor Scheduling l Real-Time Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling Basic.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 5 CPU Scheduling Slide 1 Chapter 5 CPU Scheduling.
6.1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Purpose of Operating System Part 2 Monil Adhikari.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Lecture 4 CPU scheduling. Basic Concepts Single Process  one process at a time Maximum CPU utilization obtained with multiprogramming CPU idle :waiting.
CPU Scheduling G.Anuradha Reference : Galvin. CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time.
1 Module 5: Scheduling CPU Scheduling Scheduling Algorithms Reading: Chapter
Basic Concepts Maximum CPU utilization obtained with multiprogramming
1 Lecture 5: CPU Scheduling Operating System Fall 2006.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
1 Chapter 5: CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5a: CPU Scheduling
CPU Scheduling Shmuel Wimer prepared and instructed by
Scheduling (Priority Based)
CPU Scheduling Basic Concepts Scheduling Criteria
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter 5: CPU Scheduling
CPU Scheduling: Basic Concepts
Presentation transcript:

Operating Systems Lecture Notes CPU Scheduling Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002

CPU Scheduling Main Question: Which process to select from ready queue? –Preemption vs. non-preemption –Evaluating scheduling algorithms –Algorithms (FCFS, SJF, RR, Priority, Multilevel Queue) Readings: Silberschatz et al., chapter 6 head tail ready queue registers PCB 7 PCB 9 registers... PCB 1

CPU Scheduling: What Policy? Multiprogramming goal: keep busy. Run some process at all times Policy determines how you allocate resources to processes No single policy is best for all situations! Best policy depends on goal of the system –Single-user desktop PC –Compute server for scientific applications –Interactive time-sharing system

CPU Burst --- I/O Burst Cycle Empirically, most programs alternate between CPU bursts and I/O bursts. This makes multiprogramming desirable.

CPU Burst Times Varies with application and hardware. But histogram almost always looks exponential. Most bursts short, a few are long.

Short-term scheduler Selects next job from ready queue. –Ready queue not necessarily FIFO! Must run when: –A process switches from running to waiting (I/O, wait(), etc.) –A process terminates If preemptive, can also run when: –A process switches from running to ready (Interrupt) –A process switches from waiting to ready (I/O completion)

Preemptive scheduler: Pros and Cons Preemption seems a good choice to avoid this. BUT: –Interrupt during shared user data update Problem: Can cause inconsistency or corruption Remedy: Synchronization (Chapter 7) –Interrupt during system call Problem: Could cause kernel data inconsistency or corruption Remedy: Disable interrupts during kernel data updates Must keep disable time super short or might miss interrupts Headache for app programmers Headache for OS designer OS’s like Windows 3.1 and early Apple MacOS were non-preemptive. Badly-behaved apps could kill these systems. Preemption increases complexity for OS designer AND programmers

Note on Dispatch Latency The dispatcher is a piece of kernel code that: –Switches context –Flips protection bit to user mode –Jumps to correct location in user program Dispatch latency is the time it takes from the interrupt to the final jump

Scheduling algorithm: Evaluation criteria Generally want to maximize –CPU utilization % of time CPU is in use –Throughput # of processes completed per unit time Generally want to minimize –Turnaround time time from submission to completion admit time + ready time + CPU time + I/O time –Wait time amount of time spend in ready queue –Response time time from submission to first output (important in interactive systems) Usually optimize average but there are other choices.

Algorithm 1: First Come, First Served (FCFS) Characteristics: –A non-preemptive scheme. –Like Bangkok Bank when only one service desk is open. –One long-running process can clog the queue for a long time. Example: Process Arrival Burst time P1024 P213 P323 Avg wait time: ( ) / 3 = 17 ms BUT opposite order wait time = ??? P1P1 P2P2 P3P Gantt Chart ( ) / 3 = 3 ms. Much improved!

Algorithm 2: Non-Preemptive Shortest Job First (SJF) Characteristics: –Always assign job with shortest next CPU burst to CPU –Provably optimizes average wait time among non-preemptive algorithms. Example: Process Arrival Burst P1 0 7 P2 2 4 P3 4 1 P4 5 4 Avg wait time: ( ) / 4 = 4 ms FCFS wait time: ( ) / 4 = 4.75 ms Gantt Chart P1P1 P3P3 P2P P4P4 812

Algorithm 3: Preemptive Shortest Job First (SJF) Characteristics: –Like Shortest Job First, but running job can be preempted. –Provably optimizes average wait time among preemptive algorithms. Example: Process Arrival Burst P1 0 7 P2 2 4 P3 4 1 P4 5 4 Average waiting time = ( )/4 = 3 ms Reason that SJF is provably optimal: moving a shorter process earlier always decreases short process’ wait time more than it increases long process’ wait time. Gantt Chart 2110 P4P4 7 P2P2 P1P1 16 P1P1 P3P3 P2P2 45

Implementing SJF SJF is great, but how do we implement it? –We don’t know a priori how long a job’s burst time is –We have to try to predict the burst time

Burst time prediction with exponential average

Priority Scheduling Characteristics: –Always schedule the ready process with highest priority –Priority scheduling can be preemptive or non-preemptive SJF is a special case of priority scheduling: –process priority = the inverse of remaining CPU time

Priority Scheduling Issues Priorities backwards or forwards? –Unix: -20 is “highest” priority, +20 is “lowest” –Show output of the “top” Unix program on the ITLAB server Where do the priorities come from? –Usually internally derived by the OS –Sometimes externally derived by users/managers Problem: Low-priority processes suffer from starvation. They may have to wait indefinitely. Solution: Process aging (gradually increase priority of old processes)

Round-Robin Characteristics: –For time-sharing systems –Similar to FCFS but preemptive –Ready queue is a circular queue –Define a short time quantum, e.g. 20 ms Algorithm: Before starting a process, set timer to generate interrupt after quantum expires If (CPU burst time < quantum) thenprocess gives up CPU voluntarily elsetimer generates interrupt after quantum expires interrupt causes context switch to kernel mode running process is moved to tail of the ready queue switch to next process in queue

Round Robin Example [Quantum = 20] Process Arrival Burst Time P P P P Notice the long wait times but short response times Issue: What’s the “right” time quantum? Too short: too many context switches (too much overhead) Too long: approaches FCFS performance Rule of thumb: large enough to handle 80% of the CPU bursts P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P Gantt Chart

Variations on scheduling: Multilevel queues Use more than one ready queue –e.g. “foreground queue” for interactive programs and “background queue” system maintenance, batch programs Use different scheduling algorithm for each queue –e.g. RR for the foreground queue, FCFS for background queue New problem: how to split time between the queues? –Absolute priority: can cause starvation –Time division: e.g. 80% foreground, 20% background

Variations on scheduling: Multilevel feedback queues Don’t fix a process in a queue: let it move. One example: several queues with different priorities –Let I/O bound processes float upward (higher priority) –Move CPU hogs downward (lower priority) –Move processes waiting a too long gradually upward Flexible system but complex implementation.

What have we learned? What CPU scheduling is Preemptive vs. non-preemptive scheduling How to evaluate different algorithms Some of the important scheduling algorithms: –FCFS –SJF (both preemptive and non-preemptive versions) Provably optimal, but impossible to implement Can be approximated with burst time prediction –Priority scheduling –Round-robin