CPU Scheduling Chapter 5. CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Thread Scheduling UNIX.

Slides:



Advertisements
Similar presentations
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.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5-CPU Scheduling
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 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 Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
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: 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
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
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.
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.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
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.
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.
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.
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
Chapter 6: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Outline Scheduling algorithms Multi-processor scheduling
Chapter 5: CPU Scheduling
Shortest-Job-First (SJR) Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Presentation transcript:

CPU Scheduling Chapter 5

CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Thread Scheduling UNIX example

Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait CPU times are generally much shorter than I/O times.

CPU-I/O Burst Cycle Process A Process B

Histogram of CPU-burst Times

Schedulers Process migrates among several queues –Device queue, job queue, ready queue Scheduler selects a process to run from these queues Long-term scheduler: –load a job in memory –Runs infrequently Short-term scheduler: –Select ready process to run on CPU –Should be fast Middle-term scheduler –Reduce multiprogramming or memory consumption

CPU Scheduler CPU scheduling decisions may take place when a process: 1.Switches from running to waiting state (by sleep). 2.Switches from running to ready state (by yield). 3.Switches from waiting to ready (by an interrupt). 4.Terminates (by exit). Scheduling under 1 and 4 is nonpreemptive. All other scheduling is preemptive.

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 Dispatch latency – time it takes for the dispatcher to stop one process and start another running

Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time (TAT) – amount of time to execute a particular process 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 (for time-sharing environment)

“The perfect CPU scheduler” Minimize latency: response or job completion time Maximize throughput: Maximize jobs / time. Maximize utilization: keep I/O devices busy. –Recurring theme with OS scheduling Fairness: everyone makes progress, no one starves

Scheduling Algorithms FCFS First-come First-served (FCFS) (FIFO) –Jobs are scheduled in order of arrival –Non-preemptive Problem: –Average waiting time depends on arrival order –Troublesome for time-sharing systems Convoy effect short process behind long process Advantage: really simple!

First Come First Served Scheduling Example:ProcessBurst Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 Suppose that the processes arrive in the order: P 2, P 3, P 1. P1P1 P3P3 P2P P1P1 P2P2 P3P Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: ( )/3 = 17 Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: ( )/3 = 3

Shortest-Job-First (SJR) Scheduling Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time Two schemes: –nonpreemptive – 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 current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF) SJF is optimal – gives minimum average waiting time for a given set of processes

Shortest Job First Scheduling Example:ProcessArrival Time Burst Time P 1 07 P 2 24 P 3 41 P 4 54 Non preemptive SJF P1P1 P3P3 P2P2 7 P 1 (7) 160 P4P4 812 Average waiting time = ( )/4 = P 2 (4) P 3 (1) P 4 (4) P 1 ‘s wating time = 0 P 2 ‘s wating time = 6 P 3 ‘s wating time = 3 P 4 ‘s wating time = 7

Shortest Job First Scheduling Cont’d Example:ProcessArrival Time Burst Time P 1 07 P 2 24 P 3 41 P 4 54 Preemptive SJF P1P1 P3P3 P2P P4P4 57 P2P2 P1P1 16 Average waiting time = ( )/4 = 3 P 1 (7) P 2 (4) P 3 (1) P 4 (4) P 1 ‘s wating time = 9 P 2 ‘s wating time = 1 P 3 ‘s wating time = 0 P 4 ‘s wating time = 2 P 1 (5) P 2 (2)

Shortest Job First Scheduling Cont’d Optimal scheduling However, there are no accurate estimations to know the length of the next CPU burst

Optimal for minimizing queueing time, but impossible to implement. Tries to predict the process to schedule based on previous history. Predicting the time the process will use on its next schedule: t( n+1 ) = w * t( n ) + ( 1 - w ) * T( n ) Here: t(n+1) is time of next burst. t(n) is time of current burst. T(n) is average of all previous bursts. W is a weighting factor emphasizing current or previous bursts. Shortest Job First Scheduling Cont’d

A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer  highest priority in Unix but lowest in Java). –Preemptive –Non-preemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem  Starvation – low priority processes may never execute. Solution  Aging – as time progresses increase the priority of the process. Priority Scheduling

Round Robin (RR) Each process gets a small unit of CPU time (time quantum), usually 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.

time quantum = 20 ProcessBurst TimeWait Time P = 81 P P = 94 P = 97 Round Robin Scheduling P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P Average wait time = ( )/4 = P 1 (53) P 2 (17) P 3 (68) P 4 (24) P 1 (33) P 1 (13) P 3 (48) P 3 (28) P 3 (8) P 4 (4)

Typically, higher average turnaround than SJF, but better response. Performance –q large  FCFS –q small  q must be large with respect to context switch, otherwise overhead is too high. Round Robin Scheduling

Turnaround Time Varies With The Time Quantum TAT can be improved if most process finish their next CPU burst in a single time quantum.

Multilevel Queue Ready queue is partitioned into separate queues: EX: foreground (interactive) background (batch) Each queue has its own scheduling algorithm EX –foreground – RR –background – FCFS Scheduling must be done between the queues –Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. –Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; EX 80% to foreground in RR 20% to background in FCFS

Multilevel Queue Scheduling

Multi-level Feedback Queues Implement multiple ready queues –Different queues may be scheduled using different algorithms –Just like multilevel queue scheduling, but assignments are not static Jobs move from queue to queue based on feedback –Feedback = The behavior of the job, EX does it require the full quantum for computation, or does it perform frequent I/O ? Need to select parameters for: –Number of queues –Scheduling algorithm within each queue –When to upgrade and downgrade a job

Example of Multilevel Feedback Queue Three queues: –Q 0 – RR with time quantum 8 milliseconds –Q 1 – RR time quantum 16 milliseconds –Q 2 – FCFS Scheduling –A new job enters queue Q 0 which is served FCFS. When it gains CPU, job receives 8 milliseconds (RR). If it does not finish in 8 milliseconds, job is moved to queue Q 1. –At Q 1 job is again served FCFS and receives 16 additional milliseconds (RR). If it still does not complete, it is preempted and moved to queue Q 2. –AT Q 2 job is served FCFS

Multilevel Feedback Queues

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available  Different rules for homogeneous or heterogeneous processors. Load sharing in the distribution of work, such that all processors have an equal amount to do. Asymmetric multiprocessing – only one processor accesses the system data structures, alleviating the need for data sharing Symmetric multiprocessing (SMP) – each processor is self-scheduling  Each processor can schedule from a common ready queue OR each one can use a separate ready queue.

Thread Scheduling On operating system that support threads the kernel-threads (not processes) that are being scheduled by the operating system. Local Scheduling (process-contention-scope PCS )– How the threads library decides which thread to put onto an available LWP PTHREAD_SCOPE_PROCESS Global Scheduling (system-contention-scope SCS )– How the kernel decides which kernel thread to run next PTHREAD_SCOPE_PROCESS

Linux Scheduling Two algorithms: time-sharing and real-time Time-sharing –Prioritized credit-based – process with most credits is scheduled next –Credit subtracted when timer interrupt occurs –When credit = 0, another process chosen –When all processes have credit = 0, recrediting occurs Based on factors including priority and history Real-time –Defined by Posix.1b –Real time Tasks assigned static priorities. All other tasks have dynamic (changeable) priorities.

The Relationship Between Priorities and Time-slice length

List of Tasks Indexed According to Prorities

Conclusion We’ve looked at a number of different scheduling algorithms. Which one works the best is application dependent. –General purpose OS will use priority based, round robin, preemptive –Real Time OS will use priority, no preemption.

References Some slides from –Text book slides –Kelvin Sung - University of Washington, Bothell –Jerry Breecher - WPI –Einar Vollset - Cornell University