III. Process Scheduling

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

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

CPU Scheduling. CPU Scheduling

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

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 System: Scheduling

Chapter 5 Process Scheduling

CPU Scheduling Outline

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

W4118 Operating Systems. Instructor: Junfeng Yang

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

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

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

OPERATING SYSTEMS SCHEDULING

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

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

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

CPU Scheduling. Core Definitions

Processor Scheduling. Queues Recall OS maintains various queues

Operating Systems. III. Scheduling.

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

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

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

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

OS OBJECTIVE QUESTIONS

Real-Time Scheduling 1 / 39

Introduction. Scheduling. Types of scheduling. The basics

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Operating Systems, 6 th ed. Test Bank Chapter 7

PROCESS SCHEDULING ALGORITHMS: A REVIEW

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

Operating Systems Lecture #6: Process Management

Operating Systems Concepts: Chapter 7: Scheduling Strategies

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

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

A Comparative Study of CPU Scheduling Algorithms

Analysis and Comparison of CPU Scheduling Algorithms

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

Linux Process Scheduling Policy

Operating System Tutorial

Chapter 2: OS Overview

Chapter 6, The Operating System Machine Level

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Scheduling Algorithms

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

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Processes and Non-Preemptive Scheduling. Otto J. Anshus

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

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

Performance Comparison of RTOS

Job Scheduling Model

CS414 SP 2007 Assignment 1

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

Chapter 2 System Structures

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

3 - Introduction to Operating Systems

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

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

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

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Operating System Components

Operating Systems. Rafael Ramirez (T, S)

Principles of Operating Systems CS 446/646

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

ELEC 377. Operating Systems. Week 1 Class 3

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.

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

Chapter 1 8 Essay Question Review

Chapter 3 Operating-System Structures

Chapter 11 I/O Management and Disk Scheduling

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

Multi-core Programming System Overview

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

OPERATING SYSTEM SERVICES

How To Understand The History Of An Operating System

Chapter 1 13 Essay Question Review

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

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

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

REAL TIME OPERATING SYSTEMS. Lesson-10:

W4118 Operating Systems. Instructor: Junfeng Yang

Overview of Presentation. (Greek to English dictionary) Different systems have different goals. What should CPU scheduling optimize?

Undergraduate Course Syllabus

Syllabus MCA-404 Operating System - II

Final Report. Cluster Scheduling. Submitted by: Priti Lohani

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

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

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

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

System Structures. Services Interface Structure

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

File System & Device Drive. Overview of Mass Storage Structure. Moving head Disk Mechanism. HDD Pictures 11/13/2014. CS341: Operating System

Chapter 1: Introduction. What is an Operating System?

Web Server Architectures

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

Types Of Operating Systems

Transcription:

Intended Schedule III. Process Scheduling Date Lecture Hand out Submission 0 20.04. Introduction to Operating Systems Course registration 1 27.04. Systems Programming using C (File Subsystem) 1. Assignment 2 04.05. Systems Programming using C (Process Control) 2. Assignment 1. Assignment 3 11.05. Process Scheduling 3. Assignment 2. Assignment 4 18.05. Process Synchronization 4. Assignment 3. Assignment 5 25.05. Inter Process Communication 5. Assignment 4. Assignment 6 01.06. Pfingstmontag 6. Assignment 5. Assignment 7 08.06. Input / Output 7. Assignment 6. Assignment 8 15.06. Memory Management 8. Assignment 7. Assignment 9 22.06. 9. Assignment 8. Assignment Filesystems 10 29.06. 10. Assignment 9. Assignment 11 06.07. Special subject: Transactional Memory 10. Assignment 12 13.07. Special subject: XQuery your Filesystem 13 20.07. Wrap up session 27.07. First examination date 12.10. Second examination date 1 2 Processes An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks Textbooks use the terms job and process almost interchangeably Process a program in execution; process execution must progress in sequential fashion For the OS, processes are the unit of all resource allocation A process includes: program counter stack data section Process in memory 3 4

Information associated with each process Process state Program counter CPU registers CPU scheduling information Memory-management information As a process executes, it changes state new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a process terminated: The process has finished execution Accounting information I/O status information 5 6 At any time, processes can be described as either: Single Process I/O-bound spends more time doing I/O than computations, many short CPU bursts CPU-bound spends more time doing computations; few very long CPU bursts typical processes follow a CPU I/O burst cycle Process execution consists of a cycle of CPU execution and I/O wait Process Switching Operating system tries to maximize CPU utilization: multiprogramming run multiple processes and try to interleave their CPU-I/O burst cycles Scheduling 7 8

When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process Context-switch time is overhead; the system does no useful work while switching Time dependent on hardware support Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue controls the degree of multiprogramming invoked very infrequently (sec, min) may be slow Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU invoked very frequently (msec) must be fast Medium-term scheduler swaps running processes out 9 10 Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device Processes migrate among the various queues 11 12

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 All other scheduling is preemptive 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 13 14 Scheduling CPU utilization keep the CPU as busy as possible Throughput # of processes that complete their execution per time unit Turnaround time amount of time to execute a particular process Waiting time amount of time a process has been waiting in the ready queue Optimization Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time Scheduling Strategies 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) Deadlines esp. for real-time scheduling 15 16

Process Burst Time (duration) P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order P 2, P 3, P 1 The Gantt chart for the schedule is: Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: P 2 P 3 P 1 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 0 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 3 6 30 Convoy effect (or phenomenon) short processes behind long process 17 18 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. This scheme is know as the Shortest-Remaining-Time-First (SRTF) 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 SJF is optimal gives minimum average waiting time for a given set of processes 0 3 7 8 12 16 Average waiting time = (0 + 6 + 3 + 7)/4 = 4 19 20

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) Can only estimate the length Can be done by using the length of previous CPU bursts, using exponential averaging P 1 P 2 P 3 P 4 P 2 P 1 0 2 4 5 7 11 16 Average waiting time = (9 + 1 + 0 +2)/4 = 3 21 22 = 0 n+1 = n Recent history does not count = 1/2 = 1 0 = 10 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 -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 23 24

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 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 rule of thumb: 80% of CPU bursts should be smaller than time quantum 25 26 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 turnaround than SJF, but better response 27 28

Ready queue is partitioned into separate queues, e.g., 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 29 30 A process can move between the various queues; aging can be implemented this 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 31 32

Three queues: Q 0 RR with time quantum 8 milliseconds Q 1 RR 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. 33 34 Multiple Processors 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 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 Threads 35 36

Threads...? Multiple streams of program execution within a single process Light-weight processes Switching from one thread to another requires less effort Threads share (some) context... can be implemented on top, e.g., in a library (userlevel threads) or inside the kernel (kernel-level threads) 37 38 Responsiveness Resource Sharing Economy Utilization of MP Architectures Thread management done by user-level threads library Three primary thread libraries: POSIX Pthreads Win32 threads Java threads Supported by the Kernel Examples Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X 39 40

Many-to-One: Many user-level threads mapped to single kernel thread Solaris Green Threads GNU Portable Threads One-to-One: Each user-level thread maps to kernel thread Windows NT/XP/2000 Linux Solaris 9 and later Many-to-Many Allows many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads Solaris prior to version 9 Windows NT/2000 with the ThreadFiber package 41 42 43 44

Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples IRIX HP-UX Tru64 UNIX Solaris 8 and earlier Semantics of fork() and exec() system calls Does fork() duplicate only the calling thread or all threads? Thread cancellation Terminating a thread before it has finished Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled Signal handling Thread pools Thread specific data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool) Scheduler activations 45 46 Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application Scheduler activations provide upcalls - a communication mechanism from the kernel to the thread library This communication allows an application to maintain the correct number kernel threads Examples 47 48

A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization API specifies behavior of the thread library, implementation is up to development of the library Common in UNIX operating systems (Solaris, Linux, Mac OS X) Implements the one-to-one mapping Each thread contains A thread id Register set Separate user and kernel stacks Private data storage area The register set, stacks, and private storage area are known as the context of the threads The primary data structures of a thread include: ETHREAD (executive thread block) KTHREAD (kernel thread block) TEB (thread environment block) 49 50 Linux refers to them as tasks rather than threads Thread creation is done through clone() system call clone() allows a child task to share the address space of the parent task (process) Java threads are managed by the JVM Java threads may be created by: Extending Thread class Implementing the Runnable interface 51 52

Intended Schedule Date Lecture Hand out Submission 0 20.04. Introduction to Operating Systems Course registration 1 27.04. Systems Programming using C (File Subsystem) 1. Assignment 2 04.05. Systems Programming using C (Process Control) 2. Assignment 1. Assignment 3 11.05. Process Scheduling 3. Assignment 2. Assignment 4 18.05. Process Synchronization 4. Assignment 3. Assignment 5 25.05. Inter Process Communication 5. Assignment 4. Assignment 6 01.06. Pfingstmontag 6. Assignment 5. Assignment 7 08.06. Input / Output 7. Assignment 6. Assignment 8 15.06. Memory Management 8. Assignment 7. Assignment 9 22.06. 9. Assignment 8. Assignment Filesystems 10 29.06. 10. Assignment 9. Assignment 11 06.07. Special subject: Transactional Memory 10. Assignment 12 13.07. Special subject: XQuery your Filesystem 13 20.07. Wrap up session 27.07. First examination date 12.10. Second examination date IV. Process Synchronization 53 54