Chapter 4 Processor Management

Slides:



Advertisements
Similar presentations
1 Uniprocessor Scheduling Types of scheduling –The aim of processor scheduling is to assign processes to be executed by the processor so as to optimize.
Advertisements

Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
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.
Scheduling Algorithms
Ceng Operating Systems Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Processes and Their Scheduling.
Day 25 Uniprocessor scheduling. Algorithm: Selection function Selection function – which process among ready processes to select. w – time spent in system,
A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.
Understanding Operating Systems Fifth Edition
Understanding Operating Systems Sixth Edition
Chapter 3: CPU Scheduling
Operating Systems 1 K. Salah Module 2.1: CPU Scheduling Scheduling Types Scheduling Criteria Scheduling Algorithms Performance Evaluation.
Scheduling in Batch Systems
Understanding Operating Systems Sixth Edition
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.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
CPU-Scheduling Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. The short term scheduler.
CPU Scheduling Chapter 6 Chapter 6.
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.
Lecture 5: Uniprocessor Scheduling
Processor Management Introduction
Chapter 4 Processor Management
Chapter 4 - Processor Management Ivy Tech State College Northwest Region 01 CIS106 Microcomputer Operating Systems Gina Rue CIS Faculty.
OPERATING SYSTEMS CPU SCHEDULING.  Introduction to CPU scheduling Introduction to CPU scheduling  Dispatcher Dispatcher  Terms used in CPU scheduling.
Chapter 6 CPU SCHEDULING.
Chapter Four : Processor Management
1 Scheduling Processes. 2 Processes Each process has state, that includes its text and data, procedure call stack, etc. This state resides in memory.
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.
Operating Systems Process Management.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
1 Our focus  scheduling a single CPU among all the processes in the system  Key Criteria: Maximize CPU utilization Maximize throughput Minimize waiting.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
3.1 : Resource Management Part2 :Processor Management.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5 Processor Scheduling Introduction Processor (CPU) scheduling is the sharing of the processor(s) among the processes in the ready queue.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
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.
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 G.Anuradha Reference : Galvin. CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time.
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
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.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
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.
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
Copyright ©: Nahrstedt, Angrave, Abdelzaher
Understanding Operating Systems Seventh Edition
Chapter 2.2 : Process Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Understanding Operating Systems Seventh Edition
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
CPU Scheduling: Basic Concepts
Presentation transcript:

Chapter 4 Processor Management Understanding Operating Systems, Fourth Edition

Objectives You will be able to describe: The difference between job scheduling and process scheduling, and how they relate The advantages and disadvantages of process scheduling algorithms that are preemptive versus those that are nonpreemptive The goals of process scheduling policies Up to six different process scheduling algorithms The role of internal interrupts and the tasks performed by the interrupt handler Understanding Operating Systems, Fourth Edition

Overview Program (Job): Process (Task): A unit of work that has been submitted by user to an operating system An inactive unit, such as a file stored on a disk Process (Task): An active entity, which requires a set of resources, including a processor and special registers, to perform its function A single instance of an executable program Understanding Operating Systems, Fourth Edition

Overview (continued) Processor (CPU): performs calculations and executes programs In single-user systems: Processor is busy only when user is executing a job, at all other times it is idle Processor management is simple In a multiprogramming environment: Processor must be allocated to each job in a fair and efficient manner Requires scheduling policy and a scheduling algorithm Understanding Operating Systems, Fourth Edition

Overview (continued) Interrupt: A hardware signal that suspends execution of a program and activates the execution of interrupt handler Context Switch: Saving a job’s processing information in its PCB when interrupted Context switching occurs in all preemptive policies Understanding Operating Systems, Fourth Edition

Job Scheduling Versus Process Scheduling Processor Manager has two submanagers: Job Scheduler: In charge of job scheduling Initiates the job based on certain criteria Process Scheduler: In charge of process scheduling Assigns the CPU to execute processes of those jobs placed on READY queue by Job Scheduler Understanding Operating Systems, Fourth Edition

Job Scheduling Versus Process Scheduling (continued) Job Scheduler (High level scheduler): Initiates the job based on certain criteria Puts jobs in a sequence that uses all system’s resources as fully as possible Strives for balanced mix of jobs with large I/O interaction and jobs with lots of computation Tries to keep most system components busy most of time Understanding Operating Systems, Fourth Edition

Job Scheduling Versus Process Scheduling (continued) Process Scheduler (Low level scheduler): Determines which jobs will get the CPU, when, and for how long Decides when processing should be interrupted Determines which queues the job should be moved to during its execution Recognizes when a job has concluded and should be terminated Understanding Operating Systems, Fourth Edition

Job Scheduling Versus Process Scheduling (continued) I/O-bound jobs have many brief CPU cycles and long I/O cycles, e.g., printing a series of documents CPU-bound jobs have long CPU cycles and shorter I/O cycles, e.g., finding the first 300 prime numbers Total effect of all CPU cycles, from both I/O-bound and CPU-bound jobs, approximates a Poisson distribution curve Understanding Operating Systems, Fourth Edition

Job Scheduling Versus Process Scheduling (continued) Figure 4.1: Distribution of CPU cycle times Understanding Operating Systems, Fourth Edition

Job Scheduling Versus Process Scheduling (continued) Middle level scheduler (third layer): Used in a highly interactive environment Removes active jobs from memory to reduce degree of multiprogramming Allows jobs to be completed faster Understanding Operating Systems, Fourth Edition

Job and Process Status Job status: A job takes one of the following states as it moves through the system HOLD READY WAITING RUNNING FINISHED Understanding Operating Systems, Fourth Edition

Job and Process Status (continued) Figure 4.2: A typical job (or process) changes status as it moves through the system from HOLD to FINISHED Understanding Operating Systems, Fourth Edition

Job and Process Status (continued) Transition from one status to another is initiated by either the Job Scheduler (JS) or the Process Scheduler (PS): HOLD to READY: JS, using a predefined policy READY to RUNNING: PS, using some predefined algorithm RUNNING back to READY: PS, according to some predefined time limit or other criterion RUNNING to WAITING: PS, and is initiated by an instruction in the job Understanding Operating Systems, Fourth Edition

Job and Process Status (continued) Transition (continued): WAITING to READY: PS, and is initiated by signal from I/O device manager that I/O request has been satisfied and job can continue. RUNNING to FINISHED: PS or JS, if job is finished or error has occurred Understanding Operating Systems, Fourth Edition

Process Control Blocks Process Control Block (PCB): Data structure that contains basic info about the job including What it is Where it’s going How much of its processing has been completed Where it’s stored How much it has spent in using resources Understanding Operating Systems, Fourth Edition

Process Control Blocks (continued) Figure 4.3: Contents of each job’s Process Control Block Understanding Operating Systems, Fourth Edition

Process Control Blocks (continued) Contents of Process Control Block (PCB): Process identification Process status (HOLD, READY, RUNNING, WAITING) Process state (process status word, register contents, main memory info, resources, process priority) Accounting (CPU time, total time, memory occupancy, I/O operations, number of input records read, etc.) Understanding Operating Systems, Fourth Edition

PCBs and Queuing PCB of a job: Contains all of the data about the job needed by the operating system to manage the processing of the job Created when job scheduler accepts the job Updated as job goes from beginning to end of its execution Queues use PCBs to track jobs PCBs, not jobs, are linked to form queues – Queues must be managed by process scheduling policies and algorithms Understanding Operating Systems, Fourth Edition

PCBs and Queuing (continued) Figure 4.4: Queuing paths from HOLD to FINISHED Understanding Operating Systems, Fourth Edition

Process Scheduling Policies Operating system must resolve three limitations of a system before scheduling all jobs in a multi-programming environment: Finite number of resources (e.g., disk drives, printers, and tape drives) Some resources can’t be shared once they’re allocated (e.g., printers) Some resources require operator intervention (e.g., tape drives) Understanding Operating Systems, Fourth Edition

Process Scheduling Policies (continued) A good process scheduling policy should Maximize throughput by running as many jobs as possible in a given amount of time Minimize response time by quickly turning around interactive requests Minimize turnaround time by moving entire jobs in and out of system quickly Minimize waiting time by moving jobs out of READY queue as quickly as possible Understanding Operating Systems, Fourth Edition

Process Scheduling Policies (continued) Maximize CPU efficiency by keeping CPU busy 100 percent of time Ensure fairness for all jobs by giving every one an equal amount of CPU and I/O time Understanding Operating Systems, Fourth Edition

Process Scheduling Policies (continued) Need for Interrupts: When a job claims CPU for a very long time before issuing an I/O request Builds up READY queue & empties I/O queues Creates an unacceptable imbalance in the system Process Scheduler uses interrupts when a predetermined slice of time has expired Suspends all activity on the currently running job Reschedules it into the READY queue Understanding Operating Systems, Fourth Edition

Process Scheduling Policies (continued) Types of Scheduling Policies: Preemptive scheduling policy: Interrupts processing of a job and transfers the CPU to another job Nonpreemptive scheduling policy: Functions without external interrupts Understanding Operating Systems, Fourth Edition

Process Scheduling Algorithms Types of Process Scheduling Algorithms: First Come, First Served (FCFS) Shortest Job Next (SJN) Priority Scheduling Shortest Remaining Time (SRT) Round Robin Multiple Level Queues Understanding Operating Systems, Fourth Edition

First-Come, First-Served Nonpreemptive Handles jobs according to their arrival time: the earlier they arrive, the sooner they’re served Simple algorithm to implement: uses a FIFO queue Good for batch systems; unacceptable for interactive systems Turnaround time is unpredictable Understanding Operating Systems, Fourth Edition

First-Come, First-Served (continued) Jobs arrival sequence: A, B, C Job A has a CPU cycle of 15 milliseconds • Job B has a CPU cycle of 2 milliseconds • Job C has a CPU cycle of 1 millisecond Average turnaround time: 16.67 s Figure 4.5: Timeline for job sequence A, B, C using the FCFS algorithm Understanding Operating Systems, Fourth Edition

First-Come, First-Served (continued) Jobs arrival sequence: C, B, A Job A has a CPU cycle of 15 milliseconds • Job B has a CPU cycle of 2 milliseconds • Job C has a CPU cycle of 1 millisecond Average turnaround time: 7.3 s Figure 4.6: Timeline for job sequence C, B, A using the FCFS algorithm Understanding Operating Systems, Fourth Edition

Shortest Job Next (SJN) Nonpreemptive Handles jobs based on length of their CPU cycle time Easiest to implement in batch environments Doesn’t work in interactive systems Optimal only when all jobs are available at same time and the CPU estimates are available and accurate Understanding Operating Systems, Fourth Edition

Shortest Job Next (continued) Four batch jobs A, B, C, D, all in the READY queue Job: A B C D CPU cycle: 5 2 6 4 Average turnaround time: 9 s Figure 4.7: Timeline for job sequence B, D, A, C using the SJN algorithm Understanding Operating Systems, Fourth Edition

Priority Scheduling Nonpreemptive Gives preferential treatment to important jobs Programs with highest priority are processed first Not interrupted until CPU cycles are completed or a natural wait occurs FCFS policy is used if two or more jobs with equal priority in READY queue System administrator or Processor Manager use different methods of assigning priorities Understanding Operating Systems, Fourth Edition

Shortest Remaining Time Preemptive version of the SJN algorithm Processor allocated to job closest to completion Current job can be preempted if newer job in READY queue has shorter time to completion Cannot be implemented in interactive system Requires advance knowledge of the CPU time required to finish each job SRT involves more overhead than SJN OS monitors CPU time for all jobs in READY queue and performs context switching Understanding Operating Systems, Fourth Edition

Shortest Remaining Time (continued) Arrival time: 0 1 2 3 Job: A B C D CPU cycle: 6 3 1 4 Job: A B C D Turnaround: 14 4 1 6 Average Turnaround: 6.25s Figure 4.8: Timeline for job sequence A, B, C, D using the preemptive SRT algorithm Understanding Operating Systems, Fourth Edition

Shortest Remaining Time (continued) Arrival time: 0 1 2 3 Job: A B C D CPU cycle: 6 3 1 4 Job: A B C D Turnaround: 6 9 5 11 Average Turnaround: 7.75s Figure 4.9: Timeline for job sequence A, B, C, D using the nonpreemptive SJN algorithm Understanding Operating Systems, Fourth Edition

Round Robin Preemptive Used extensively in interactive systems Based on a predetermined slice of time (time quantum) that’s given to each job Size of time quantum crucial to system performance Usually varies from 100 ms to 1-2 s Ensures CPU is equally shared among all active processes and is not monopolized by any one job Understanding Operating Systems, Fourth Edition

Round Robin (continued) Arrival time: 0 1 2 3 Job: A B C D CPU cycle: 8 4 9 5 Job: A B C D Turnaround: 20 7 24 22 Average Turnaround: 18.25 s Time slice: 4ms Figure 4.10: Timeline for job sequence A, B, C, D using the preemptive round robin algorithm Understanding Operating Systems, Fourth Edition

Round Robin (continued) If Job’s CPU cycle > time quantum Job is preempted and put at the end of the READY queue and its information is saved in its PCB If Job’s CPU cycle < time quantum If job is finished, all resources allocated to it are released & completed job is returned to user If interrupted by I/O request, then info is saved in PCB & it is linked at end of the appropriate I/O queue Once I/O request is satisfied, job returns to end of READY queue to await allocation of CPU Understanding Operating Systems, Fourth Edition

Round Robin (continued) CPU cycle of job A: 8 ms Figure 4.11: Context switches for job A with three different time quantums. In (a) the job finishes before the time quantum expires. In (b) and (c), the time quantum expires first, interrupting the job. Understanding Operating Systems, Fourth Edition

Round Robin (continued) Efficiency depends on the size of time quantum in relation to the average CPU cycle If the quantum is too large - larger than most CPU cycles Algorithm reduces to the FCFS scheme If the quantum is too small Amount of context switching slows down the execution of the jobs Amount of overhead is dramatically increased Understanding Operating Systems, Fourth Edition

Round Robin (continued) General rules of thumb for selecting the proper time quantum: Should be long enough to allow 80% of CPU cycles to run to completion Should be at least 100 times longer than the time required to perform one context switch These rules are flexible and depend on the system Understanding Operating Systems, Fourth Edition

Multiple-Level Queues Work in conjunction with several other schemes Found in systems with jobs that can be grouped according to a common characteristic Examples: Priority-based system with different queues for each priority level System with all CPU-bound jobs in one queue and all I/O-bound jobs in another Hybrid system with batch jobs in background queue and interactive jobs in a foreground queue Understanding Operating Systems, Fourth Edition

Multiple-Level Queues (continued) Four primary methods to the movement of jobs: No Movement Between Queues Movement Between Queues Variable Time Quantum Per Queue Aging Understanding Operating Systems, Fourth Edition

Multiple-Level Queues (continued) No Movement Between Queues: The processor is allocated to the jobs in the high-priority queue in FCFS fashion Allocated to jobs in lower priority queues only when the high priority queues are empty Movement Between Queues Adjusts the priorities assigned to each job A job may also have its priority increased Good in interactive systems Understanding Operating Systems, Fourth Edition

Multiple-Level Queues (continued) Variable Time Quantum Per Queue: Each of the queues is given a time quantum twice as long as the previous queue CPU-bound job can execute for longer and longer periods of time, thus improving its chances of finishing faster Aging: System moves the old job to the next highest queue, and so on until it reaches the top queue Ensures that jobs in the lower-level queues will eventually complete their execution Understanding Operating Systems, Fourth Edition

A Word About Interrupts Types of Interrupts: Page interrupts to accommodate job requests Time quantum expiration interrupts I/O interrupts when READ or WRITE command is issued Internal interrupts (synchronous interrupts) result from arithmetic operation or job instruction Illegal arithmetic operations (e.g., dividing by 0). Illegal job instructions (e.g., attempts to access protected storage locations) Understanding Operating Systems, Fourth Edition

A Word About Interrupts (continued) Interrupt handler: Control program that handles the interruption sequence of events When operating system detects a nonrecoverable error, the interrupt handler follows this sequence: The type of interrupt is described and stored The state of the interrupted process is saved The interrupt is processed The processor resumes normal operation Understanding Operating Systems, Fourth Edition

Summary Process scheduler assigns the CPU to execute processes of those jobs placed on READY queue by Job Scheduler Total effect of all CPU cycles, from both I/O-bound and CPU-bound jobs, approximates a Poisson distribution curve Transition from one status to another is initiated by either Job Scheduler (JS) or Process Scheduler (PS) PCB of a job contains all data about the job needed by OS to manage the processing of the job Understanding Operating Systems, Fourth Edition

Summary (continued) A good process scheduling policy should maximize CPU efficiency by keeping CPU busy 100 percent of time FIFO has simple algorithm to implement but turnaround time is unpredictable SJN minimizes average waiting time but results in infinite postponement of some jobs Priority scheduling ensures fast completion of important jobs but results in infinite postponement of some jobs Understanding Operating Systems, Fourth Edition

Summary (continued) SRT ensures fast completion of short jobs but involves more overhead than SJN, incurred by context switching Efficiency in round robin policy depends on the size of time quantum in relation to the average CPU cycle Multiple-level queues counteract indefinite postponement with aging or other queue movement Understanding Operating Systems, Fourth Edition