CS 326: Operating Systems. CPU Scheduling. Lecture 6

Similar documents
Multi-Level Feedback Queues

Last Class: Processes

Operating Systems. Process scheduling. Thomas Ropars.

COSC243 Part 2: Operating Systems

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Scheduling II. Today. Next Time. ! Proportional-share scheduling! Multilevel-feedback queue! Multiprocessor scheduling. !

Operating Systems. Scheduling

CS370 Operating Systems

CPU Scheduling: Objectives

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

LECTURE 3:CPU SCHEDULING

Chapter 5 CPU scheduling

Chapter 5: CPU Scheduling

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

CS Computer Systems. Lecture 6: Process Scheduling

Advanced Operating Systems (CS 202) Scheduling (1)

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

Scheduling in the Supermarket

CS3733: Operating Systems

Process- Concept &Process Scheduling OPERATING SYSTEMS

CS370 Operating Systems

Process Scheduling. Copyright : University of Illinois CS 241 Staff

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Unit 3 : Process Management

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Comp 310 Computer Systems and Organization

Example: CPU-bound process that would run for 100 quanta continuously 1, 2, 4, 8, 16, 32, 64 (only 37 required for last run) Needs only 7 swaps

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

W4118: advanced scheduling

Course Syllabus. Operating Systems

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Frequently asked questions from the previous class survey

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

Scheduling. Today. Next Time Process interaction & communication

Frequently asked questions from the previous class survey

Properties of Processes

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

Chapter 5: CPU Scheduling

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Operating System Concepts Ch. 5: Scheduling

CS370 Operating Systems

Announcements/Reminders

CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. Dispatcher. CPU Scheduler. Alternating Sequence of CPU and I/O Bursts

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

8: Scheduling. Scheduling. Mark Handley

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Scheduling of processes

Chapter 5: Process Scheduling

Operating Systems Unit 3

Scheduling. Multi-processing. Process Characterization. time. ...makes use of idle. COS450-F18-05-Scheduling - October 8, 2018

CS307: Operating Systems

Start of Lecture: February 10, Chapter 6: Scheduling

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Chapter 6: CPU Scheduling

Scheduling. Scheduling 1/51

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Recap. Run to completion in order of arrival Pros: simple, low overhead, good for batch jobs Cons: short jobs can stuck behind the long ones

Scheduling. CS 161: Lecture 4 2/9/17

CS 318 Principles of Operating Systems

CPU Scheduling Algorithms

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

Chapter 5: CPU Scheduling

Subject Name: OPERATING SYSTEMS. Subject Code: 10EC65. Prepared By: Kala H S and Remya R. Department: ECE. Date:

Scheduling. Scheduling 1/51

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

But this will not be complete (no book covers 100%) So consider it a rough approximation Last lecture OSPP Sections 3.1 and 4.1

Uniprocessor Scheduling

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

by Maria Lima Term Paper for Professor Barrymore Warren Mercy College Division of Mathematics and Computer Information Science

CHAPTER 2: PROCESS MANAGEMENT

1.1 CPU I/O Burst Cycle

Chapter 5: Process Scheduling

EECS 750: Advanced Operating Systems. 01/29 /2014 Heechul Yun

INF1060: Introduction to Operating Systems and Data Communication. Pål Halvorsen. Wednesday, September 29, 2010

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Chapter 5 Process Scheduling

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

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

238P: Operating Systems. Lecture 14: Process scheduling

Networks and Operating Systems ( ) Chapter 3: Scheduling

Process management. Scheduling

Chapter 9 Uniprocessor Scheduling

Operating Systems CS 323 Ms. Ines Abbes

CS 326: Operating Systems. Process Execution. Lecture 5

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

CS 4284 Systems Capstone. Resource Allocation & Scheduling Godmar Back

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

Transcription:

CS 326: Operating Systems CPU Scheduling Lecture 6

Today s Schedule Agenda? Context Switches and Interrupts Basic Scheduling Algorithms Scheduling with I/O Symmetric multiprocessing 2/7/18 CS 326: Operating Systems 2

Today s Agenda Context Switches and Interrupts Basic Scheduling Algorithms Scheduling with I/O Symmetric multiprocessing 2/7/18 CS 326: Operating Systems 3

Context Switching As discussed previously, switching execution between processes requires a context switch Saving and restoring the process control block You may wonder if transitioning between user and kernel space requires a context switch In general, no Only a privilege change occurs 2/7/18 CS 326: Operating Systems 4

Process Control Block (Isolated from other processes) Call Stack Heap Permissions, ownership Isolate file access Environment Variables Register States Stack pointer, program counter Memory Addressing 2/7/18 CS 326: Operating Systems 5

Basic Scheduling We mentioned earlier that the OS can preempt running processes This is accomplished via interrupts The OS configures a hardware timer to fire on a set interval: Interrupt CPU in X ms 2/7/18 CS 326: Operating Systems 6

Interrupt Handling The trap table is used to determine what to do when the hardware timer fires Ultimately moves us back into kernel space When this occurs, save the running PCB and replace with the next in the run queue 2/7/18 CS 326: Operating Systems 7

Advanced Scheduling How do we decide what to run next? Several scheduling algorithms exist, all with different run time properties Maybe you want your algorithm to be fair to all processes? Or certain processes may get higher priority than others 2/7/18 CS 326: Operating Systems 8

Today s Agenda Context Switches and Interrupts Basic Scheduling Algorithms Scheduling with I/O Symmetric multiprocessing 2/7/18 CS 326: Operating Systems 9

Scheduling Concerns How long each process runs for Scheduling quantum When jobs start or stop At boot: lots of processes starting at once During run time: less frequent start/stop Whether the process performs I/O Process priorities Kernel threads, multimedia, games, etc. 2/7/18 CS 326: Operating Systems 10

Scheduling Metrics CPU Utilization Throughput Turnaround time Response time 2/7/18 CS 326: Operating Systems 11

Scheduling Metrics CPU Utilization Amount of time the CPU spends doing productive work A bad scheduler won t keep the CPU pipeline full of tasks Utilization = 1 idle_time Throughput Turnaround time Response time 2/7/18 CS 326: Operating Systems 12

Scheduling Metrics CPU Utilization Throughput Number of processes that are completed per time unit For instance, 54 processes serviced per second Turnaround time Response time 2/7/18 CS 326: Operating Systems 13

Scheduling Metrics CPU Utilization Throughput Turnaround time Amount of time from process arrival to process completion turnaround = completion - arrival Response time 2/7/18 CS 326: Operating Systems 14

Scheduling Metrics CPU Utilization Throughput Turnaround time Response time How quickly a process starts running after submission response_time = start - arrival 2/7/18 CS 326: Operating Systems 15

Basic Scheduling Algorithms FIFO SJF STCF Round Robin Priority Lottery 2/7/18 CS 326: Operating Systems 16

FIFO The first in, first out (FIFO) scheduler works just like a queue data structure Processes are executed in the order they arrive: If A arrives, followed by B: 1. A executes completely 2. B executes completely Works reasonably well IF the processes run for about the same amount of time 2/7/18 CS 326: Operating Systems 17

FIFO: Uniform Run Times 2/7/18 CS 326: Operating Systems 18

FIFO: Issues If one task takes a very long time, the other (shorter) tasks will have to wait, and wait, and wait This is called the convoy effect Here, the average process completion time is low A process may only need 2 seconds to run, but waits for 20 seconds before it can even start 2/7/18 CS 326: Operating Systems 19

Convoy Effect 2/7/18 CS 326: Operating Systems 20

SJF With shortest job first (SJF) scheduling, we don t have to worry about long tasks causing a convoy Assuming all the jobs are scheduled at the same time, the smallest will be executed first Little jobs get finished quickly Long jobs are delayed, but the impact is not as noticable 2/7/18 CS 326: Operating Systems 21

SJF: Prioritize Small Tasks 2/7/18 CS 326: Operating Systems 22

SJF: Issues First of all, how can we really know how long a job will take ahead of time? This research question is still relevant today If your OS routinely runs lots of small tasks and one large task all at the same time, the larger task will always have to wait Once the large task is running, we ll still have a convoy effect if we schedule new, smaller tasks 2/7/18 CS 326: Operating Systems 23

SJF: Late Arrivals 2/7/18 CS 326: Operating Systems 24

STCF In the shortest time to completion first (STCF) algorithm, we introduce preemption Run whichever task will complete first and preempt running processes that don t meet the criteria Now the large task causing the convoy effect can be swapped out when small jobs arrive This keeps average turnaround time high: most small tasks will be taken care of quickly 2/7/18 CS 326: Operating Systems 25

STCF: Preemption 2/7/18 CS 326: Operating Systems 26

STCF: Issues STCF de-prioritizes large tasks the most Poor large tasks! L We also have a problem with resource starvation If the OS continuously receives small tasks, the large task may never get a turn to execute 2/7/18 CS 326: Operating Systems 27

Round Robin Round robin scheduling tries to be as fair as possible Using preemption, all processes get a scheduling quantum (time slice) If I have 10 processes and a quantum of 1ms, then I ll run each process for 1ms for each iteration of the algorithm After one pass completes, start back over again 2/7/18 CS 326: Operating Systems 28

Round Robin: Response Time 2/7/18 CS 326: Operating Systems 29

Round Robin: Issues While RR is fair, the scheduling quantum has a big impact on performance Too small? Not much actual work getting done, most effort expended on context switching Too large? Programs aren t responsive Exhibits poor turnaround time As the number of processes grows, response time can also begin to take a hit 2/7/18 CS 326: Operating Systems 30

Priority Scheduling Priority based scheduling allows some tasks to be considered more important than others In this scheme, a number is assigned to the process to designate its priority The scheduler sorts tasks by their priorities and executes them in that order Unix systems: process nice level 2/7/18 CS 326: Operating Systems 31

Lottery Scheduling With lottery scheduling, each process is allocated lottery tickets The scheduler picks a number at random, and the winning ticket gets the CPU The more tickets a process has, the higher the chance it will be scheduled This lets us allocate tickets to assign CPU priorities Want to give a process 30% of the CPU? Give it 30% of the overall number of tickets 2/7/18 CS 326: Operating Systems 32

Lottery Scheduling: Issues If processes frequently stop/start, assigning tickets becomes difficult! Lottery scheduling works well on systems with longrunning processes Great for server environments: Web server gets 70% of the CPU Database server gets 20% 10% goes to other background processes Workloads with highly variable thread counts suffer 2/7/18 CS 326: Operating Systems 33

Basic Scheduling: Conclusions By now you may be wondering what s the point of these algorithms? They all do have glaring weaknesses In general, they are not suitable for consumer operating systems like Windows, macos, Linux However, they can be used for problem-specific OS The tradeoffs here impact the more complicated schedulers as well 2/7/18 CS 326: Operating Systems 34

Real-Time Operating Systems RTOS operate in embedded applications and have different scheduling constraints Processes expect to be scheduled at certain intervals and run for fixed amounts of time For example, your car might need to update the LCD speedometer display every 10 ms This needs to be done constantly, and will probably take the same amount of time to execute Embedded systems, robots 2/7/18 CS 326: Operating Systems 35

Linux RT Scheduling Linux can be configured to provide real-time (ish) scheduling SCHED_RR SCHED_FIFO The time quantum can also be configured: cat /proc/sys/kernel/sched_rr_timeslice_ms 10 2/7/18 CS 326: Operating Systems 36

Today s Agenda Context Switches and Interrupts Basic Scheduling Algorithms Scheduling with I/O Symmetric multiprocessing 2/7/18 CS 326: Operating Systems 37

Input/Output Thus far, we ve ignored I/O When a process performs I/O, it blocks to wait for the operation to complete Q: Can a process still work on other things while waiting for I/O? A: Yes by using other threads If the scheduler does not account for this, CPU usage drops (CPU is idle during I/O) 2/7/18 CS 326: Operating Systems 38

I/O: A executes, then B 2/7/18 CS 326: Operating Systems 39

Preempt During I/O When a process begins an I/O operation, the scheduler will preempt it This allows another process to use the CPU during the I/O Boosts overall CPU usage An interrupt informs the OS when the I/O operation completes, allowing the first task to run again I/O Interleaving 2/7/18 CS 326: Operating Systems 40

I/O Interleaving 2/7/18 CS 326: Operating Systems 41

Today s Agenda Context Switches and Interrupts Basic Scheduling Algorithms Scheduling with I/O Symmetric multiprocessing 2/7/18 CS 326: Operating Systems 42

Multiprocessing The days of having just a single CPU are over Even our Raspberry Pi has four cores! All of our discussion thus far assumes that there is only one CPU In symmetric multiprocessing (SMP), each processor has access to the same memory and devices This is the common configuration 2/7/18 CS 326: Operating Systems 43

Queuing In an SMP configuration, each processor gets its own process run queue Contains processes ready for execution Sharing a single queue would require locking and coordination The OS assigns new processes to the queues based on processor load 2/7/18 CS 326: Operating Systems 44

Processor Affinity CPUs generally contain cache memory that operates much faster than system memory (RAM) As processes are switched in and out, the cache may already contain some program state To take advantage of this, the OS tries to keep processes running on the same CPU/core Processor Affinity Hard affinity always scheduled to the same CPU Soft affinity best effort to schedule to the same CPU 2/7/18 CS 326: Operating Systems 45

Migration Processor affinity boosts performance by reducing context switch overhead However, processor affinity can lead to imbalances in load Push migration: OS finds too many processes in one run queue, moves them to balance it out Pull migration: OS finds an empty run queue, so it moves a process from a full queue 2/7/18 CS 326: Operating Systems 46

Kernel Ticks If the system gets interrupted every X ms, does this impact multiple processors/cores? Yes! Most modern OS kernels are now tickless Interrupts are set up and fired on demand rather than periodically (e.g., process A has scheduling quantum of 18ms, so set the interrupt to fire in 18ms) Also known as dynamic ticks Idle CPUs can stay idle, reducing power consumption 2/7/18 CS 326: Operating Systems 47

References Scheduling figures from this lecture: Operating Systems: Three Easy Pieces http://pages.cs.wisc.edu/~remzi/ostep/ 2/7/18 CS 326: Operating Systems 48