CPU Scheduling Andy Wang Operating Systems COP 4610 / CGS 5765.

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,
CPU Scheduling CPU Scheduler Performance metrics for CPU scheduling
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.
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.
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
Day 25 Uniprocessor scheduling. Algorithm: Selection function Selection function – which process among ready processes to select. w – time spent in system,
Chapter 3: CPU Scheduling
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
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (2) Process Management 10/03/2008 Yang Song (Prepared by Yang Song and.
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
1 Scheduling Algorithms FCFS First-Come, First-Served Round-robin SJF Multilevel Feedback Queues.
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
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.
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Chapter 6 CPU SCHEDULING.
1 Scheduling Processes. 2 Processes Each process has state, that includes its text and data, procedure call stack, etc. This state resides in memory.
Chapter 7 Scheduling Chien-Chung Shen CIS, UD
Scheduling. Alternating Sequence of CPU And I/O Bursts.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
1 Our focus  scheduling a single CPU among all the processes in the system  Key Criteria: Maximize CPU utilization Maximize throughput Minimize waiting.
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.
S CHEDULING A LGORITHMS Dr. Adil Yousif 1. CPU S CHEDULING How is the OS to decide which of several tasks to take off a queue? Scheduling: deciding which.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 Computer Systems II Process Scheduling. 2 Review of Process States.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
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.
Lecture 12 Scheduling Models for Computer Networks Dr. Adil Yousif.
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
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
1 Lecture 5: CPU Scheduling Operating System Fall 2006.
Lecture 5 Scheduling. Today CPSC Tyson Kendon Updates Assignment 1 Assignment 2 Concept Review Scheduling Processes Concepts Algorithms.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Chapter 7 Scheduling Chien-Chung Shen CIS/UD
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.
DEPARTMENT OF COMPUTER SCIENCE Operating Systems BCA 3 RD YR Process Scheduling Algorithms PRESENTED BY ZAHID IQBAL Dated:27/06/2015 Operating Systems1.
CPU SCHEDULING.
Scheduling (Priority Based)
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Andy Wang Operating Systems COP 4610 / CGS 5765
Operating System Concepts
Chapter5: CPU Scheduling
COT 4600 Operating Systems Spring 2011
Chapter 5: CPU Scheduling
Scheduling 21 May 2019.
Don Porter Portions courtesy Emmett Witchel
CPU Scheduling.
CPU Scheduling: Basic Concepts
Chapter 5: CPU Scheduling
Presentation transcript:

CPU Scheduling Andy Wang Operating Systems COP 4610 / CGS 5765

CPU Scheduler A CPU scheduler is responsible for  Removal of running process from the CPU  Selection of the next running process Based on a particular strategy

Goals for a Scheduler Maximize  CPU utilization: keep the CPU as busy as possible  Throughput: the number of processes completed per unit time

Goals for a Scheduler Minimize  Response time: the time of submission to the time the first response is produced  Wait time: total time spent waiting in the ready queue  Turnaround time: the time of submission to the time of completion

Goals for a Scheduler Suppose we have processes A, B, and C, submitted at time 0 We want to know the response time, waiting time, and turnaround time of process A ABCABCACAC Time response time = wait time turnaround time

Goals for a Scheduler Suppose we have processes A, B, and C, submitted at time 0 We want to know the response time, waiting time, and turnaround time of process B ABCABCACAC Time response time + wait time turnaround time

Goals for a Scheduler Suppose we have processes A, B, and C, submitted at time 0 We want to know the response time, waiting time, and turnaround time of process C ABCABCACAC Time response time + ++ wait time turnaround time

Goals for a Scheduler Achieve fairness  There are tensions among these goals

Assumptions Each user runs one process Each process is single threaded Processes are independent They are not realistic assumptions; they serve to simplify analyses

Scheduling Policies FIFO (first in, first out) Round robin SJF (shortest job first) Multilevel feedback queues Lottery scheduling

FIFO FIFO: assigns the CPU based on the order of requests  Nonpreemptive: A process keeps running on a CPU until it is blocked or terminated  Also known as FCFS (first come, first serve) + Simple - Short jobs can get stuck behind long jobs

Round Robin Round Robin (RR) periodically releases the CPU from long-running jobs  Based on timer interrupts so short jobs can get a fair share of CPU time  Preemptive: a process can be forced to leave its running state and replaced by another running process  Time slice: interval between timer interrupts

More on Round Robin If time slice is too long  Scheduling degrades to FIFO If time slice is too short  Throughput suffers  Context switching cost dominates

FIFO vs. Round Robin With zero-cost context switch, is RR always better than FIFO?

FIFO vs. Round Robin Suppose we have three jobs of equal length ABCABC Time ABC turnaround time of A turnaround time of B turnaround time of C Round Robin AB Time C turnaround time of A turnaround time of B turnaround time of C FIFO

FIFO vs. Round Robin Round Robin + Shorter response time + Fair sharing of CPU - Not all jobs are preemptive - Not good for jobs of the same length

Shortest Job First (SJF) SJF runs whatever job puts the least demand on the CPU, also known as STCF (shortest time to completion first) + Provably optimal + Great for short jobs + Small degradation for long jobs Real life example: supermarket express checkouts

SJF Illustrated AB Time C turnaround time of A turnaround time of B turnaround time of C Shortest Job First response time of A = 0 response time of B response time of C wait time of A = 0 wait time of B wait time of C

Shortest Remaining Time First (SRTF) SRTF: a preemptive version of SJF  If a job arrives with a shorter time to completion, SRTF preempts the CPU for the new job  Also known as SRTCF (shortest remaining time to completion first)  Generally used as the base case for comparisons

SJF and SRTF vs. FIFO and Round Robin If all jobs are the same length, SJF  FIFO  FIFO is the best you can do If jobs have varying length  Short jobs do not get stuck behind long jobs under SRTF

A More Complicated Scenario (Arrival Times = 0) Process A (6 units of CPU request)  100% CPU  0% I/O Process B (6 units of CPU request)  100% CPU  0% I/O Process C (infinite loop)  33% CPU  67% I/O A Time B C C C C C C

A More Complicated Scenario FIFO  CPU  I/O Round Robin with time slice = 3 units  CPU  I/O ABC C Time Poor response and wait time for process C ABC C ABC C Time Disk utilization: 29% (2 out of 7 units)

A More Complicated Scenario Round Robin with time slice = 1 unit  CPU  I/O SRTCF  CPU  I/O Time ABABC C CAB C CAB C CAB C CAB C Disk utilization 66% (2 out of 3 units) Time C CA C CAC C AC C BC C B Disk utilization: 66% (2 out of 3 units)

Drawbacks of Shortest Job First - Starvation: constant arrivals of short jobs can keep long ones from running - There is no way to know the completion time of jobs (most of the time)  Some solutions Ask the user, who may not know any better If a user cheats, the job is killed

Priority Scheduling (Multilevel Queues) Priority scheduling: The process with the highest priority runs first Priority 0: Priority 1: Priority 2: Assume that low numbers represent high priority A B C AB Time C Priority Scheduling

+ Generalization of SJF  With SJF, priority = 1/requested_CPU_time - Starvation

Multilevel Feedback Queues Multilevel feedback queues use multiple queues with different priorities  Round robin at each priority level  Run highest priority jobs first  Once those finish, run next highest priority, etc  Jobs start in the highest priority queue  If time slice expires, drop the job by one level  If time slice does not expire, push the job up by one level

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): ABC time = 0 Time

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): BC time = 1 A A Time

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): C time = 2 AB AB Time

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): C time = 3 AB ABC Time

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): C time = 3 AB ABC Time suppose process A is blocked on an I/O

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): C time = 3 A B ABC Time suppose process A is blocked on an I/O

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): time = 5 BABC Time C A suppose process A is returned from an I/O

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): time = 6 BABC Time C A

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): time = 8 BABC Time AC C

Multilevel Feedback Queues Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4): time = 9 BABC Time ACC

Multilevel Feedback Queues Approximates SRTF  A CPU-bound job drops like a rock  I/O-bound jobs stay near the top  Still unfair for long running jobs  Counter-measure: Aging Increase the priority of long running jobs if they are not serviced for a period of time Tricky to tune aging

Lottery Scheduling Lottery scheduling is an adaptive scheduling approach to address the fairness problem  Each process owns some tickets  On each time slice, a ticket is randomly picked  On average, the allocated CPU time is proportional to the number of tickets given to each job

Lottery Scheduling To approximate SJF, short jobs get more tickets To avoid starvation, each job gets at least one ticket

Lottery Scheduling Example short jobs: 10 tickets each long jobs: 1 ticket each # short jobs/# long jobs % of CPU for each short job % of CPU for each long job 1/191%9% 0/20%50% 2/050%0% 10/110%1% 1/1050%5%