Chapter 5: CPU Scheduling

Slides:



Advertisements
Similar presentations
CPU Scheduling.
Advertisements

Scheduling Criteria CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – # of processes that complete their execution per.
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 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.
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.
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 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 – 7 th Edition, Feb 2, 2005 Basic Concepts Maximum CPU utilization.
Chapter 6: CPU Scheduling
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
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.
1 张惠娟 副教授 实用操作系统概念. 2 内容框架 概述 体系结构 进程管理 内存管理 文件管理 外设管理.
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.
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
Chapter 6: CPU Scheduling
CPU Scheduling G.Anuradha
Module 5: CPU Scheduling
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Presentation transcript:

Chapter 5: CPU Scheduling

Outline Why scheduling? Scheduling Criteria Scheduling Algorithms Real-Time Scheduling Thread Scheduling Example: Solaris Algorithm Evaluation

Process Execution Process execution consists of alternating cycles of CPU execution and I/O wait Long-term scheduler gets a good mix of CPU-bound & I/O-bound jobs Given that, how to scheudle ready processes? – Shor-term scheduling: focus of this chapter

Why scheduling is necessary? Maximize CPU utilization via multiprogramming, while minimizing response time and/or maximizing throughput → Efficient CPU scheduling required

CPU Scheduler Decide which process to execute next among the ready processes in memory Order ready processes according to the specified policy such as FCFS (First Come First Serve)

Preemptive vs. nonpreemptive scheduling A hihger priority process can preempt a currently running low priority process to avoid priority inversion Most real-time scheduling algorithms, e.g., EDF & RM More details about RT scheduling will be discussed later Nonpreemptive scheduling: A higher priority process waits a currently running process to finish regardless of the priority e.g., FCFS Others such as I/O & networking devices are not preemptive

Dispatcher Gives control of the CPU to the process selected by the short-term scheduler Context switch between the two user processes Context switch to user mode Jump to the proper location in the user program to restart it → Dispatch latency : Time for dispatcher to stop one process and start another

Scheduling Criteria CPU utilization: #CPU cycles used for computation/#total CPU cycles per unit time Throughput: # of processes that complete the execution per unit time Response time: Amount of time it takes from when a request was submitted until the first response is produced

Scheduling Criteria Waiting time Amount of time a process has been waiting in the ready queue Response time = waiting time + execution time

Optimization Criteria Maximize CPU utilization Maximize throughput Minimize response time Minimize waiting time Sometimes they may conflict with each other e.g., system can be overloaded while trying to maximize CPU utilization; response time may significantly increase as a result

First-Come, First-Served (FCFS) Scheduling Process Burst Time (Execution Time) P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: 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 (Cont.) Suppose that processes arrive in the order P2 , P3 , P1 Gantt chart: Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Convoy effect: A short process behind a long process suffer long wating/response time P1 P3 P2 6 3 30

Shortest-Job-First (SJF) Schedule the process with the shortest execution time Two schemes: Nonpreemptive Once the CPU is given to a process it cannot be preempted until completes its execution Preemptive Shortest-Remaining-Time-First (SRTF) If a new process arrives with exec time shorter than the remaining time of the currently running process executing process, preempt

Shortest-Job-First (SJF) SJF is optimal: It minimizes average waiting time for a given set of processes

Example of Non-Preemptive SJF Process Arrival Time Exec Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 Average waiting time = (0 + 6 + 3 + 7)/4 = 4 P1 P3 P2 7 3 16 P4 8 12

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

Hard to implement SJF Don’t know the exact exec time when a process arrives Can only estimate it by using the length of previous exec time (Take moving average) Doesn’t always work

Prediction of the Length of the Next CPU Burst

Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer  highest priority) Preemptive nonpreemptive

Priority Scheduling SJF is a priority scheduling where priority is determined based on the exec time Problem: Starvation Low priority processes may never execute or suffer very long waiting time Solution: Aging As time progresses increase the priority of the process How to support fairness while preferring high priority processes? Hard problem

Round Robin (RR) Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds After the time quantum, preempt the process and add to the end of the ready queue

Round Robin 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

Example of RR with Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24 Gantt chart: P1 P2 P3 P4 20 37 57 77 97 117 121 134 154 162

Time Quantum and Context Switch Time

Multilevel Queue Ready queue is partitioned into separate queues, e.g., foreground (interactive) & background (batch) Each queue can have its own scheduling algorithm foreground – RR background – FCFS

Multilevel Queue Scheduling must be done between the queues Time slice Fixed priority scheduling Serve all foreground process first Serve background process only if the foreground queue is empty Possibility of starvation Time slice Each queue gets a certain amount of CPU time which it can schedule amongst its processes, e.g., 80% to foreground in RR 20% to background in FCFS

Multilevel Queue Scheduling

Multilevel Feedback Queue A process can move between queues Aging can be implemented this way Defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to demote/upgrade a process method used to determine which queue a process will enter when that process needs service

Multilevel Feedback Queues

Example of Multilevel Feedback Queue Q0 – RR with time quantum 8 milliseconds Q1 – RR time quantum 16 milliseconds Q2 – FCFS A new job enters queue Q0 . When it gets CPU, it receives 8 ms. If it does not finish in 8 milliseconds, it is moved to Q1. At Q1 job receives 16 ms. If it does not complete within 16ms, it is preempted and moved to queue Q2.

Real-Time Scheduling Hard real-time systems Soft real-time systems A deadline miss may cause catastrophic results, e.g., air traffic control, flight control, engine control, etc. Soft real-time systems A deadline miss does not cause catastrophic results Meet as many deadlines as possible, e.g., video streaming

Earliest Deadline First Optimal Dynamic scheduling algorithm Schedule the task with the earliest absolute deadline Advantage: 100% utilization bound Disadvantage: Domino effect under overload

Rate Monotonic Scheduling Optimal fixed priority scheduling algorithm Assign the highest priority to the task with the shortest period Advantage: Easy to implement Disadvantage Low utilization bound, i.e., 69% Blind to deadlines RMS schedules T1 first T1 T2

Multiple Processor Scheduling Asymmetric multiprocessing One processor, called master, makes all scheduling decisions Symmetric multiprocessing (SMP) Each processor is self-scheduling Need to avoid for two processors to schedule one process at the same time Supported by most OS – Linux, Solaris, Mac OS X, Windows XP, Windows 2000 … Load balancing: Push vs. pull migration

Thread Scheduling Local Scheduling (process contention scope) How the threads library decides which thread to put onto an available LWP Threads belonging to one process compete for a LWP Global Scheduling (system contention scope) How the kernel decides which kernel thread to run next Assign priority POSIX Thread API Select scheduling algorithm Assign priority to threads

Example: Solaris 2 Scheduling Assign the highest priority to RT threads Apply fixed priority among thread groups

Algorithm Evaluation Deterministic model Queuing model Simulation Little’s Formula: Queue length n = average arrival rate * average waiting time Simulation Implementation

5.15

End of Chapter 5: Any Questions?