CS 153 Design of Operating Systems Spring 2015 Lecture 10: Scheduling.

Slides:



Advertisements
Similar presentations
Scheduling Criteria CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – # of processes that complete their execution per.
Advertisements

Operating Systems ECE344 Ding Yuan Scheduling Lecture 10: Scheduling.
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.
Chapter 3: CPU Scheduling
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
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.
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.
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.
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.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
1 CSE451 Scheduling Autumn 2002 Gary Kimura Lecture #6 October 11, 2002.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
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.
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.
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.
Processor Scheduling Hank Levy. 22/4/2016 Goals for Multiprogramming In a multiprogramming system, we try to increase utilization and thruput by overlapping.
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.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
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.
Lecture 4 CPU scheduling. Basic Concepts Single Process  one process at a time Maximum CPU utilization obtained with multiprogramming CPU idle :waiting.
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
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.
CPU SCHEDULING.
Chapter 5a: CPU Scheduling
April 6, 2001 Gary Kimura Lecture #6 April 6, 2001
Operating Systems Processes Scheduling.
Scheduling (Priority Based)
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU SCHEDULING.
Chapter 5: CPU Scheduling
CSE 451: Operating Systems Winter 2003 Lecture 6 Scheduling
Processor Scheduling Hank Levy 1.
Operating System , Fall 2000 EA101 W 9:00-10:00 F 9:00-11:00
Chapter 6: CPU Scheduling
CSE 153 Design of Operating Systems Winter 2019
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling.
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
CSE 451: Operating Systems Winter 2001 Lecture 6 Scheduling
Presentation transcript:

CS 153 Design of Operating Systems Spring 2015 Lecture 10: Scheduling

Announcements l Project 1 due Friday u TAs will send out instructions for how to submit l Mid-term coming up soon u 4/27 and 4/29 review, 5/1 exam 2

3 Scheduling Overview l Scheduler runs when we context switching among processes/threads on the ready queue u What should it do? Does it matter? l Making this decision is called scheduling l Now, we’ll look at: u The goals of scheduling u Starvation u Various well-known scheduling algorithms u Standard Unix scheduling algorithm

4 Multiprogramming l In a multiprogramming system, we try to increase CPU utilization and job throughput by overlapping I/O and CPU activities u Doing this requires a combination of mechanisms and policy l We have covered the mechanisms u Context switching, how and when it happens u Process queues and process states l Now we’ll look at the policies u Which process (thread) to run, for how long, etc. l We’ll refer to schedulable entities as jobs (standard usage) – could be processes, threads, people, etc.

5 Scheduling Goals l Scheduling works at two levels in an operating system 1. To determine the multiprogramming level – the number of jobs loaded into primary memory »Moving jobs to/from memory is often called swapping »Long term scheduler: infrequent 2. To decide what job to run next to guarantee “good service” »Good service could be one of many different criteria »Short term scheduler: frequent »We are concerned with this level of scheduling »Is scheduler a thread always running in kernel space?

6 Scheduling l The scheduler (aka dispatcher) is the module that manipulates the queues, moving jobs to and from them l The scheduling algorithm determines which jobs are chosen to run next and what queues they wait on l In general, the scheduler runs: u When a job switches from running to waiting u When an interrupt occurs u When a job is created or terminated l The scheduler runs inside the kernel (for kernel-level threads). Therefore, kernel has to be entered before scheduler can run.

Preemptive vs. Non- preemptive scheduling l We’ll discuss scheduling algorithms in two contexts u In preemptive systems the scheduler can interrupt a running job (involuntary context switch) u In non-preemptive systems, the scheduler waits for a running job to explicitly block (voluntary context switch) 7

8 Scheduling Goals l What are some reasonable goals for a scheduler? l Scheduling algorithms can have many different goals: u CPU utilization u Job throughput (# jobs/unit time) u Turnaround time (T finish – T start ) u Waiting time (Avg(T wait ): avg time spent on wait queues) u Response time (Avg(T ready ): avg time spent on ready queue) l Batch systems u Strive for job throughput, turnaround time (supercomputers) l Interactive systems u Strive to minimize response time for interactive jobs (PC)

9 Starvation Starvation is a scheduling “non-goal”: l Starvation is a situation where a process is prevented from making progress because some other process has the resource it requires u Resource could be the CPU, or a lock (recall readers/writers) l Starvation usually a side effect of the sched. algorithm u A high priority process always prevents a low priority process from running on the CPU u One thread always beats another when acquiring a lock l Starvation can be a side effect of synchronization u Constant supply of readers always blocks out writers

First In First Out (FIFO) l Schedule tasks in the order they arrive u Continue running them until they complete or give up the processor l Example: many cases in real life l On what workloads is FIFO particularly bad? u Imagine being at supermarket to buy a drink of water, but get stuck behind someone with a huge cart (or two!) »…and who pays in pennies! u Can we do better? 10

Shortest Job First (SJF) l Always do the task that has the shortest remaining amount of work to do u Often called Shortest Remaining Time First (SRTF) l Suppose we have five tasks arrive one right after each other, but the first one is much longer than the others u Which completes first in FIFO? Next? u Which completes first in SJF? Next? 11

FIFO vs. SJF Whats the big deal? Don’t they finish at the same time? 12

13 SJF Example – Turnaround Time ATT = (8 + (8+4)+(8+4+2))/3 = ATT = (4 + (4+8)+(4+8+2))/3 = 10 ATT = (4+ (4+2)+(4+2+8))/3 = 8 ATT = (2 + (2+4)+(2+4+8))/3 = 7.33

14 SJF Example – Response Time ART = ( (8+4))/3 = 6.67 ART = ( (4+8))/3 = 5.33 ART = ( (4+2))/3 = 3.33 ART = ( (2+4))/3 = 2.67

SJF l Claim: SJF is optimal for average response time u Why? l For what workloads is FIFO optimal? u For what is it pessimal (i.e., worst)? l Does SJF have any downsides? u Does it work in a supermarket? 15

16 Shortest Job First (SJF) l Problems? u Impossible to know size of CPU burst »Like choosing person in line without looking inside basket/cart u How can you make a reasonable guess? u Can potentially starve l Flavors u Can be either preemptive or non-preemptive u Preemptive SJF is called shortest remaining time first (SRTF)

Round Robin l Each task gets resource for a fixed period of time (time quantum) u If task doesn’t complete, it goes back in line l Need to pick a time quantum u What if time quantum is too long? »Infinite? u What if time quantum is too short? »One instruction? 17

Round Robin 18

Round Robin vs. FIFO l Many context switches can be costly l Other than that, is Round Robin always better than FIFO? 19

Round Robin vs. FIFO Is Round Robin always fair? 20

Mixed Workload 21

Max-Min Fairness l How do we balance a mixture of repeating tasks: u Some I/O bound, need only a little CPU u Some compute bound, can use as much CPU as they are assigned l One approach: maximize the minimum allocation given to a task u Schedule the smallest task first, then split the remaining time using max-min 22

23 Priority Scheduling l Priority Scheduling u Choose next job based on priority »Airline checkin for first class passengers u Can implement SJF, priority = 1/(expected CPU burst) u Also can be either preemptive or non-preemptive l Problem? u Starvation – low priority jobs can wait indefinitely l Solution u “Age” processes »Increase priority as a function of waiting time »Decrease priority as a function of CPU consumption

24 More on Priority Scheduling l For real-time (predictable) systems, priority is often used to isolate a process from those with lower priority. Priority inversion is a risk unless all resources are jointly scheduled. x->Acquire() x->Release() x->Acquire() priority time priority time How can this be avoided? PHPH PLPL PHPH PLPL PMPM

Priority Inversion on Mars Pathfinder l P H = (Frequent) Bus Management l P M = (Long-Running) Communications l P L = (Infrequent and short) Data Gathering 25 x->Acquire() x->Release() priority time PHPH PLPL PMPM Killed by watchdog

26 Combining Algorithms l Scheduling algorithms can be combined u Have multiple queues u Use a different algorithm for each queue u Move processes among queues l Example: Multiple-level feedback queues (MLFQ) u Multiple queues representing different job types »Interactive, CPU-bound, batch, system, etc. u Queues have priorities, jobs on same queue scheduled RR u Jobs can move among queues based upon execution history »Feedback: Switch from interactive to CPU-bound behavior

27 Scheduling Summary l Scheduler (dispatcher) is the module (not a thread) that gets invoked when a context switch needs to happen l Scheduling algorithm determines which process runs, where processes are placed on queues l Many potential goals of scheduling algorithms u Utilization, throughput, wait time, response time, etc. l Various algorithms to meet these goals u FCFS/FIFO, SJF, Priority, RR l Can combine algorithms u Multiple-level feedback queues

28 Next class l Deadlock u Read Chapter 7 in book