Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 7 Scheduling.

Similar presentations


Presentation on theme: "Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 7 Scheduling."— Presentation transcript:

1 Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 7 Scheduling

2 Slide 7-2 Copyright © 2004 Pearson Education, Inc. Scheduling CPU scheduling refers to the task of managing CPU sharing among a community of ready processes Real life example: room scheduler Mechanism: Hardware and process manager’s data structure and algorithms implement the mechanism Policy : scheduling policies are implemented as part of OS

3 Slide 7-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Model of Process Execution Ready List Ready List Scheduler CPU Resource Manager Resource Manager Resources Preemption or voluntary yield AllocateRequest Done New Process job “Ready” “Running” “Blocked”

4 Slide 7-4 Copyright © 2004 Pearson Education, Inc. Scheduling Operating Systems: A Modern Perspective, Chapter 7 In a single CPU system, only one process at a time can use the CPU. There can be only one process in the running state at a time. The running process may cease using the CPU for any of the 4 reasons The process completes its execution and leaves the system The process requests a resource, but the resource manager decides that it cannot allocate the resource to the process The process decides to voluntarily release the CPU and return to the ready state The process involuntarily releases the CPU because the system decides to pre-empt

5 Slide 7-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Scheduler as CPU Resource Manager Scheduler Process Units of time for a time-multiplexed CPU ReleaseReady to run Dispatch Release Ready List

6 Slide 7-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 The Scheduler Ready Process Enqueuer Ready List Ready List Dispatcher Context Switcher Context Switcher Process Descriptor Process Descriptor CPU From Other States Running Process

7 Slide 7-7 Copyright © 2004 Pearson Education, Inc. The scheduler Operating Systems: A Modern Perspective, Chapter 7 Scheduling mechanism is composed of several different parts. The logical part is incorporated into every scheduler The enqueuer The dispatcher The context switcher

8 Slide 7-8 Copyright © 2004 Pearson Education, Inc. When a process is changed to ready state, its descriptor is updated to reflect the change and the enqueuer component places a pointer to the descriptor into a list of processes that are waiting for the CPU. When the scheduler switches the CPU from executing another, the context switcher components saves the contents of all CPU registers for the process being removed from the CPU in its descriptor Dispatcher is invoked after the application process has been removed from the CPU. The dispatcher selects one of the ready process from the ready list and then allocates the CPU to that proces. Operating Systems: A Modern Perspective, Chapter 7

9 Slide 7-9 Copyright © 2004 Pearson Education, Inc. Saving the context Whenever the CPU is multiplexed, the old process is removed from the CPU and a new process is installed to begin using the CPU. The CPU contains various registers that hold data and status relevant to the currently executing process. When ever a CPU execution is paused, the contents of all the CPU registers must be saved in that process’s descriptors so that just before the process resumes execution, those register contents can be copied back into the physical CPU registers Operating Systems: A Modern Perspective, Chapter 7

10 Slide 7-10 Copyright © 2004 Pearson Education, Inc. Saving the context Context switching can significantly affect the performance, since modern computers have lot of general purpose & status registers to be saved. Each context requires, (n+m)*b *K time units To save the stauts of n gen registers and m status registers, assuming b operations are required to save a single register and each store instruction requires K time units Operating Systems: A Modern Perspective, Chapter 7

11 Slide 7-11 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Context Switching CPU New process Descriptor Old process Descriptor

12 Slide 7-12 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 n=32, m=8, b*K =50ns (n+m)*b*K = 2 microseconds 4 microsec for both restoring and loading A 1 GHz processor can execute a register instruction in about 2 nano seconds The processor could execute 2000 instructions during useful work So the cost of context switching is a significant factor in CPU multiplexing

13 Slide 7-13 Copyright © 2004 Pearson Education, Inc. Pre-emptive &non pre-emptive kernels Operating Systems: A Modern Perspective, Chapter 7 A scheduler that uses involuntary CPU sharing is called a non-preemptive scheduler A scheduler that uses voluntary CPU sharing is called pre-emptive scheduler

14 Slide 7-14 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Contemporary Scheduling voluntary CPU sharing – timer interrupts –Time quantum determined by interval timer – usually fixed size for every process using the system –Sometimes called the time slice length

15 Slide 7-15 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Choosing a Process to Run Mechanism never changes Strategy = policy the dispatcher uses to select a process from the ready list Different policies for different requirements Ready Process Enqueue Ready List Ready List Dispatch Context Switch Context Switch Process Descriptor Process Descriptor CPU Running Process

16 Slide 7-16 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Policy Considerations The CPU scheduling is remarkably similar to other types of scheduling that have been studied for years. CPU can be thought of as a teller in a bank, where processes are customers Policy can control/influence: –CPU utilization –Average time a process waits for service –Average amount of time to complete a job

17 Slide 7-17 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Model of Process Execution Ready List Ready List Scheduler CPU Resource Manager Resource Manager Resources Preemption or voluntary yield AllocateRequest Done New Process job “Ready” “Running” “Blocked”

18 Slide 7-18 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 A model to study scheduling

19 Slide 7-19 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Commonly used performance matrics Let P = {p i | 0  i < n} = set of processes Let S(p i )  {running, ready, blocked} Let  (p i ) = Time process needs to be in running state (the service time) Let W(p i ) = Time p i is in ready state before first transition to running (wait time) Let T TRnd (p i ) = Time from p i first enter ready to last exit ready (turnaround time) Batch Throughput rate = inverse of avg T TRnd Timesharing response time = W(p i )

20 Slide 7-20 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Simplified Model Ready List Ready List Scheduler CPU Resource Manager Resource Manager Resources AllocateRequest Done New Process job “Ready” “Running” “Blocked” Simplified, but still provide analysis result Easy to analyze performance No issue of voluntary/involuntary sharing Preemption or voluntary yield

21 Slide 7-21 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Nonpreemptive Schedulers Ready List Ready List Scheduler CPU Done New Process Try to use the simplified scheduling model Only consider running and ready states Blocked or preempted processes

22 Slide 7-22 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 0 ) =  (p 0 ) = 350 W(p 0 ) = 0 0350

23 Slide 7-23 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = 125+350 = 475 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 475350

24 Slide 7-24 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 p2p2 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = 125+350 = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = 475+475 = 950 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) = 475 475950

25 Slide 7-25 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 p2p2 p3p3 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = 125+350 = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = 475+475 = 950 T TRnd (p 3 ) = (  (p 3 ) +T TRnd (p 2 )) = 250+950 = 1200 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) = 475 W(p 3 ) = T TRnd (p 2 ) = 950 1200950

26 Slide 7-26 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 First-Come-First-Served i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = 125+350 = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = 475+475 = 950 T TRnd (p 3 ) = (  (p 3 ) +T TRnd (p 2 )) = 250+950 = 1200 T TRnd (p 4 ) = (  (p 4 ) +T TRnd (p 3 )) = 75+1200 = 1275 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) = 475 W(p 3 ) = T TRnd (p 2 ) = 950 W(p 4 ) = T TRnd (p 3 ) = 1200 12001275

27 Slide 7-27 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 FCFS Average Wait Time i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 ) = 350 T TRnd (p 1 ) = (  (p 1 ) +T TRnd (p 0 )) = 125+350 = 475 T TRnd (p 2 ) = (  (p 2 ) +T TRnd (p 1 )) = 475+475 = 950 T TRnd (p 3 ) = (  (p 3 ) +T TRnd (p 2 )) = 250+950 = 1200 T TRnd (p 4 ) = (  (p 4 ) +T TRnd (p 3 )) = 75+1200 = 1275 W(p 0 ) = 0 W(p 1 ) = T TRnd (p 0 ) = 350 W(p 2 ) = T TRnd (p 1 ) = 475 W(p 3 ) = T TRnd (p 2 ) = 950 W(p 4 ) = T TRnd (p 3 ) = 1200 W avg = (0+350+475+950+1200)/5 = 2974/5 = 595 127512009004753500 Easy to implement Ignores service time, etc Not a great performer

28 Slide 7-28 Copyright © 2004 Pearson Education, Inc. Shortest Job Next SJN scheduling algorithm chooses the process requiring minimum service time as the highest priority job SJN minimizes average waiting time because it services small process before it services large ones. Even though it minimizes AWT, it may penalize process with high service time requests. Arrival order is irrelevant here Operating Systems: A Modern Perspective, Chapter 7

29 Slide 7-29 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) 0 350 1 125 2 475 3 250 4 75 p4p4 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 4 ) = 0 750

30 Slide 7-30 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) 0 350 1 125 2 475 3 250 4 75 p1p1 p4p4 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = 125+75 = 200 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 1 ) = 75 W(p 4 ) = 0 200750

31 Slide 7-31 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) 0 350 1 125 2 475 3 250 4 75 p1p1 p3p3 p4p4 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = 125+75 = 200 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = 250+125+75 = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 1 ) = 75 W(p 3 ) = 200 W(p 4 ) = 0 450200750

32 Slide 7-32 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = 350+250+125+75 = 800 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = 125+75 = 200 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = 250+125+75 = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 0 ) = 450 W(p 1 ) = 75 W(p 3 ) = 200 W(p 4 ) = 0 800450200750

33 Slide 7-33 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = 350+250+125+75 = 800 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = 125+75 = 200 T TRnd (p 2 ) =  (p 2 )+  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = 475+350+250+125+75 = 1275 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = 250+125+75 = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 0 ) = 450 W(p 1 ) = 75 W(p 2 ) = 800 W(p 3 ) = 200 W(p 4 ) = 0 1275800450200750

34 Slide 7-34 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Shortest Job Next i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = 350+250+125+75 = 800 T TRnd (p 1 ) =  (p 1 )+  (p 4 ) = 125+75 = 200 T TRnd (p 2 ) =  (p 2 )+  (p 0 )+  (p 3 )+  (p 1 )+  (p 4 ) = 475+350+250+125+75 = 1275 T TRnd (p 3 ) =  (p 3 )+  (p 1 )+  (p 4 ) = 250+125+75 = 450 T TRnd (p 4 ) =  (p 4 ) = 75 W(p 0 ) = 450 W(p 1 ) = 75 W(p 2 ) = 800 W(p 3 ) = 200 W(p 4 ) = 0 W avg = (450+75+800+200+0)/5 = 1525/5 = 305 1275800450200750 Minimizes wait time May starve large jobs Must know service times

35 Slide 7-35 Copyright © 2004 Pearson Education, Inc. If the ready list is saturated, then the process with large service time tend to be left in the ready list while small process receive service. In extreme case, process with larger service time will never be served This starvation of large process can be serious liability of the scheduling algorithm Operating Systems: A Modern Perspective, Chapter 7

36 Slide 7-36 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Priority scheduling In this, process are allocated to the CPU on the basis of an externally assigned priority A process external priority is determined from the abitrary criteria(user identification, nature of the work etc) Policies –Static priority : computed once –Dynamic priority : process to become more or less important depending on how much service it has recently recieved Operating Systems: A Modern Perspective, Chapter 7

37 Slide 7-37 Copyright © 2004 Pearson Education, Inc. Priority scheduling Static priority may cause low priority processs to starve This can be addressed by using dynamic priorities Operating Systems: A Modern Perspective, Chapter 7

38 Slide 7-38 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Priority Scheduling i  (p i ) Pri 0 350 5 1 125 2 2 475 3 3 250 1 4 75 4 p0p0 p1p1 p2p2 p3p3 p4p4 T TRnd (p 0 ) =  (p 0 )+  (p 4 )+  (p 2 )+  (p 1 ) )+  (p 3 ) = 350+75+475+125+250 = 1275 T TRnd (p 1 ) =  (p 1 )+  (p 3 ) = 125+250 = 375 T TRnd (p 2 ) =  (p 2 )+  (p 1 )+  (p 3 ) = 475+125+250 = 850 T TRnd (p 3 ) =  (p 3 ) = 250 T TRnd (p 4 ) =  (p 4 )+  (p 2 )+  (p 1 )+  (p 3 ) = 75+475+125+250 = 925 W(p 0 ) = 925 W(p 1 ) = 250 W(p 2 ) = 375 W(p 3 ) = 0 W(p 4 ) = 850 W avg = (925+250+375+0+850)/5 = 2400/5 = 480 12759258503752500 Reflects importance of external use May cause starvation Can address starvation with aging

39 Slide 7-39 Copyright © 2004 Pearson Education, Inc. Deadline Scheduling Hard real time systems are often characterized as having certain process that must complete execution prior to some time deadline The critical performance measure is whether the system will be able to meet all such process’s scheduling deadlines. Measure of turnaround time and wait time are irrelevant here Operating Systems: A Modern Perspective, Chapter 7

40 Slide 7-40 Copyright © 2004 Pearson Education, Inc. As a result, these schedulers require complete knowledge of maximum service time for each process Eg: in streaming media systems, dead line required to prevent jitter and latency in audio or video processing Earliest deadline first scheduling (EDFS) is an optimal algorithm for certain types of deadline scheduling. Operating Systems: A Modern Perspective, Chapter 7

41 Slide 7-41 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Deadline Scheduling i  (p i ) Deadline 0 350 575 1 125 550 2 475 1050 3 250 (none) 4 75 200 1275 1050550200 0 Allocates service by deadline May not be feasible p0p0 p1p1 p2p2 p3p3 p4p4 575

42 Slide 7-42 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Preemptive Schedulers Ready List Ready List Scheduler CPU Preemption or voluntary yield Done New Process Highest priority process is guaranteed to be running at all times –Or at least at the beginning of a time slice Dominant form of contemporary scheduling But complex to build & analyze

43 Slide 7-43 Copyright © 2004 Pearson Education, Inc. Preemptive versions of SJN & priority scheduling Preemptive versions of SJN and priority algorithms are also available This versions differ from the nonpreemptive versions by keeping the highest priority job in the running state at all times. If p i is executing and is pre-empted by the arrival of p j, then SJN need only compare  (p i ) and  (p j) Operating Systems: A Modern Perspective, Chapter 7

44 Slide 7-44 Copyright © 2004 Pearson Education, Inc. Round Robin Scheduling RR is the most widely used of all the scheduling algorithms. The goal of RR is equitable distribution of the processing time among all processes requesting the processor. This distribution will tend to fit in with the multiprogramming philosophy in which each of n process receive approximately 1/n time units of processing time Operating Systems: A Modern Perspective, Chapter 7

45 Slide 7-45 Copyright © 2004 Pearson Education, Inc. A system with a timer interrupt naturally fits with RR scheduling, since the interrupt interval can be set to the desired time quantum When the timer interrupt occurs, the executing process’s time quantum has completed. There for scheduler removes the running process form the CPU. The scheduler then adjusts the ready queue list according the implementation, resets the timer and dispatches the process at the head of the ready list to the CPU Operating Systems: A Modern Perspective, Chapter 7

46 Slide 7-46 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 W(p 0 ) = 0 050

47 Slide 7-47 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 W(p 0 ) = 0 W(p 1 ) = 50 1000 p1p1

48 Slide 7-48 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 1000 p2p2 p1p1

49 Slide 7-49 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 2001000 p3p3 p2p2 p1p1

50 Slide 7-50 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 2001000 p4p4 p3p3 p2p2 p1p1

51 Slide 7-51 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 3002001000 p0p0 p4p4 p3p3 p2p2 p1p1

52 Slide 7-52 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 4754003002001000 p4p4 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3

53 Slide 7-53 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 1 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 4754003002001000 p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 550

54 Slide 7-54 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 1 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 4754003002001000 p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 550650 750850950

55 Slide 7-55 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 4754003002001000 p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p0 550650 7508509501050

56 Slide 7-56 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 2 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 4754003002001000 p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p0 p2p2 p2p2 p2p2 p2p2 550650 7508509501050115012501275

57 Slide 7-57 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Round Robin (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 2 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 50 W(p 2 ) = 100 W(p 3 ) = 150 W(p 4 ) = 200 W avg = (0+50+100+150+200)/5 = 500/5 = 100 4754003002001000 Equitable Most widely-used Fits naturally with interval timer p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p0 p2p2 p2p2 p2p2 p2p2 550650 7508509501050115012501275 T TRnd _ avg = (1100+550+1275+950+475)/5 = 4350/5 = 870

58 Slide 7-58 Copyright © 2004 Pearson Education, Inc. The wait times illustrates the obvious benefit of RR in terms of how quickly a process begins to receive service. Consider the effect of context switching time on RR scheduling. Let C be the time to perform a context switch between user processes. Each of n processes will receive q units of time on the CPU for every n*(q+C) units of real time. Operating Systems: A Modern Perspective, Chapter 7

59 Slide 7-59 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 RR with Overhead=10 (TQ=50) i  (p i ) 0 350 1 125 2 475 3 250 4 75 p0p0 T TRnd (p 0 ) =  T TRnd (p 1 ) =  T TRnd (p 2 ) =  T TRnd (p 3 ) =  T TRnd (p 4 ) =  W(p 0 ) = 0 W(p 1 ) = 60 W(p 2 ) = 120 W(p 3 ) = 180 W(p 4 ) = 240 W avg = (0+60+120+180+240)/5 = 600/5 = 120 5404803602401200 Overhead must be considered p4p4 p1p1 p0p0 p4p4 p3p3 p2p2 p1p1 p1p1 p2p2 p3p3 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p3p3 p2p2 p0p0 p2p2 p0p0 p2p2 p2p2 p2p2 p2p2 575790 910103011501270139015101535 T TRnd _ avg = (1320+660+1535+1140+565)/5 = 5220/5 = 1044 635670 790

60 Slide 7-60 Copyright © 2004 Pearson Education, Inc. Multiple Level Queues They are an extension of priority scheduling in which all processes of the same priority are placed in a single pool. The scheduler allocates the CPU across processes in priority pools using one strategy and allocates the CPU to processes in the same queue according to the second strategy Operating Systems: A Modern Perspective, Chapter 7

61 Slide 7-61 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 Multi-Level Queues Ready List 0 Ready List 1 Ready List 2 Ready List 3 Scheduler CPU Preemption or voluntary yield Done New Process All processes at level i run before any process at level j At a level, use another policy, e.g. RR

62 Slide 7-62 Copyright © 2004 Pearson Education, Inc. Multi level feed back queue A system that allows processes to change ready sub lists is called a multilevel feedback queue Eg: an interrupt handler process might run at priority 1. device driver at 2, interactive process at 3, interacting editing job at 4, normal batch job at 5, long batch job at 6 If in this choice, priority of a process change dynamically during execution, depending on the phase of the execution they are currently executing If an interactive editing processes became computation-intensive process, its priority might be dropped to a lower level, since it is attempting to use an extra share of CPU

63 Slide 7-63 Copyright © 2004 Pearson Education, Inc. Batch (accounts receivable, payroll…..) Interactive Real time (deadlines) Depends on the use to which the CPU is being put Categories of Scheduling Algorithms Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

64 Slide 7-64 Copyright © 2004 Pearson Education, Inc. Scheduling Algorithm Goals Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

65 Slide 7-65 Copyright © 2004 Pearson Education, Inc. First-come first-served Shortest job first Shortest remaining time next Scheduling in Batch Systems Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

66 Slide 7-66 Copyright © 2004 Pearson Education, Inc. Round robin Priority Multiple Queues Shortest Process Next Guaranteed Scheduling Lottery Scheduling Fair Share Scheduling Scheduling in Interactive Systems Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

67 Slide 7-67 Copyright © 2004 Pearson Education, Inc. Linux schedulers Rotating Staircase Deadline Staircase Deadline scheduler Noop scheduler CFQ (Completely Fair Queuing ) Fair-share scheduling CFS (completely fair scheduler) BFS O(1) Scheduler Operating Systems: A Modern Perspective, Chapter 7

68 Slide 7-68 Copyright © 2004 Pearson Education, Inc. Fair share scheduling Fair scheduling is a method of assigning resources to jobs such that all jobs get, on average, an equal share of resources over time. When there is a single job running, that job uses the entire cluster. When other jobs are submitted, tasks slots that free up are assigned to the new jobs, so that each job gets roughly the same amount of CPU time. Operating Systems: A Modern Perspective, Chapter 7

69 Slide 7-69 Copyright © 2004 Pearson Education, Inc. O(1) Scheduler An O(1) scheduler is a kernel scheduling design that can schedule processes within a constant amount of time, regardless of how many processes are running on the operating system. One of the major goals of operating system designers is to minimize overhead and jitter of OS services. In Linux, it has replaced the previously used O(n) scheduler. Designed & implemented by Ingo Molnár Operating Systems: A Modern Perspective, Chapter 7

70 Slide 7-70 Copyright © 2004 Pearson Education, Inc. Completely Fair Scheduler (CFS) Con Kolivas's work with CPU scheduling, most significantly his implementation of "fair scheduling" named Rotating Staircase Deadline, inspired Ingo Molnár to develop his CFS, as a replacement for the earlier O(1) scheduler. In contrast to the previous O(1) scheduler used in older Linux 2.6 kernels, the CFS scheduler implementation is not based on run queues. Instead, a red-black tree implements a "timeline" of future task execution. Additionally, the scheduler uses nanosecond granularity accounting, the atomic units by which an individual process' share of the CPU was allocated Operating Systems: A Modern Perspective, Chapter 7

71 Slide 7-71 Copyright © 2004 Pearson Education, Inc. Brain Fuck Scheduler(BFS) The Brain Fuck Scheduler (BFS) is a process scheduler designed for the Linux kernel in August 2009 as an alternative to the Completely Fair Scheduler and the O(1) scheduler.BFS was created by veteran kernel programmer Con Kolivas( Australian anaesthetist) The objective of BFS, compared to other schedulers, is to provide a scheduler with a simpler algorithm, that does not require adjustment of heuristics or tuning parameters to tailor performance to a specific type of computation workload. Operating Systems: A Modern Perspective, Chapter 7

72 Slide 7-72 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7

73 Slide 7-73 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7


Download ppt "Slide 7-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 7 7 Scheduling."

Similar presentations


Ads by Google