Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.

Slides:



Advertisements
Similar presentations
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 17 Scheduling III.
Advertisements

Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling.
A. Frank - P. Weisberg Operating Systems Advanced 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.
Scheduling Algorithms
CPU Scheduling Algorithms
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.
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.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
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
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
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
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.
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.
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.
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,
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.
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
3. CPU Scheduling. CPU Scheduling Process execution – a cycle of CPU execution and I/O wait – figure Preemptive Non-Preemptive.
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.
CPU Scheduling Algorithms CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
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.
CPU SCHEDULING.
Chapter 5a: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter5: CPU Scheduling
Chapter 5: CPU Scheduling
CPU Scheduling: Basic Concepts
Presentation transcript:

Operating Systems Scheduling

Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution –The Process is selected from the Ready queue Ready queue is not necessarily a FIFO queue It can be –Priority based –A Tree –Unordered linked list etc

When to select a new process to Run Four circumstances New Exit Admit Release Running Ready Dispatch Time-out Blocked Event occurs Event wait 1. Wait for I/O/ waitpid()/ P()/ Acquire() etc 2. Interrupt occurs, move from Running to Ready 3. Event I/O Completion/ exit(0) / V() / Release() 4. A Process terminates

Only the case 1 and 4 Must select a new process, if any, from the Ready Queue Non Preemptive Scheduling New Exit Admit Release Running Ready Dispatch Time-out Blocked Event occurs Event wait 1. Wait for I/O/ waitpid()/ P()/ Acquire() etc 4. A Process terminates

Non Preemptive Scheduling Once the CPU has been allocated to a process The process keeps it until –It Terminates –Or has to wait for: I/O Mutex Child process Semaphore Conditional Variables etc There is no way, to get the CPU back, FORCEFULLY

All four cases, 1,2,3 and 4 Preemptive Scheduling New Exit Admit Release Running Ready Dispatch Time-out Blocked Event occurs Event wait 1. Wait for I/O/ waitpid()/ P()/ Acquire() etc 4. A Process terminates 2. Interrupt occurs, move from Running to Ready 3. Event I/O Completion/ exit(0) / V() / Release()

All four cases, 1,2,3 and 4 Preemptive Scheduling New Exit Admit Release Running Ready Dispatch Time-out Blocked Event occurs Event wait 2. Interrupt occurs, move from Running to Ready 3. Event I/O Completion/ exit(0) / V() / Release() In case of 2 and 3, there is a choice Whether to continue, with the same process or select a new one from the ready queue

Scheduling Issues Fairness –Don’t starve process Priorities –Most important first Deadlines –Task X must be done by time t Optimization –Throughput, response time Reality - No universal scheduling policy Many models

Optimization Criteria CPU Utilization –Keep the CPU as busy as possible –May range from 0% to 100% Throughput –Number of processes completed per unit time –E.g. long processes 1 process / hr –Short processes 10 processes / hr

Turnaround Time –How long it take to execute a Process –Turnaround = Completion_Time – Submission_Time –Turnaround = Wait_Time GetIntoMemory + Wait_Time ReadyQueue + Wait_Time BlockQueue + CPU_Execution_Time Optimization Criteria

Scheduling Algorithm does not effect the waiting time in Block Queue It only effect the Waiting Time in the Ready Queue Waiting Time –Sum of the periods spent waiting in the Ready Queue

Optimization Criteria Turnaround Time is not a good criteria for Interactive Systems A process may –Produce “Some” output –Computes new results, while previous results are output to the user Response Time Response_Time = First_Response_Start_Time – Submission_Time

Optimization Criteria - Summary We would like to Maximize –CPU Utilization –Throughput And Minimize –Turnaround Time –Waiting Time –Response Time

Scheduling Algorithms First come, First serve Shortest Job First Priority Scheduling Round-Robin Scheduling Multi-level Queue Scheduling Multi-level Feed back queue Scheduling

First come, First serve Simplest scheduling algorithm: –Run jobs in order that they arrive Uni-programming: –Run until done Multi-programming: –Run until done or Blocks on I/O Nonpreemptive –A Process keeps CPU until done or I/O Advantage: –Simplicity

First come, First serve Disadvantage –Wait time depends on arrival order –Unfair to later jobs –(worst case: long job arrives first) Three jobs (times: A=100, B=1, C=2) arrive in the order A, B, C time cpu A BC Average Waiting Time = ( ) / 3 = 67

First come, First serve Average Waiting Time = ( ) / 3 = 1.33 Now if they arrive in the order B, C, A cpu time A BC

FCFS Convoy effect A CPU bound job will hold CPU until –Terminates –Or it causes an I/O burst Rare occurrence, since the thread is CPU-bound Long periods where no I/O requests issued, and CPU held Result: –Poor I/O device utilization

FCFS Convoy effect : Example One CPU bound job, many I/O bound CPU bound runs –I/O jobs blocked in ready queue –I/O devices idle CPU bound blocks –I/O bound job(s) run, quickly block on I/O CPU bound runs again I/O of the I/O bound jobs completes CPU bound still runs while I/O devices idle (continues…)

Round robin (RR) Solution to job monopolizing CPU? Interrupt it. –Run job for some “time slice,” –When time is up, or it blocks –It moves to back of a FIFO queue Advantage: –Fair allocation of CPU across jobs –Low average waiting time when job lengths vary CPU time A B C A C A What is avg completion time? = ( ) / 3

Round Robin’s Disadvantage Good for Varying sized jobs But what about same-sized jobs? Assume 2 jobs of time =100 each: time CPU A B A B A B A B A Avg completion time? ( ) / 2 = 200 How does this compare with FCFS for same two jobs? ( ) / 2 = 150

RR Time slice tradeoffs Performance depends on length of the time slice Context switching isn’t a free operation. If timeslice time is set too high (attempting to amortize context switch cost) –You get FCFS. –i.e. Processes will finish or block before their slice is up anyway If it’s set too low you’re spending all of your time context switching between threads.

Priority scheduling Not all jobs equal –So: rank them. Each process has a priority –Run highest priority ready job in system Priorities can be static or dynamic or both Among the Processes of equal priority –Round robin –FCFS

Priority scheduling Priority scheduling can be Preemptive or Non- Preemptive When a process arrives and enters the Ready Queue Its priority is compared with the currently Running Process If Higher –Preemptive Scheduling Run the New Thread –Non-Preemptive Scheduling Continue running the Current Thread

Priority scheduling High priority always runs over low priority. Starvation –A low Priority process may indefinitely wait for the CPU Solution: Aging –Gradually increase the Priority of processes that wait in the system for a long time. Which type of processes should be given Higher Priority: –I/O Bound??? –CPU Bound??? In order to keep I/O busy increase priority for jobs that often block on I/O

Shortest Job First (SJF) Consider 4 jobs, a, b, c, d, run in lexical order CPU time D ACB a a+b a+b+c a+b+c+d  The first (a) finishes at time a  The second (b) finishes at time a+b  The third (c) finishes at time a+b+c  The fourth (d) finishes at time a+b+c+d  Therefore average completion = (a + ( a + b) + (a +b+c) + (a + b + c + d))/4 = (4a+3b+2c+d)/4  Minimizing this requires a <= b <= c <= d.  or Shortest Job First

Shortest Job First (SJF) Run whatever job has smallest next CPU burst Can be pre-emptive or non-pre-emptive Example: same jobs (given jobs A, B, C) cpu time A BC Average completion = ( ) / 3 = ~35

ProcessArrival TimeBurst Time P P P P SJF (non-preemptive) Example of Non-Preemptive SJF P1P1 P3P3 P2P P4P4 812 Average waiting time = ( )/4 = 4

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

I/O idle ~90% RR with 100ms time slice: SJF vs. RR Two processes P1, P2 P1 P2 I/O idle P2 100ms 1ms P2 100ms 1ms P1 SJF Offers better I/O utilization blocked 10ms 1ms 10ms 1ms 10ms 1ms …. blocked I/O busy I/O idle...

Shortest Job First The most important issue in SJF –Accuracy in estimation of Job length

Multilevel Queue Scheduling Sometimes processes are classified into groups One classification can be: –Foreground (or Interactive) processes –Background (or batch) processes Different response time requirement => Different scheduling requirements Foreground processes usually have higher priorities

Multilevel Queue Scheduling (MQS) Partition the Ready queue into a number of queues Processes are permanently assigned to one of the queues Each queue may have its own scheduling algorithm In addition, there must be scheduling between the queues

Multilevel Queue Scheduling Example: Foreground Processes Background Processes FCFS RR Priority Scheduling

Multilevel Queue Scheduling Example: System Processes Interactive Processes Interactive editing Processes Student Processes Batch Processes

Multilevel Queue Scheduling System Processes Interactive Processes Interactive editing Processes Student Processes Batch Processes Each queue may have absolute priority over the other queue Alternatively, Time slice between the queues Time slots can be equal Or 80% time for Foreground processes 20% time for Background processes

Multilevel Feedback Queue Scheduling In Multilevel Queue a process is permanently assigned to a queue The queue to which a process should belong is decided statically Multilevel Feedback Queue Scheduling: –A Process may move between the Queues –Aging can be implemented this way.

Multilevel Feedback Queue Scheduling Multilevel-feedback-queue scheduler defined by: –Number of queues –Scheduling algorithms for each queue –Method used to select when upgrade process –Method used to select when demote process –Method used to determine which queue a process will enter when that process needs service

Multilevel Feedback Queue Scheduling Example –If a process used too much CPU time, then move it to a lower-priority queue –If a process waits too long in a lower priority queue, then move it to a higher priority queue

Multilevel Feedback Queue Scheduling Example: Three queues:  Q 0 – RR time quantum 8 milliseconds  Q 1 – RR time quantum 16 milliseconds  Q 2 – FCFS Scheduling  A new job enters queue Q 0 served by RR.  Then job receives 8 milliseconds.  If not finished in 8 milliseconds, moved to Q 1.  At Q 1 job served by RR.  Then receives 16 milliseconds.  If not complete, preempted and moved to Q 2.