Return to Contents

Scheduling


Definition


Types of schedulers:


CPU burst


CPU burst: the amount of time the process uses the processor before it is no longer ready

Types of CPU bursts:


Scheduling Algorithms

a) First-Come, First-Served (FCFS) e.g. A,B,C,D,E are processes
	time units - discrete amounts of time    
	status: running =>  pid    
		waiting =>  w    
    
P   E |                                                 W   E   E   E||    
R     |    
O   D |                                     W   W   W   D||      
C     |    
E   C |                     W   W   W   W   W   W   C||    
S     |    
S   B |                 W   W   W   B   B   B   B||    
      |    
    A | A   A   A   A   A   A   A||    
      |_________________________________________________________________
       0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16
	              	T I M E  =>     
    
TABLE:    
	T = elapsed time (includes waiting)    
	t = processing time required    
	M = T-t = missed (idle) time    
	R = t/T = ratio (response) time    
	P = T/t = penalty rate = 1/R    
    
Arrival   Process    time (t)	elapsed    missed   ratio    Penalty 
time		     required   time (T)    time	
    
0            A		7	    7	      0        1        1    
4	     B		7	    7         3	     4/7     7/4    
5	     C		1	    7	      6	     1/7       7    
9	     D		1	    4	      3	     1/4       4    
12	     E		3	    4	      1	     3/4     4/3    
b) Round Robin (RR)
e.g. let quantum (q) = 1.
    
P   E |                                                   W   E   E   E  || 
R     |    
O   D |                                       W   D||  
C     |    
E   C |                       W   C||    
S     |    
S   B |                   B   W   W   B   W   B   W   W   B||    
      |    
    A |   A   A   A   A   W   A   W   W   A   W   W   A||    
      |___________________________________________________________________   
        0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16
	              	T I M E  =>     
    
TABLE:    
	T = elapsed time (includes waiting)    
	t = processing time required    
	M = T-t = missed (idle) time    
	R = t/T = ratio (response) time    
	P = T/t = penalty rate = 1/R    
     
Arrival	   Process   time (t)	 elapsed     missed   ratio    penalty 
time		     required    time (T)     time	    
    
0	      A		7	    12		5	7/12	 12/7    
4             B		4	     9		5	4/9       9/4    
5	      C		1            2		1	1/2	    2    
9	      D		1	     2		1	1/2	    2    
12	      E		3	     4		1	3/4  	  4/3    
    
Compare RR with FCFS
c) Shortest-Job-First (SJF)


(d) Shortest Remaining Time (SRT) Algorithm

    
P   E |                                         W   W   W   E   E   E||    
R     |    
O   D |                                 W   D||      
C     |    
E   C |                     C||    
S     |    
S   B |             W   W   W   W   W   B   W   B   B   B||    
      |    
    A | A   A   A   A   A   W   A   A||    
      |___________________________________________________________________  
      0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16      
	              	T I M E  =>     
    
at time: 
0: e(A) = 7 choose A 1: (no decision required) 2: 3: 4: e(A) = 3; e(B) = 4 choose A 5: e(A) = 2; e(B) = 4; e(C) = 1 choose C -> done 6: e(A) = 2; e(B) = 4 choose A 7: no decision; A -> done 8: e(B) = 4 choose B 9: e(B) = 3; e(D) = 1 choose D -> done 10: e(B) = 3 choose B 11: 12: e(B) = 1; e(E) = 3 choose B -> done 13: e(E) = 3 choose E 14: 15: E -> done
  • very short processes get very good service
  • a process may mislead the scheduler if it previously ran quickly but now may be cpu intensive (this algorithm fails very badly for such a case)
  • the penalty ratios are small;
  • this algorithm works extremely well in most cases
  • this algorithm provably gives the highest throughput (number of processes completed) of all scheduling algorithms if the estimates are exactly correct.


    (e) Nonpreemptive Priority Algorithm

  • processor is allocated to the ready process with the highest priority (we will assume that the highest priority is 0, as in UNIX and LINUX)
  • shortest remaining time (SJF) algorithm is a priority algorithm with the priority defined as the expected time
    choose priority equal to the expected CPU burst time (p=t).
    use 0 as highest priority.
        
    e.g.	priority p = t    
    	A  	7    
    	B	4    
    	C	1    
    	D	1    
    	E	3    
    
  • if all arrive at time 0 and are to run to completion, the C, D have the highest priority, etc.
  • if there is a tie, choose the processes in alphabetical order
  • impractical and unrealistic in practice


    (f) Preemptive Priority Algorithm

  • when a process arrives at the ready queue with a higher priority than the running process, the new one preempts the running process;
  • low priority processes can starve

    - UNIX also has priorities; it uses aging to prevent starvation
    - aging: if a process has not received service for a long time, its priority is increased again

    (g) Multilevel Feedback-Queue Scheduling (FB)



  • priorities are implicit in the position of the queue that the ready process is currently waiting in
  • when process is running on the processor, the OS must remember which queue it came from
  • after a process has executed for one time quantum, it is moved down one queue
  • process is placed at the back of the queue
  • this is close to what is used for the traditional UNIX scheduler
  • a ready process is initially (implicitly) given a high priority, then, as it uses time while still remaining ready, its priority is lowered

    Main Parameters for FB
    1. how long of a time quantum a process gets (quantum q)
    2. how many queues are present (number of queues Q)
    3. the scheduling algorithm for each queue (usually RR at each level, but only one time around at each level but the last level); text says that bottom level is FCFS--this is inaccurate because a time quantum is used even at the bottom level.
    4. the method used to determine when to upgrade a process to a higher priority queue (usually this is some type of aging, whereby a process that has waited a long time in a queue (say 15 minutes) gets upgraded by one level)
    5. the method used to determine when to demote a process to a lower-priority queue (in the simple case, move down one level at the end of each quantum)
    6. the method used to determine which queue a process will enter when it becomes ready (in the simple case, all ready processes enter at the end of queue 0)

    Variations of FB
    1. give queues quantums of different lengths, e.g. #1, queue 0 - 1, queue 1 - 2, queue 2 - 3, queue 3 - 4, etc.; e.g. #2, queue 0 - 1, queue 1 - 2, queue 2 - 4, queue 3 - 8, etc.
    2. how many times a process executes before being removed from the queue:

  • fixed maximum for each queue i.e. - one as in the simple FB algorithm given above
  • execute n times for each level n
  • for level n, execute 2**n times
    3. use a time slice among the queues i.e. 50% for level 0; 30% for level 1; and 20% for level 2
  • the simple FB algorithm given above allows starvation because processes with long bursts get no processor time for as long as those with short bursts are present



    Scheduling Handouts
  • Blank forms for scheduling trace in PDF format
  • Trace of scheduling algorithms in PDF format



    Example 1: Solaris (hercules)



    Example 2: Windows XP Scheduling



    Example 3: Linux 2.5 Scheduling