Advanced Operating Systems (CS 202) Scheduling Jan, 20, 2016.

Slides:



Advertisements
Similar presentations
LOTTERY SCHEDULING: FLEXIBLE PROPORTIONAL-SHARE RESOURCE MANAGEMENT
Advertisements

CPU Scheduling Questions answered in this lecture: What is scheduling vs. allocation? What is preemptive vs. non-preemptive scheduling? What are FCFS,
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
CPU Scheduling Section 2.5.
Chapter 3: CPU Scheduling
Project 2 – solution code
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
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.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (2) Process Management 10/03/2008 Yang Song (Prepared by Yang Song and.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
Job scheduling Queue discipline.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
CS 153 Design of Operating Systems Spring 2015 Lecture 10: Scheduling.
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
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.
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Chapter 6 CPU SCHEDULING.
1 Scheduling Processes. 2 Processes Each process has state, that includes its text and data, procedure call stack, etc. This state resides in memory.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Chapter 6 Scheduling. Basic concepts Goal is maximum utilization –what does this mean? –cpu pegged at 100% ?? Most programs are I/O bound Thus some other.
Operating Systems Lecture Notes CPU Scheduling Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
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.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
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.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
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.
ITFN 2601 Introduction to Operating Systems Lecture 4 Scheduling.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
CS333 Intro to Operating Systems Jonathan Walpole.
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.
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.
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.
Basic Concepts Maximum CPU utilization obtained with multiprogramming
CPU Scheduling Andy Wang Operating Systems COP 4610 / CGS 5765.
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
Chapter 5a: CPU Scheduling
Advanced Operating Systems (CS 202) Scheduling (2)
Chapter 2 Scheduling.
Chapter 6: CPU Scheduling
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 6: CPU Scheduling
CPU SCHEDULING.
CPU scheduling decisions may take place when a process:
Process Scheduling Decide which process should run and for how long
CSE 451: Operating Systems Winter 2003 Lecture 6 Scheduling
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
Module 5: CPU Scheduling
CSE 451: Operating Systems Winter 2001 Lecture 6 Scheduling
Presentation transcript:

Advanced Operating Systems (CS 202) Scheduling Jan, 20, 2016

Administrivia Lab has been released – You may work in pairs – Some more details about how to test your implementation may be added But feel free to come up with your own TA status: Khaled Khasawneh is the TA for the class – Unfortunately, he is not at UCR this quarter So, we’ll have to be creative with office hours – He graded your first critique 2

3 Today: CPU Scheduling Scheduler runs when we context switching among processes/threads on the ready queue – What should it do? Does it matter? Making the decision on what process to run is called scheduling – What are the goals of scheduling? – What are common scheduling algorithms? – Lottery scheduling Scheduling activations – User level vs. Kernel level scheduling of threads

4 Scheduling Right from the start of multiprogramming, scheduling was identified as a big issue – CCTS and Multics developed much of the classical algorithms Scheduling is a form of resource allocation – CPU is the resource – Resource allocation needed for other resources too; sometimes similar algorithms apply Requires mechanisms and policy – Mechanisms: Context switching, Timers, process queues, process state information, … – Scheduling looks at the policies: i.e., when to switch and which process/thread to run next

Preemptive vs. Non- preemptive scheduling In preemptive systems where we can interrupt a running job (involuntary context switch) – We’re interested in such schedulers… In non-preemptive systems, the scheduler waits for a running job to give up CPU (voluntary context switch) – Was interesting in the days of batch multiprogramming – Some systems continue to use cooperative scheduling – Example algorithms: RR, Shortest Job First (how to determine shortest), … 5

6 Scheduling Goals What are some reasonable goals for a scheduler? Scheduling algorithms can have many different goals: – CPU utilization – Job throughput (# jobs/unit time) – Response time (Avg(T ready ): avg time spent on ready queue) – Fairness (or weighted fairness) – Other? Non-interactive applications: – Strive for job throughput, turnaround time (supercomputers) Interactive systems – Strive to minimize response time for interactive jobs Mix?

7 Goals II: Avoid Resource allocation pathologies Starvation no progress due to no access to resources – E.g., a high priority process always prevents a low priority process from running on the CPU – One thread always beats another when acquiring a lock Priority inversion – A low priority process running before a high priority one – Could be a real problem, especially in real time systems Mars pathfinder: us/um/people/mbj/Mars_Pathfinder/Authoritative_Account.html Other – Deadlock, livelock, convoying …

Non-preemptive approaches Introduced just to have a baseline FIFO: schedule the processes in order of arrival – Comments? Shortest Job first – Comments? 8

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

Mixed Workload

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

12 More on Priority Scheduling 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

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

Multi-level Feedback Queue (MFQ) Goals: – Responsiveness – Low overhead – Starvation freedom – Some tasks are high/low priority – Fairness (among equal priority tasks) Not perfect at any of them! – Used in Unix (and Windows and MacOS)

MFQ

16 Unix Scheduler The canonical Unix scheduler uses a MLFQ – 3-4 classes spanning ~170 priority levels Timesharing: first 60 priorities System: next 40 priorities Real-time: next 60 priorities Interrupt: next 10 (Solaris) Priority scheduling across queues, RR within a queue – The process with the highest priority always runs – Processes with the same priority are scheduled RR Processes dynamically change priority – Increases over time if process blocks before end of quantum – Decreases over time if process uses entire quantum

LOTTERY SCHEDULING 17

Problems with Traditional schedulers Priority systems are ad hoc: highest priority always wins Try to support fair share by adjusting priorities with a feedback loop – Works over long term – highest priority still wins all the time, but now the Unix priorities are always changing Priority inversion: high-priority jobs can be blocked behind low-priority jobs Schedulers are complex and difficult to control

Lottery scheduling Elegant way to implement proportional share scheduling Priority determined by the number of tickets each thread has: – Priority is the relative percentage of all of the tickets whose owners compete for the resource Scheduler picks winning ticket randomly, gives owner the resource Tickets can be used for a variety of resources

Example Three threads – A has 5 tickets – B has 3 tickets – C has 2 tickets If all compete for the resource – B has 30% chance of being selected If only B and C compete – B has 60% chance of being selected

Its fair Lottery scheduling is probabilistically fair If a thread has a t tickets out of T – Its probability of winning a lottery is p = t/T – Its expected number of wins over n drawings is np Binomial distribution Variance σ 2 = np(1 – p)

Fairness (II) Coefficient of variation of number of wins σ/np = √((1-p)/np) – Decreases with √n Number of tries before winning the lottery follows a geometric distribution As time passes, each thread ends receiving its share of the resource

Ticket transfers How to deal with dependencies? – Explicit transfers of tickets from one client to another Transfers can be used whenever a client blocks due to some dependency – When a client waits for a reply from a server, it can temporarily transfer its tickets to the server Server has no tickets of its own – Server priority is sum of priorities of its active clients Can use lottery scheduling to give service to the clients Similar to priority inheritance – Can solve priority inversion

Ticket inflation Lets users create new tickets – Like printing their own money – Counterpart is ticket deflation – Lets mutually trusting clients adjust their priorities dynamically without explicit communication Currencies: set up an exchange rate – Enables inflation within a group – Simplifies mini-lotteries (e.g., for mutexes)

Example (I) A process manages three threads – A has 5 tickets – B has 3 tickets – C has 2 tickets It creates 10 extra tickets and assigns them to process C – Why? – Process now has 20 tickets

Example (II) These 20 tickets are in a new currency whose exchange rate with the base currency is 10/20 The total value of the processes tickets expressed in the base currency is still equal to 10

Compensation tickets (I) I/O-bound threads are likely get less than their fair share of the CPU because they often block before their CPU quantum expires Compensation tickets address this imbalance

Compensation tickets (II) A client that consumes only a fraction f of its CPU quantum can be granted a compensation ticket – Ticket inflates the value of all client tickets by 1/f until the client starts gets the CPU

Example CPU quantum is 100 ms Client A releases the CPU after 20ms – f = 0.2 or 1/5 Value of all tickets owned by A will be multiplied by 5 until A gets the CPU Is this fair? – What if A alternates between 1/5 and full quantum?

Compensation tickets (III) Compensation tickets – Favor I/O-bound—and interactive—threads – Helps them getting their fair share of the CPU

IMPLEMENTATION On a MIPS-based DECstation running Mach 3 microkernel – Time slice is 100ms Fairly large as scheme does not allow preemption Requires – A fast RNG – A fast way to pick lottery winner

Example Three threads – A has 5 tickets – B has 3 tickets – C has 2 tickets List contains – A (0-4) – B (5-7) – C (8-9) Search time is O(n) where n is list length

Optimization – use tree 4 A 7 BC ≤ ≤ > > RB Tree used in Linux Completely fair scheduler(CFS) --not lottery based

Long-term fairness (I)

Short term fluctuations For 2:1 ticket alloc. ratio

Discussion Opinions of the paper and contributions? – Fairness not great Mutex 1.8:1 instead of 2:1 Multimedia apps 1.9:1.5:1 instead of 3:2:1 – Can we exploit the algorithm? Consider also indirectly – processes getting kernel cycles by using high priority kernel services – Real time? Multiprocessor? – Short term unfairness Later this lead to stride scheduling from same authors 36

Stride scheduling Deterministic version of lottery scheduling Mark time virtually (counting passes) – Each process has a stride: number of passes between being scheduled – Stride inversely proportional to number of tickets – Regular, predictable schedule Can also use compensation tickets Similar to weighted fair queuing – Linux CFS is very similar 37

SCHEDULER ACTIVATIONSBREWER 38

Context Neither user level threads nor kernel level threads work ideally – User level threads have application information They are also cheap But not visible to kernel – Kernel level threads Expensive Lack application information 39

Idea Abstraction: threads in a shared address space – Others possible? Can be implemented in two ways – Kernel creates and dispatches threads Expensive and inflexible – User level One kernel thread for each virtual processor 40

User level on top of kernel threads Each application gets a set of virtual processors – Each corresponds to a kernel level thread User level threads implemented in user land – Any user thread can use any kernel thread (virtual processor) Fast thread creation and switch – no system calls Fast synchronization! – What happens when a thread blocks? – Any other issues? 41

Goals (from paper) Functionality – No processor idles when there are ready threads – No priority inversion (high priority thread waiting for low priority one) when its ready – When a thread blocks, the processor can be used by another thread Performance – Closer to user threads than kernel threads Flexibility – Allow qpplication level customization or even a completely different concurrency model 42

Problems User thread does a blocking call? – Application loses a processor! Scheduling decisions at user and kernel not coordinated – Kernel may de-schedule a thread at a bad time (e.g., while holding a lock) – Application may need more or less computing Solution? – Allow coordination between user and kernel schedulers 43

Scheduler activations Allow user level threads to act like kernel level threads/virtual processors Notify user level scheduler of relevant kernel events – Like what? Provide space in kernel to save context of user thread when kernel stops it – E.g., for I/O or to run another application 44

Kernel upcalls New processor available – Reaction? Run time picks user thread to use it Activation blocked (e.g., for page fault) – Reaction? Runtime runs a different thread on the activation Activation unblocked – Activation now has two contexts – Running activation is preempted – why? Activation lost processor – Context remapped to another activation What do these accomplish? 45

Runtime->Kernel Informs kernel when it needs more resources, or when it is giving up some Could involve the kernel to preempt low priority threads – Only kernel can preempt Almost everything else is user level! – Performance of user-level, with the advantages of kernel threads! 46

Preemptions in critical sections Runtime checks during upcall whether preempted user thread was running in a critical section – Continues the user thread using a user level context switch in this case Once lock is released, it switches back to original thread Keep track of critical sections using a hash table of section begin/end addresses 47

Discussion Summary: – Get user level thread performance but with scheduling abilities of kernel level threads – Main idea: coordinating user level and kernel level scheduling through scheduler activations Limitations – Upcall performance (5x slowdown) – Performance analysis limited Connections to exo-kernel/spin/microkernels? 48