CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.

Slides:



Advertisements
Similar presentations
Scheduling Criteria CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – # of processes that complete their execution per.
Advertisements

CPU Scheduling Questions answered in this lecture: What is scheduling vs. allocation? What is preemptive vs. non-preemptive scheduling? What are FCFS,
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 17 Scheduling III.
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.
Operating Systems Chapter 6
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.
CPU Scheduling Algorithms
Chapter 3: CPU Scheduling
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.
02/04/2008CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
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.
CPU-Scheduling Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. The short term scheduler.
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.
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.
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.
Chapter 5 CPU Scheduling Bernard Chen Spring 2007.
Process A program in execution. But, What does it mean to be “in execution”?
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.
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.
Introduction to Operating System Created by : Zahid Javed CPU Scheduling Fifth Lecture.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
1 Uniprocessor Scheduling Chapter 3. 2 Alternating Sequence of CPU And I/O Bursts.
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.
CPU scheduling.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
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.
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.
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter5: CPU Scheduling
CPU Scheduling: Basic Concepts
Presentation transcript:

CPU Scheduling CSCI 444/544 Operating Systems Fall 2008

Agenda What is scheduling? –scheduling vs. allocation Scheduling criteria Scheduling algorithms –What are FCFS, SJF, RR and priority-based scheduling policies? Multi-level queue scheduling

Types of Resources Resources can be classified into one of two groups - non-preemptible resources - preemptible resources Type of resource determines how the OS manages it

Non-preemptible Resources Once given resource, cannot be reused until voluntarily relinquished Resource has complex or costly state associated with it Need many instances of this resource Example: Blocks on disk OS management: allocation –Decide which process gets which resource

Preemptible Resources Can take resource away, give it back later Resource has little state associated with it May only have one of this resource Example: CPU OS management: scheduling –Decide order in which requests are serviced –Decide how long process keeps resource

Levels of CPU Management Dispatcher Low-level mechanism Performs context-switch –Save execution state of old process in PCB –Add PCB to appropriate queue (ready or waiting) –Load state of next process from PCB to registers –Switch from kernel to user mode –Jump to instruction in user process Scheduler Policy to determine which process gets CPU and when Maximize CPU utilization with multiprogramming

CPU and I/O Bursts

CPU Workload Model Workload contains a collection of jobs (processes) Job model Job alternates between CPU and I/O bursts (i.e., moves between ready and waiting queues) CPU-bound job: Long CPU bursts I/O-bound job: Short CPU bursts Do not know type of job before it executes Do not know duration of CPU or I/O burst Need job scheduling for each ready job Schedule each CPU burst

Scheduling Metrics CPU utilization Throughput the number of completed process / s Turnaround time the time interval from submission of a process to its completion Waiting time the sum of the periods spent waiting in the ready queue Response time the time it takes to start responding the time interval from submission of a process to the first response

Scheduling Goals Maximize resource utilization Keep expensive devices (e.g., CPU) busy Maximize throughput Want many jobs to complete per unit of time Minimize turnaround time Do not want to wait long for job to complete Minimize waiting time Do not want to spend much time in Ready queue Minimize response time Schedule interactive jobs promptly so users see output quickly Minimize overhead Reduce number of context switches Maximize fairness All jobs get same amount of CPU over some time interval

Design Space Two dimensions Selection algorithm –Which of the ready jobs should be run next? Preemption –Preemptive: currently running job may be interrupted and moved to Ready state –Non-preemptive: once a process is in Running state, it continues to execute until it terminates or it blocks for I/O

Gantt Chart Illustrates how jobs are scheduled over time on CPU Example: ABC Time

First-Come-First-Served (FCFS) Job ArrivalCPU burst A010 B12 C24 ABC Time Average wait time: (0 + (10-1) + (12-2))/3=6.33 Average turnaround time: (10 + (12-1) + (16-2))/3=11.67 Idea: Maintain FIFO list of jobs as they arrive Non-preemptive policy Allocate CPU to job at head of list

FCFS Discussion Advantage: Very simple implementation Disadvantage Waiting time depends on arrival order Potentially long wait for jobs that arrive later Convoy effect: Short jobs stuck waiting for long jobs –Hurts waiting time of short jobs –Reduces utilization of I/O devices –Example: 1 mostly CPU-bound job, 3 mostly I/O-bound jobs CBD A CBD A CBD Idle A CBDA CPU Disk Time

Shortest-Job-First (SJF) Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time Two schemes: non-preemptive – 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. This scheme is know as the Shortest-Remaining- Time-First (SRTF) SJF is optimal – gives minimum average waiting time for a given set of processes

Example of Non-Preemptive SJF ProcessArrival TimeBurst Time P P P P SJF (non-preemptive) - use FCFS if jobs are of same length Average waiting time = ( )/4 = 4 P1P1 P3P3 P2P P4P4 812

Example of Preemptive SJF ProcessArrival TimeBurst Time P P P P SJF (preemptive) Average waiting time = ( )/4 = 3 P1P1 P3P3 P2P P4P4 57 P2P2 P1P1 16

SJF Discussion Advantages Provably optimal for minimizing average wait time –Moving shorter job before longer job improves waiting time of short job more than it harms waiting time of long job Helps keep I/O devices busy Disadvantages Not practical: Cannot predict future CPU burst time –OS solution: Use past behavior to predict future behavior Starvation: Long jobs may never be scheduled

Round-Robin (RR) Idea: Run each job for a time-slice and then move to back of FIFO queue Preempt job if still running at end of time-slice Job ArrivalCPU burst A010 B12 C24 ABCABCACACA Average wait time: ( )/3=4 Time

RR Discussion Advantages Jobs get fair share of CPU Shortest jobs finish relatively quickly Disadvantages Poor average waiting time with similar job lengths –Example: 10 jobs each requiring 10 time slices –RR: All complete after about 100 time slices –FCFS performs better! Performance depends on length of time-slice –If time-slice too short, pay overhead of context switch –If time-slice too long, degenerate to FCFS

RR Time-Slice IF time-slice too long, degenerate to FCFS Example: –Job A w/ 1 ms compute and 10ms I/O –Job B always computes –Time-slice is 50 ms BABA CP U Disk A Idle A Goal: Adjust length of time-slice to match CPU burst Time

Priority-Based Idea: Each job is assigned a priority Schedule highest priority ready job May be preemptive or non-preemptive Priority may be static or dynamic Advantages Static priorities work well for real time systems Dynamic priorities work well for general workloads Disadvantages Low priority jobs can starve How to choose priority of each job? Goal: Adjust priority of job to match CPU burst Approximate SRTF by giving short jobs high priority

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 queues fixed priority scheduling Time slice

Multilevel Queue Scheduling