New Optimized Priority CPU Scheduling Algorithm by Using Knapsack (NOPSACK)

Page 1

GRD Journals- Global Research and Development Journal for Engineering | Volume 5 | Issue 6 | May 2020 ISSN- 2455-5703

New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) Abdulrafa Hoseen Maree Department of Computer Science and Engineering Northern Technical University, Iraq

Najim Abdullah Tahhan Department of Computer Science and Engineering Northern Technical University, Iraq

Maher Talal Alasaady Department of Computer Science and Engineering Northern Technical University, Iraq

Abstract The concept of processes scheduling has had a major role since the advent of operating scheduling policies, the CPU plays a significant role in the computer system by transferring control between different processes and must work efficiently, the operating system performs a basic task, which is scheduling the processor for its efficient and optimized use. Scheduling the processor is one of the most important operational implemented through the operating system. Different algorithms for processor scheduling exist including the scheduling algorithm of priority. The priority number makes the algorithm effective. In this research, a proposed algorithm for scheduling the processor between processes was adopted using the KNAPSACK algorithm in order to eliminate the waiting state and starvation situation that occurs for low priority processes. Keywords- CPU Scheduling, Priority CPU Scheduling, Turnaround Time, Waiting Time, Context Switching, Gantt Chart, Knapsack Algorithm, Starvation

I. INTRODUCTION The operating system manages the hardware and software resources of the computer and execute different tasks. The processor scheduling is considered a basic task. All resources are scheduled before use, that is to give them to processes as needed and at new state in the life cycle of the process[3]. In the computer system, scheduling is the basic function of the operating system, a process is selected from ready queue for implementation and by a short-term scheduler (STS)[9]. These algorithms are designed to schedule processes in CPU, each one better than the others in some performance measures and each has its advantages and disadvantages[10]. The proposed algorithm (NOPSACK) is a priority algorithm using a KNAPSACK algorithm by obtaining optimal results for any given problem[10], in order for the proposed algorithm to be more specific, relying on continuous or fractional knapsack algorithm by dividing process execution time and using the ratio between values(v) and weights(w), v/w[10].

II. SCHEDULING CRITERIA CPU scheduling algorithm have different features and characteristics, and the decision is made to choose the process for execution and depending on different measures, these measures are used to compare different algorithms [1][3][6][7][9][11][12][13]. The scheduler is concerned with [2][3][6][7][11] [12]: A. CPU Utilization Exploit all CPU time optimally in process executing, so cpu remains as busy as possible for being precious time. B. Throughput Number of processes completed within a specified period of time. C. Turnaround Time (TAT) – Refers to the total time it takes to execute a particular process from the moment it enters the system into the moment the execution ends[1][3][6][7][9][12][13], interspersed with time periods thereof[6]: – Wait before entering the memory. – Time in ready queue. – Time to execute the input and output operations. It can be calculated as [9][11] : TAT=Process completed time – Process arrival time.

All rights reserved by www.grdjournals.com

24


New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) (GRDJE/ Volume 5 / Issue 6 / 005)

D. Waiting Time (WT) The total time of the process in the ready queue, it can be calculated as [9][11] : WT=TAT– CPU execution time. 1) Response time The time from taken the moment the process enters until the system makes the first response[12] . 2) Context Switch Switch the CPU from one process to another. Performing fewer contexts switching for algorithms increase the system performance[4]. So we conclude that a good scheduling algorithm must have following characteristics[6][9][11]: – CPU utilization ( Max.). – Throughput ( Max.). – Turnaround time ( Min.). – Waiting time ( Min.). – Response time ( Min.). – Context switches ( Min.).

III. SCHEDULING TYPES Scheduling algorithms can be broadly categorized into [3][9][12][14][15]: A. Preemptive Scheduling The operating system remove the CPU for a specific reason from the process in progress, such as the arrival of a new process at higher priority or shortest execution time, depending on the type of algorithm used[3][9][12][14]. B. Nonpreemptive Scheduling The operating system does not remove the CPU from the process in progress and leaves it to the end of the time allocated for execution, although a new process arrives at a higher priority or a shortest time process, and the CPU is automatically returned to the system after the execution.

IV. SCHEDULERS TYPES There are three types of schedulers [1][8][9] [10][12], they are: A. Long- Term Scheduler (LTS) It is named a JOB scheduler and is performed when new jobs are created. It is responsible for selecting jobs from the jobs pool and loading them into main memory. It controls the number of processes in the main memory and is called a (degree of multiprogramming) as in figure(1) [1], LTS executes much less frequently. B. Short- Term Scheduler (STS) It is named a CPU scheduler, selects the process from among these processes in ready queue in memory, which are ready to execute. As in figure (1), the STS must be very fast[1].

Fig. 1: Scheduler and Queuing Diagram

C. Medium- Term Scheduler (MTS) Remove processes temporarily from the main memory and puts them in the secondary memory and vice versa[12].

V. KNAPSACK PROBLEM Problem occurs in combinatorial optimization, where there are a number of elements(n), for each of weight(w) and value(v) is required to determine the number contained in the group of each element so that the total weight is less than or equal to the required limit of the bag's capacity and the total value is as large as possible[5].

All rights reserved by www.grdjournals.com

25


New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) (GRDJE/ Volume 5 / Issue 6 / 005)

VI. KNAPSACK PROBLEM TYPES A. Continuous Knapsack Problem Elements are divisible; you can take any fraction of an element, also called Fractional knapsack, is a classic problem that can be solved by greedy algorithms[5]. B. 0-1 Knapsack Problem Elements are indivisible; you either take an element or not. Some special instances can be solved with dynamic programming[5].

VII.

GREEDY ALGORITHM

There are more than one method:1) Max value(v). 2) Min weight(w). 3) Ratio (v/w). Compute the ratio between the values and weights and then arrange them in descending order, fill the bag with the values and weights corresponding to the largest percentage, and repeat it on condition that the total weights do not exceed the capacity of the bag [5].

VIII. RELATED WORK DONE In Neel sack algorithm[10] the idea of a knapsack problem is related to the concept of process scheduling. The knapsack weight was considered as the CPU capacity, knapsack elements were considered to be processes and the element weight was considered to be execution time, and also the element value was considered the priority given to process. The main subject of using the similarity is that knapsack is designed to determine the best element for the thief to get the greatest profit, as well as the case of CPU scheduling is the choice of the best process for the CPU by considering its priority.

IX. PROPOSED ALGORITHM (NOPSACK)

Fig. 2: The Flowchart Steps for (NOPSACK) Algorithm

All rights reserved by www.grdjournals.com

26


New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) (GRDJE/ Volume 5 / Issue 6 / 005)

The algorithm needs Parameters such as number of processes in queue, CPU execution time(Et) in addition to priority (Pri) for each process. The CPU capacity(ß) can computed by dividing the sum of the execution time of all processes by the number of processes(n) in the current iteration, ratio of process priority respective CPU execution time(v/w).

X. RULES AND ALGORITHM 1) No. of processes(n). 2) CPU execution time(Et). 3) Process priority(Pri). Each process should get the processor. Steps: 1) Input No. of processes(n). 2) Respectively for each process, input CPU execution time(Et), Priority(Pri) . 3) Compute ratio (Pri/Et) for each process. 4) Processes are arranged in descending order depending on the ratio value. 5) Compute initial (ß) value (sum of execution time of all the processes(ɑ)/No. of processes(n) in the system). 6) Apply the knapsack algorithm by entering input parameters: – (n) No. of processes represent the knapsack elements. – (Et) CPU execution time represent the elements weight. – (Pri) Process priority represent the element cost. 7) Invert processes priority that got the processor in the current iteration, ( (Pri) value * (-1)) and cancel the processes were completed. 8) Go-to step 5 (continue until all processes got CPU and completed execution). 9) Display and print result for each process. The vital reason of the above steps to avoiding starvation of least priority processes unlike priority based scheduling[10].

XI. RESULT Measurement parameters such as (TAT), (T) are considered, in different cases measured and compared with current scheduling algorithms such as priority based and RR alg. . In order to verify the quality and efficiency of the algorithm, some of cases have been shown, result of each iterations was analyzed and the last output was compared using the priority based and RR algorithm. Case study: Sample 1: random cpu execution time with random priority Table 1[10], Five processes which have different cpu execution time with different priority. Table 1: Input for sample 1

Initially calculation of ratio for each process, and arranged in descending order depending on ratio value. Ratio=Priority(Pri)/CPU execution time(Et)[5]. =Value(v)/Weight(w) …………….. Equ.(1) Capacity of Knapsack:

Where ɑ=∑n−1 i=0 Et Iteration 1:

By applying knapsack algorithm using Equ.(2), Ƥ2,Ƥ3 were selected with the capacity ( 5 ) . Then priority of Ƥ2 and Ƥ3 has been canceled shown below in the table 1(b) and so on with other iterations successively.

All rights reserved by www.grdjournals.com

27


New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) (GRDJE/ Volume 5 / Issue 6 / 005)

Table 1(a): for sample 1 with ratio value

Processes P3 P2 P1 P4 P0

Cpu execution time (w) 2 3 2 6 12

Priority (v)

Ratio (v/w)

4 3 1 2 3

2 1 0.5 0.3 0.25

Our major idea is to approximate the computed ß value to the nearest smallest integer number, this approximate is done in order for the value of capacity to be identical to the value of execution time without fractions. Iteration 2: ß=(2+6+12)/3=20/3=6.666=6 Iteration 3: ß=(2+12)/2=14/2=7

Iteration 4: ß=(2+5)/2=7/2=3.5=3 Iteration 5: ß=(5)/1=5

Table 2: (c) Comparison of context switch for sample 1 Neelsack alg. NOPSACK 6 6

Sample 2: randomly cpu execution time with equal priority The work is similar to that in sample 1, table 3 [10], we have four processes, input has random cpu execution time but equal priorities.

All rights reserved by www.grdjournals.com

28


New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) (GRDJE/ Volume 5 / Issue 6 / 005)

Fig. 3: sample (2) Gantt chart

Initially as sample 1 we compute ratio for each process and arranged in descending order depending on ratio value.

The computation is for capacity of knapsack Iteration 1: ɑ=(11+18+4+13)=46 ß=46/4=11.5=11 Iteration 2: ɑ=(4+13+18)=35 ß=35/3=11.6=11

Iteration 3: ɑ=(4+2+18)=24 ß=24/3=8 Iteration 4: ɑ=(2+14)=16 ß=16/2=8

All rights reserved by www.grdjournals.com

29


New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) (GRDJE/ Volume 5 / Issue 6 / 005)

Iteration 5: ɑ=14 ß=14/1=14

Fig. 4: sample (2) Gantt chart

Table 4: (c) Comparison of context switch for sample 2 Neelsack alg. NOPSACK 7 6

XII.

RESULT AND COMPARISON

Fig. 5: Result for sample 1

Fig. 6: Result for sample 2

All rights reserved by www.grdjournals.com

30


New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK) (GRDJE/ Volume 5 / Issue 6 / 005)

As in the result for sample 1 as shown in the above Figure(5), the result of (TAT) and (WT) of NOPSACK is better than Neelsack algorithm and other two algorithms ( RR , priority based ) . so this can describe that the NOPSACK algorithm can be implemented. The result for sample 2 as shown in the above Figure(6), (TAT) of NOPSACK is same as Neelsack algorithm but (WT) and context switches is less than Neelsack algorithm , also better than other two algorithms ( RR , priority based ) .

XIII. CONCLUSION Algorithm NOPSACK it is better than few other algorithms, on the whole it is better than the RR alg. and priority based, but in some cases they works best. Any algorithm is not the best in all situations. It is not possible to observe any scheduling algorithm that works accurately, but accurate performance can be observed in live operating system operation. There are several factors that have a significant impact on performance such as variable capacity selection and priority iversion and operators can be selected on hardware configuration and process delivery mechanism used.

REFERENCES [1] [2] [3] [4] [5] [6] [7] [8]

[9] [10] [11]

[12] [13] [14] [15]

Ahmed M. Al-Safar (2012), "Hybrid CPU Scheduling algorithm SJF-RR in Static Set of Process", Al-Rafidain University College for Sciences , Issue:29, Issn:16816870 , pp. 36-60. Amar R. Dash, Sandipta K. Sahu and Sanjay K. Samantra (February 2015),"An Optimized Round Robin CPU Scheduling Algorithm with Dynamic Time Quantum", (IJCSEIT) International Journal of Computer Science Engineering and Information Technology, Vol. 5, No. 1, DOI:10.5121/ijcseit.2015.5102. Amit Kumar Sain (2013), “Dynamical Modified R.R. CPU Scheduling Algorithm", International Journal of Computer Trend and Technology, Volume 4, Issue 2, PP. 90-93, ISSN:2231-2803. Muhammad A. , Bushra Hamid , Inayat Ur-Rehman , Mamoon H. , Maryam H. and Hira Khurshid (December 2015), " An Optimized Shortest job first Scheduling Algorithm for CPU Scheduling", Journal of Applied Environmental and Biological Science, pp. 42-46 , ISSN:2090-4274, 5(12)42-46, Pakistan. E. M. Badr (2016), "Knapsack Problem", Information and Computer College, Banha University. Ishwari Singh and Deepa Gupta (Oct 2012)," A Priority based Round Robin CPU Scheduling Algorithm for Real Time System", (IJIET) International Journal of Innovations in Engineering and Technology, Vol. 1, Issue 3, ISSN:2319-1058, India. Lipika Datta (June 2015), "Efficient Round Robin Scheduling Algorithm with Dynamic Time Slice", (IJEME) I.J.Education and Management Engineering, pp. 10-19, DOI:10.5815/ijeme.2015.02.02 . N.Srilatha, SK.Mastanimurtazanaz and B.Ganga Bhavani (January 2018), "An Optimized Round Robin With Dynamic And Static Quanyum(ORDS)", (ijpam) International Journal of Pure and Applied Mathematics, Volume 118, No. 16,pp. 243-252, ISSN:1311-8080(printed version);ISSN:1314-3395(on-line version). Najim A. Al-Tahhan (April 2014),"Hybrid Algorithm for CPU Scheduling by Using Dynamic Time Quantum", Future Research Journal, Al-Hadba university Collage, PP. 99-136, ISSN 1680-9300. Iraq . Neelakantagouda Patil (October 2015)," A Knapsack Based CPU Process Scheduling Using Neelsack Algorithm", (IJSEAS) International Journal of Scientific Engineering and Applied Science,Volume-1, pp. 138-144, Issue-7, ISSN:2395-3470, India. Rashid Al Asif, Mehedi Raihan, Zakaria Hossain, Alam Hossain and Abdul Momin (December 2017), " Improved Performance of Round Robin CPU Scheduling Algorithm Using Non-Preemptive SJF",(IJSER) International Journal of Scientific & Engineering Research, Volume 8, pp. 1,734-1,738, Issue 12, ISSN 2229-5518. Ryan R. Guadana, Maria R. Perez and Larry R. Jr.(January 2013), " A Comprehensive Review for Central Processing Unit Scheduling Algorithm" (IJCSI) International Journal of Computer Science Issues, Vol 10, PP. 353-358, Issue 1, No 2, ISSN (Print):1694-0784; ISSN (Online):1694-0814. Siddharth Tyagi, Sudheer Choudhary and Akshant Poonia (October 2012), “Enhanced Priority Scheduling Algorithm to minimize Process Starvation", (IJETAE) International Journal of Emerging Technology And Advanced Engineering", Volume 2, PP.288-294, Issue 10, ISSN 2250-2459, India. Sonia Z., Lotfi B. and Abdellatif Mtibaa (December 2016), "CPU Scheduling Algorithms: Case & Comparative Study", https://www.researchgate.net/publication/317723403. Taqwa Flayyih Hasan (March 2014), "CPU SCHEDULING VISUALIZATION", Diyala Journal of Engineering Sciences, Vol. 07, No. 01, PP.16-29, ISSN 1999-8716, Iraq .

All rights reserved by www.grdjournals.com

31


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.