CPU scheduling. CPU Scheduling

Similar documents
Chapter 6: CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. CPU Scheduler. Dispatcher. Alternating Sequence of CPU And I/O Bursts

Principles of Operating Systems

CPU Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Unix Scheduler

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - V CPU Scheduling - I. Louisiana State University.

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - V CPU Scheduling - I. University at Buffalo.

Motivation. Types of Scheduling

Lecture 11: CPU Scheduling

Advanced Types Of Scheduling

CS 153 Design of Operating Systems Winter 2016

Scheduling I. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Advanced topics on scheduling

CPU Scheduling. Disclaimer: some slides are adopted from book authors and Dr. Kulkarni s slides with permission

Project 2 solution code

Uniprocessor Scheduling

Intro to O/S Scheduling. Intro to O/S Scheduling (continued)

Journal of Global Research in Computer Science

Operating System 9 UNIPROCESSOR SCHEDULING

CPU Scheduling. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Process Scheduling Course Notes in Operating Systems 1 (OPESYS1) Justin David Pineda

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

A Paper on Modified Round Robin Algorithm

Scheduling II. To do. q Proportional-share scheduling q Multilevel-feedback queue q Multiprocessor scheduling q Next Time: Memory management

CS162 Operating Systems and Systems Programming Lecture 10. Tips for Handling Group Projects Thread Scheduling

Recall: FCFS Scheduling (Cont.) Example continued: Suppose that processes arrive in order: P 2, P 3, P 1 Now, the Gantt chart for the schedule is:

Operating Systems Process Scheduling Prof. Dr. Armin Lehmann

Pallab Banerjee, Probal Banerjee, Shweta Sonali Dhal

Review of Round Robin (RR) CPU Scheduling Algorithm on Varying Time Quantum

Process Scheduling for John Russo generated Mon Nov 07 13:57:15 EST 2011

A COMPARATIVE ANALYSIS OF SCHEDULING ALGORITHMS

LEAST-MEAN DIFFERENCE ROUND ROBIN (LMDRR) CPU SCHEDULING ALGORITHM

SELF OPTIMIZING KERNEL WITH HYBRID SCHEDULING ALGORITHM

Lecture Note #4: Task Scheduling (1) EECS 571 Principles of Real-Time Embedded Systems. Kang G. Shin EECS Department University of Michigan

ENGG4420 CHAPTER 4 LECTURE 3 GENERALIZED TASK SCHEDULER

GENERALIZED TASK SCHEDULER

Queue based Job Scheduling algorithm for Cloud computing

Lecture 6: Scheduling. Michael O Boyle Embedded Software

Job Scheduling in Cluster Computing: A Student Project

OPERATING SYSTEMS. Systems and Models. CS 3502 Spring Chapter 03

Efficient Round Robin Scheduling Algorithm with Dynamic Time Slice

Mixed Round Robin Scheduling for Real Time Systems

Real-Time and Embedded Systems (M) Lecture 4

Analysis of Adaptive Round Robin Algorithm and Proposed Round Robin Remaining Time Algorithm

Smarter Round Robin Scheduling Algorithm for Cloud Computing and Big Data

Scheduling: Introduction

Comparative Study of Parallel Scheduling Algorithm for Parallel Job

Gang Scheduling Performance on a Cluster of Non-Dedicated Workstations

Motivating Examples of the Power of Analytical Modeling

A COMPARATIVE ANALYSIS OF SCHEDULING POLICIES IN A DISTRIBUTED SYSTEM USING SIMULATION

3. Scheduling issues. Common approaches /2. Common approaches /1. Common approaches / /17 UniPD / T. Vardanega 06/03/2017

Clock-Driven Scheduling

Limited-preemptive Earliest Deadline First Scheduling of Real-time Tasks on Multiprocessors

CHAPTER 4 CONTENT October :10 PM

SCHEDULING AND CONTROLLING PRODUCTION ACTIVITIES

The BEST Desktop Soft Real-Time Scheduler

Priority-Driven Scheduling of Periodic Tasks. Why Focus on Uniprocessor Scheduling?

Dependency-aware and Resourceefficient Scheduling for Heterogeneous Jobs in Clouds

Production Job Scheduling for Parallel Shared Memory Systems

10/1/2013 BOINC. Volunteer Computing - Scheduling in BOINC 5 BOINC. Challenges of Volunteer Computing. BOINC Challenge: Resource availability

EFFECT OF CROSS OVER OPERATOR IN GENETIC ALGORITHMS ON ANTICIPATORY SCHEDULING

Job Scheduling Challenges of Different Size Organizations

Real-Time Scheduling Theory and Ada

IJRASET: All Rights are Reserved

St Louis CMG Boris Zibitsker, PhD

DEADLINE MONOTONIC ALGORITHM (DMA)

Resource Allocation Strategies in a 2-level Hierarchical Grid System

Integrated Scheduling: The Best of Both Worlds

Application the Queuing Theory in the Warehouse Optimization Jaroslav Masek, Juraj Camaj, Eva Nedeliakova

CS 318 Principles of Operating Systems

Node Allocation In Grid Computing Using Optimal Resouce Constraint (ORC) Scheduling

Energy-Efficient Scheduling of Interactive Services on Heterogeneous Multicore Processors

A Survey of Resource Scheduling Algorithms in Green Computing

Reference model of real-time systems

Real-time System Overheads: a Literature Overview

Today s Papers. Composability is Essential. The Future is Parallel Software. EECS 262a Advanced Topics in Computer Systems Lecture 12

Stride Scheduling. Robert Grimm New York University

HETEROGENEOUS SYSTEM ARCHITECTURE: FROM THE HPC USAGE PERSPECTIVE

OPTIMAL ALLOCATION OF WORK IN A TWO-STEP PRODUCTION PROCESS USING CIRCULATING PALLETS. Arne Thesen

Hadoop Fair Scheduler Design Document

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

EPOCH TASK SCHEDULING IN DISTRIBUTED SERVER SYSTEMS

A TECHNICAL LOOK INSIDE ASE 15.7 S HYBRID THREADED KERNEL

Preference-Oriented Fixed-Priority Scheduling for Real-Time Systems

General Terms Measurement, Performance, Design, Theory. Keywords Dynamic load balancing, Load sharing, Pareto distribution, 1.

Bias Scheduling in Heterogeneous Multicore Architectures. David Koufaty Dheeraj Reddy Scott Hahn

Fixed-Priority Preemptive Multiprocessor Scheduling: To Partition or not to Partition

Real-Time Systems. Modeling Real-Time Systems

Chapter III TRANSPORTATION SYSTEM. Tewodros N.

On-line Multi-threaded Scheduling

Utilization and Predictability in Scheduling. the IBM SP2 with Backlling. The Hebrew University of Jerusalem.

Job Scheduling based on Size to Hadoop

System. Figure 1: An Abstract System. If we observed such an abstract system we might measure the following quantities:

Dynamic Fractional Resource Scheduling for HPC Workloads

Effective load balancing for cluster-based servers employing job preemption

SimSo: A Simulation Tool to Evaluate Real-Time Multiprocessor Scheduling Algorithms

Optimized Virtual Resource Deployment using CloudSim

THE advent of large-scale data analytics, fostered by

Justifying Simulation. Why use simulation? Accurate Depiction of Reality. Insightful system evaluations

Job Batching and Scheduling for Parallel Non- Identical Machines via MILP and Petri Nets

COMPUTATIONAL ANALYSIS OF A MULTI-SERVER BULK ARRIVAL WITH TWO MODES SERVER BREAKDOWN

LOADING AND SEQUENCING JOBS WITH A FASTEST MACHINE AMONG OTHERS

Transcription:

EECS 3221 Operating System Fundamentals No.4 CPU scheduling Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University CPU Scheduling CPU scheduling is the basis of multiprogramming CPU scheduling consists of two components: CPU scheduler: when CPU becomes idle, the CPU scheduler must select from among the processes in ready queue. Dispatcher: the module which gives control of CPU to the process selected by the CPU scheduler. Switching context Switching to user mode Jumping to the proper location in user program to restart Dispatch latency: the time it takes for the dispatcher to stop one process and start another running Dispatcher should be as fast as possible 1

CPU burst vs. I/O burst Process (thread) execution = CPU burst + I/O burst Process (thread) alternates between these two states. Length of these bursts is very different. Histogram of CPU-burst Times 2

Non-preemptive vs. Preemptive scheduling CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready. 4. Terminates. Non-preemptive scheduling takes place under 1 and 4. Once the CPU has been allocated to a process, the process keeps the CPU until it releases CPU. Preemptive scheduling takes place in 1,2,3,4. A running process can be preempted by another process Not easy to make OS kernel to support preemptive scheduling How about if the preempted process is updating some critical data structure? Disable interrupt / Safety points Process synchronization Scheduling Criteria CPU utilization keep the CPU as busy as possible. Usage percentage (40% -- 90%) Throughput # of processes that complete their execution per time unit. Turnaround time amount of time to execute a particular process. The interval from the time of submission a process to the time of completion. Waiting time amount of time a process has been waiting in the ready queue. Response time amount of time it takes from when a request was submitted until the first response is produced, not the final output (for time-sharing environment). 3

Scheduling Algorithms First-come, first-served (FCFS) scheduling Shortest-Job-First (SJF) Scheduling Priority Scheduling Round-Robin (RR) scheduling Multi-level Queue Scheduling Multilevel Feedback Queue Scheduling First-Come, First-Served (FCFS) Scheduling Process Burst Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive at time 0 in the order: P 1, P 2, P 3 The Gantt Chart for the scheduling is: P 1 " P 2 " P 3 " 0" 24" 27" 30" Waiting time for P 1 = 0; P 2 = 24; P 3 = 27. Average waiting time: (0 + 24 + 27)/3 = 17. 4

FCFS Scheduling (Cont.) Suppose that the processes arrive in the order: P 2, P 3, P 1. The Gantt chart for the schedule is: P 2 " P 3 " P 1 " 0" 3" 6" 30" Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3. Average waiting time: (6 + 0 + 3)/3 = 3. FCFS is easy to implement (as a FIFO sequence). FCFS results in long wait in most cases and suffers convoy effect. Convoy effect : all the other processes wait for one big process to get off the CPU. Shortest-Job-First (SJF) Scheduling Associate with each process the length of its next CPU burst. Schedule CPU to process with the shortest time. The shortest one is the first. Implementation: ready queue sorted list. Two schemes: 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, it preempts. This scheme is know as the Shortest-Remaining- Time-First (SRTF). SJF is optimal gives minimum average waiting time for a given set of processes. 5

Example of Non-Preemptive SJF Process Arrival Time Burst Time P 1 0.0 7 P 2 2.0 4 P 3 4.0 1 P 4 5.0 4 SJF (non-preemptive) P 1 " P 3 " P 2 " P 4 " 0" 3" 7" 8" 12" 16" Average waiting time = (0 + 6 + 3 + 7)/4 = 4 Example of Preemptive SJF (shortest-remaining-time-first) Process Arrival Time Burst Time SJF (preemptive) P 1 0.0 7 P 2 2.0 4 P 3 4.0 1 P 4 5.0 4 P 1 " P 2 " P 3 " P 2 " P 4 " P 1 " 0" 2" 4" 5" 7" 11" 16" Average waiting time = (9 + 1 + 0 +2)/4 = 3 6

Determining Length of Next CPU Burst Length of next CPU burst is unknown. Can only estimate the length. Can be done by using the length of previous CPU bursts, using exponential averaging, to predict the next one. 1. t n = actual lenght of n 2. τ n + 1 CPU burst = predicted value for the next CPU burst 3. α, 0 α 1 4. Define : τ n+ 1 = α tn + 1 α τ n th ( ). Examples of Exponential Averaging α=0 α=1 τ n+1 = τ n = = τ 0 Recent history does not count. τ n+1 = t n Only the actual last CPU burst counts. If we expand the formula, we get: τ n+1 = α t n +(1 α) tn-1 + +(1 - α ) j tn-j + +(1 - α ) n-1 t0 Since both α and (1 - α) are less than or equal to 1, each successive term has less weight than its predecessor. 7

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 SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem Starvation low priority processes may never execute. Solution Aging as time progresses increase the priority of the process. 8

Round Robin (RR) Each process gets a small slice 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. Ready queue is a circular queue or FIFO queue. Fairness: 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 FCFS q small too many context switches, so overhead is high. q must be large with respect to most CPU bursts lengths. Time Quantum and Context Switch Time 9

Example of RR with Time Quantum = 20 Process Burst Time P 1 53 P 2 17 P 3 68 P 4 24 The Gantt chart is: P 1 " P 2" P 3" P 4" P 1" P 3" P 4" P 1" P 3" P 3" 0" 20" 37" 57" 77" 97" 117" 121" 134" 154" 162" Typically, higher average waiting time than SJF, but better response. Turnaround Time Varies With The Time Quantum 10

Multilevel Queue Ready queue is partitioned into separate queues: foreground (interactive) background (batch) Any process is permanently assigned to one of these queues Each queue has its own scheduling algorithm, i.e., foreground RR background FCFS Scheduling must be done 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 One example of multilevel Queue Scheduling 11

Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way. If used too much CPU time lower-priority queue If waited too long higher-priority queue Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method to determine when to upgrade a process method to determine when to demote a process method to determine which queue a process will enter when that process needs service It is the most general CPU scheduling algorithm. Can be configured to match a specific system under design. Example of Multilevel Feedback Queue Three queues: Q 0 time quantum 8 milliseconds Q 1 time quantum 16 milliseconds Q 2 FCFS Scheduling A new job enters queue Q 0. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q 1. At Q 1 job is again served RR and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q 2. Always preemptive. 12

Scheduling in multi-cpu Era Multiple-Processor Scheduling Multi-core scheduling Scheduling for multiple systems Load balancer (long-term scheduler) Scheduling for distributed systems Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available. Homogeneous processors within a multiprocessor. Any available processor can then be used to run any process in the queue. One common ready queue vs. a separate queue for each CPU. Asymmetric multiprocessing one processor (master) schedules for all processors only one processor accesses the system data structures alleviating the need for data sharing. Symmetric multiprocessing each processor is self-scheduling Each processor select its processes from the queue Process synchronization when accessing common queues 13

Real-Time Scheduling Hard real-time systems requires to complete a critical task within a guaranteed amount of time. Hard to achieve in a general-purpose computer. Soft real-time computing requires that the real-time processes receive priority over others (no aging). The dispatch latency must be small preempt system call (kernel) Adding preemption points (safe points) in system calls Making the entire kernel preemptive by using process synchronization technique to protect all critical region Linux Scheduling Linux scheduling algorithm is preemptive, priority-based, variablelength RR, with complexity O(1). Priority values are dynamically adjusted. Use two so-called run-queues for READY queue: 14

Scheduling Algorithm Evaluation Analytic evaluation: deterministic modeling Given a pre-determined workload, calculate the performance of each algorithm for that workload. Queuing Models No static workload available, so use the probabilistic distribution of CPU and I/O bursts. Use queuing-network analysis. The classes of algorithms and distributions that can be handled in this way are fairly limited. Simulation: use a simulator to model a computer system simulator is driven by random-number generator according to certain distributions. Simulator is driven by a trace file, which records actual events happened in a real system. 15