Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems CSE 411 CPU Management Sept. 20 2006 - Lecture 7 Instructor: Bhuvan Urgaonkar.

Similar presentations

Presentation on theme: "Operating Systems CSE 411 CPU Management Sept. 20 2006 - Lecture 7 Instructor: Bhuvan Urgaonkar."— Presentation transcript:

1 Operating Systems CSE 411 CPU Management Sept. 20 2006 - Lecture 7 Instructor: Bhuvan Urgaonkar

2 Last class –Dispatcher –Context switch, FCFS, SJF, SRPT, RR, Priority, Quantum size –Read on your own: Multi-level (feedback) queue based scheduling Today –More on CPU scheduling

3 Proportional-Share Schedulers A general class of scheduling algorithms Process P i given a CPU weight w i > 0 The scheduler needs to ensure the following –forall i, j, |T i (t 1, t 2 )/T j (t 1,t 2 ) - w i /w j | ≤ e –Given P i and P j were backlogged during [t 1,t 2 ] Who chooses the weights and how? Application modeling problem: non-trivial –Approaches: analytical, empirical A part of my Ph.D. thesis Many PS schedulers developed in the 90s –E.g., Start-time Fair Queueing (Qlinux UT-Austin/Umass-Amherst)

4 Lottery Scheduling [Carl Waldspurger, MIT, ~1995] Perhaps the simplest proportional-share scheduler Create lottery tickets equal to the sum of the weights of all processes –What if the weights are non-integral? Draw a lottery ticket and schedule the process that owns that ticket –What if the process is not ready? Draw tickets only for ready processes –Homework 1: Calculate the time/space complexity of the operations Lottery scheduling will involve –Likely question on Exam 1 !!!

5 Lottery Scheduling Example 14 25 36 710 811 912 13 14 15 9 P1=6P2=9 Schedule P2

6 Lottery Scheduling Example 14 25 36 710 811 912 13 14 15 3 P1=6P2=9 Schedule P1

7 Lottery Scheduling Example 14 2511 6 710 8 3912 13 14 15 11 As t ∞, processes will get their share (unless they were blocked a lot) Problem with Lottery scheduling: Only probabilistic guarantee What does the scheduler have to do –When a new process arrives? –When a process terminates? P1=6P2=9 Schedule P2

8 Work Conservation Examples of work-conserving schedulers: All schedulers we have studied so far Examples of non-work-conserving schedulers: –DFS, a PS scheduler for multi-processors (Abhishek Chandra, Umass, 2000, now at Univ. of Minnesota) Experiments showed the scheduler had become NWC! Fair Airport to convert into a WC scheme NWC Scheduler WC Scheduler

9 Reservation-based Schedulers Each process has a pair (x, y) –Divide time into periods of length y each –Guaranteed to get x time units every period Can be Non-work-conserving

10 Rate Regulation: Leaky Bucket A type of reservation-based scheduling Leaky bucket policing –Rate r i for process P i –CPU cycles over period t  r i * t riri bibi CPU requirement CPU the process gets Max. rate at which the process may progress burst

11 Rate Regulation: Token Bucket A type of reservation-based scheduling Token bucket policing –Rate r i and burst b i for process P i –CPU cycles over period t  r i * t + b i riri b i tokens CPU requirement burst

12 Deadline-based Scheduling Can be NWC Several variants NP-hard Real-time systems “Soft” real-time systems –E.g., media servers: 30 MPEG-1 frames/sec –A few violations may be tolerable

13 An Interesting Problem: An Invitation to do Research on CPU Scheduling Can we achieve the effect of a scheduler that can provide resource guarantees using a priority-based scheduler? You are welcome to talk to me during office hours if you find this interesting or if you have any thoughts on this

14 Hierarchical Schedulers Variety of schedulers Subsets of processes with different scheduling needs Reservation-based (4, 10) (6, 10) LotteryRound-robin w=1 w=2 UNIX Processes

15 Scheduler Considerations: Context-Switch Overhead Switching context –User mode to Kernel mode –Save PCB –Process interrupt (e.g, TCP/IP processing) if needed –Run scheduling algorithm –Load registers (e.g., PC) from PCB of chosen process –Flush TLB (will discuss this under memory management) Switching to user mode Jumping to the proper location in the user program to restart that program Context switch time for Pentium/Linux: tens of microsec So how often should the scheduler be invoked?

16 Scheduler Considerations: Quantum Length The duration for which a CPU-intensive process will run before being scheduled out in favor of another process Different processes may have different quantum lengths –E.g., UNIX: Higher priority => Larger quantum Typically tens of msec in modern systems Small => Context switch overhead high Large => Bad responsiveness => Interactive processes suffer

17 Scheduler Considerations: CPU Accounting Scheduler maintains CPU usage, last scheduling instant etc. in each PCB Who should be charged for the CPU usage during interrupt processing? –Optional reading: Resource containers (Rice University, OSDI 1999, Gaurav Banga et al. )

18 Scheduler Considerations: Time and Space Requirements Run time (n processes) –FCFS: O(1) –RR: O(1) –Deadline-based algos: NP-hard variants, poly-time heuristics Update time: Operations done when set of processes changes (new, terminate, block, become ready) Space requirements –Space to store various data structs

19 Scheduler Evaluation Optimize one or more of response time, waiting time, throughput, fairness, utilization,.. Overheads –Run time (time to pick the next process to schedule) –Update time –Space requirements

20 Analytical Approaches to Scheduler Evaluation Example 1: Our evaluation of FCFS and SJF Example 2: Queueing Theory –Little’s Law: applies to any scheduling discipline –avg_num_processes_in_system = tput * avg_time_spent_in_system –Queuing theory provides expressions for mean response time for certain scheduling policies (FCFS, PS, LCFS) –Other statistical properties of response time only under restrictive assumptions on arrival process and service time runningwaiting yet to arriveserviced

21 Discussion: Analytical Approaches Pros: –Intellectually satisfying! –Quick, no code to be written –May provide generally applicable results Cons: –Often over-simplified Hard to model complex scheduling algorithms Lack of info about workloads

22 Simulation-based Evaluation Write software that mimics the behavior of the scheduler Subject it to realistic workload Observe output and make inferences about performance of scheduler Only need to know the algorithms, no need to do complex math Easier to implement than the actual system

23 Prototyping Build it!

24 Analysis, Simulation, and Prototyping Compared Analysis Simulation Prototyping accuracy, programming skills effort, time investment, mathematical skills, generality

25 Hybrid Approaches Analysis SimulationPrototyping

26 Threads

27 What is a Thread? A basic unit of CPU utilization like a process (not necessarily known to the OS though) “Smaller” than a process –Part of a process –Shares code + data + some other OS resources with other threads that belong to the same process

28 User Threads Thread management done by user-level threads library OS doesn’t know about the existence of these threads Three primary thread libraries: – POSIX Pthreads – Win32 threads – Java threads

29 Kernel Threads OS sees and manages these threads OS provides system calls to create, terminate, etc. (just like the system calls it provides for processes) Examples –Windows XP/2000 –Solaris –Linux –Tru64 UNIX –Mac OS X

30 Benefits Responsiveness Resource Sharing Economy Utilization of MP Architectures

Download ppt "Operating Systems CSE 411 CPU Management Sept. 20 2006 - Lecture 7 Instructor: Bhuvan Urgaonkar."

Similar presentations

Ads by Google