Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.

Similar presentations


Presentation on theme: "1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling."— Presentation transcript:

1

2 1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling algorithm. In batch and time-sharing systems, since CPU time is a scarce resource, scheduler can make a big difference in perceived performance and user satisfaction. In PC, the situation changed: –Most of the time there is only one active process. –CPU is no longer a scarce resource.

3 2 Scheduling In high-end networked workstations and servers, scheduling makes big difference to the user. (ex. Email vs. screen update) Scheduler also has to make efficient use of the CPU since process switching is expensive: 1.User mode switch to kernel mode 2.Storing process state, including storing its registers in the process table so that they could be reloaded later 3.Select a new process 4.The new process must be started Memory cache reloaded twice Upon entering the kernel and upon leaving it

4 3 Scheduling(Process behavior) Bursts of CPU usage alternate with periods of I/O wait –(a) a CPU-bound process (b) an I/O bound process The key factor in distinguishing the above two is the length of the CPU burst As CPUs get faster, the scheduling of I/O bound processes is likely to become more important to keep disk busy

5 4 Scheduling When to schedule –When a new process is created –When a process exits –When a process blocks, on I/O, on a semaphore, or for some other reason –When an I/O interrupt occurs Two ways to handle clock interrupts: –Non-preemptive ( 不被搶先 ): let it run until it blocks or until it voluntarily releases the CPU –Preemptive ( 可以搶先 ): let it run for a maximum of a fixed time

6 5 Scheduling Algorithm Goals (Non-preemptive or preemptive with long time periods)

7 6 Scheduling Algorithm Goals (preemptive) (sometimes preemption not needed)

8 7 Scheduling in Batch Systems First Come First Served –Easy to program, sometimes slow progress Shortest Job First Average turn around time for (a) is 14, and that for (b) is 11.

9 8 Scheduling in Batch Systems Shortest Job First is optimal when all the jobs are available simultaneously. (not true in most cases) Consider jobs A to E with run times of 2, 4,1,1,1. If the arrival times are 0,0,3,3,3, using shortest job first will run in the order A,B,C,D,E for average turn around of 4.6. However, the average turn around for the order B,C,D,E,A is 4.4.

10 9 Scheduling in Batch Systems Shortest Remaining time next –Always choose the process with shortest remaining time. –The above example will run in the order A,B,C,D,E,B, at time 0,2,3,4,5,6 with average turn around of 3.4

11 10 Scheduling in Batch Systems Three level scheduling 1.How many processes to keep in memory 2 What kind of processes

12 11 Scheduling in Batch Systems The criteria that a memory scheduler use to make its decisions: –How long has it been since the process was swapped in or out? –How much CPU time has the process had recently? –How big is the process? –How important is the process?

13 12 Scheduling in Interactive Systems (Round Robin ) (a) list of runnable processes (b) list of runnable processes after B uses up its quantum Setting the quantum too short causes too many process switches and lowers the CPU efficiency. Setting it too long may cause poor response to short interactive requests. Quantum normally is set as 20-50 msec.

14 13 Scheduling in Interactive Systems (Priority) A scheduling algorithm with four priority classes

15 14 Scheduling in Interactive Systems (Priority) To prevent high priority processes to run indefinitely, the scheduler may decrease the priority of the currently running process at each clock tick. Priorities may be assigned statically or dynamically. –A simple dynamic assignment for I/O bound process is to set the priority to 1/f, where f is the fraction of the last quantum that a process used. Normally use priority scheduling among the classes but round-robin within each class.

16 15 Scheduling in Interactive Systems Multiple Queues –Processes in the highest classes were run for one quantum. Processes in the next highest class were run for two quanta, and so on. Whenever a process used up all the quanta allocated, it was moved down one class. Shortest Process Next –Make estimates based on past behavior, and run the process with the shortest estimated running time –The technique of estimating by taking the weighted average of the current value and previous estimates is called aging.

17 16 Scheduling in Interactive Systems Guaranteed Scheduling –Example: if n users logged in, then each user receive about 1/n of the CPU power. Lottery Scheduling –Give processes lottery tickets for various system resources. Whenever a scheduling decision has to be made, a lottery ticket is chosen at random, and the process holding that ticket gets the resource. –Important processes can be given extra tickets. –It is highly responsive. –Cooperating processes may exchange tickets. Fair-Share scheduling –Take into account who owns a process before scheduling. Each user is allocated equal fraction of the CPU.

18 17 Scheduling in Real-Time Systems Real-time behavior is achieved by dividing the program into a number of processes, each of whose behavior is predictable and known in advance. Schedulable real-time system –Given m periodic events event i occurs within period P i and requires C i seconds –Then the load can only be handled if

19 18 Policy versus Mechanism Separate what is allowed to be done with how it is done –a process knows which of its children threads are important and need priority, for example, database management processes Scheduling algorithm parameterized –mechanism in the kernel Parameters filled in by user processes –policy set by user process

20 19 Thread Scheduling Possible scheduling of user-level threads 50-msec process quantum threads run 5 msec/CPU burst

21 20 Thread Scheduling Possible scheduling of kernel-level threads 50-msec process quantum threads run 5 msec/CPU burst

22 21 Thread Scheduling A major difference between user-level threads and kernel-level threads is the performance. User-level threads can employ an application specific thread scheduler. Skip 2.6


Download ppt "1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling."

Similar presentations


Ads by Google