Chapter 6 CPU SCHEDULING.

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.
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.
Chapter 5-CPU Scheduling
A. Frank - P. Weisberg Operating Systems 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.
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.
Chapter 6: CPU Scheduling
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
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.
Chapter 5 CPU Scheduling Bernard Chen Spring 2007.
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.
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.
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.
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.
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.
Process Scheduling B.Ramamurthy 9/16/2018.
Scheduling (Priority Based)
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling.
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Presentation transcript:

Chapter 6 CPU SCHEDULING

Process Scheduling In most programs, there is alternating between I/O bursts and CPU bursts like: Waiting time Sum of periods spent waiting in ready queue Average is across all visits to ready queue Goal: short waiting time cin>>n>> a>> b; /* I/O wait */ for (i=1; i<=n; i++) /* CPU burst */ x = x + a*b; cout<<x; /* I/O wait */ for (i=1; i<=n; i++) /* CPU burst */ cout<<x; /* I/O wait */

The CPU-I/O Burst Cycle Maximum CPU utilization obtained with multiprogramming. CPU-I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait. Each cycle consists of a CPU burst followed by a (usually longer) I/O burst. A process usually terminates on a CPU burst.

Alternating Sequence of CPU and I/O Bursts

CPU-Bound and I/O-Bound Processes I/O Bound processes: processes that perform lots of I/O operations. Each I/O operation is followed by a short CPU burst to process the I/O, then more I/O happens. CPU bound processes: processes that perform lots of computation and do little I/O. Tend to have a few long CPU bursts.

Non-preemptive vs. Preemptive Scheduling Non-preemptive scheduling Each running process keeps the CPU until it completes or it switches to the waiting (blocked) state. Preemptive scheduling A running process may be also forced to release the CPU even though it is neither completed nor blocked.

CPU Scheduling Criteria 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, from submission to termination. 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. Fairness– A scheduler makes sure that each process gets its fair share of the CPU and no process can suffer indefinite postponement.

CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. CPU scheduling decision (5 below) may take place when a process: Switches from running to waiting state Switches from running to ready state Switches from waiting to ready Terminates Scheduling under 1 and 4 is non-preemptive All other scheduling is preemptive Waiting Ready Running Terminate Start 1 2 3 4 5 Process life-cycle

Dispatcher Not the same as scheduler. Dispatcher module gives control of the CPU to the process selected by the scheduler; this involves: switching context. switching to user mode. jumping to the proper location in the user program to restart that program. Dispatch latency – time it takes for the dispatcher to stop one process and start another running.

Optimization Criteria In CPU scheduling, the following results are sought: Maximum CPU utilization Maximum throughput Minimum turnaround time Minimum waiting time Minimum response time

CPU Scheduling Algorithms There are four well-known scheduling algorithms: First Come First Served (FCFS) Scheduling Shortest Job First (SJF) Scheduling Priority-Based Scheduling Round-Robin (RR) Scheduling

First Come First Served (FCFS) Scheduling Selection function: the process that has been waiting the longest in the ready queue (hence, FCFS) Decision mode: non-preemptive a process runs until it blocks for an I/O

First Come First Served (FCFS) Scheduling Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: Waiting time for P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 P1 P2 P3 24 27 30

First Come First Served (FCFS) Scheduling What if the processes arrive in the next order? P2 , P3 , P1 The Gantt chart for the schedule is: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Convoy effect short process behind long process P1 P3 P2 6 3 30

FCFS and Convoy Effect Consider: P1: CPU-bound (More CPU processing) P2, P3, P4: I/O-bound ( More I/O operations) P2, P3, and P4 could quickly finish their I/O request → ready queue, waiting for CPU. Note: I/O devices are idle then. Then, P1 finishes its CPU burst and move to an I/O device. P2, P3, and P4 which have short CPU bursts, finish quickly → back to I/O queue.

FCFS and Convoy Effect (Cont’d) Note: CPU is idle then. P1 moves then back to ready queue is gets allocated CPU time. Again P2, P3, and P4 wait behind P1 when they request CPU time. One Reason behind this problem is that, FCFS is non-preemptive. P1 keeps the CPU as long as it needs

FCFS: Critique Favors CPU-bound processes A CPU-bound process monopolizes the processor I/O-bound processes have to wait until completion of CPU-bound process I/O-bound processes may have to wait even after their I/Os are completed (poor device utilization) Better I/O device utilization could be achieved if I/O bound processes had higher priority

Shortest Job First (SJF) Scheduling Selection function: the process with the shortest expected CPU burst time I/O-bound processes will be selected first Decision mode: non-preemptive The required processing time, i.e., the CPU burst time, must be estimated for each process

Shortest Job First (SJF) Scheduling 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 currently executing process, preempt the current process. This scheme is know as the Shortest Remaining Time First (SRTF) SJF algorithm is optimal Gives a schedule with least average waiting time among all possible scheduling algorithms SJF is proven optimal only when all jobs are available simultaneously.

Non-Preemptive SJF (Example-1) Assume all processes arrive at the same time: P1 , P2 , P3 , P4 Non-preemptive scheduling Gantt chart Average waiting time: (3+16+9+0)/4=7 ms PID Burst P1 6 P2 8 P3 7 P4 3 P2 P1 P4 9 3 24 P3 16

Non-Preemptive SJF (Example-2) Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (non-preemptive) Average waiting time = (0 + 6 + 3 + 7)/4 = 4 P1 P3 P2 7 3 16 P4 8 12

Preemptive SJF or Shortest Remaining Time First (SRTF)-Example Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (preemptive) Average waiting time = (9 + 1 + 0 +2)/4 = 3 P1 P3 P2 4 2 11 P4 5 7 16

SJF: Critique SJF implicitly incorporates priorities. Possibility of starvation for longer processes. Lack of preemption is not suitable in a time sharing environment. SJF implicitly incorporates priorities. Shortest jobs are given preferences CPU bound process have lower priority, but a process doing no I/O could still monopolize the CPU if it is the first to enter the system

Priority-Based Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer  highest priority) Again two types Preemptive nonpreemptive SJF is a priority scheduling algorithm where priority is the (inverse of) predicted next CPU burst time Problem  Starvation  low priority processes may never execute Solution  Aging  as time progresses increase the priority of a lower priority process that is not receiving CPU time. Example with four priority classes

Example of Priority-Based Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Gantt Chart Average waiting time =(0+1+6+16+18)/5=8.2 msec P2 P3 P5 1 18 16 P4 19 6 P1

Round-Robin (RR) Scheduling Selection function: same as FCFS Decision mode: preemptive a process is allowed to run until the time slice period (quantum, typically from 10 to 100 ms) has expired a clock interrupt occurs and the running process is put on the ready queue

Round-Robin (RR) Scheduling (Cont’d) Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. Performance q large  FCFS q small  Too much context switching. q must be large compared to context switch time, otherwise overhead is too high

Choosing RR Time Quantum Quantum must be substantially larger than the time required to handle the clock interrupt and dispatching Quantum should be larger then the typical interaction but not much larger, to avoid penalizing I/O bound processes

Choosing RR Time Quantum (Cont’d)

Choosing RR Time Quantum (Cont’d) The effect of quantum size on context-switching time must be carefully considered. Larger the time quantum, larger the response time. Smaller the time quantum, more the number of context switches. Modern systems use quanta from 10 to 100 msec with context switch taking < 10 msec

Choosing RR Time Quantum (Cont’d)

Turnaround Time Varies With The Time Quantum 80% of CPU bursts should be shorter than q

Example of RR with Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24 The Gantt chart is: Typically, higher average turnaround than SJF, but better response time P1 P2 P3 P4 20 37 57 77 97 117 121 134 154 162

Example of RR with Time Quantum = 4 Assume processes arrive in this order: P1 , P2 , P3 Preemptive scheduling Time quantum: 4 ms Gantt chart P1 uses a full time quantum; P2, P3 use only a part of a quantum P1 waits 0+6=6; P2 waits 4; P3 waits 7 Average waiting time: (6+4+7)/3=5.66 ms PID Burst P1 24 P2 3 P3 P1 P2 P3 4 7 10 14 18 22 26 30

Round Robin: Critique Still favors CPU-bound processes An I/O bound process uses the CPU for a time less than the time quantum before it is blocked waiting for an I/O A CPU-bound process runs for all its time slice and is put back into the ready queue May unfairly get in front of blocked processes