Advanced Operating Systems (CS 202) Scheduling (2)

Slides:



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

Embedded System Lab. 1 Embedded system Lab.
CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5.
Threads, Events, and Scheduling Andy Wang COP 5611 Advanced Operating Systems.
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
G Robert Grimm New York University Lottery 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.
Scheduler Activations Effective Kernel Support for the User-Level Management of Parallelism.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Scheduler Activations Jeff Chase. Threads in a Process Threads are useful at user-level – Parallelism, hide I/O latency, interactivity Option A (early.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
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.
Lottery Scheduling: Flexible Proportional-Share Resource Management Sim YounSeok C. A. Waldspurger and W. E. Weihl.
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
1 Scheduling Processes. 2 Processes Each process has state, that includes its text and data, procedure call stack, etc. This state resides in memory.
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.
Scheduler Activations: Effective Kernel Support for the User- Level Management of Parallelism. Thomas E. Anderson, Brian N. Bershad, Edward D. Lazowska,
Scheduler Activations: Effective Kernel Support for the User-level Management of Parallelism Thomas E. Anderson, Brian N. Bershad, Edward D. Lazowska,
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch.
Lecture 6 Page 1 CS 111 Online Preemptive Scheduling Again in the context of CPU scheduling A thread or process is chosen to run It runs until either it.
CS333 Intro to Operating Systems Jonathan Walpole.
Advanced Operating Systems (CS 202) Scheduling Jan, 20, 2016.
Stride Scheduling: Deterministic Proportional-Share Resource Management Carl A. Waldspurger, William E. Weihl MIT Laboratory for Computer Science Presenter:
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
Jonas Johansson Summarizing presentation of Scheduler Activations – A different approach to parallelism.
Lecture 6 The Rest of Scheduling Algorithms and The Beginning of Memory Management.
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.
Introduction to Operating Systems
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
PROCESS MANAGEMENT IN MACH
Chapter 5a: CPU Scheduling
Processes and Threads Processes and their scheduling
Chapter 2 Scheduling.
Threads, Events, and Scheduling
Chapter 2.2 : Process Scheduling
Lottery Scheduling: Flexible Proportional-Share Resource Management
Lottery Scheduling Ish Baid.
CS 3204 Operating Systems Lecture 14 Godmar Back.
CS 143A - Principles of Operating Systems
CS140 – Operating Systems Midterm Review
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Andy Wang Operating Systems COP 4610 / CGS 5765
Operating System Concepts
Chapter 2: The Linux System Part 3
TDC 311 Process Scheduling.
COT 4600 Operating Systems Spring 2011
CPU SCHEDULING.
Virtual-Time Round-Robin: An O(1) Proportional Share Scheduler
Fast Communication and User Level Parallelism
CPU scheduling decisions may take place when a process:
Threads, Events, and Scheduling
Chapter 6: CPU Scheduling
Process Scheduling Decide which process should run and for how long
CS703 – Advanced Operating Systems
Scheduling of Regular Tasks in Linux
Threads, Events, and Scheduling
Thomas E. Anderson, Brian N. Bershad,
Operating System , Fall 2000 EA101 W 9:00-10:00 F 9:00-11:00
Threads vs. Processes Hank Levy 1.
CSE 153 Design of Operating Systems Winter 19
CS703 – Advanced Operating Systems
Don Porter Portions courtesy Emmett Witchel
CPU Scheduling CSE 2431: Introduction to Operating Systems
Scheduling of Regular Tasks in Linux
Presentation transcript:

Advanced Operating Systems (CS 202) Scheduling (2) Jan, 23, 2017

Lottery Scheduling

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

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() PH priority time x->Acquire() x->Release() PL x->Acquire() How can this be avoided? PH priority time PM x->Acquire() PL

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 If all compete for the resource 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) 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 List contains Search time is O(n) 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 B C ≤ > ≤ > 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

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 similar

Stride Scheduling – Basic Algorithm Client Variables: Tickets Relative resource allocation Strides ( Interval between selection Pass ( Virtual index of next selection - minimum ticket allocation Select Client with Minimum Pass Advance Client’s Pass by Client’s Stride Slide and example from Dong-hyeon Park

Stride Scheduling – Basic Algorithm 3:2:1 Allocation ∆ - A (stride = 2) ○ - B (stride = 3) □ - C (stride = 6) Time 1: 2 3 6 +2 Time 2: 4 3 6

Stride Scheduling – Basic Algorithm 3:2:1 Allocation ∆ - A (stride = 2) ○ - B (stride = 3) □ - C (stride = 6) Time 1: 2 3 6 +2 Time 2: 4 3 6 +3 Time 3: 4 6 6

Stride Scheduling – Basic Algorithm 3:2:1 Allocation ∆ - A (stride = 2) ○ - B (stride = 3) □ - C (stride = 6) Time 1: 2 3 6 +2 Time 2: 4 3 6 +3 Time 3: 4 6 6 +2 Time 4: 6 6 6

Stride Scheduling – Basic Algorithm 3:2:1 Allocation ∆ - A (stride = 2) ○ - B (stride = 3) □ - C (stride = 6) Time 1: 2 3 6 +2 Time 2: 4 3 6 +3 Time 3: 4 6 6 +2 Time 4: 6 6 6 …

Throughput Error Comparison Error is independent of the allocation time in stride scheduling Absolute Error (quanta) Hierarchical stride scheduling has more balance distribution of error between clients. Time (quanta)

Accuracy of Prototype Implementation Lottery Scheduler Stride Scheduler Lottery and Stride Scheduler implemented on real-system. Stride scheduler stayed within 1% of ideal ratio. Low system overhead relative to standard Linux scheduler.

Linux scheduler Went through several iterations Currently CFS Fair scheduler, like stride scheduling Supersedes O(1) scheduler: emphasis on constant time scheduling –why? CFS is O(log(N)) because of red-black tree Is it really fair? What to do with multi-core scheduling?

Scheduler Activations brewer

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

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

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?

Goals (from paper) Functionality Performance Flexibility 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

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

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

Kernel upcalls What do these accomplish? 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?

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!

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

Discussion Summary: Limitations 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?