Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.

Slides:



Advertisements
Similar presentations
CPU Scheduling.
Advertisements

COT 4600 Operating Systems Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3:00-4:00 PM.
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.
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
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.
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.
COT 4600 Operating Systems Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3:00-4:00 PM.
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.
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.
Advanced Operating Systems - Spring 2009 Lecture 14 – February 25, 2009 Dan C. Marinescu Office: HEC 439 B. Office.
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.
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.  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  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU SCHEDULING.
Chapter 6: CPU Scheduling
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
Chapter 5a: CPU Scheduling
CPU Scheduling Algorithms
Operating Systems Processes Scheduling.
Scheduling (Priority Based)
CPU Scheduling.
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
COT 4600 Operating Systems Spring 2011
Operating System Concepts
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
COT 4600 Operating Systems Spring 2011
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Outline Scheduling algorithms Multi-processor scheduling
Operating System Concepts
COT 4600 Operating Systems Fall 2009
CGS 3763 Operating Systems Concepts Spring 2013
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:

Advanced Operating Systems - Spring 2009 Lecture 13 – February 23, 2009 Dan C. Marinescu Email: dcm@cs.ucf.edu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM. TA: Chen Yu Email: yuchen@cs.ucf.edu Office: HEC 354. Office hours: M, Wd 1.00 – 3:00 PM.

Last, Current, Next Lecture Last time: Birth-death processes M/M/1 systems Today CPU Scheduling Scheduling Algorithms M/M/m systems Next time: Caching and Virtual Memory

Histogram of CPU-burst Times

Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: 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

Performance metrics and objectives CPU Utilization  Fraction of time CPU does useful work over total time Throughput  Number of jobs finished per unit of time Turnaround time  Time spent by a job in the system Response time  Time to get the results Waiting time  Time waiting to start processing All these are random variables  we are interested in averages!! The objectives of system managers (M) and users (U): Maximize CPU utilization M Maximize throughput  M Minimize turnaround time  U Minimize waiting time  U Minimize response time  U

First-Come, First-Served (FCFS) Process Burst Time P1 24 P2 3 P3 3 Processes arrive in the order: P1  P2  P3 Gantt Chart for the schedule: Waiting time for P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 Convoy effect short process behind long process P1 P2 P3 24 27 30

FCFS Scheduling (Cont’d.) Now processes arrive in the order: P2  P3  P1 Gantt chart: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better!! P1 P3 P2 6 3 30

Shortest-Job-First (SJF) Use the length of the next CPU burst to schedule the process with the shortest time. SJF is optimal minimum average waiting time for a given set of processes Two schemes: Non-preemptive  the process 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. known as Shortest-Remaining-Time-First (SRTF)

Non-preemptive SJF example 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

Shortest-Remaining-Time-First (SRTF) (Preemptive SJF) example Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 Shortest-Remaining-Time-First Average waiting time = (9 + 1 + 0 +2)/4 = 3 P1 P3 P2 4 2 11 P4 5 7 16

Estimating the length of next CPU burst Done using the length of previous CPU bursts, using exponential averaging

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 -j + … +(1 -  )n +1 0 Since both  and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor

Predicting the length of the next CPU burst

Priority scheduling Each process has a priority and the process with the highest priority (smallest integer  highest priority) is scheduled next. 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 Solution to sarvation  Aging – as time progresses increase the priority of the process

Round Robin (RR) 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 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 large  FIFO q small  q must be large with respect to context switch, otherwise overhead is too high

RR with time slice q = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24 Typically, higher average turnaround than SJF, but better response P1 P2 P3 P4 20 37 57 77 97 117 121 134 154 162

Time slice (quantum) and context switch time

Turnaround time function of time quantum

Multilevel queue Ready queue is partitioned into separate queues each with its own scheduling algorithm : foreground (interactive)  RR background (batch)  FCFS Scheduling 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

Multilevel Queue Scheduling

Multilevel feedback queue A process can move between the various queues; aging can be implemented this way Multilevel-feedback-queue scheduler characterized by: number of queues scheduling algorithms for each queue strategy when to upgrade/demote a process strategy to decide the queue a process will enter when it needs service

Multilevel feedback queue example Three queues: Q0 – RR with time quantum 8 milliseconds Q1 – RR 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.

Multilevel Feedback Queues

Unix scheduler The higher the number quantifying the priority the lower the actual process priority. Priority = (recent CPU usage)/2 + base Recent CPU usage  how often the process has used the CPU since the last time priorities were calculated. Does this strategy raises or lowers the priority of a CPU-bound processes? Example: base = 60 Recent CPU usage: P1 =40, P2 =18, P3 = 10

Multiple-processor scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Load sharing Asymmetric multiprocessing – only one processor accesses the system data structures, alleviating the need for data sharing

Comparison of scheduling algorithms Round Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest Remaining Job Next Throughput Response time May be low is quantum is too small Shortest average response time if quantum chosen correctly Not emphasized May be poor Good for I/O bound but poor for CPU-bound processes High Good for short processes But maybe poor for longer processes

Comparison of scheduling algorithms (cont’d) Round Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest Remaining Job Next IO-bound Infinite postponement No distinction between CPU-bound and Does not occur Gets a high priority if CPU-bound processes are present May occur for CPU bound processes May occur for processes with long estimated running times

Comparison of scheduling algorithms (cont’d) Round Robin FIFO MFQ Multi-Level Feedback Queue SFJ Shortest Job First SRJN Shortest Remaining Job Next Overhead CPU-bound Low No distinction between CPU-bound and IO-bound The lowest Can be high Complex data structures and processing routines Gets a low priority if IO-bound processes are present Can be high Routine to find to find the shortest job for each reschedule Can be high Routine to find to find the minimum remaining time for each reschedule

Scheduling algorithms A scheduling problems is defined by : The machine environment A set of side constrains and characteristics The optimality criterion Machine environments: 1  One-machine. P  Parallel identical machines Q  Parallel machines of different speeds R  Parallel unrelated machines O  Open shop. m specialized machines; a job requires a number of operations each demanding processing by a specific machine F  Floor shop

One-machine environment n jobs 1,2,….n. pj amount of time required by job j. rj  the release time of job j, the time when job j is available for processing. wj  the weight of job j. dj due time of job j; time job j should be completed. A schedule S specifies for each job j which pj units of time are used to process the job. CSj  the completion time of job j under schedule S. The makespan of S is: CSmax = max CSj The average completion time is

One-machine environment (cont’d) Average weighted completion time: Optimality criteria  minimize: the makespan CSmax the average completion time : The average weighted completion time:  the lateness of job j  maximum lateness of any job under schedule S. Another optimality criteria, minimize maximum lateness.

Priority rules for one machine environment Theorem: scheduling jobs according to SPT – shortest processing time is optimal for Theorem: scheduling jobs in non-decreasing order of is optimal for

Earliest deadline first (EDF) Dynamic scheduling algorithm for real-time OS. When a scheduling event occurs (task finishes, new task released, etc.) the priority queue will be searched for the process closest to its deadline. This process will then be scheduled for execution next. EDF is an optimal scheduling preemptive algorithm for uniprocessors, in the following sense: if a collection of independent jobs, each characterized by an arrival time, an execution requirement, and a deadline, can be scheduled (by any algorithm) such that all the jobs complete by their deadlines, the EDF will schedule this collection of jobs such that they all complete by their deadlines.

EDF The schedulability test for EDF is: In this case U = 1/8 +2/5 + 4/10 = 0.925 = 92.5% It has been proved that the problem of deciding if it is possible to schedule a set of periodic processes is NP-hard if the periodic processes use semaphores to enforce mutual exclusion. Process Execution Time Period P1 1 8 P2 2 5 P3 4 10

Priority Inversion A high priority process is blocked by a lower priority one. Example: J1 and J3 share a data structure guarded by a binary semaphore S. prty(J1) > prty(J2) > prty(J3). J1 in initiated while J3 is in its critical section When J1 attempts to enter the critical section it is blocked. The duration of this blocking cannot be determined as because J3 can be preempted by a higher priority job J2. prty