Improving Waiting Time of Tasks Scheduled Under Preemptive Round Robin Using Changeable Time Quantum
IImproving Waiting Time of Tasks Scheduled Under Preemptive Round Robin Using Changeable Time Quantum
Saad Zagloul Rida * Safwat Helmy Hamad ** Samih Mohemmed Mostafa *** *
Faculty of Science, Mathematics Department, South Valley University, Egypt, Quena. ** Faculty of Computer and Information Sciences, Ain Shams University, Egypt, Cairo. ***
Faculty of Science, Computer Science Department, South Valley University, Egypt, Quena.
ABSTRACT
Minimizing waiting time for tasks waiting in the queue for execution is one of the important scheduling cri-teria which took a wide area in scheduling preemptive tasks. In this paper we present Changeable Time Quan-tum (CTQ) approach combined with the round-robin algorithm, we try to adjust the time quantum according to the burst times of the tasks in the ready queue. There are two important benefits of using (CTQ) approach: minimizing the average waiting time of the tasks, consequently minimizing the average turnaround time, and keeping the number of context switches as low as possible, consequently minimizing the scheduling overhead. In this paper, we consider the scheduling problem for preemptive tasks, where the time costs of these tasks are known a priori. Our experimental results demonstrate that CTQ can provide much lower scheduling overhead and better scheduling criteria.
General Terms:
Algorithm, round-robin, CPU length.
Keywords:
Processor sharing, proportional sharing, residual time, survived tasks, cyclic queue. INTRODUCTION
Modern operating systems (OS) nowadays have become more complex than ever before. They have evolved from a single task, single user architecture to a multitasking environment in which tasks run in a con-current manner. Allocating CPU to a task requires careful attention to assure fairness and avoid task starvation for CPU. Scheduling decision try to minimize the following: average turnaround time, average waiting time for tasks and the number of context switches [3].
Scheduling algorithms are the mechanism by which a resource is allocated to a client. In our research we restrict the concept of a resource to CPU time and clients to tasks. A scheduling decision refers to the concept of selecting the next process for execution. The scheduler runs the first task in the queue for the specified time quantum, which is the maximum time interval the task is allowed to run before another scheduling decision is made. Note that the time quantum is typically expressed in time units of constant size. As a result, we refer to the units of time quanta as time units (tu) in this paper rather than an abso-lute time measure such as seconds. During each scheduling decision, a context switch occurs, meaning that the current process will stop its execution and put back to the ready queue and another process will be dispatched. We define scheduling overhead as the incurred overhead when making a scheduling decision. One of the oldest, simplest and most widely used scheduling algorithms is round-robin. RR algorithms are widely used in modern OSs like Linux, BSD and Windows. All use multi-level feedback queues with priorities and a RR scheduler over each task queue. In addition, RR algorithms have low scheduling overhead of (1), which means schedul-ing the next task takes a constant time [5, 4, 10]. The performance of the RR algorithm depends heavily on the size of the time quantum. At one extreme, if the time quantum is extremely large, the RR policy is the same as the FCFS policy. If the time quantum is extremely small, the RR approach is called processor sharing [3]. In O his paper we try to minimize waiting time, turnaround time and number of the context switches by changing time quantum according to the burst times of the tasks in the queue. Our results show that CTQ scheduler can provide better scheduling criteria than these other schedulers that dealing with fixed time quantum. Further-more, our results show that CTQ achieves this minimization with lower scheduling overhead. This paper presents the design and implementation of CTQ in which we try to minimize the scheduling cri-teria by adjusting the time quantum of the tasks with respect to their burst times. Section 2 discusses back-ground. Section 3 presents the proposed algorithm. Section 4 presents the changeable consideration. Section 5 presents the simulation studies. Finally we present some concluding remarks and directions for future work. BACKGROUND
The round-robin (RR) scheduling algorithm is designed especially for time-sharing systems. As known that the concept of processor sharing introduces a heuristics to prevent long jobs from blocking short jobs in queue. In practice round-robin has to be used. RR is also one of the oldest, simplest and most widely used proportional share scheduling algorithms, and because of its usefulness, many proportional share scheduling mechanisms have been developed [7, 1, 12, 6, 8, 2, 11, 9].
A modified version of RR is the Weighted Round Robin (WRR) in which each task T has a specified weight that specifies its share of the CPU time. If a time quantum is specified to be time units (tu), and we have three tasks A, B, and C having weights , , and , then the time quantum given to each task is proportional to the task weight. An example of one round of WRR will assign, for example, task A % of the time quantum. Similarly task B will receive % of the time quantum and task C will receive % [13]. WRR is the simplest proportional-share scheduling algorithm. Weighted round-robin (WRR) provides proportional sharing by running all clients with the same frequency but adjusting the size of their time quanta. A more recent variant called deficit round-robin [11] has been developed for network packet scheduling with similar behavior to a weighted round-robin CPU scheduler. WRR is simple to implement and schedules clients in (1) time. Burst Round Robin (BRR) [13] is another weighting technique for round-robin CPU scheduler as an attempt to combine the low scheduling overhead of round-robin algorithms and favor short jobs. TQ O THE PROPOSED ALGORITHM
In this section we introduce the equations that determine the time quantum TQ that gives the smallest aver-age waiting time in each round. TQ is confined in the range from 1 to LBT, where LBT is the largest burst time of the tasks. Equation 1: ⎪⎪⎪⎪⎩⎪⎪⎪ ⎪ ⎨ ⎧ = =− = ≠= ⎥⎦⎥⎢⎣⎢ ,...3,2,1 *1 ,...3,2,1 *)( l TQlBTifTQBT l TQlBTifiTNTQ ii ii TQBT where is the burst time of the task , and is the number of times the task exploits the time quantum . In the following example: i BT i T )( i TNTQ i T TQ ASK BURST TIME
T1 24 T2 3 T3 3 if we use a time quantum of time units, then we see from the Gantt Chart: T1 T2 T3 T1 T1 T1 T1 T1 0 4 7 10 14 18 22 26 30 that the is 5, the is , and the is . But the number of context switches of is , the number of context switches of is , and the number of context switches of is . )( TNTQ )( TNTQ )( TNTQ T T T Equation 2: ⎪⎪⎪⎪⎭⎪⎪⎪⎪⎬⎫⎪⎪⎪⎪⎩⎪⎪⎪⎪⎨⎧ >⎪⎪⎭⎪⎪⎬⎫⎪⎪⎩⎪⎪⎨⎧ <>+ >≥ <= ≠<+ =⎭⎬⎫⎩⎨⎧ =>+= ∑∑ ≠=−= n ikk kiki iki ikk ikkiik ikk ki TNTQifikandTNTQTNTQifTQTNTQ ikandTNTQTNTQifTQTNTQ ikandTNTQTNTQifBT ikandTNTQTNTQifBTTQTNTQ TNTQifTNTQifBT TNTQifTQTSLTQ ,111 where is the number of the tasks, and is the starting of the last time quantum of . In the above ex-ample the is , the is , and the is . n )( i TSLTQ i T )( TSLTQ )( TSLTQ )( TSLTQ
Equation : nTWTAVGWT TWTTWT TQTNTQTSLTQTWT ni i iii /)( *)()()( == −= ∑ = where is the waiting time of task , TWT is the total waiting time of all tasks, and is the av-erage waiting time of the tasks in the run queue. )( i TWT i T AVGWT THE CHANGEABLE CONSIDERATION
CTQ combines the benefit of low overhead round-robin scheduling with low average waiting time, this de-pends on the size of the preselected time quantum. The CTQ scheduling algorithm can be briefly described in the following steps: 1.
Order the tasks in the run queue as FIFO manner. . Starting from the beginning of the run queue, run each task for one time quantum in a round-robin man-ner, until the task number n reaches. This is the first round in the cyclic queue. 3.
Calculate the burst times for the survived tasks ( residual times ) in the next round, and implement the equations that determine the candidate time quantum. 4.
Repeat the step 3 till there are no tasks waiting in the run queue. Changing the time quantum in each round in the cyclic queue will give better results in the above criteria. Using the Changeable Time Quantum (CTQ) technique, in each round a different TQ is used. If we have n tasks in a round r and m tasks that have burst times equal to or less than the time quantum used in r , then there are mn − tasks in the next round, where mn ≥ . The residual time of the task in the round number is determined from the equation: i T q ∑ −= −= ][)(_][_Re qkii kTQTTimeBurstTTimesidual where is the time quantum in the round number . In each successive round we implement the equations with respect to the residual times of the survived tasks. To demonstrate the previous consideration, we take the following example: ][ kTQ k Consider the following set of tasks that arrive at time , each of which with the length of the CPU burst time. TASK BURST TIME T1 20 T2 20 T3 5 T4 3 T5 1
If we use the time quantum equal to tu in the round-robin, this gives: THE AVERAGE WAITING TIME = 17
THE AVERAGE TURNAROUND TIME = 26.8
THE TOTAL NUMBER OF CONTEXT SWITCHES IS When we apply the (CTQ) technique: if the time quantum in the first round is equal to ( = ]1[ TQ (ROUND NO. 1) ( = ]1[ TQ T1 T2 T3 T4 T5 0 1 2 3 4 5
The survived tasks are
T1, T2, T3 , and T4 each of which with the length of the CPU burst time: TASK RESIDUAL TIME T1 19 T2 19 T3 4 T4 2 fter implementing the equations, we obtain: TQ = 2
After using equal to , the Gantt Chart is: ]2[ TQ (ROUND NO. 2) ( = ]2[ TQ T1 T2 T3 T4 5 7 9 11 13 from the survived tasks:
TASK RESIDUAL TIME T1 17 T2 17 T3 2 the equations give:
TQ = 2
Again we use equal to , the Gantt Chart is: ]3[ TQ (ROUND NO. 3) ( = ]3[ TQ T1 T2 T3 13 15 17 19 from the survived tasks:
TASK RESIDUAL TIME T1 15 T2 15 in the last round we have = , the Gantt Chart is: ]4[ TQ (ROUND NO. 4) (TQ [4] = 15) T1 T2 19 34 49 THE AVERAGE WAITING TIME = (14 + 29 + 14 + 10 + 4) / 5 = 14.2
THE AVERAGE TURNAROUND TIME = (34 + 49 + 19 + 13 + 5) / 5 = 24
THE TOTAL NUMBER OF CONTEXT SWITCHES IS (3 + 3 + 2 + 1 +0) = 9. . SIMULATION STUDIES
To demonstrate the effectiveness of the CTQ, we built a scheduling simulator that is a user-space program which takes four inputs, the scheduling algorithm, the number of tasks, the burst time of each task, and the first time quantum that will be used in the traditional round-robin, this time quantum will be selected to give the smallest average waiting time in the fixed round-robin. The simulator randomly assigns burst times to tasks. To measure the effectiveness, we ran simulations for the proposed algorithm against fixed round-robin al-gorithm considered on 30 different combinations of and , the burst times of the tasks varying from 1 to 500 tu. For each set of ( , n sBT ' n BT ), we ran different number of tasks with different CPU lengths. Our results show a significant improvement in waiting time, turnaround time, and context switches as shown in figures 1, 2, and 3. We also ran simulations for the proposed algorithm against the BRR [13] algorithm and fixed round-robin considered on 30 different combinations of and , the burst times of the tasks varying from 1 to 100 tu, and the time quantum is 10 tu as proposed in BRR technique. For each set of ( n , n sBT ' BT ), we ran different number of tasks with different CPU lengths. Figures 4, 5, and 6 show the comparative result between CTQ, BRR, and fixed RR. The data produced by our simulations show that CTQ has the smallest average waiting time, average turn-around time, and number of context switches. Figures 1: Average waiting time for Fixed_RR and CTQ.
FIXED_RR CTQ a v e r a g e w a iti ng ti m e no. of tasks
10 20 30 40 50 60 70 80 90 100 110 120 130 140 1500500100015002000250030003500400045005000550060006500
Figures 2: Average turnaround time for Fixed_RR and CTQ.
FIXED_RR CTQ a v e r a g e t u r n a rr ound ti m e no. of tasks Figures 3: Number of context switche for Fixed_RR and CTQ.
FIXED_RR CTQ no . o f c on t e x t s w it c h e s no. of tasks
10 20 30 40 50 60 70 80 90 100 110 120 130 140 15005001000150020002500300035004000450050005500
Figures 4: Average waiting time for Fixed_RR, BRR and CTQ. a v e r a g e w a iti ng ti m e no. of tasks Fixed_RR BRR CTQ Figures 5: Average turnaround time for Fixed_RR, BRR and CTQ.
Fixed_RR BRR CTQ a v e r a g e t u r n a r ound ti m e no. of tasks
10 20 30 40 50 60 70 80 90 100 110 120 130 140 1500100200300400500600700800900100011001200130014001500
Figures 6: Number of context switches for Fixed_RR, BRR and CTQ.
Fixed_RR BRR CTQ no . o f c on t e x t s w it c h e s no. of tasks CONCLUSION AND FUTURE WORK
In this view the round-robin has been studied as a function of the time quantum values. In this paper, we have proposed a new technique for round-robin scheduling algorithm based on process CPU burst time. In each round the algorithm adjusts the time quantum with respect to the residual times of the tasks and gives all possi-ble
TQs , each of which gives the smallest average waiting time. This technique has shown a good improvement over using a fixed time quantum RR . We introduced formulas which could be used to choose an appropriate time quantum value for practical use. As a future work, we would like to apply this technique with all possible round-robin variants. Another future work is to study the influence of selecting a time quantum in a round in the cyclic queue on the successive rounds and determine the relation between the current TQ and the succes-sive TQs . denotes the largest integer smaller than or equal to ⎣ ⎦ x x . REFERENCES A. Demers, S. Keshav, and S. Shenker, “Analysis and Simulation of a Fair Queueing Algorithm,” in Proceedings of ACM SIGCOMM ’89 , Austin, TX, Sept. 1989, pp. 1–12. 2.
A. Parekh and R. Gallager, “A Generalized Processor Sharing Approach to Flow Control in Integrated Services Networks: The Single-Node Case,”
IEEE/ACM Transactions on Networking , 1(3), June 1993, pp. 344–357. 3.
A. Silberschatz, P.B. Galvin, and G. Gagne, “Operating Systems Concepts,”
John Wiley and Sons . 6Ed 2005 . B. Caprita, W.C. Chan, and J. Nieh, “Group Round-Robin: Improving the Fairness and Complexity of Packet Scheduling”,
Technical Report CUCS-018-03, Columbia University , June 2003. B. Caprita, W.C. Chan, J. Nieth, C. Stein, and H. Zheng, “Group ratio round-robin: O(1) proportional share scheduling for uni-processor and multiprocessor systems,”
In USENIX Annual Technical Con-ference , 2005. G. Henry, “The Fair Share Scheduler,”
AT&T Bell Laboratories Technical Journal , 63(8), Oct. 1984, pp. 1845–1857. 7.
J. Bennett and H. Zhang, “WF Q: Worst-case Fair Weighted Fair Queueing,” in Proceedings of INFOCOM ’96 , San Francisco, CA, Mar. 1996. 8.
J. Kay and P. Lauder, “A Fair Share Scheduler,”
Communications of the ACM , 31(1), Jan. 1988, pp. 44–55. 9.
J. Nieh, C. Vaill and, H. Zhong, “Virtual-Time Round-Robin: An O(1) Proportional Share Scheduler,”
In Proceedings of the 2001 USENIX Annual Technical Conference , June 2001. 10.
L. Abeni, G. Lipari, and G. Buttazzo, “Constant bandwidth vs. proportional share resource allocation”,
In Proceedings of the IEEE International Conference on Multimedia Computing and Systems , Florence, Italy, June 1999. 11.
M. Shreedhar and G. Varghese, “Efficient Fair Queueing Using Deficit Round-Robin,” in Proceedings of ACM SIGCOMM ’95 , 4(3), Sept. 1995. PP. 231-242. 12.
R. Essick, “An Event-Based Fair Share Scheduler,” in Proceedings of the Winter 1990 USENIX Confe-rence , USENIX Berkeley, CA, USA, Jan. 1990, pp. 147–162. 13.
T. Helmy and A. Dekdouk, “Burst Round Robin: As A Proportional-Share Scheduling Algorithm,”
In Proceedings of The fourth IEEE-GCC Conference on Towards Techno-Industrial Innovations , pp. 424-428, 11-14 November 2007, at the Gulf International Convention Center, Bahrain ..