Process Scheduling Decide which process should run and for how long

Slides:



Advertisements
Similar presentations
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Advertisements

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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
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
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
Process Scheduling Decide which process should run and for how long Policy: Maximize CPU utilization Mechanism:Multiprogramming Dispatch latency Time required.
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.
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.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 5 CPU Scheduling Slide 1 Chapter 5 CPU Scheduling.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
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.
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.
UNIT–II: Process Management
CPU SCHEDULING.
Chapter 6: CPU Scheduling
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
Chapter 5a: CPU Scheduling
CPU Scheduling Algorithms
Operating Systems Processes Scheduling.
Scheduling (Priority Based)
Chapter 5: CPU Scheduling
CPU Scheduling.
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Process management Information maintained by OS for process management
Chapter 5: CPU Scheduling
CS 143A - Principles of Operating Systems
CPU Scheduling Basic Concepts Scheduling Criteria
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter 5: CPU Scheduling
Chapter 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
Operating System Concepts
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.
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Presentation transcript:

Process Scheduling Decide which process should run and for how long CPU-I/O burst cycles Process execution and I/O wait Dispatch latency Time required to switch contexts Policy: Maximize CPU utilization Mechanism:Multiprogramming (multiple processes in memory at once)

Dispatcher Text chapter 5 Give control of the CPU to the process selected by the short-term scheduler This involves: switching context (writing registers from values in PCB for incoming process) switching to user mode Setting the program counter for incoming process Dispatch latency – Time required to stop one process and start another running

Histogram of CPU-burst Times Average burst times per process

Scheduling Decisions Gives CPU control to a process in the ready queue CPU scheduling decisions occurs when a process changes state 1.Switch: running to waiting state 2.Switch: running to ready state 3.Switch: waiting to ready 4.Switch: running to terminated Give an example of what happened to cause each of the above switches. non-preemptive switch – process ‘willingly’ gives up control (1, 4 above) preemptive switch – process wants to run, but is forced to wait (2, 3 above) Scheduling tradeoffs: Maximize Throughput (processes completed per time unit) Minimize Turnaround time (total time to execute a particular process) Minimize Wait time (total time waiting in the ready queue) Minimize Response time (delay in time from request until first response) Maximize CPU utilization (CPU idle time percentage)

First-Come, First-Served (FCFS) Scheduling Run as long as a process wants Second arrival order: P2 , P3 , P1 The Gantt chart schedule is: Waiting time: P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case If maximizing for response, schedule short processes first if you can determine whether a process is short or long … Process Burst Time P1 24 P2 3 P3 3 First arrival order: P1 , P2 , P3 The Gantt Chart schedule is: Waiting time: P1=0; P2=24; P3=27 Average waiting time: (0 + 24 + 27)/3 = 17 P1 P3 P2 6 3 30 P1 P2 P3 24 27 30

Shortest Job First Scheduling Algorithm Estimate the length of the next process CPU burst – by keeping burst times on each process as it is running. Schedule the process with the shortest exponential (weighted) avg burst time – weighting allows OS to prefer recent history over total history Two schemes: Shortest Job First (SJF): Process guaranteed to finish its next burst (non-preemptive) Shortest-Remaining-Time-First (SRTF): Schedule a ready process when its burst estimate is less than what remains for the running process (preemptive) Evaluation Advantage: Minimizes wait time if the burst estimate is accurate Disadvantage: CPU bursts cannot be known in advance

Preemptive and non-preemptive Examples Schedule using the length of the next cpu burst Process ArrivalTime EstimatedBurst P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (non-preemptive) Average wait: (0+6+3+7)/4 = 4 SRTF (preemptive) Average wait: (9 + 1 + 0 +2)/4 = 3 P1 P3 P2 4 2 11 P4 5 7 16 P1 P3 P2 7 3 16 P4 8 12 Question: How to estimate CPU bursts? Answer: exponential averaging tn = nth burst length, τn=estimated nth burst length, α=weighting factor where 0≤α≤1 τn+1 ≈ α tn + (1- α )τn

Exponential Averaging Examples Project the time for the next CPU burst Fixed quantums, history doesn’t count  =0 , n+1 = n Only the Last burst counts  =1 , n+1 = tn Vary the impact of past bursts  and (1 - ) ≤ 1 Example on right: Initialize 0 to 10,  = ½ Example: 1 =  t0 + (1- )0 = ½ 6 + ½ 10 = 8 (0 initialized to 10)

Priority Scheduling Assign a priority integer value to each process Highest priority wins (Some systems: smallest integer  highest priority) Priority algorithms can be either preemptive or non-preemptive SJF is a priority scheduler: priority = predicted next CPU burst FIFO is a non-preemptive priority scheduler: priority = time waiting Round Robin (RR) – quantum (timeslice) used for preemption Schedule when quantum expires (10-100 millisecond) Large quantum (q) ≈ FIFO; Small q – more equitable sharing but higher overhead. Maximum wait is (n-1)*q for n processes of the same priority Each process uses 1/n of CPU (minus scheduling overhead) Problem and solution Problem: Low priority processes may never execute (starvation) Solution: Increase a process priority as wait time increases (aging)

Example of RR with Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24 Compared to SJF: Worse average turnaround; better response, i.e., shorter wait time. P1 P2 P3 P4 20 37 57 77 97 117 121 134 154 162

Round Robin Scheduling (RR) Turnaround Vs. Quantum Size Text Fig. 5.5 Context switches vs quantum Processes exceeding their time quantum go to the back of the queue See notes/hndout3.1.xlsx

Multilevel Queues Multiple Ready Queues Design questions and possible answers How many queues? Usually a number of interactive foreground queues; a single background batch queue Which scheduling algorithms? Interactive – RR, Background – FCFS When to upgrade or demote a process? Demote processes whose quantum expires, Promote if I/O to compute ratio falls below chosen threshold. Scheduling among queues? Favor foreground over background. Allocate CPU % to each queue by giving each queue a number of quantums. Higher priority queues preempt. Multilevel-feedback: Allows processes to migrate between multilevel queues (Like ‘aging’ in a single RR queue.)

Multilevel Feedback Example Three queues Q0 Processes have 8 millisecond quantum, FCFS algorithm Q1 Processes have 16 millisecond quantum, FCFS algorithm Q2 – FCFS Scheduling New jobs enters queue Q0. They move to Q1 if quantum expires Jobs in Q1 receive a new quantum. They move to Q2 if their Q1 quantum expires Larger quantum does not mean the process is not preempted.

Solaris Scheduling Interactive and Time Share Categories Note: real-time threads before the scheduler, but below interrupt handling threads, which are not shown here – whew.

Solaris Dispatch Table Priority: a higher number indicates a higher priority. Processes that wait too long get a priority boost. Time Quantum: the time quantum for the associated priority Time Quantum expired: the new priority of a thread that has used its entire time quantum without blocking. (Demoted) Return from sleep: the priority of a thread that is returning from sleeping (such as waiting for I/O). (Promoted)

Windows XP Scheduling Multilevel feedback queue Algorithm: Priority-based, preemptive; time critical processes preempt lower priority classes (soft real time scheduling). Columns: process priority classes. For example: real time, high, above normal, normal, below normal, and idle. Rows: relative priority values a particular process can assume. For example, real time processes can have priorities from 16 to 31.

Linux Scheduling Time-sharing algorithm Soft Real-time algorithm Low number == high priority Each entering process given a number of credits Timer interrupt: reduce credit Context switch if credits = 0 Re-credit (based on priority and history ) if no processes have credits left – next slide Soft Real-time algorithm 2 priority ranges – real-time and other longer time slices for real-time priorities Quantum length vs. Priority

Linux List of Tasks Indexed According to Priorities Constant order O(1) scheduling algorithm with two arrays of run queues for each priority Active array: tasks ready and still have credits left Expired array: tasks with no credits left Run highest priority active array tasks, move to expired when quanta expires If a priority active array empties, swap active/expired arrays. Then re-credit quanta and possibly adjust priority by +/- 5. More process wait time means higher priority

Java Threads Create thread: implements Runnable or extends thread Spawn thread: call the start() method Scheduling: dependent on underlying OS. Threads run till: Quantum expires Blocks for I/O Leave run() method Sleep() or yield() Priority range (Between 1 and 10) Thread.MIN_PRIORITY (1) Thread.NORM_PRIORITY (5) Thread.MAX_PRIORITY (10) Set priority: thread.setPriority(Thread.NORM_PRIORITY);

Java to OS Scheduling Java and Windows Java and Solaris