CS 149: Operating Systems February 3 Class Meeting

Slides:



Advertisements
Similar presentations
CPU Scheduling.
Advertisements

Chapter 5: CPU Scheduling
Scheduling Criteria CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – # of processes that complete their execution per.
OS, , Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 17 Scheduling III.
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.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 16 Scheduling II.
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.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Processes and Their Scheduling.
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.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
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.
CS 149: Operating Systems February 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
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.
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.
Chapter 6: CPU Scheduling
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 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 Scheduler What is the job of.
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
Chapter 6 CPU SCHEDULING.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
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  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 7: CPU Scheduling Chapter 5.
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.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU 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.
CPU Scheduling G.Anuradha Reference : Galvin. CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time.
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 ©2013 Operating System Concepts – 9 th Edition Chapter 6: CPU Scheduling.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU SCHEDULING.
Chapter 2 Scheduling.
Scheduling (Priority Based)
Process management Information maintained by OS for process management
Chapter 6: CPU Scheduling
Operating System Concepts
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
Presentation transcript:

CS 149: Operating Systems February 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Processes A process is basically an abstraction of a running program. The most central concept in any operating system. Each process runs in its own address space. _

Context Switching A process’s state information is kept in its process control block (PCB). Operating Systems: Design and Implementation, 3rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc. 0-13-142938-8

Contents of a Process Control Block (PCB) Operating Systems: Design and Implementation Tanenbaum & Woodhull (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8

Process States Running Ready Blocked Actually using the CPU at that instant. Ready Runnable, but temporarily stopped to let another process run. Blocked Unable to run until some external event happens. Operating Systems: Design and Implementation, 3rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc. 0-13-142938-8

Process Scheduler Transitions 2 and 3 are caused by the process scheduler. A part of the operating system. A process does not know about the transitions. Transition 2 can happen at the end of a time slice. Transition 3 can happen when it’s the process’s turn again to run.

Process Scheduling Goals The process scheduler decides which process can run, i.e., which process can have the CPU. The goal is to keep all parts of the computer system as busy as possible. Which scheduling algorithm to use depends on The type of system How it’s used What policies are in place

Process Behavior A process may be: Computing: using the CPU Performing I/O A compute-bound process spends most of its time computing. Long CPU bursts and infrequent I/O waits. An I/O-bound process spends most of its time waiting for I/O operations to complete. Long I/O waits punctuated by short CPU bursts.

Process Behavior, cont’d As CPUs become faster relative to disks: Programs are becoming more I/O bound. Scheduling I/O-bound processes becomes more important. Operating Systems: Design and Implementation Tanenbaum & Woodhull (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8

Process Behavior, cont’d Histogram of CPU burst durations. CPU-bound process: A few long bursts. I/O bound process: Many short bursts. Silberschatz, Galvin, and Gagne Operating Systems Concepts with Java, 8th edition (c) 2010 John Wiley & Sons. All rights reserved. 0-13-142938-8

When to Schedule When scheduling is absolutely required: When a process exits. When a process blocks on I/O, or on a semaphore. When scheduling usually done (although not absolutely required): When a new process is created. When an I/O interrupt occurs. When a clock interrupt occurs.

Types of Scheduling Algorithms Preemptive Each process is assigned a time interval to run, called the quantum or time slice. At the end of a process’s time quantum, the scheduler suspends the process and schedules another process to run. Non-preemptive The scheduler allows a process to run until it blocks: Waiting for I/O. Waiting for another process. The process voluntarily releases the CPU.

Scheduling Criteria CPU utilization Throughput Turnaround time Keep the CPU as busy as possible. Throughput Number of processes that complete their execution per time unit. Turnaround time The amount of elapsed time from when a process enters the ready queue to when it completes execution.

Scheduling Criteria, cont’d Waiting time Amount of time a process waits in the ready queue. Response time In an interactive environment, the amount of elapsed time from when a request was submitted until the first response is produced.

Scheduling Criteria, cont’d Proportionality “Simple” tasks (as perceived by human users) should take little time. “Complex” tasks can take longer time.

Scheduling Goals Operating Systems: Design and Implementation Tanenbaum & Woodhull (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8

First-Come First-Served (FCFS) Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 . The timeline 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 Operating Systems Concepts with Java, 8th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved. 0-13-142938-8

Shortest Job First (SJF) Now suppose that the processes arrive in the order: P2 , P3 , P1 The timeline for the schedule is: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case. Schedule short processes ahead of long processes. Process Burst Time P1 24 P2 3 P3 3 P1 P3 P2 6 3 30 Operating Systems Concepts with Java, 8th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved. 0-13-142938-8 Operating Systems Concepts with Java, 8th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved. 0-13-142938-8

Shortest Job First (SJF), cont’d Shortest Job First (SJF) gives the optimal average waiting time for a given set of processes. How can you know in advance each process’s expected run time? It’s possible if you run the same jobs frequently.

Practice Problem #1 Assume: What is the average turnaround time with the FCFS scheduling algorithm? With the SJF scheduling algorithm? Process Arrival Time Burst Time P1 0.0 8 P2 0.4 4 P3 1.0 1 P1 P2 P3 P1 P3 P2

Shortest Remaining Time (SRT) When a new job (process) arrives, its expected run time is compared to the expected remaining run time of the currently executing process. If the new job needs less time to finish than the current process, the scheduler suspends the current process and starts the new job. New short jobs get good service. As with Shortest Job First, you must know in advance each process’s expected run time.

Round Robin (RR) Each process is assigned a time interval called a quantum during which it is allowed to run. If the process is still running at the end of its quantum, the CPU is preempted and given to the next process. The preempted process moves to the end of the ready queue. Preemption can also occur if a process blocks.

Round Robin (RR), cont’d Operating Systems: Design and Implementation Tanenbaum & Woodhull (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8

Round Robin (RR), cont’d Round Robin example with time quantum 4: Process Burst Time P1 24 P2 3 P3 3 The timeline is: Typically, higher average turnaround than SJF, but with better response time. P1 P2 P3 4 7 10 14 18 22 26 30 Operating Systems Concepts with Java, 8th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved. 0-13-142938-8

Time Quantum vs. Context Switch Time A smaller time quantum increases the number of processor switches. Recall each context switch takes time. Operating Systems Concepts with Java, 8th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved. 0-13-142938-8

Scheduling Interactive Systems Turnaround time varies with the time quantum. Each context switch incurs certain OS administrative overhead: Save and load registers and memory maps. Switch memory maps. Update system tables and lists. Flush and reload the cache. etc.

Scheduling Interactive Systems, cont’d Increasing the time quantum can increase response time. Example with 100 msec quantum: 10 users press carriage return simultaneously. The last user has to wait 1 second for a response

Highest Priority First (HPF) Operating Systems Concepts with Java, 8th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved. 0-13-142938-8

Highest Priority First (HPF), cont’d HPF scheduling with four priority classes: Use Round Robin scheduling within each priority class. Operating Systems: Design and Implementation Tanenbaum & Woodhull (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8

Highest Priority First (HPF), cont’d A serious problem with HPF is starvation. The lowest priority processes may never get to execute. A solution is aging. As time progresses, the process scheduler automatically raises the process’s priority. HPF can be preemptive. A higher priority task that’s arriving can preempt a currently executing process with a lower priority.

Practice Problem #2 Assume: Draw timelines for the scheduling algorithms FCFS, SJF, HPF (nonpreemptive), and RR. What is the turnaround time of each process for each of these scheduling algorithms? What is the total waiting time for each process for each of these scheduling algorithms? Which of these scheduling algorithms results in the minimum average waiting time over all the processes? Process Burst Time Priority P1 10 3 P2 1 P3 2 P4 4 P5 5 All arrived at time 0 in the order P1, P2, P3, P4, P5. Highest priority = 1 Time quantum = 1

Practice Problem #2 Timelines: Turnaround times: P1 P2 P3 P4 P5 FCFS 6 7 8 9 10 11 12 13 14 15 16 17 18 19 FCFS P1 P2 P3 P4 P5 SJF HPF RR Turnaround times:   P1 P2 P3 P4 P5 FCFS 10 11 13 14 19 SJF 1 4 2 9 HPF 16 18 6 RR 7