CPU Scheduling.

Slides:



Advertisements
Similar presentations
PROCESS SCHEDULING AND SYNCRONIZATION
Advertisements

CPU Scheduling.
Chapter 5: CPU Scheduling
Schedulers Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue. Short-term scheduler (or CPU scheduler)
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
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.
CPU Scheduling CS 3100 CPU Scheduling1. Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various.
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.
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.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
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 – 7 th Edition, Feb 2, 2005 Basic Concepts Maximum CPU utilization.
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.
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.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 6 CPU Scheduling.
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
Chapter 6: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Operating System Concepts
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
Lecture 2 Part 3 CPU Scheduling
Operating System , Fall 2000 EA101 W 9:00-10:00 F 9:00-11:00
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

Outline Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation

Basic Concepts multiprogramming has been introduced in order to maximize CPU utilization CPU–I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait. CPU and I/O burst distribution Can be viewed as a random variable Can be characterized with an empirical and/or theoretical probability distribution

Alternating Sequence of CPU And I/O Bursts

Histogram of CPU-burst Times

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 nonpreemptive. Once a process is given the CPU it holds it until it terminates or changes state to waiting All other scheduling is preemptive.

Dispatcher The Dispatcher module gives control of the CPU to the process selected by the CPU (short-term) scheduler The dispatcher’s function involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency The time it takes for the dispatcher to stop one process and start running running.

Scheduling Algorithms Before we look into scheduling algorithms need to set Criteria (measures) and objectives that will be used in designing and evaluating such algorithms Scheduling algorithms should optimize some objectives derived from certain criteria Need to understand various properties of scheduling algorithms so that we can choose an algorithm that is most suited to a particular computing environment

Scheduling Criteria CPU utilization Throughput Turnaround time Percent of time the CPU is busy executing processes Throughput number of processes that complete their execution per time unit Turnaround time 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 (program) was submitted until the first response is produced, Does not include output time

Optimization Objectives Maximize CPU utilization Maximize throughput Minimize the maximum turnaround time Minimize average waiting time Minimize average response time Minimize the variance of response time Etc We will consider Minimizing the average waiting time

First-Come First-Served (FCFS) Scheduling Process requesting the CPU first gets it first Simple to implement with a single FIFO queue of ready processes Link their PCB’s into that queue Non-preemptive scheduling algorithm

FCFS Scheduling Example Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive at time 0 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

FCFS Scheduling Example Suppose that the processes arrive in the 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 Average waiting time depends on order of processes in FIFO queue Convoy effect Arises when a number of short (I/O bound) processes wait behind a long (CPU bound) process P1 P3 P2 6 3 30

Shortest-Job-First (SJF) 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: Non-preemptive once the CPU is 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 the remaining time of the current executing process, preempt it. This scheme is known as the Shortest-Remaining-Time-First (SRTF). SJF is optimal It gives the minimum average waiting time for a given set of processes.

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

Preemptive SJF Example Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 4 1 P4 5 4 SJF (preemptive) Average waiting time = (9 + 1 + 0 +2)/4 =3 P1 P3 P2 4 2 11 P4 5 7 16

Difficulties with SJF Length of next CPU burst is generally not known ahead of time Can only estimate the length of the next CPU burst Need appropriate estimating functions Can be done by using the length of previous CPU bursts, using exponential averaging.

Prediction of the Length of the Next CPU Burst

Examples of Exponential Averaging  =0 n+1 = n Recent history does not count.  =1 n+1 = tn Only the actual last CPU burst counts. If we expand the formula, we get: n+1 =  tn+(1 - )  tn -1 + … +(1 -  )j  tn -1 + … +(1 -  )n=1 tn 0 Since both  and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor.

Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority Here, we use the convention that smallest integer  highest priority. It can be Preemptive Non-preemptive SJF is a priority scheduling where priority is determined by the predicted next CPU burst time. Can cause Starvation A low priority processes may never execute Aging is a technique that can be used to avoid starvation as time progresses increase the priority of processes waiting for the CPU

Round Robin (RR) Scheduling Each process gets a small unit of CPU time (time quantum or slice), usually 10-100 milliseconds. After this time slice 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. When deciding on the time slice need to consider the overhead due to the dispatcher Performance characteristics q large  FIFO q small  q must be large with respect to context switch, otherwise overhead is too high.

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

Time Quantum and Context Switch Time

Turnaround Time Varies With The Time Quantum

Multilevel Queue Scheduling Ready queue is partitioned into separate queues foreground (interactive) background (batch) Each queue has its own scheduling algorithm foreground – RR background – FCFS

Multilevel Queue Scheduling

Multilevel Queue Scheduling Scheduling must be done between the queues. Fixed priority scheduling 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; i.e., 80% to foreground in RR, 20% to background in FCFS

Multilevel Feedback Queue Scheduling A process can move between the various queues aging can be implemented this way. Multilevel-feedback-queue scheduler is defined by the following parameters number of queues scheduling algorithms for each queue method used to determine when to promote a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service

Multilevel Feedback Queue Scheduling Example

Multilevel Feedback Queue Scheduling Example Three queues Q0 – time quantum 8 milliseconds Q1 – time quantum 16 milliseconds Q2 – FCFS Scheduling A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1. At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.

Multiple-Processor Scheduling CPU scheduling is more complex when multiple CPUs are available. Homogeneous processors All processors are identical within the multiprocessor system Load sharing Idle processors share the load of busy processors Maintain a single ready queue shared among all the processors Symmetric multiprocessing Each processor schedules a process autonomously from the shared ready queue Asymmetric multiprocessing only one processor accesses the system data structures, alleviating the need for data sharing.

Real-Time Scheduling Hard real-time systems Soft real-time computing When it is required to complete a critical task within a guaranteed amount of time Soft real-time computing When it is required that critical processes receive priority over less fortunate ones. For soft real-time scheduling System must have priority scheduling The dispatch latency must be small Problem caused by the fact that many OSs wait for a context switch until either a system call completes or an I/O blocks

Keeping the Dispatch Latency Small Introduce preemption points within the kernel Where it is safe to preempt a system call by a higher priority process Trouble is only few such points can be practically added Make the entire kernel preemptive Need to ensure that it is safe for a higher priority process to access shared kernel data structures Complex method that is widely used What happens when a high priority process waits for lower priority processes to finish using a shared kernel data structure (priority inversion)? Priority inheritance

Dispatch Latency

Evaluating Scheduling Algorithms Deterministic modeling take a particular predetermined workload and determine the performance of each algorithm for that workload Queueing Models Use mathematical formulas to analyze the performance of algorithms under some (simple and possible unrealistic) workloads Simulation Models Use probabilistic models of workloads Use workloads captured in a running system (traces) Implementation

Queueing Models Assuming that Process inter-arrival times and CPU burst times are independent identical exponentially distributed random variables FCFS scheduling

Evaluation of CPU Scheduling Algorithms by Simulation

Solaris 2 Scheduling

Windows 2000 Priorities

Linux Scheduling Two algorithms: time-sharing and real-time 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 Soft real-time Posix.1b compliant – two classes FCFS and RR Highest priority process always runs first

The Relationship Between Priorities and Time-slice length

List of Tasks Indexed According to Prorities