180 likes | 327 Views
Operating Systems Lecture 19 Scheduling IV. Multilevel Queues. Ready queue is partitioned into separate queues: E.g.: foreground (interactive) background (batch) Each queue has its own scheduling algorithm, e.g.: foreground – RR background – FCFS
E N D
Operating SystemsLecture 19 Scheduling IV Operating System Concepts
Multilevel Queues • Ready queue is partitioned into separate queues: E.g.:foreground (interactive)background (batch) • Each queue has its own scheduling algorithm, e.g.:foreground – RRbackground – FCFS • Scheduling must be done between the queues. Possible methods: • Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. • Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; • i.e., 80% to foreground in RR • 20% to background in FCFS • Works well for time sharing systems. Operating System Concepts
Multilevel Queue scheduling Operating System Concepts
Multilevel Feedback Queue • A process can move between the various queues; aging can be implemented this way. • Multilevel-feedback-queue scheduler defined by the following parameters: • number of queues • scheduling algorithms for each queue • method used to determine when to upgrade a process • method used to determine when to demote a process • method used to determine which queue a process will enter when that process needs service (where to put new processes) Operating System Concepts
Typical behavior for multilevel feedback queues • New processes go to the highest priority queue for that job type. • Top priorities reserved for system processes. • If process uses full time slice, it moves down a priority. • If process blocks before using full time slice, it remains at the same priority. • Higher priority queues have smaller time slices than lower priority queues. Operating System Concepts
Example of a Multilevel Feedback Queue • Three queues: • Q0 – time quantum 8 milliseconds • Q1 – time quantum 16 milliseconds • Q2 – FCFS • Scheduling • A new job enters queue Q0which is servedFCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1. • At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2. Operating System Concepts
Multilevel Feedback Queues Operating System Concepts
Notes on Multilevel Feedback Queues • Short processes are favored. • Good for interactive processes with short CPU bursts. • Is starvation Possible? • Yes--Long processes may wait forever. • To avoid--increase the priority of a process if it has been waiting for some period of time in some queue. Operating System Concepts
Scheduling Multiple Processors • Scheduling for multiple processors is more complex than for a single process. • Identical processors: • Accomplish load sharing between processes • Use a single ready queue. (Question: Why not a queue for each processor?) • Scheduling methods • Each processor is self scheduling. (Requires careful programming). • One processor is scheduler for all the other processors. • One processor does all scheduling, I/O and system activities. Other processors only execute user code. This is asymmetric multiprocessing. • Asymmetric multiprocessing is easier to program, but less efficient than symmetric processing. Operating System Concepts
Algorithm Evaluation • How do we choose a scheduling algorithm? • First, choose the criteria you want to use to judge the algorithm. E.g. • Maximize the CPU utilization under the constraint that the maximum response time is 1 second. • Maximize throughput such that turnaround time is on average linearly proportional to total execution time. • Next, evaluate the algorithms under consideration. • Methods of evaluation: • Analytic evaluation (Deterministic modeling) • Queueing models • Simulations • Implementation Operating System Concepts
Deterministic Modeling • Analytic Evaluation is a method in which a given algorithm and system workload are used to produce a formula or number that evaluates the performance of the algorithm for that particular workload. • Deterministic modeling is one type of analytic evaluation. Operating System Concepts
Example of Deterministic Modeling ProcessBurst Time P1 10 P2 29 P3 3 P4 7 P5 12 • Compute the average wait time for FCFS, SJF and RR (quantum = 10 msec) • Which algorithm gives the minimum wait time? • FCFS: 28 msec • SJF: 13 msec • RR: 23 msec • SJF gives the shortest wait time (as expected, since it is optimal for shortest wait time). Operating System Concepts
Pros and Cons of Deterministic Modeling • Advantages of deterministic modeling • Simple and fast • Gives an exact number • Makes it easy to compare algorithms • Disadvantages: • Requires exact numbers for input. • Answers only apply to the specific case tested. • Does not give a general answer (too specific). Operating System Concepts
Queueing Models • Network queueing analysis models the system as a set of servers with associated queues of waiting processes: • CPU and ready queue • I/O system and device queues • etc. • This method uses information about the distribution of CPU and I/O bursts (determined by measurement or estimation). • The distribution is used to obtain a formula for the probability of a particular CPU burst length. • The method also requires a distribution of process arrival times (either measured or estimated). • Using the above information, queueing analysis can be used to compute CPU utilization, average queue length, average wait time, etc. Operating System Concepts
Little's Formula At steady state, the same number of processes are arriving in a queue as are leaving the queue. In this case, Little's formula applies: n = l W where: n = the average queue length W = the average wait time l = the average arrival rate of processes If one knows two of the above variables, one can compute the third. Operating System Concepts
Limitations of Queueing analysis • There are limited classes of algorithms and distributions that can be handled by queueing analysis. • Mathematics can be difficult to work with. • Distributions are often defined in mathematically tractable ways that are unrealistic. • To work with the mathematics, inaccurate assumptions may be made. • The theory therefore only yields approximate answers. Operating System Concepts
Simulations • Simulations are programs that models the components of the computer system. • Software data structures represent system components (e.g. a variable is used to represent the system clock). • The simulator modifies the system state to reflect the activities of the devices, scheduler and processes. • The simulator keeps track of statistics about system performance. • Input data (arrival times and burst times) can be generated by either: • A random number generator • A trace tape (a record of arrival and burst times on an actual system). • Drawbacks of simulation: • Simulation is very expensive. It can take hours of computing time. • More detail yields more accurate results, but takes more time to compute. • Trace tapes may need a large amount of storage space. Operating System Concepts
Implementation • The most accurate way to measure performance is to implement the algorithm and run it. • Drawbacks: • Expensive--Coding the algorithm and modifying the O.S. to support it can take many hours of programming. • The environment in which the algorithm is used may change, so that the initial results no longer apply. • Flexible scheduling algorithms can be altered by the system manager or users to accommodate changes in the environment. Operating System Concepts