CPU Scheduling. CPU Scheduling



Similar documents
Objectives. Chapter 5: CPU Scheduling. CPU Scheduler. Non-preemptive and preemptive. Dispatcher. Alternating Sequence of CPU And I/O Bursts

CPU Scheduling. Basic Concepts. Basic Concepts (2) Basic Concepts Scheduling Criteria Scheduling Algorithms Batch systems Interactive systems

Objectives. Chapter 5: Process Scheduling. Chapter 5: Process Scheduling. 5.1 Basic Concepts. To introduce CPU scheduling

Announcements. Basic Concepts. Histogram of Typical CPU- Burst Times. Dispatcher. CPU Scheduler. Burst Cycle. Reading

ICS Principles of Operating Systems

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition

OPERATING SYSTEMS SCHEDULING

CPU Scheduling Outline

Chapter 5 Process Scheduling

Operating System: Scheduling

Processor Scheduling. Queues Recall OS maintains various queues

/ Operating Systems I. Process Scheduling. Warren R. Carithers Rob Duncan

W4118 Operating Systems. Instructor: Junfeng Yang

Comp 204: Computer Systems and Their Implementation. Lecture 12: Scheduling Algorithms cont d

Operating Systems. III. Scheduling.

Deciding which process to run. (Deciding which thread to run) Deciding how long the chosen process can run

Scheduling. Yücel Saygın. These slides are based on your text book and on the slides prepared by Andrew S. Tanenbaum

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

2. is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput

CPU Scheduling. Core Definitions

CPU Scheduling. CSC 256/456 - Operating Systems Fall TA: Mohammad Hedayati

CPU Scheduling. Multitasking operating systems come in two flavours: cooperative multitasking and preemptive multitasking.

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

Scheduling. Scheduling. Scheduling levels. Decision to switch the running process can take place under the following circumstances:

Operating Systems Lecture #6: Process Management

Main Points. Scheduling policy: what to do next, when there are multiple threads ready to run. Definitions. Uniprocessor policies

OS OBJECTIVE QUESTIONS

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Introduction. Scheduling. Types of scheduling. The basics

Scheduling 0 : Levels. High level scheduling: Medium level scheduling: Low level scheduling

Operating Systems, 6 th ed. Test Bank Chapter 7

CPU Scheduling 101. The CPU scheduler makes a sequence of moves that determines the interleaving of threads.

Process Scheduling CS 241. February 24, Copyright University of Illinois CS 241 Staff

PROCESS SCHEDULING ALGORITHMS: A REVIEW

Process Scheduling. Process Scheduler. Chapter 7. Context Switch. Scheduler. Selection Strategies

Analysis and Comparison of CPU Scheduling Algorithms

Job Scheduling Model

A Comparative Study of CPU Scheduling Algorithms

Readings for this topic: Silberschatz/Galvin/Gagne Chapter 5

Scheduling Algorithms

Syllabus MCA-404 Operating System - II

A Group based Time Quantum Round Robin Algorithm using Min-Max Spread Measure

A Priority based Round Robin CPU Scheduling Algorithm for Real Time Systems

Lecture Outline Overview of real-time scheduling algorithms Outline relative strengths, weaknesses

CS Fall 2008 Homework 2 Solution Due September 23, 11:59PM

CS414 SP 2007 Assignment 1

REDUCING TIME: SCHEDULING JOB. Nisha Yadav, Nikita Chhillar, Neha jaiswal

Real-Time Scheduling 1 / 39

4. Fixed-Priority Scheduling

Operating System Tutorial

A LECTURE NOTE ON CSC 322 OPERATING SYSTEM I DR. S. A. SODIYA

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Lecture 3 Theoretical Foundations of RTOS

A Review on Load Balancing In Cloud Computing 1

Scheduling policy. ULK3e 7.1. Operating Systems: Scheduling in Linux p. 1

Analysis of Job Scheduling Algorithms in Cloud Computing

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

This tutorial will take you through step by step approach while learning Operating System concepts.

Konzepte von Betriebssystem-Komponenten. Linux Scheduler. Valderine Kom Kenmegne Proseminar KVBK Linux Scheduler Valderine Kom

Chapter 19: Real-Time Systems. Overview of Real-Time Systems. Objectives. System Characteristics. Features of Real-Time Systems

Real-Time Scheduling (Part 1) (Working Draft) Real-Time System Example

Real-time scheduling algorithms, task visualization

174: Scheduling Systems. Emil Michta University of Zielona Gora, Zielona Gora, Poland 1 TIMING ANALYSIS IN NETWORKED MEASUREMENT CONTROL SYSTEMS

Real-Time Software. Basic Scheduling and Response-Time Analysis. René Rydhof Hansen. 21. september 2010

Real- Time Scheduling

Module 6. Embedded System Software. Version 2 EE IIT, Kharagpur 1

Operating System Aspects. Real-Time Systems. Resource Management Tasks

Predictable response times in event-driven real-time systems

W4118 Operating Systems. Instructor: Junfeng Yang

Linux Process Scheduling Policy

REAL TIME OPERATING SYSTEMS. Lesson-10:

Load Balancing Scheduling with Shortest Load First

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

ò Scheduling overview, key trade-offs, etc. ò O(1) scheduler older Linux scheduler ò Today: Completely Fair Scheduler (CFS) new hotness

Convenience: An OS makes a computer more convenient to use. Efficiency: An OS allows the computer system resources to be used in an efficient manner.

Tasks Schedule Analysis in RTAI/Linux-GPL

Exercises : Real-time Scheduling analysis

Linux scheduler history. We will be talking about the O(1) scheduler

Aperiodic Task Scheduling

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

Performance Comparison of RTOS

Resource Reservation & Resource Servers. Problems to solve

Comparison between scheduling algorithms in RTLinux and VxWorks

Overview and History of Operating Systems

Chapter 2: OS Overview

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Periodic Task Scheduling

What is best for embedded development? Do most embedded projects still need an RTOS?

Efficient Parallel Processing on Public Cloud Servers Using Load Balancing

Chapter 3. Operating Systems

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

CPUInheritance Scheduling. UniversityofUtah

<Insert Picture Here> An Experimental Model to Analyze OpenMP Applications for System Utilization

Real Time Scheduling Basic Concepts. Radek Pelánek

Transcription:

CPU Scheduling Electrical and Computer Engineering Stephen Kim (dskim@iupui.edu) ECE/IUPUI RTOS & APPS 1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation ECE/IUPUI RTOS & APPS 2 1

Basic Concepts Maximum CPU utilization obtained with multiprogramming by making some process running at all times. CPU Burst vs. I/O Burst Process execution consists of a cycle of CPU execution and I/O wait. CPU burst distribution ECE/IUPUI RTOS & APPS 3 Alternating Sequence of CPU And I/O Bursts IO Request CPU Burst IO Burst IO Complete ECE/IUPUI RTOS & APPS 4 2

Histogram of CPU-burst Times exponential or hyperexponential IO bound program many very short CPU burst eg.) CPU bound program a few very long CPU burst ECE/IUPUI RTOS & APPS 5 CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. 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. Scheduling under 1 and 4 is nonpreemptive. A new ready process must be selected for execution. All other scheduling is preemptive. ECE/IUPUI RTOS & APPS 6 3

Nonpreemptive vs. Preemptive Nonpreemptive A process keeps the CPU until it release the CPU either by terminating, or by switching to the waiting state. eg) MS Windows 3.1, Apple Macintosh Preemptive limited by hardware support. A process can be interrupted any time. Possible Inconsistency A process can be interrupted while it modifies some data, which other process tries to modify or read. Frequent between a system call and a user process. A simple solution is to disallow to interrupt in a kernel mode. The solution is not adequate for real-time systems. ECE/IUPUI RTOS & APPS 7 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. ECE/IUPUI RTOS & APPS 8 4

Scheduling Criteria CPU utilization keep the CPU as busy as possible. A reasonable range is from 40% to 90%. Throughput # of processes that complete their execution per time unit. Turnaround time amount of time to execute a particular process from submission to 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 output (for time-sharing environment). ECE/IUPUI RTOS & APPS 9 Optimization Criteria What we want to Maximize CPU utilization Maximize throughput Minimize turnaround time Minimize waiting time Minimize response time In most cases optimize the average measure In the following, we will use the average waiting time ECE/IUPUI RTOS & APPS 10 5

First-come, First-served (FCFS) Scheduling Process Burst Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule 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 ECE/IUPUI RTOS & APPS 11 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 Much better than previous case. Convoy effect: short processes behind long process ECE/IUPUI RTOS & APPS 12 6

Shortest-Job-First (SJR) Scheduling Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes: nonpreemptive once CPU given to the process, it 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. SJF is optimal gives minimum average waiting time for a given set of processes. ECE/IUPUI RTOS & APPS 13 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 ECE/IUPUI RTOS & APPS 14 7

Example of 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 (preemptive) P 1 P 2 P 3 P 4 Average waiting time = (9 + 1 + 0 +2)/4 = 3 Even the SJF is optimal, it cannot be implemented because we cannot see future. t ECE/IUPUI RTOS & APPS 15 Predicting Length of Next CPU Burst Can only estimate the length. Can be done by using the length of previous CPU bursts, using exponential averaging. 1. t n = actual length of n th CPU burst 2. τ n+1 = predicted value for the next CPU burst 3. 0 α 1 4. Define: τ n+1 = α t n + (1- α) τ n ECE/IUPUI RTOS & APPS 16 8

Predicting Length of Next CPU Burst, cont ECE/IUPUI RTOS & APPS 17 Examples of Exponential Averaging α =0 τ n+1 = τ n Recent history does not count. α =1 τ n+1 = t n Only the actual last CPU burst counts. If we expand the formula, we get: τ n+1 = α t n +(1 - α) α t n -1 + +(1 - α ) j α t n -1 + +(1 - α ) n=1 t n τ 0 Since both α and (1 - α) are less than or equal to 1, each successive term has less weight than its predecessor. ECE/IUPUI RTOS & APPS 18 9

Implementation Consideration The coefficient of exponential average is a floating number The computation of floating number is burden in designing a kernel. Even worse, many microprocessor used for real-time operating systems do not have floating point unit (FPU). What we can do for that type of processors? ECE/IUPUI RTOS & APPS 19 Priority Scheduling A priority number (integer) is associated with each process UNIX: -20 (highest) to 19 (lowest), default is 10 microc/os-ii: 0 (highest) to 63 (lowest) The CPU is allocated to the process with the highest priority Preemptive nonpreemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Starvation low priority processes may never execute. Solution: Aging as time progresses increase the priority of the process. ECE/IUPUI RTOS & APPS 20 10

Round Robin (RR) Each process gets a small unit of CPU time (time quantum or time slice), 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. ECE/IUPUI RTOS & APPS 21 Example of RR with Time Quantum = 4 RR SJF Process Burst Time P 1 24 P 2 3 P 3 3 The Gantt chart is: P 1 P 2 P 3 P 1 P 1 P 1 P 1 P 1 P 2 P 3 P 1 P 1 P 1 P 1 P 1 P 1 Average waiting time of RR = (6+4+7)/3=5.66 Average waiting time of SJF = (6+0+3)/3=3 The average waiting time of RR is often quite long. ECE/IUPUI RTOS & APPS 22 11

Time Quantum and Context Switch Time The average turnaround of RR is longer than SJF because CPU bursts of all processes interleave. But, better response. ECE/IUPUI RTOS & APPS 23 Turnaround Time Varies With The Time Quantum ECE/IUPUI RTOS & APPS 24 12

Multilevel Queue Ready queue is partitioned into separate queues: foreground (interactive) background (batch) Each queue has its own scheduling algorithm, 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 Is this true? ECE/IUPUI RTOS & APPS 25 Multilevel Queue Scheduling ECE/IUPUI RTOS & APPS 26 13

Multilevel Feedback Queue Scheduling A process can move between the various queues If a process uses to much CPU time, it will be moved to a lowerpriority queue, but leaves IO-bound and interactive processes in the higher priority queue. Aging can be implemented with the same way. Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service ECE/IUPUI RTOS & APPS 27 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 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 Q 1. At Q 1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q 2. ECE/IUPUI RTOS & APPS 28 14

Multilevel Feedback Queues ECE/IUPUI RTOS & APPS 29 Example, Scheduling For the given processes, answer the following question for FCFS, SJF, RR(q=1), RR(q=4), 3Level Feedback(q=1), and 3Level Feedback(q=1&2). What is the average waiting times for each scheduling? What is the turnaround time for each scheduling? Prcess Name A B C D E Arrival Time 0 1 3 9 12 Processing Time 3 5 2 5 5 ECE/IUPUI RTOS & APPS 30 15

Real-time Scheduling Hard real-time systems required to complete a critical task within a guaranteed amount of time Soft real-time computing requires that critical processes receive priority over less fortunate ones Priority inversion When a higher-priority process needs to access kernel data currently being accessed by another lower-priority process. The higher-priority process must wait for the lower-priority process to finish Solution: priority inheritance scheme all processes accessing resources that a higher-priority process needs, inherit the high priority until they are done with the resources. When they are completed the resource access, their priority reverts to its original value ECE/IUPUI RTOS & APPS 31 Dispatch Latency The conflict phase consists of Preemption of any process running in the kernel Release by low-priority processes resources needed by the high-priority process. If the preemption is not allowed, the dispatch latency is quite long, so most of real-time OS s support preemption. ECE/IUPUI RTOS & APPS 32 16

Rate Monotonic Scheduling (RMS) In an RT system, how can we assign priorities to critical tasks? Rate monotonic scheduling Task priorities are assigned based on how often tasks executes Tasks with the highest rate of execution are given the highest priority Assumption All tasks are periodic Tasks do not synchronize with one another, share resouces, or exchange data OS supports preemption ECE/IUPUI RTOS & APPS 33 RMS Theorem Given n tasks, all task hard real-time deadlines are always met if the inequality hold. E T i i n(2 1/ n 1) where E i is the maximum execution time of task i, and T i is the execution period of task i. Note that E i is always smaller than T i and E i /T i corresponds to the fraction of CPU time required to execute task i. eg) 2(2 1/2-1)=0.828, 100(2 1/100-1)=0.695 If the system has 100 tasks, the total CPU utilization must be less than 69.5% to meet the real-time deadline. ECE/IUPUI RTOS & APPS 34 17

n (2 1/n -1) 1.2 1 0.8 0.6 0.4 0.2 0 0 5 10 15 20 25 30 35 ECE/IUPUI RTOS & APPS 35 Example, RMS Consider three periodic tasks, Task P 1 : E 1 =40, T 1 =150, Task P 2 : E 2 =100, T 2 =350, and Task P 3 : E 3 =20, T 3 =100 What priorities will you assign to each task from 1 to 3? (The smaller number, the higher priority) Can the tasks be scheduled in real-time? ECE/IUPUI RTOS & APPS 36 18