CISC3595 CPU Scheduling.

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.
Chapter 3: CPU Scheduling
Cs238 CPU Scheduling Dr. Alan R. Davis.
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.
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.
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
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU Scheduling Introduction to Operating Systems: Module 13.
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.
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.
5.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 5: Process Scheduling Objectives To introduce CPU scheduling To describe various.
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.
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
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:

CISC3595 CPU Scheduling

Goal: improve CPU utilization Basic Concepts Multiprogramming Load multiple program into memory, and run them simultaneously A process (or kernel-level thread) is executed until it must wait (for I/O completion, child exiting…), OS then switches to run another process (or thread) Goal: improve CPU utilization

Short-term scheduling (CPU scheduling) Process Scheduling Short-term scheduling (CPU scheduling) Select one process from ready queue to be executed Medium-term scheduling, Long-term scheduling What is ready queue ? Contains PCB for all processes that lines up waiting for CPU Not necessarily FIFO queue

Process Control Block (PCB): review Information associated with each process Process state Program counter: address of next instruction to be executed CPU registers: Contents of CPU registers CPU scheduling information Process priority, … Memory-management information Value of base and limit registers, page/segmentation tables (to be studied later) Accounting information Amount of CPU time used … I/O status information I/O device allocated, list of open files… 4

Process Control Block (PCB): review 5

Context Switch: review P0, P1 are running concurrently, i.e., their executions are interleaved. 6

Process Scheduling Queues: review OS maintain multiple process queues for scheduling purpose: Job queue – set of all processes in the system Ready queue – set of all processes residing in main memory, ready and waiting to execute Device queues – set of processes waiting for an I/O device Processes migrate among the various queues 7

Ready Queue And I/O Device Queues: review 8

CPU and I/O Bursts Process execution consists of a cycle of CPU execution and I/O wait CPU burst: Data processing, calculation E.g. sorting, searching I/O burst: Read from I/O device File system access What about the myCopy program?

Histogram of CPU-burst Times A large number short CPU burst Small number of long CPU burst

CPU Scheduler Selects one process from ready queue, and allocates CPU to execute it When to make CPU scheduling : 1. a process switches from running to waiting state 2. a process switches from running to ready state 3. a Process switches from waiting to ready 4. a process terminates Nonpreemptive scheme: only run CPU scheduling under 1 and 4 i.e., current running process gives up CPU Otherwise, preemptive scheduling scheme

Dispatcher module Scheduler => Dispatcher Dispatcher module: gives control of CPU to the process selected by short-term scheduler 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 Including context switching latency

CPU Scheduling Algorithms First-come, First-Served Scheduling Shortest-Job-First Scheduling Priority Scheduling Round-Robin Scheduling Multilevel Queue Scheduling Multilevel Feedback Queue Scheduling

CPU Scheduling Criteria CPU utilization – percentage of time CPU is busy (not idle) Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process From process submission to time of completion Waiting time – amount of time a process has been waiting in ready queue Response time – amount of time it takes from when a request was submitted until first response is produced (for time-sharing environment)

Optimization Criteria Maximize CPU utilization Maximize throughput Minimize turnaround time Minimize waiting time Minimize response time Achieved performance measure is random variable depending on the statistics of workload Usually, optimize average measure (average case performance) Sometimes, optimize minimum or maximum value (worst case performance) Or sometimes, variance of the measure

First-Come First-Served Scheduling Serve processes in the order of arrivals, non- preemptive Process Burst Time P1 24 P2 3 P3 3 Suppose that processes arrive in the order: P1 , P2 , P3 Gantt Chart for FCFS 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 (Cont.) Process Burst Time P1 24 P2 3 P3 3 Suppose that processes arrive in the order P2 , P3 , P1 The Gantt chart for FCFS schedule is: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Short process behind long process P1 P3 P2 6 3 30

Process Burst Time P1 10 P2 4 P3 6 P4 5 Exercise Draw Gantt chart for FCFS schedule for the following set of processes arrived in the order of P1, P2, P3, P4. Process Burst Time P1 10 P2 4 P3 6 P4 5 Average waiting time What order of arrival of these processes will give smallest average waiting time ?

FCFS Scheduling A Convoy effect happens when What will happen if the system has one CPU-bound process many I/O-bound processes A Convoy effect happens when a set of processes need to use a resource for a short time one process holds the resource for a long time, blocking all of the other processes Result: poor utilization of the other resources in the system. Other problems of FCFS ? Ill-suited for time-sharing systems (interactive environment)

Shortest-Job-First (SJF) Scheduling Schedule process with shortest-next-CPU-burst (i.e., the length/duration of next CPU burst) 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. Also called Shortest-Remaining-Time-First (SRTF)

Shortest-Job-First (SJF) Scheduling Among non-preemptive scheduling algorithms, SJF achieves minimum average waiting time for a given set of processes that arrives at the same time. Suppose the duration of CPU burst of n processes is l1,l2,…ln , li<lj for i<j, (it’s sorted in ascending order Assume the schedule that achieves minimum average waiting time is not SJF, it means that there exists at least a pair of processes, j and k, such that lj<lk, but process j is scheduled to run after process k The schedule: … lk … lj … We can switch lk and lj to decrease avg. waiting time. Assumption is wrong, and SJF achieves minimum avg. waiting time. 21 21

Example of Non-Preemptive SJF 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

Example of Preemptive SJF 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

Length of Next CPU Burst ? Predict next CPU burst length Using length of previous CPU bursts, using exponential moving averaging

Exponential Average Prediction

Examples of Exponential Averaging  =0 n+1 = n,, recent history does not count  =1 n+1 =  tn, only previous CPU burst counts Expand formula: n+1 =  tn+(1 - ) tn -1 + … +(1 -  )j  tn -j + … +(1 -  )n +1 0 each successive term has less weight than its predecessor Both  and (1 - ) are less than or equal to 1

Priority Scheduling Can be Preemptive or Nonpreemptive CPU is allocated to process with the highest priority A priority number (integer) is associated with each process smallest integer  highest priority Can be Preemptive or Nonpreemptive Preemptive: newly arrived higher priority process preempt current running process Priority can be internal or external Internal: decided based on some quantities of process resource requirement, ratio of I/O burst and avg burst, next CPU bursts length External: importance, funds paid,…

Priority Scheduling Problem of priority scheduling Solution Indefinite blocking, starvation: low priority processes may never execute Solution Aging – as time progresses increase the priority of the waiting process E.g., increase the priority of a waiting process by 1 every 15 minutes… 28 28

Round Robin (RR) So far, we see FCFS, SJF, Priority Scheduling How they perform for time-sharing system ? 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 ready queue and time quantum is q, then each process gets 1/n of CPU time in chunks of at most q time units at once. No process waits more than (n- 1)q time units.

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 P1 P2 P3 P4 20 37 57 77 97 117 121 134 154 162

Round Robin (RR) Downside of having very small q ? Choosing q, time quantum q large  FIFO q small  processor sharing Downside of having very small q ? q must be large with respect to context switch, otherwise overhead is too high 31 31

Quantum and Context Switch

Turnaround Time Varies vs Time Quantum

Multilevel Queue Ready queue is partitioned into separate queues Realtime process foreground (interactive) process background (batch) process Each queue has its own scheduling algorithm Realtime – Earliest Deadline First foreground – RR background – FCFS Scheduling must be done between queues Fixed priority scheduling; (i.e., serve all from realtime, then foreground, then from background). Low priority process might experience starvation Time slice – each queue gets a certain amount of CPU time i.e., 80% to foreground in RR, 20% to background in FCFS

Multilevel Queue Scheduling How do we assign process to appropriate queue ?

Multilevel Feedback Queue Scheduling Compared to multilevel queue scheduling A process can move between various queues; aging can be implemented this way To favor shorter jobs, or process with short CPU burst Penalize process that have been run longer by moving it to lower priority queue … Feed the process back to a different queue

Example of Multilevel Feedback Queue I/O, terminate Process becomes ready Timer goes off I/O, terminate I/O, terminate Q0 – RR with quantum 8 milliseconds Q1 – RR quantum 16 milliseconds Q2 – FCFS Strict priority among queues Q1>Q2>Q3

Multilevel Feedback Queue Effect of multilevel feedback queue I/O bound and interactive processes stay in highest priority queue CPU bound process stays in low priority queue Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade 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

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Two appraches Symmetric multiprocessing: each processor is self-scheduling Share a common queue, or private queue Asymmetric multiprocessing: one processor (master server) handles scheduling decision, I/O Processing, and other system activities – only one processor accesses the system data structures, alleviating the need for data sharing

Multiple-Processor Scheduling: considerations Recall L1 cache ? To avoid cache invalidation and repopulation, scheduling taking into account processor affinity: a process has an affinity to the processor that it is currently running on Avoid migrating a process to other processor Load balancing: keep workload balanced among processors Needed if each processor has its private queue Push migration and pull migration

Real-Time Scheduling Hard real-time systems – required to complete a critical task within a guaranteed amount of time Soft real-time computing – requires that critical processes receive priority over less fortunate ones

Thread Scheduling Local Scheduling – How the threads library decides which thread to put onto an available LWP Global Scheduling – How the kernel decides which kernel thread to run next

Case studies: Windows XP and Linux Homework: comparing CPU scheduling used by Windows XP and Linux Details to come Evaluation of different CPU scheduling algorithms By hand Through mathematical model Through simulation studies Actual Implementation and measurement