SchedulingCS-3013 C-term 20081 Scheduling The art and science of allocating the CPU and other resources to processes (Slides include materials from Operating.

Slides:



Advertisements
Similar presentations
CPU Scheduling.
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.
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 (continued)CS-3013 C-term Scheduling (continued) CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System.
Scheduling in Batch Systems
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
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.
SchedulingCS-3013 A-term Scheduling The art and science of allocating the CPU and other resources to processes & threads CS-3013 Operating Systems.
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
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
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  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.
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.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 6: CPU Scheduling
CPU Scheduling G.Anuradha
Module 5: CPU Scheduling
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Scheduling The art and science of allocating the CPU and other resources to processes (Slides include materials from Operating System Concepts, 7th ed.,
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Presentation transcript:

SchedulingCS-3013 C-term Scheduling The art and science of allocating the CPU and other resources to processes (Slides include materials from Operating System Concepts, 7 th ed., by Silbershatz, Galvin, & Gagne and from Modern Operating Systems, 2 nd ed., by Tanenbaum)

SchedulingCS-3013 C-term Why Scheduling? We know how to switch the CPU among processes or threads, but … How do we decide which to choose next? Reading Assignment – Chapter 5 of Silbershatz –Especially §§5.1–5.5

SchedulingCS-3013 C-term Bursts of CPU usage alternate with periods of I/O wait –a CPU-bound process (a) –an I/O bound process (b) Which process should have preferred access to CPU? Which process should have preferred access to I/O or disk? Why? Example

SchedulingCS-3013 C-term Alternating Sequence of CPU And I/O Bursts

SchedulingCS-3013 C-term Histogram of CPU-burst Times

SchedulingCS-3013 C-term 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 non-preemptive All other scheduling is preemptive

SchedulingCS-3013 C-term Dispatcher Dispatcher module gives control of CPU to the process selected by the scheduler:– switching context (registers, etc.) Loading the PSW to switch to user mode and restart the selected program Dispatch latency – time it takes for the dispatcher to stop one process and start another one running Non-trivial in some systems

SchedulingCS-3013 C-term Potential Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process Waiting time – amount of time process has been waiting in the ready queue Response time – amount of time from request submission until first response is produced

SchedulingCS-3013 C-term Scheduling – Policies Issues –Fairness – don’t starve process –Priorities – most important first –Deadlines – task X must be done by time t –Optimization – e.g. throughput, response time Reality — No universal scheduling policy –Many models –Determine what to optimize - metrics –Select an appropriate one and adjust based on experience

SchedulingCS-3013 C-term Scheduling – Metrics Simplicity – easy to implement Job latency – time from start to completion Interactive latency – time from action start to expected system response Throughput – number of jobs completed Utilization – keep processor and/or subset of I/O devices busy Determinism – insure that jobs get done before some time or event Fairness – every job makes progress

SchedulingCS-3013 C-term Some Process Scheduling Strategies First-Come, First-Served (FCFS) Round Robin (RR) Shortest Job First (SJF) –Variation: Shortest Completion Time First (SCTF) Priority Real-Time

SchedulingCS-3013 C-term Scheduling Policies First Come, First Served (FCFS) Easy to implement Non-preemptive –I.e., no task is moved from running to ready state in favor of another one Minimizes context switch overhead

SchedulingCS-3013 C-term Process States

SchedulingCS-3013 C-term Scheduling Policies First Come, First Served (FCFS) Easy to implement Non-preemptive –I.e., no task is moved from running to ready state in favor of another one Minimizes context switch overhead

SchedulingCS-3013 C-term Example: FCFS Scheduling ProcessBurst Time P 1 24 P 2 3 P 3 3 Suppose that processes arrive in the order: P 1, P 2, P 3 The time line for the schedule is:– Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: ( )/3 = 17 P1P1 P2P2 P3P

SchedulingCS-3013 C-term Example: FCFS Scheduling (continued) Suppose instead that the processes arrive in the order P 2, P 3, P 1 The time line for the schedule becomes: Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: ( )/3 = 3 Much better than previous case Previous case exhibits the convoy effect: –short processes stuck behind long processes P1P1 P3P3 P2P

SchedulingCS-3013 C-term FCFS Scheduling (summary) Favors compute bound jobs or tasks Short tasks penalized –I.e., once a longer task gets the CPU, it stays in the way of a bunch of shorter task Appearance of random or erratic behavior to users Does not help in real situations

SchedulingCS-3013 C-term Scheduling Policies – Round Robin Round Robin (RR) –FCFS with preemption based on time limits –Ready processes given a quantum of time when scheduled –Process runs until quantum expires or until it blocks (whichever comes first) –Suitable for interactive (timesharing) systems –Setting quantum is critical for efficiency

SchedulingCS-3013 C-term Round Robin (continued) Each process gets small unit of CPU time (quantum), usually milliseconds. –After quantum has elapsed, process is preempted and added to end of ready queue. If n processes in ready queue and quantum = q, then each process gets 1/n of CPU time in chunks of  q time units. –No process waits more than (n-1)q time units. Performance –q large  equivalent to FCFS –q small  may be overwhelmed by context switches

SchedulingCS-3013 C-term Example of RR with Time Quantum = 20 ProcessBurst Time P 1 53 P 2 17 P 3 68 P 4 24 The time line is: Typically, higher average turnaround than SJF, but better response P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P

SchedulingCS-3013 C-term Comparison of RR and FCFS Assume: 10 jobs each take 100 seconds – look at when jobs complete FCFS – job 1: 100s, job 2: 200s, … job 10:1000s RR –1 sec quantum –Job 1: 991s, job 2 : 992s … RR good for short jobs – worse for long jobs

SchedulingCS-3013 C-term Application of Round Robin Time-sharing systems Fair sharing of limited resource –Each user gets 1/n of CPU Useful where each user has one process to schedule –Very popular in 1970s, 1980s, and 1990s Not appropriate for desktop systems! –One user, many processes with very different characteristics

SchedulingCS-3013 C-term Shortest-Job-First (SJF) Scheduling For each process, identify duration (i.e., length) of its next CPU burst. Use these lengths to schedule process with shortest burst Two schemes:– –Non-preemptive – once CPU given to the process, it is not preempted until it 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 known as the Shortest-Remaining-Time-First (SRTF) …

SchedulingCS-3013 C-term Shortest-Job-First (SJF) Scheduling (cont.) … SJF is provably optimal – gives minimum average waiting time for a given set of process bursts –Moving a short burst ahead of a long one reduces wait time of short process more than it lengthens wait time of long one.

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

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

SchedulingCS-3013 C-term Determining Length of Next CPU Burst Predict from previous bursts exponential averaging Let –t n = actual length of n th CPU burst –τ n = predicted length of n th CPU burst –α in range 0  α  1 Then define

SchedulingCS-3013 C-term Note This is called exponential averaging because α = 0  history has no effect α = 1  only most recent burst counts Typically, α = 0.5 and τ 0 is system average

SchedulingCS-3013 C-term Predicted Length of the Next CPU Burst Notice how predicted burst length lags reality –α defines how much it lags!

SchedulingCS-3013 C-term Applications of SJF Scheduling Multiple desktop windows active at once Document editing Background computation (e.g., Photoshop) Print spooling & background printing Sending & fetching Calendar and appointment tracking Desktop word processing (at thread level) Keystroke input Display output Pagination Spell checker

SchedulingCS-3013 C-term Priority Scheduling A priority number (integer) is associated with each process CPU is allocated to the process with the highest priority (smallest integer  highest priority) –Preemptive –nonpreemptive

SchedulingCS-3013 C-term Priority Scheduling (Usually) preemptive Process are given priorities and ranked –Highest priority runs next –May be done with multiple queues – multilevel SJF = priority scheduling where priority is next predicted CPU burst time Recalculate priority – many algorithms –E.g. increase priority of I/O intensive jobs –E.g. favor processes in memory –Must still meet system goals – e.g. response time

SchedulingCS-3013 C-term Priority Scheduling Issue #1 Problem: Starvation – low priority processes may never execute Solution: Aging – as time progresses, increase priority of waiting processes

SchedulingCS-3013 C-term Priority Scheduling Issue #2 Priority inversion –A has high priority, B has medium priority, C has lowest priority –C acquires a resource that A needs to progress –A attempts to get resource, fails and busy waits C never runs to release resource! or –A attempts to get resources, fails and blocks B (medium priority) enters system & hogs CPU C never runs! Priority scheduling can’t be naive

SchedulingCS-3013 C-term Solution Some systems increase the priority of a process/task/job to Match level of resource or Match level of waiting process Some variation of this is implemented in almost all real-time operating sytems

SchedulingCS-3013 C-term Priority Scheduling (conclusion) Very useful if different kinds of tasks can be identified by level of importance –Real-time computing (later in this course) Very irritating if used to create different classes of citizens

SchedulingCS-3013 C-term Multilevel Queue Ready queue is partitioned into separate queues: –foreground (interactive) –background (batch) Each queue has its own scheduling algorithm –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; i.e., 80% to foreground in RR –20% to background in FCFS

SchedulingCS-3013 C-term Multilevel Queue Scheduling

SchedulingCS-3013 C-term Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way 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

SchedulingCS-3013 C-term 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 –New job enters queue Q 0 (FCFS). When it gains CPU, job receives 8 milliseconds. 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. If it still does not complete, it is preempted and moved to queue Q 2.

SchedulingCS-3013 C-term Multilevel Feedback Queues

SchedulingCS-3013 C-term Thread Scheduling Local Scheduling – How the threads library decides which user thread to run next within the process Global Scheduling – How the kernel decides which kernel thread to run next

SchedulingCS-3013 C-term Scheduling – Examples Unix – multilevel - many policies and many policy changes over time Linux – multilevel with 3 major levels –Realtime FIFO –Realtime round robin –Timesharing Win/NT – multilevel –Threads scheduled – fibers not visible to scheduler –Jobs – groups of processes are given quotas that contribute to priorities

SchedulingCS-3013 C-term Reading Assignments Silbershatz, Chapter 5: CPU Scheduling –§ Love, Chapter 4, Process Scheduling –Esp. pp Much overlap between the two –Silbershatz tends to be broader overview –Love tend to be more practical about Linux

SchedulingCS-3013 C-term Instructive Example O(1) scheduling in Linux kernel Supports 140 priority levels Derived from nice level and previous bursts No queue searching Next ready task identified in constant time Depends upon hardware instruction to find first bit in bit array. See Love, p. 47

SchedulingCS-3013 C-term Scheduling – Summary General theme – what is the “best way” to run n processes on k resources? ( k < n) Conflicting Objectives – no one “best way” –Latency vs. throughput –Speed vs. fairness Incomplete knowledge –E.g. – does user know how long a job will take Real world limitations –E.g. context switching takes CPU time –Job loads are unpredictable

SchedulingCS-3013 C-term Scheduling – Summary (continued) Bottom line – scheduling is hard! –Know the models –Adjust based upon system experience –Dynamically adjust based on execution patterns

SchedulingCS-3013 C-term Questions?