Presentation is loading. Please wait.

Presentation is loading. Please wait.

Process Scheduling Schedulers and Scheduling Methods.

Similar presentations


Presentation on theme: "Process Scheduling Schedulers and Scheduling Methods."— Presentation transcript:

1 Process Scheduling Schedulers and Scheduling Methods

2 Processes and CPU utilization Processes often need to be suspended Reason for suspension may include Lack of resources Waiting for signals I/O operations Kernel operations Page Fault (later more) Whatever the reason, the OS must suspend the process and allow another to utilize the CPU

3 The framework Two strategies: Preemptive Scheduling Non-Preemptive Scheduling Scheduling decisions must be made in any of the following situation: Process switches from running to waiting state; Process switches from running to ready state Process switches from waiting to ready state When a process terminates

4 CPU Burst Time Time, T b that a process could run without needing to be put into a waiting queue. We can think of program as a series of CPU- Bursts and I/O Bursts, interspersed. Alternatively, CPU Burst is the time that a process could stay in the CPU before the next interrupt IF we were running a non-preemptive scheduler

5 Priority Scheduling All schedulers use some sort of process priority level to decide which process will execute next. Priority P of process p i can be viewed as a function P = prio(p i ), where the function prio() may by as simple as retrieving the process’ user assigned priority or as complex as necessary to take runtime conditions of the system into consideration. In general, priority can be static  no change during the runtime of the process; dynamic  it may change do to the dynamic nature of the system of processes in the system; In case of dynamic priority, the scheduler may re-calculate the priority of each process whenever it executes. Regardless of how the priorities are computed, they divide the set of processes into multiple priority levels (or classes) These levels are manifested in a data structure called Ready List (RL). We may think of a priority list (queues), i.e., a list of list such that the priority of processes on list RL[i] have precedence of processes on list RL[j] if j < i.

6 Priority Functions The decision which process will be allowed to execute is generally based on some measure of priority p. System measures that may determine the priority level of a process include: attained service time real-time in the system total service time deadline periodicity external priority memory requirements Many of these parameters are dynamic in nature and will cause the priority of a process to change over time. External priorities may be assigned to processes to indicate an initial difference among processes. A function that combines external (statically assigned) priorities with dynamic priority measures will determine the outcome of a scheduling decision Arbitration becomes necessary when two processes with equal priority are to be scheduled. This is the function of the arbitration rule! In a quantum-based system, the arbitration rule may be “round-robin”. In most other systems (e.g.,FIFO), chronological ordering is used.

7 Scheduling Methods We can categorize the various scheduling methods by: PF  Priority Function DM  Decision Mode AR  Arbitration Rule FIFO SJF SRT RR First In / First Out (FIFO): Processes that arrive earlier have higher priority. PF  P = r, where r is the amount of real-time that the process has spent in the system. DM  Non-Preemtive AR  random choice among processes arriving at exactly the same time

8 … methods cont’d Shortest Job First (SJF): Processes with lower total service time have priority! PF  P = -t, where t is the total service time DM  Non-Preemptive AR  either chronological or random among processes with same service time. SJF is provably optimal, in that it results in the minimum average waiting time for a given set of processes!! Example: Consider the following set of processes ProcessBurst Time P 1 6 P 2 8 P 3 7 P 4 3 Calculate the average waiting time when FIFO is used ( 1-2-3-4 order) and compare with the avg. waiting time for SJF.

9 SJF optimality … The average waiting time for FIFO scheduling is computed as: (P 1 (0) + P 2 (6) + P 3 (14) + P 4 (21)) / 4 = 10.25 time units. The average waiting time for SJF is computed as: (P 4 (0) + P 1 (3) + P 3 (9) + P 2 (16)) / 4 = 7 time units. We need to prove that this is true in general. How do we do that? Hint: Consider how we calculate the average waiting time of a sequence of processes with corresponding burst time t bi. awt = 1/n Σ i=1 (n-i) x t bi We clearly would like the largest burst time to occur in the sum as the n th element  with weight 0.

10 …methods cont’d SJF is Non-Preemptive! We can show optimality of SJF on a static set of processes. However, if we consider arbitrary arrival times of processes, we must re-define SJF to allow for the preemption of already executing processes. This yields a new version of SJF, sometimes referred to as Shortest Remaining Time First (SRT). Shortest Remaining Time (SRT): A preemptive and dynamic version of SJF giving processes with the least amount of remaining time to complete the highest priority. PF  P = (t – a), where t-a is the remaining time; DM  preemptive; AR  Same as SJF – chronological or random among processes with the same time to completion.

11 More Scheduling Methods Round Robin (RR): Round Robin imposes a fixed time quantum (time slice) on the amount of continuous CPU time that can be used by a process. When the time slice expires, the process is preempted and place on the ready-list. PF  P = 0; all processes have the same priority; DM  preemptive quantum oriented AR  cyclic; Multilevel Priority (ML): Uses a fixed set of priorities 1 (lowest) thru n (highest). Each process is assigned an external priority e upon creation. This priority can only be changed by authorized kernel calls. PF  P = e; DM  preemptive if newly arriving process has a higher priority. Within each priority queue, scheduling may be preemptive RR or non-preemptive FIFO. AR  cyclic if RR, random/chronological if FIFO.

12 Example of RR with Time Quantum = 20 ProcessBurst Time P 1 53 P 2 17 P 3 68 P 4 24 The Gantt chart is: Typically, higher average turnaround than SJF, but better response P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P3 02037577797117121134154162

13 The Relationship Between Priorities and Time- slice length

14 Summary of Scheduling Methods AlgorithmDecision ModePriority FunctionArbitration Rule FIFOnonpreemptiver random SJFnonpreemptive -t-t chronological or random SRTpreemptive- (t-a) chronological or random RRpreemptiveO cyclic RMpreemptive-d chronological or random EDFpreemptive- (d-r%d) chronological or random a = attained service time r = real time in system t = total service time d = period e = external priority


Download ppt "Process Scheduling Schedulers and Scheduling Methods."

Similar presentations


Ads by Google