CSC 322 Operating Systems Concepts Lecture - 10: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,

Slides:



Advertisements
Similar presentations
CSC 322 Operating Systems Concepts Lecture - 11: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
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.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
CPU Scheduling Section 2.5.
Chapter 3: 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.
Scheduling in Batch Systems
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
Chapter 5-CPU Scheduling
5: CPU-Scheduling1 Jerry Breecher OPERATING SYSTEMS SCHEDULING.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
Job scheduling Queue discipline.
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.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
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.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
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.
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.
CPU Scheduling Basic Concepts. Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
2.5 Scheduling Given a multiprogramming system. Given a multiprogramming system. Many times when more than 1 process is waiting for the CPU (in the ready.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 7: CPU Scheduling Chapter 5.
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.
Scanf n, a, b /* I-O wait */ for (i=1; i
ITFN 2601 Introduction to Operating Systems Lecture 4 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.
Processor Scheduling Hank Levy. 22/4/2016 Goals for Multiprogramming In a multiprogramming system, we try to increase utilization and thruput by overlapping.
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.
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.
INTRO TO PROCESS SCHEDULING Module 2.4 COP4600 – Operating Systems Richard Newman.
Chapter 5a: CPU Scheduling
Chapter 2 Scheduling.
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Scheduling 21 May 2019.
Presentation transcript:

CSC 322 Operating Systems Concepts Lecture - 10: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. (Chapter-2) Ahmed Mumtaz Mustehsan, CIIT, Islamabad

2 One CPU and many process to run (Multiprogramming) A choice is to be made that which process to run next! Usually many processes in ready state Ready to run on CPU Focus on a single CPU here Need strategies for Allocating CPU time (time quantum) 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 Scheduling Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

Scheduler and Scheduling Algorithms The part of the operating system that makes the choice that which process to run next is called the scheduler. The algorithm used by scheduler is called the scheduling algorithm. Note:Generally the issues that apply to process scheduling also apply to thread scheduling.

Personal Computer User One user who only competes with himself for the CPU Computers have gotten so much faster over the years that the CPU is not a limited resource any more. Hardly any scheduling is required. Scheduling algorithm – Does not Matter For Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad4

Batch servers; Carry out background processing computing insurance claim Time sharing machines; serving interactive users Networked servers; sharing resources You care if you have a bunch of users and/or if the demands of the jobs differ from process to process (I/O bound jobs and CPU bound jobs) Scheduling algorithms – Do Matter For Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad5

Bursts of CPU usage alternate with periods waiting for I/O. (a)A CPU-bound or compute-bound process (b)An I/O-bound process. (enters the bocked state waiting for an external device to complete its work.) Scheduling – Process Behavior Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad6

Scheduler to observe the Process states 7Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

When to Schedule: 1.New process creation (run parent or child; both are in ready state) 2.A process exits (if no process is ready, a system supplied idle process is executed). 3.A process blocks (e.g. on a semaphore, but scheduler does not have the dependency information) 4.I/O interrupt happens (should the blocked process or some other process to run?) When to make scheduling decisions Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad8

non-preemptive scheduling; Picks up a process to run and then just lets it run until: it blocks on I/O or waiting for another process or it voluntarily releases the CPU. not suspended forcefully no scheduling decisions made during clock interrupts preemptive scheduling; picks a process and lets it run for an allocated time quantum. If still running at the end of the time quantum it is suspended and the scheduler picks another process preemptive scheduling requires a clock interrupt that gives control of the CPU back to the scheduler If no clock interrupt then no preemptive scheduling. Preemptive and non-preemptive scheduling Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad9

In different environments different scheduling algorithms are needed: 1.Batch (payroll, inventory, accounts receivable payable, interest calculation, claims processing) 2.Interactive ( users are in big hurry) 3.Real time (Hard and soft deadlines) Categories of Scheduling Algorithms Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad10

When do Batch, Multiprogramming & Multitasking System do Scheduling? 1.When a process terminates 2.When a process switches from running to waiting state e.g., when it does an I/O request 3.When a process switches from running to ready state e.g., when a timer interrupt occurs 4.When a process switches from waiting state to ready state e.g., completion of I/O Batch Multiprogramming Multi-tasking or time-sharing Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad11

Scheduling Algorithm Goals Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad12

First-come first-served Shortest job first Shortest remaining time next Scheduling in Batch Systems Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad13

14 FCFS: First-Come First-Served Ready queue data structure: a FIFO queue – Assuming we have (at least) a multi-programmed system Example – 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 Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

15 Solution: Gantt Chart Method 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 Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

16 FCFS: First-Come First-Served Advantage: Relatively simple algorithm Disadvantage: long waiting times Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

Need to know run times in advance Non pre-emptive algorithm Provably optimal eg 4 jobs with runs times of a,b,c,d First finishes at a, second at a+b, third at a+b+c, last at a+b+c+d (a + a+b + a+ b+c + a+b+c+d ) Mean turnaround time is (4a+3b+2c+d)/4 smallest time has to come first to minimize the mean turnaround time Shortest Job First Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad17

18 SJF: Shortest Job First The job with the shortest next CPU burst time is selected Example (from before): CPU job burst times and ready queue order: P1: 20 P2: 12 P3: 8 P4: 16 P5: 4 Draw Gantt chart and compute the average waiting time given SJF CPU scheduling Assume 0 context switch time Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

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 Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad19

20 SJF Provably shortest average wait time BUT: But how do you know the execution time? Will discuss in detail under Shortest Job Next !!! Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

Round robin Priority Multiple Queues Shortest Process Next Guaranteed Scheduling Lottery Scheduling Fair Share Scheduling Scheduling in Interactive Systems Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad21

Process list-before and after Round-Robin Scheduling Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad22

Quantum too short => too many process switches Quantum too long => wasted CPU time Don’t need to know run times in advance Round robin Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad23

RR (Round Robin) Scheduling 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 TQ is 100ms 24Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

25 RR (Round Robin) Scheduling: Example 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 Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

26 Solution 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 completes 0 P1: 20 P2: 12 P3: 8 P4: 16 P5: 4 ( )/5 = 152/5= 30.2 Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad

Run jobs according to their priority Priority can be static or can be changed dynamically Typically combine RR with priority. Each priority class uses RR inside Priority Scheduling Lecture-10Ahmed Mumtaz Mustehsan, CIIT, Islamabad27