Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.

Slides:



Advertisements
Similar presentations
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling.
Advertisements

 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 CS 3100 CPU Scheduling1. Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various.
Chapter 3: CPU Scheduling
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
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.
6/25/2015Page 1 Process Scheduling B.Ramamurthy. 6/25/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
Chapter 5-CPU Scheduling
7/12/2015Page 1 Process Scheduling B.Ramamurthy. 7/12/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 8 Chapter 5: CPU Scheduling.
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.
Chapter 6: CPU Scheduling
Lecture 5: Uniprocessor Scheduling
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Peng Lu. CPU Scheduling 1. Basic Concepts 2. Scheduling Criteria 3. Scheduling Algorithms 4. Multiple-Processor Scheduling 5. Real-Time Scheduling 2.
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 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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: Process Scheduling.
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 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.
CSC 322 Operating Systems Concepts Lecture - 10: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Purpose of Operating System Part 2 Monil Adhikari.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Introduction to Operating System Created by : Zahid Javed CPU Scheduling Fifth Lecture.
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.
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 6: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling.
CPU Scheduling: Basic Concepts
Chapter 5: CPU Scheduling
Presentation transcript:

Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms  First-Come, First-Served (FCFS)  Shortest Job First (SJF)  Priority (PRI)  Round-Robin (RR) 1

CPU Scheduling 2 Scheduling: deciding which process are given access to resources from moment to moment.

Chapter 5: CPU Scheduling 3 Always want to have CPU (or CPU’s) working Usually many processes in ready queue  Ready to run on CPU  Focus on a single CPU here Need strategies for  Allocating CPU time  Selecting next process to run  Deciding what happens after a process completes a system call, or completes I/O Short-term scheduling  Must not take much CPU time to do the scheduling

CPU & I/O Bursts Process execution is nothing but a sequence of CPU & I/O bursts Processes alternate between these two states 4

CPU Burst & I/O Burst Alternation (Fig. 5.1) 5 What happens when the I/O burst occurs? What is the process state at that time? In general, most programs have short CPU bursts

Types of Scheduling Long-term scheduling the decision to add to pool of processes to be executed Mid-term scheduling the decision to add to the number of processes that are partially or fully in memory Short-term scheduling decision as to which available process will be executed I/O scheduling decision as to which process’s pending request shall be handled by an available I/O device 6

Short term CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them CPU scheduling decisions may take place when a process: 1.Switches from running to waiting state 2.Switches from running to ready state 3.Switches from waiting to ready 4.Terminates Scheduling under 1 and 4 is non-preemptive All other scheduling is preemptive 7

Preemptive & Non-preemptive Scheduling SO what is Preemptive & Non-preemptive scheduling? Non-preemptive  Once CPU is allocated to a process, it holds it till it  Terminates (exits)  Blocks itself to wait for I/O  Requests some OS service 8

Preemptive & Non-preemptive Scheduling Preemptive  Currently running process may be interrupted and moved to the ready state by the OS  Windows 95 introduced preemptive scheduling 9

Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves:  switching context  switching to user mode  jumping to the proper location in the user program to restart that program (IP) Dispatch latency – time it takes for the dispatcher to stop one process and start another running 10

For scheduling Criteria & Objectives CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process (total time spent on the system) Waiting time – amount of time a process has been waiting in the ready queue Response time – amount of time it takes from when a request was submitted until the first response is produced, not output 11

Optimization Criteria Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time 12

CPU Scheduling Algorithms 13 First-Come, First-Served (FCFS)  Complete the jobs in order of arrival Shortest Job First (SJF)  Complete the job with shortest next CPU burst Priority (PRI)  Processes have a priority  Allocate CPU to process with highest priority Round-Robin (RR)  Each process gets a small unit of time on CPU (time quantum or time slice)

FCFS: First-Come First-Served 14 Ready queue data structure: a FIFO queue  Assuming we have (at least) a multiprogrammed system Example 1  Draw Gantt chart  Compute the average waiting time for processes with the following next CPU burst times and ready queue order:  P1: 20  P2: 12  P3: 8  P4: 16  P5: 4  Waiting time:  Time period spent in the ready queue (assume processes terminate)  Also calculate average waiting time across processes  Assume 0 context switch time CPU burst times E.g., time units are milliseconds

Solution: Gantt Chart Method 15 Waiting times? P1: 0 P2: 20 P3: 32 P4: 40 P5: 56 Average wait time: 148/5 = 29.6 FCFS: First-Come First-Served P1 20 P2 32 P3P4P

FCFS: First-Come First-Served 16 Advantage: Relatively simple algorithm Disadvantage: long waiting times

Scheduling Algorithms: First-Come, First-Served (FCFS) 17 Example 2: Three processes arrive in order P1, P2, P3.  P1 burst time: 24  P2 burst time: 3  P3 burst time: 3 Waiting Time  P1: 0  P2: 24  P3: 27 Completion Time:  P1: 24  P2: 27  P3: 30 Average Waiting Time: ( )/3 = 17 Average Completion Time: ( )/3 = 27 P1P2P

Scheduling Algorithms: First-Come, First-Served (FCFS) 18 What if their order had been P2, P3, P1?  P1 burst time: 24  P2 burst time: 3  P3 burst time: 3

Scheduling Algorithms: First-Come, First-Served (FCFS) 19 What if their order had been P2, P3, P1?  P1 burst time: 24  P2 burst time: 3  P3 burst time: 3 Waiting Time  P1: 0  P2: 3  P3: 6 Completion Time:  P1: 3  P2: 6  P3: 30 Average Waiting Time: (0+3+6)/3 = 3 (compared to 17) Average Completion Time: (3+6+30)/3 = 13 (compared to 27) P1P2P

SJF Provably shortest average wait time BUT: What do we need to actually implement this?

SJF Solution Waiting times (how long did process wait before being scheduled on the CPU?): P1: 40 P2: 12 P3: 4 P4: 24 P5: 0 Average wait time: 16 (Recall: FCFS scheduling had average wait time of 29.6) P1 4 P2 12 P3P4P

Priority Scheduling 22 Have to decide on a numbering scheme  0 can be highest or lowest

Starvation Problem 23 Priority scheduling algorithms can suffer from starvation (indefinite waiting for CPU access) In a heavily loaded system, a steady stream of higher-priority processes can result in a low priority process never receiving CPU time  I.e., it can starve for CPU time One solution: aging  Gradually increasing the priority of a process that waits for a long time

Which CPU Scheduling Algorithms Can be Preemptive? 24 FCFS (First-come, First-Served)  Non-preemptive SJF (Shortest Job First)  Can be either  Choice when a new (shorter) job arrives  Can preempt current job or not Priority  Can be either  Choice when a processes priority changes or when a higher priority process arrives

RR (Round Robin) Scheduling 25 Used in time-sharing or multi-tasking systems  typical kind of scheduling algorithm in a contemporary general purpose operating system Method  Give each process a unit of time (time slice, quantum) of execution on CPU  Then move to next process in ready queue  Continue until all processes completed Necessarily preemptive  Requires use of timer interrupt Time quantum typically between 10 and 100 milliseconds  Linux default appears to be 100ms

RR (Round Robin) Scheduling: Example 26 CPU job burst times & order in queue  P1: 20  P2: 12  P3: 8  P4: 16  P5: 4 Draw Gantt chart, and compute average wait time  Time quantum of 4  Like our previous examples, assume 0 context switch time

Solution 27 Waiting times: P1: = 40 P2: = 32 P3: = 24 P4: = 40 P5: = 16 Average wait time: 30.4 P1P2 4 P3P4P5P P2P3 28 P4P1P2P P1P4 52 P complete s 0

Example 2of RR with Time Quantum = 4 28 ProcessBurst Time P 1 24 P 2 3 P 3 3 The Gantt chart is: P1P1 P2P2 P3P3 P1P1 P1P1 P1P1 P1P1 P1P

Example of RR with Time Quantum = 4 29 Process Burst Time P 1 24 P 2 3 P 3 3 Waiting Time:  P1: (10-4) = 6  P2: (4-0) = 4  P3: (7-0) = 7 Completion Time:  P1: 30  P2: 7  P3: 10 Average Waiting Time: ( )/3= 5.67 Average Completion Time: ( )/3=15.67 P1P1 P2P2 P3P3 P1P1 P1P1 P1P1 P1P1 P1P

Example 3 of RR with Time Quantum = Waiting Time:  P1: (68-20)+(112-88) = 72  P2: (20-0) = 20  P3: (28-0)+(88-48)+( ) = 85  P4: (48-0)+(108-68) = 88 Completion Time:  P1: 125  P2: 28  P3: 153  P4: 112 Average Waiting Time: ( )/4 = Average Completion Time: ( )/4 = A process can finish before the time quantum expires, and release the CPU.

Performance Characteristics of Scheduling Algorithms 31 Different scheduling algorithms will have different performance characteristics RR (Round Robin)  Average waiting time often high  Good average response time  Important for interactive or timesharing systems SJF  Best average waiting time  Some overhead with respect to estimates of CPU burst length & ordering ready ‘queue’