Fair Resource Access & Allocation  OS Scheduling

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.
 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 Algorithms
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.
6/25/2015Page 1 Process Scheduling B.Ramamurthy. 6/25/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
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.
Chapter 5: CPU Scheduling
7/12/2015Page 1 Process Scheduling B.Ramamurthy. 7/12/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Lecture 5: CPU Scheduling. Lecture 5 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents Why CPU Scheduling Scheduling Criteria & Optimization.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling.
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.
CPU-Scheduling Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. The short term scheduler.
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.
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
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.
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  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 7: CPU Scheduling Chapter 5.
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.
Purpose of Operating System Part 2 Monil Adhikari.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU 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
1 Lecture 5: CPU Scheduling Operating System Fall 2006.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 6: CPU Scheduling.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
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.
Scheduling (Priority Based)
Outline Scheduling algorithms Multi-processor scheduling
Shortest-Job-First (SJR) Scheduling
Presentation transcript:

Fair Resource Access & Allocation  OS Scheduling

Scheduling Criteria (Optimization) CPU utilization: keep CPU as busy as possible (maximize) Throughput: # of processes completed/time unit (maximize) Turnaround time: average amount of time to execute a particular process (minimize) Waiting time: process wait time in ready queue (minimize) Response time (min): amount of time it takes from when a request was submitted until the first response (not output) is produced. [result output time = RT deadline] Optimize all  plus want “Fair & Efficient” solutions!

1. Task/Process/Thread Types Non pre-emptive (NP): An ongoing task cannot be displaced Pre-emptive: Ongoing tasks can be switched in/out as needed

2. Sequences of CPU And I/O Bursts Patterns can be CPU or I/O-bound

A: First-Come, First-Served (FCFS) Scheduling Process Length (CPU Burst Time) P1 24 P2 3 P3 3 Suppose the processes arrive in the order: P1 , P2 , P3 Gantt Chart for the schedule (single queue of ready processes: NP): 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 (NP: Non-Preemptive) Suppose that the processes arrive in the order P2 , P3 , P1 Gantt chart for the schedule: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Variability of wait time – control? Convoy effect: cluster short processes behind long process (starvation possible!) P1 P3 P2 6 3 30

Scheduling in Batch Systems Shortest job first (SJF) scheduling

B: 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 Options: non-preemptive – once CPU given to the process it cannot be 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. … Shortest-Remaining-Time-First (SRTF)

Example of Non-Preemptive SJF Process Arrival Time Burst Time P1 0.00 7 P2 0.0+ 4 P3 0.0+ 1 P4 0.0+ 4 SJF (non-preemptive) P1, then P3 then P2, P4 (FCFS here) Average waiting time = (0 + 8 + 7 + 12)/4 = 6.75 (fixed arrival) Av. waiting = (0 + [8-2] + [7-4] + [12-5])/4 = 4.00 (staggered arrival) 0.0 2.0 4.0 5.0 P1 P3 P2 7 3 16 P4 8 12

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 Options: non-preemptive – once CPU given to the process it cannot be 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. … Shortest-Remaining-Time-First (SRTF)

Preemptive SJF (Shortest Remaining Time First) 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 = P1:[0, (11-2)]; P2:[0, (5-4)]; P3: 0; P4: (7-5) Average waiting time = (9 + 1 + 0 +2)/4 = 3 …[6.75;4.00] Dynamic scheduling (SRT) calculations: cost factor! P1: 5 left P2: 2 left P2:2, P4:4, P1:5 P1 P3 P2 4 2 11 P4 5 7 16

Determining Length of Next CPU Burst Can only estimate the length (easy for batch jobs) Use the length of previous CPU bursts (history logs) (0) direct fn. of history (1) direct fn. of most recent run

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 Options: non-preemptive – 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. Shortest-Remaining-Time-First (SRTF) SJF is optimal – gives minimum average waiting time for a given set of processes SJF can still lead to starvation: if new short jobs keep coming in and getting considered in the “shortest” ranking, a “long” job can potentially starve!

Variations SJF  EDF (Earliest Deadline First)

C: Round Robin (RR/TDMA): Fixed Slots Each process gets a fixed slice of CPU time (time quantum: q), 10-100ms After this time has elapsed, the process is “forcefully” 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. Performance? q too large  FIFO (poor response time & poor CPU utilization) q too small  q must be large with respect to context switch ovhd., else context switching overhead reduces efficiency ReadyQ

Example of RR with Time Quantum = 20 (Dynamic Q: if a process finishes in less than 20, then the next slot starts earlier!) Process Burst Time P1 53 P2 17 P3 68 P4 24 Gantt chart: Typically, higher average turnaround than SJF, but better response Turnaround time – amount of time to execute a particular process (minimize) Response time (min) – amount of time it takes from request submission until first response Scheduling is static though calculating/estimation “right” length of quantum is crucial!!! Possible to have quanta of varying lengths!!! (dynamic scheduling costs ~ SJF) P1 P2 P3 P4 20 37 57 77 97 117 121 134 154 162

D: Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to process with the highest priority (For Unix BSD: smallest integer  highest priority) 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 also…remember priority-inversion case? Interrupt Disabling for ME? Spinlock cases? Solution  Aging: as time progresses increase priority of process

Priority Scheduling (Solaris, Windows, Linux) (FCFS within a priority level) Higher Priority: Small quanta Lower Priority: Bigger quanta * Kernel process: generally non-preemptive; User processes: pre-emptable Priority can be static or dynamic (fn. time for fairness etc) P_user-pri = P_USER + P_cpu/4 + (2 * P_nice) process using CPU: P_cpu increases with time  P_user-pri goes up (BSD: large # =‘s low priority ) process waiting: P_cpu keeps decreasing  P_user-pri keeps going down ( higher priority)

Scheduling in Real-Time Systems Hard/Firm/Soft Real-time: Missing deadline catastrophic/acceptable Issues: Priority, periodicity, compute time, deadlines Periodic Task Model: Process assigned static priority based on their run_length (or period): Shortest Period  Highest Priority (RM) Schedulable real-time system, given: m periodic events event i occurs within period Pi and requires Ci seconds Then the load can only be handled if Composite Periodic/A periodic Model: Dynamic priority with highest priority to task whose deadline is closest! EDF: Earliest Deadline First

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

Thread Scheduling (User Scheduler) Possible scheduling of user-level threads 50-msec process quantum; threads run 5 msec/CPU burst simple process level context switch; thread block  process blocks split level scheduling (kernel + dedicated application/thread type specific)

Thread Scheduling (Kernel Scheduler) Possible scheduling of kernel-level threads 50-msec process quantum; threads run 5 msec/CPU burst flexible…costly full context switch for threads monolithic kernel scheduler also avoids thread blocks (on I/O etc)

OS Examples Solaris scheduling Windows XP scheduling Linux scheduling

Solaris 2 Scheduling

Solaris Dispatch Table * Lowest priority 0 (diff. from BSD) is given largest quantum * TQE: new (reduced) priority for tasks that have used quanta without blocking * RFS: (raised) priority of awakened tasks

Windows XP: Priority Based, Preemptive priority classes relative priority within a priority class (High # =‘s High Priority; diff. from BSD)

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, re-crediting occurs Based on factors including priority and history Real-time Soft real-time Two classes FCFS and RR Highest priority process always runs first