CS162 Operating Systems and Systems Programming Lecture 11 Thread Scheduling (con’t) Protection: Address SpacesReview: Last TimeReview: Example with Different Time QuantumReview: What if we Knew the Future?Review: SRTF ExampleGoals for TodayPredicting the Length of the Next CPU BurstMulti-Level Feedback SchedulingScheduling DetailsWhat about Fairness?Lottery SchedulingLottery Scheduling ExampleHow to Evaluate a Scheduling algorithm?A Final Word On SchedulingAdministriviaVirtualizing ResourcesRecall: Single and Multithreaded ProcessesImportant Aspects of Memory MultiplexingBinding of Instructions and Data to MemoryMulti-step Processing of a Program for ExecutionRecall: UniprogrammingMultiprogramming (First Version)Multiprogramming (Version with Protection)Segmentation with Base and Limit registersIssues with simple segmentation methodMultiprogramming (Translation and Protection version 2)Example of General Address TranslationTwo Views of MemoryExample of Translation Table FormatDual-Mode OperationFor Protection, Lock User-Programs in AsylumHow to get from KernelUserUserKernel (System Call)System Call ContinuedUserKernel (Exceptions: Traps and Interrupts)Additions to MIPS ISA to support Exceptions?Intel x86 Special RegistersCommunicationClosing thought: Protection without HardwareSummarySummary (2)CS162Operating Systems andSystems ProgrammingLecture 11Thread Scheduling (con’t)Protection: Address SpacesOctober 5, 2005Prof. John Kubiatowiczhttp://inst.eecs.berkeley.edu/~cs162Lec 11.210/05/05 Kubiatowicz CS162 ©UCB Fall 2005Review: Last Time•Suggestions for dealing with Project Partners–Start Early, Meet Often–Develop Good Organizational Plan, Document Everything, Use the right tools–Develop a Comprehensive Testing Plan–(Oh, and add 2 years to every deadline!)•Scheduling: selecting a waiting process from the ready queue and allocating the CPU to it•FCFS Scheduling:–Run threads to completion in order of submission–Pros: Simple (+)–Cons: Short jobs get stuck behind long ones (-)•Round-Robin Scheduling: –Give each thread a small amount of CPU time when it executes; cycle between all ready threads–Pros: Better for short jobs (+)–Cons: Poor when jobs are same length (-)Lec 11.310/05/05 Kubiatowicz CS162 ©UCB Fall 2005 QuantumCompletionTimeWaitTimeAverageP4P3P2P1Review: Example with Different Time QuantumP2[8]P4[24]P1[53]P3[68]0 8 32 85 153Best FCFS:6257852284Q = 1104½11215328125Q = 20100½8115330137Q = 166¼ 88852072Q = 2031¼885032Best FCFS121¾14568153121Worst FCFS69½32153885Best FCFS83½121014568Worst FCFS95½8015316133Q = 857¼5685880Q = 899½9215318135Q = 1099½8215328135Q = 561¼68851082Q = 1061¼58852082Q = 5Lec 11.410/05/05 Kubiatowicz CS162 ©UCB Fall 2005Review: What if we Knew the Future?•Could we always mirror best FCFS?•Shortest Job First (SJF):–Run whatever job has the least computation to do•Shortest Remaining Time First (SRTF):–Preemptive version of SJF: if job arrives and has a shorter time to completion than the remaining time on the current job, immediately preempt CPU•Example Three jobs:–A,B: both CPU bound, run for weekC: I/O bound, loop 1ms CPU, 9ms disk I/O–If only one at a time, C uses 90% of the disk, A or B could use 100% of the CPUCC’s I/OC’s I/OC’s I/OA or BLec 11.510/05/05 Kubiatowicz CS162 ©UCB Fall 2005Review: SRTF ExampleC’s I/OCABAB… CC’s I/ORR 1ms time sliceC’s I/OC’s I/OCA BCRR 100ms time sliceC’s I/OACC’s I/OAASRTFDisk Utilization:Approx 90%Disk Utilization:90%Disk Utilization:9/201 ~ 4.5%Lec 11.610/05/05 Kubiatowicz CS162 ©UCB Fall 2005Goals for Today•Finish discussion of Scheduling•Kernel vs User Mode•What is an Address Space?•How is it Implemented?Note: Some slides and/or pictures in the following areadapted from slides ©2005 Silberschatz, Galvin, and GagneLec 11.710/05/05 Kubiatowicz CS162 ©UCB Fall 2005Predicting the Length of the Next CPU Burst•Adaptive: Changing policy based on past behavior–CPU scheduling, in virtual memory, in file systems, etc–Works because programs have predictable behavior»If program was I/O bound in past, likely in future»If computer behavior were random, wouldn’t help•Example: SRTF with estimated burst length–Use an estimator function on previous bursts: Let tn-1, tn-2, tn-3, etc. be previous CPU burst lengths. Estimate next burst n = f(tn-1, tn-2, tn-3, …)–Function f could be one of many different time series estimation schemes (Kalman filters, etc)–For instance, exponential averagingn = tn-1+(1-)n-1with (0<1)Lec 11.810/05/05 Kubiatowicz CS162 ©UCB Fall 2005Multi-Level Feedback Scheduling•Another method for exploiting past behavior–First used in CTSS–Multiple queues, each with different priority»Higher priority queues often considered “foreground” tasks–Each queue has its own scheduling algorithm»e.g. foreground – RR, background – FCFS»Sometimes multiple RR priorities with quantum increasing exponentially (highest:1ms, next:2ms, next: 4ms, etc)•Adjust each job’s priority as follows (details vary)–Job starts in highest priority queue–If timeout expires, drop one level–If timeout doesn’t expire, push up one level (or to top)Long-Running ComputeTasks Demoted to Low PriorityLec 11.910/05/05 Kubiatowicz CS162 ©UCB Fall 2005Scheduling Details•Result approximates SRTF:–CPU bound jobs drop like a rock–Short-running I/O bound jobs stay near top•Scheduling must be done between the queues–Fixed priority scheduling: »serve all from highest priority, then next priority, etc.–Time slice:»each queue gets a certain amount of CPU time »e.g., 70% to highest, 20% next, 10% lowest•Countermeasure: user action that can foil intent of the OS designer–For multilevel feedback, put in a bunch of meaningless I/O to keep job’s priority high–Of course, if everyone did this, wouldn’t work!•Example of Othello program:–Playing against competitor, so key was to do computing at higher priority the competitors. »Put in printf’s, ran much faster!Lec 11.1010/05/05 Kubiatowicz CS162 ©UCB Fall 2005What about Fairness?•What about fairness?–Strict fixed-priority scheduling between queues is unfair (run highest, then next, etc):»long running jobs may never get CPU »In Multics, shut down machine, found 10-year-old job–Must give long-running jobs a fraction of the CPU even when there are shorter jobs to run–Tradeoff: fairness gained by hurting avg response
View Full Document