5: CPU Scheduling Last Modified: 10/25/2015 8:16:31 PM.

Slides:



Advertisements
Similar presentations
Chap 5 Process Scheduling. Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a.
Advertisements

Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
CS444/CS544 Operating Systems Introduction to Synchronization 2/07/2007 Prof. Searleman
Chapter 3: CPU Scheduling
CS444/CS544 Operating Systems Scheduling 1/31/2007 Prof. Searleman
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.
CS444/CS544 Operating Systems Scheduling 2/05/2007 Prof. Searleman
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CS444/CS544 Operating Systems CPU Scheduling 2/07/2006 Prof. Searleman
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (2) Process Management 10/03/2008 Yang Song (Prepared by Yang Song and.
5: CPU-Scheduling1 Jerry Breecher OPERATING SYSTEMS SCHEDULING.
CS444/CS544 Operating Systems Threads Introduction to CPU Scheduling 2/02/2006 Prof. Searleman
Job scheduling Queue discipline.
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
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
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
More Scheduling cs550 Operating Systems David Monismith.
Chapter 6 Scheduling. Basic concepts Goal is maximum utilization –what does this mean? –cpu pegged at 100% ?? Most programs are I/O bound Thus some other.
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.
1 CSE451 Scheduling Autumn 2002 Gary Kimura Lecture #6 October 11, 2002.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
1 Our focus  scheduling a single CPU among all the processes in the system  Key Criteria: Maximize CPU utilization Maximize throughput Minimize waiting.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
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.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
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.
Basic Concepts Maximum CPU utilization obtained with multiprogramming
1 Chapter 5: CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
CPU SCHEDULING.
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
Chapter 5a: CPU Scheduling
April 6, 2001 Gary Kimura Lecture #6 April 6, 2001
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU SCHEDULING.
Outline Scheduling algorithms Multi-processor scheduling
CPU scheduling decisions may take place when a process:
Chapter 5: CPU Scheduling
CSE 451: Operating Systems Winter 2003 Lecture 6 Scheduling
Shortest-Job-First (SJR) Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
CSE 451: Operating Systems Winter 2001 Lecture 6 Scheduling
Presentation transcript:

5: CPU Scheduling Last Modified: 10/25/2015 8:16:31 PM

-2 Scheduling Policy r We’ve talked about the context switch mechanism m How we change which process or thread is executing on the CPU r Today, we will talk about scheduling policies m How do we choose which process or thread to execute next m Unit of scheduling = process or thread

-3 Scheduler r Scheduler = the module that moves jobs from queue to queue r Scheduler typically runs when: m A process/thread blocks on a request (transitions from running to waiting) m A timer interrupt occurs m A new process/thread is created or is terminated

-4 Scheduling Algorithm r The scheduling algorithm examines the set of candidate processes/threads and chooses one to execute r Scheduling algorithms can have different goals m Maximize CPU utilization m Maximize throughput (#jobs/time) m Minimize average turnaround time ( Avg(EndTime – StartTime) ) m Minimize response time r Recall: Batch systems have which goal? Interative systems have which goal?

-5 Starvation r Starvation = process is prevented from making progress towards completion because another process has a resource that it needs r Scheduling policies should try to prevent starvation m E.g. Even low priority processes should eventually get some time on the CPU

-6 Brainstorm r What are some different ways to schedule access to a resource? m First Come First Serve Many services humans use are like this? m Prefer Short Jobs Express lane at the grocery store m Important Jobs First Order you do your TODO list? Maybe round robin? r Now what about scheduling processes?

-7 Process Model r Think of a process/ thread as an entity that alternates between two states: using the CPU and waiting for I/O (not a bad model) r For most processes, most “CPU bursts” are short

-8 First Come First Serve (FCFS) r Also called First In First Out (FIFO) r Jobs scheduled in the order they arrive r When used, tends to be non-preemptive m If you get there first, you get all the resource until you are done m “Done” can mean end of CPU burst or completion of job r Sounds fair m All jobs treated equally m No starvation (except for infinite loops that prevent completion of a job)

-9 Problems with FCFS/FIFO r Can lead to poor overlap of I/O and CPU m If let first in line run till they are done or block for I/O then can get convoy effect m While job with long CPU burst executes, other jobs complete their I/O and the I/O devices sit idle even though they are the “bottleneck” resource and should be kept as busy as possible r Also, small jobs wait behind long running jobs (even grocery stores know that) m Results in high average turn-around time

-10 Shortest Job First (SJF) r So if we don’t want short running jobs waiting behind long running jobs, why don’t we let the job with the shortest CPU burst go next m Can prove that this results in the minimum (optimal) average waiting time r Can be preemptive or non-preemptive m Preemptive one called shortest-remaining-time first

-11 Problems with SJF r First, how do you know which job will have the shortest CPU burst or shortest running time? m Can guess based on history but not guaranteed r Bigger problem is that it can lead to starvation for long-running jobs m If you never got to the head of the grocery queue because someone with a few items was always cutting in front of you

-12 Most Important Job First r Priority scheduling m Assign priorities to jobs and run the job with the highest priority next m Can be preemptive such that as soon as high priority job arrives it get the CPU r Can implement with multiple “priority queues” instead of single ready queue m Run all jobs on highest priority queue first

-13 Problems with Priority Scheduling r First, how do we decide on priorities? m SJF is basically priority scheduling where priority determined by running time – also a million other choices r Like SJF, all priority scheduling can lead to starvation r How do we schedule CPU between processes with the same priority? r What if highest priority process needs resource held by lowest priority process?

-14 Priority Inversion r Problem: Lowest priority process holds a lock that highest priority process needs. Medium priority processes run and low priority process never gets a chance to release lock. r Solution: Low priority process “inherits” priority of the highest priority process until it releases the lock and then reverts to original priority.

-15 Dealing with Starvation r FCFS has some serious drawbacks and we really do like to be able to express priorities r What can we do to prevent starvation? m Increase priority the longer a job waits m Eventually any job will accumulate enough “waiting points” to be scheduled

-16 Interactive Systems? r Do any of these sound like a good choice for an interactive system? r How did we describe scheduling on interactive systems? m Time slices m Each job given a its share of the CPU in turn m Called Round Robin (RR) scheduling r No starvation!

-17 Problems With RR r First, how do you choose the time quantum? m If too small, then spend all your time context switching and very little time making progress m If too large, then it will be a while between the times a given job is scheduled leading to poor response time m RR with large time slice => FIFO r No way to express priorities of jobs m Aren’t there some jobs that should get a longer time slice?

-18 Best of All Worlds? r Most real life scheduling algorithms combine elements of several of these basic schemes r There is no perfect scheduler for all scenarios – balancing competing demands r Examples: m Have multiple queues m Use different algorithms within different queues m Use different algorithm between queues m Have algorithms for moving jobs from one queue to another m Have different time slices for each queue m Where do new jobs enter the system

-19 Multi-level Feedback Queues (MLFQ) r Multiple queues representing different types of jobs m Example: I/O bound, CPU bound m Queues have different priorities r Jobs can move between queues based on execution history r If any job can be guaranteed to eventually reach the top priority queue given enough waiting time, then MLFQ is starvation free m E.g. If spend enough time in low priority queue, then raise its effective priority

-20 Typical UNIX Scheduler r MLFQ m 3-4 classes spanning >100 priority levels m Timesharing, Interactive, System, Real-time (highest) r Processes with highest priority always run first; Processes of same priority scheduled with Round Robin r Reward interactive behavior by increasing priority if process blocks before end of time slice granted r Punish CPU hogs by decreasing priority of process uses the entire quantum

-21 priocntl > priocntl -l CONFIGURED CLASSES ================== SYS (System Class) TS (Time Sharing) Configured TS User Priority Range: -60 through 60 IA (Interactive) Configured IA User Priority Range: -60 through 60 RT (Real Time) Maximum Configured RT Priority: 59

-22 priocntl :~> ps PID TTY TIME CMD pts/60 0:00 tcsh pts/60 0:11 pine :~> priocntl -d TIME SHARING PROCESSES: PID TSUPRILIM TSUPRI :~> priocntl -d TIME SHARING PROCESSES: PID TSUPRILIM TSUPRI :~> priocntl -d 1 TIME SHARING PROCESSES: PID TSUPRILIM TSUPRI 1 0 0

-23 nice r Users can lower the priority of their process with nice r Root user can raise or lower the priority of processes

-24 Some Special Cases

-25 Real Time Scheduling r Real time processes have timing constraints m Expressed as deadlines or rate requirements r Common Real Time Scheduling Algorithms m Rate Monotonic Priority = 1/RequiredRate Things that need to be scheduled more often have highest priority m Earliest Deadline First Schedule the job with the earliest deadline Scheduling homework? r To provide service guarantees, neither algorithm is sufficient m Need admission control so that system can refuse to accept a job if it cannot honor its constraints

-26 Multiprocessor Scheduling r Can either schedule each processor separately or together m One line all feeding multiple tellers or one line for each teller r Some issues m Want to schedule the same process again on the same processor (processor affinity) Why? Caches m Want to schedule cooperating processes/threads together (gang scheduling) Why? Don’t block when need to communicate with each other

-27 Algorithm Evaluation: Deterministic Modeling r Deterministic Modeling m Specifies algorithm *and* workload r Example : m Process 1 arrives at time 1 and has a running time of 10 and a priority of 2 m Process 2 arrives at time 5, has a running time of 2 and a priority of 1 m … m What is the average waiting time if we use preemptive priority scheduling with FIFO among processes of the same priority?

-28 Algorithm Evaluation: Queueing Models r Distribution of CPU and I/O bursts, arrival times, service times are all modeled as a probability distribution r Mathematical analysis of these systems r To make analysis tractable, model as well behaved but unrealistic distributions

-29 Algorithm Evaluation: Simulation r Implement a scheduler as a user process r Drive scheduler with a workload that is either m randomly chosen according to some distribution m measured on a real system and replayed r Simulations can be just as complex as actual implementations m At some level of effort, should just implement in real system and test with “real” workloads m What is your benchmark/ common case?

-30 One last point: Kernel vs User Level Threads r Recall: With kernel level threads, kernel chooses among all possible threads to schedule; with user level threads, kernel schedules the process and the user level thread package schedule the threads r User-level threads have benefit of fast context switch at user level r Kernel-level threads have benefit of global knowledge of scheduling choices and has more flexibility in assigning priorities to individual threads

-31 Outakes r Windows 2000 priority classes r Linux source code: kernel/sched.c m How to find m How to read online