Performance Improvement In Operating system

by

SUNDHAR RAM P R VIGNESH A VIGNESHWARASABARINATH S
A project report submitted to the FACULTY OF COMPUTER SCIENCE AND ENGINEERING

20072225 20072235 20072236

in partial fulfillment of the requirements for the award of the degree of

BACHELOR OF ENGINEERING
in

COMPUTER SCIENCE AND ENGINEERING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ANNA UNIVERSITY CHENNAI CHENNAI - 600025 April 2011

CERTIFICATE
Certified that this project report titled “Performance Improvement of Ubuntu” is the bonafide work of SUNDHAR RAM P R (20072225), VIGNESH A (20072235),VIGNESHWARASABRINATH S (20072236) who carried out the project work under my supervision, for the fulfillment of the requirements for the award of the degree of Bachelor of Engineering in Computer Science and Engineering. Certified further that to the best of my knowledge, the work reported herein does not form part of any other thesis or dissertation on the basis of which a degree or an award was conferred on an earlier occasion.

Place: Chennai Date:

Prof. Arul Siromoney Project Guide, Professor, Department of Computer Science and Engineering, Anna University Chennai, Chennai - 600025

COUNTERSIGNED

Head of the Department, Department of Computer Science and Engineering, Anna University Chennai, Chennai – 600025

ACKNOWLEDGEMENTS
We express our deep gratitude to our guide, Prof.Dr.Arul Siromoney for guiding us through every phase of the project. We appreciate his thoroughness, tolerance and ability to share his knowledge with us. We thank him for being easily approachable and quite thoughtful. Apart from adding him own input, he has encouraged us to think on our own and give form to our thoughts. We owe him for harnessing our potential and bringing out the best in us. Without his immense support through every step of the way, we could never have it to this extent. We are extremely grateful to DR.K.S.Easwarakumar, Head of the Department of Computer Science and Engineering, Anna University, Chennai 600025, for extending the facilities of the Department towards our project and for his unstinting support. We express our thanks to the panel of reviewers Prof.Dr.Arul Siromoney, Dr.A.P.Shanthi, Dr.Madhan Karky, and Dr.V.Mary Anita Rajam for their valuable suggestions and critical reviews throughout the course of our project. We thank our parents, family, and friends for bearing with us throughout the course of our project and for the opportunity they provided us in undergoing this course in such a prestigious institution. SUNDHAR RAM P R VIGNESH A VIGNESHWARASABARINATH S

The main areas of the operating system are the scheduler and the memory management unit. Our aim is to improve the performance of the operating system thereby providing faster running of the operating system. This is done by predicting the running time of a particular process in the task run queue based on fuzzy-algorithm that derives the next running time from the previous history bursts. displaying the details of all the processes and the scheduling policies used. We are aimed at improving the scheduling algorithm and the memory management techniques of the operating system. may it be at home. school or work.ABSTRACT Operating systems are a must in all the computers used today. A memory management technique that uses a new data structure for storing the free blocks and it retrieves and frees memory blocks using that structure. A Runtime CPU Scheduler Customization Framework that helps in dynamically changing the scheduling policies of the processes currently running. The performance measures can be done by calculating the booting speed. running a set of standard programs. comparing the pridicted value (in fuzzy algorithm) with the actual running timeslice .

.

. . 3 System Design 3. . . . .2. . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . .4 Problem Definition 1. . . . 2. . . . . . . . . . . . . . . . .2 Non-Functional Requirements . . . . . 2. . . . . . . 1. .1 Problem Domain . . . . . . . . . . . . . . . . .3 Fuzzy based Scheduling algorithm: . . . . . . . . .2. 2. .3 Constraints and Assumptions . . . . . . 2. . . . . . . . . . . . 2. . . . . . . . . . . .1 System Architecture . .3 Performance Characteristics . . . . . . . . . . . .3. . . . . 2. . . . . . . . . . . . . .2 Hardware Considerations . .2. . . . . . . . . . . . . . . . . . . . . . . . . . 2 Requirements Analysis 2. . . . . . . . . . . . . .3. . . . . . . . . . . 2. .1 Memory Module . . . . . . . .3 Literature Review . . . . . . . . . . 2. . . . . .4. . . . 2. . . . . . . . 2. . . .2. . . . . .4. . . . . . 2. .2 Domain Model and System Sequence diagrams . i ii iv v viii 1 1 2 2 3 3 5 5 6 6 6 6 6 7 7 7 8 8 9 10 10 . . . . . . . . .1 User Interface . . . . .2 Scope of the Project 1. . . . v . . . . .4 System Models . . . . . . .Contents Certificate Acknowledgements Abstract(English) Abstract(Tamil) List of Figures 1 Introduction 1. .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Contributions .1 Scenarios and Use Case Model . . . .1 Functional Requirements . . . 1. . . . .2 RCSC Framework . . . . . . . . . .

.2. . . . . . . . . . . . . . . . 3. . . . . . .3 Complexity analysis . . 3. . . . . . . . . 11 11 12 12 12 14 16 16 17 17 19 19 21 24 24 25 4 System Development 4. . . . . . . . . Conclusion 6. . . . . . . . . .1 Results . . . . . . . . 3. . . . . . . . . . . . . . . . . . . . . . . . . .2 Future work and extensions . . .2 Test Report and Analysis . . Results and Discussions 5.1 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . .2. 4. . . . . . . . . . . . . .2. .2. . . . .2 Memory Management 3. . 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . .3 Performance Studies . . . . . 6.2. 5 6 A Original Source Code and documentation B Snapshots C Test cases D MISCELLANEOUS 26 50 54 56 References 57 vi . . .1 Algorithms and Explanation . . . . . . . . . . . . . .2 Module Descriptions . . . . . . .1 Overall conclusion . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . . . . .2 Modules . . . . .3. . . . . . . . . . . .2 Problems And Issues . . . . . . . . . 4. . . . . .1 Process Scheduling . . . . .

. . . . . . Stream Program Comparison 2. . . . . Nqueens program comparison. . .2 3. .1 3. . . . . . .4 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 5. System Sequence diagram . . Stream Program Comparison 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . exceed . . . . . . . . . . . . . . . . .3 RCSC framework snapshot . . . . . . . . . . . . . . . . .1 5. . . . . . . . . . . . Sample pi Comparison. . . . . Running the Benchmark program. . .4 make modulesinstall while building the kernel . . . . .List of Figures 2. System Architecture . . . Running the Benchmark program2.3 5. . . vii . . . . . . .2 5. . . .4 5. . . . . . . . . . . . . . . . . . Sudoku Program Comparison. B. . . .2 3. . . . B. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B. . . . . . . . . .3 3. . .1 2. . . . . . . . . . . . .1 Grub listing the modified kernel. . . . .2 Print messages being printed as and when processes predicted runtime . . . . . . . . . . . . . . .7 5. . . . . . . . . . . . . . . . . . Byte Program Comparison 2. . . .9 Use case Diagram . . . . . . . . .5 4. . . . . . . . . . . . . . . . . Runtime CPU Scheduler Customization Framework . . . . . . . . . . . . . . . . . . . . . . . . . . Byte Program Comparison 1. . . . . . . . . . . . . .8 5.1 5. . . . . Runtime CPU Scheduler Customization Framework-DFD0 Runtime CPU Scheduler Customization Framework-DFD1 Proposed Datastructure . . . . . . . . . . . . B. . . . . . . . . . 8 9 10 12 13 14 15 17 19 20 20 21 21 22 22 23 23 50 51 52 53 System Configuration . .6 5. . . . . . . . . . . . . . . . . . . .

This project aims at enhancing performance of the Ubuntu operating system. thereby reducing the performance of the system.C HAPTER 1 I NTRODUCTION In general. In real time working environment changes dynamically. 1. Since the scope of the operating system is varied the performance measures are also widely varied and are subject to constant changes. Each scheduling policy suits well for a particular working environment. a change in working environment leads to performance degradation. 1 . In Ubuntu operating system. performance of the operating system is mainly affected by the scheduling policy adopted by the CPU-scheduler and memory management technique. CPU-scheduler uses any one of the scheduling policies to schedule the processes in the system irrespective of the working environment.It is used in many places like in servers that take millions of requests from internet users. in embedded systems and in many more such areas.The scheduling module in particular is subject to constant changes as there is no fixed algorithm that provides best results in all environments.1 Problem Domain The domain of our project is Operating System. Operating systems is a platform to run user applications . by normal personal computers that are used by millions of people around the world. in super computers.

Linux Kernel Developer.reliable and highly. 2009.2 Scope of the Project We will improve the performance of the operating system to provide enhanced service to the product users. [2] Nasr addinAl-maweriA.We will develop a memory management technique for quick. UPM Serdang. 2009 International Association of Computer Science and Information Technology . 1. cent os can benefit from this change. redhat. KhairulmizamSamsudinB. and FakhrulZamaniRokhaniC Runtime CPU Scheduler Customization Framework for a flexible mobile operating system Proceedings of 2009 Student Conference on Research and Development (SCOReD2009). as any user with a desktop and a Linux kernel driven operating system can experience the outcome of our project. Mentor.16-18 ov.The project improves the performance of Linux kernel.3 Literature Review [1] AbdolghaderPouraliand Amir MasoudRahmaniA Fuzzy-based Scheduling Algorithm for prediction of next CPU-burst time to implement Shortest Process Next.Spring Conference.efficient processing. Any operating system using Linux core like ubuntu. Malaysia [3] Randy Dunlap.2 1.We develop an operating system that could dynamically change the scheduling policy to improve the performance. Thus the scope of the project is immense. and JanitorLinux Kernel .

efficient processing. • A scheduling algorithm that predicts the next time slice of all runnable processes thereby reducing context switches 1.4 Problem Definition Performance of the Ubuntu operating system is affected by the static CPU scheduler and memory management technique. .5 Contributions We develop a CPU Scheduling algorithm based on fuzzy logic. This project aims to develop • an operating system that could dynamically change the scheduling policy to improve the performance • a memory management technique for quick. 2005 [4] Robert Love Linux Kernel Development. Fuzzy if-then rule is a phrase that some words were marked by membership functions.reliable and highly. IEEE NorthconMay 19. The objective is to provide enhanced service to the product users. Addison-Wesley 1.The heart of this system is a database which was formed with if-then rules. 3rdedition.3 Development: Getting Started. A fuzzy system is a knowledge-based rule system .

4 Resource Scheduler framework that helps in dynamically switching between scheduling policies for each process and view all the available processes and the scheduling policies. .

C HAPTER 2 R EQUIREMENTS A NALYSIS 2. • Functions for allocating and de-allocating memory using the new data structure. • A search table populating module that populates the search table using the patterns based on a logic. RUNTIME CPU SCHEDULING FRAMEWORK • a module to list the processes . Memory Management • Definition of the new data structure proposed for the list of free blocks. • A inference module which predicts the next cpu burst based on the search table values. • a module to inflict the change and display the result. 5 .1 Functional Requirements NEW SCHEDULING POLICY • A pattern generating module that generates patterns based on the history of CPU bursts. scheduling policies available.

This is an indirect measure of the memory management efficiency.2. 2.3.1 Performance Characteristics Memory Module Booting time.2 GB ram and 80 GB hard disk space.1 Non-Functional Requirements User Interface The operating system is the user interface.2.any linux kernel driven operating system could serve the purpose. keeping them constant (as that part of the code is left unchanged) the booting time will be a measure of the memory management techniques efficiency.2.2 2.2.6 2.3 2. 2. For implementing the runtime cpu scheduling framework a window based user interface design with dropdown list boxes for displaying the scheduling policies and processes is used. During booting period many memory blocks get allocated. Amount of time spent in the memory .For good performance we suggest a desktop with alteast intel Pentium 4 processor.2 Hardware Considerations Any simple desktop configuration that is fit enough to run Ubuntu operating system would suffice. Although booting time involves scheduling and processing elements too.

2. Efficiency in selecting the correct scheduling policy for a given working environment. 2.7 management code: This is a direct measure.2 RCSC Framework Number of scheduling policies available for swapping. This can be achieved by using printk() and checking the time the messages appear in the log. 2. 2. Time taken for the switch.3. .2. Or one must possess the knowledge to add the patch to the existing kernel.3 Constraints and Assumptions One must have access to changed kernel code and should have the knowledge to make and create the boot image and to update the grub. Difference between the predicted CPU burst of a process and the actual CPU burst.3 Fuzzy based Scheduling algorithm: Turnaround time of the process.3.

1 System Models Scenarios and Use Case Model F IGURE 2.4 2.8 2.1: Use case Diagram .4.

2 Domain Model and System Sequence diagrams F IGURE 2.4.9 2.2: System Sequence diagram .

1 System Architecture F IGURE 3.1: System Architecture 10 .C HAPTER 3 S YSTEM D ESIGN 3.

3.A set of patterns are generated.11 3. Runtime CPU Scheduler Customization Framework Modules Display policies this modules displays the list of policies and processes available for the user to choose and change. 1. Two triangular and two trapezoidal membership functions are used in this case.2. Modules. .pattern extraction-It uses the history of cpu bursts to generate the pattern. Effect change this modules changes the scheduling policy and intimates the user of the same.inference In this module we use the search table to come up with the membership function to which the output belongs to and then use that membership function to compute the cpu burst.2 3. 2.search table population-Search table population is based on membership functions.1 Module Descriptions Algorithms and Explanation Scheduling algorithm It is a fuzzy based scheduling algorithm that uses if then rules.

Switch scheduling policies in run-time 3. The Run-time Scheduler Customization Framework helps in switching between the policies while the os is still running. Change scheduling classes 4.2.2.2 3.12 3. But only one policy is used in a scheduler. for example FIFO. Round Robin and SJF. When a scheduler needs to use another policy. 1.2.2. Change policy 3.1 Modules Process Scheduling Runtime Scheduler Customization Framework F IGURE 3. Retrieve policies 2.2. the kernel needs to be restarted in order to account for it.2: Runtime CPU Scheduler Customization Framework CPU scheduler relies on a particular scheduling algorithm (policy).2 Memory Management Our new memory management scheme involves the implementation of a new data structure that is used for storing the free memory blocks that will be allocated to .

13 F IGURE 3. The buddy algorithm is used to split a large block into smaller blocks in order to provide memory for programs needing smaller memory and also joins smaller blocks to for bigger block if we run out of bigger blocks. . Implement a data structure The new data structure implemented looks like this. Allocation and De-allocation of free blocks The free blocks must be allocated and de-allocated from this new data structure of free blocks and this is done by using the buddy algorithm.3: Runtime CPU Scheduler Customization Framework-DFD0 the programs running over the operating system when asked for.

4: Runtime CPU Scheduler Customization Framework-DFD1 3.3 Complexity analysis Our algorithm is performed for every few microseconds during which the context switch takes place. Any fault in the algorithm could cause the kernel to crash leading to fatal errors. .14 F IGURE 3.2. So it is of atmost importance that it is optimised to the best possible level.

5: Proposed Datastructure .15 F IGURE 3.

16 .we have obtained 2 decimal place accuracy this way.the user interface for the runtime cpu scheduler framework is coded using gtk.1 Implementation Details The kernel is coded in c .so we have altered our fuzzy algorithm and made it take values ranging from 0-100 instead of the usual 0-1. The kernel does not support float datatype. hence the changes that we make are coded in C.C HAPTER 4 S YSTEM D EVELOPMENT 4.

This software is designed to effectively carry out both qualitative and quantitative benchmarks in a clean.3 Performance Studies Testing of the new kernel developed by modifications in the scheduler and the memory modules is done by using a tool called Phoronix Test Suite (http://www.1: System Configuration The details of the tests are as follows.phoronix-test-suite.com). 4. F IGURE 4. reproducible. The Phoronix Test Suite is the most comprehensive testing and benchmarking platform available for the Linux operating system.17 4. and easy-to-use .2 Test Report and Analysis Testing was performed in the machine with the following configuration.

once on specifying a program. runs the program in the computer and gives us the results of the run. The Phoronix Test Suite provides with a set of standard benchmarking programs that can be used for testing the computer. The Phoronix Test Suite is used to test both the old and the new kernels and the results are specified in the following sections. The Phoronix Test Suite consists of a lightweight processing core (pts-core) with each benchmark consisting of an XML-based profile with related resource scripts.18 manner. . The Phoronix Test Suite.

C HAPTER 5 R ESULTS AND D ISCUSSIONS 5.1: Running the Benchmark program. For the purpose of testing it performance we have used The Phoronix Test Suite and the results of usage are displayed below.Sample pi Program F IGURE 5. First Sample Test Run .1 Results The new modified kernel boots with our new scheduling algorithm and memory modules added to it. 19 .

.3: Running the Benchmark program2.2: Sample pi Comparison. Second Sample Test Run .20 F IGURE 5.Byte Program F IGURE 5.

21 F IGURE 5.4: Byte Program Comparison 1. 5.2 Problems And Issues The kernel wont boot if the algorithm that one coded is faulty. F IGURE 5.5: Byte Program Comparison 2. .it takes an hour and sometimes even 3 hrs for the kernel to make.Hence one has to wait for that time to see if the algorithm has actually worked.

.7: Sudoku Program Comparison.6: Nqueens program comparison.22 F IGURE 5. F IGURE 5.

8: Stream Program Comparison 1. .23 F IGURE 5. F IGURE 5.9: Stream Program Comparison 2.

Based on the study on the recent Linux kernel version 2.1 Overall conclusion RCSC A new runtime CPU scheduler customization framework is proposed due to the limitation of Linux CPU scheduler implementation.6. RCSC has been successfully implemented and currently is being evaluated and enhanced. 24 . RCSC architecture provides pluggable scheduling policies and important feature for kernel developers and normal users to evaluate and customize the mobile operating system to suit the workload. the current Linux CPU scheduler has adapted as the core for RCSC architecture. running a SPN scheduling algorithm or the other algorithms which need to know the next CPU-burst time of processes in a real computer system will come true. The main advantage of the proposed algorithm is to forecast the execution time of a process (next CPU-burst time) based on past history. Fuzzy based scheduling algo By using of intelligent systems such as fuzzy systems. it is possible to estimate a lot of time series including the CPU-burst time series with desirable accuracy.25. Therefore.C HAPTER 6 C ONCLUSION 6. High flexibility and desirable speed in calculation are some advantages of fuzzy systems used in such time series prediction. applications and environment. The RCSC architecture has been designed modularly with aim of reducing the complexity of the implementation.

• Develop better scheduling policies. • Develop a scheduling policy that works good for real time systems. .25 6.2 Future work and extensions • Develop a new memory management technique. • Develop a runtime scheduler which could switch scheduling policies automatically based on the change in the working environment.

j++) { if(i==-1) i=SVSHCNT-1. for(j=0. sum=0.int front.j<SVSHCNT.unsigned long temp[SVSHCNT]) // since we used circular queue we this fn to make temp hold the cpu bursts in their order of arrival { unsigned long sum. sum+=hist[i].A PPENDIX A O RIGINAL S OURCE C ODE AND DOCUMENTATION Modifications in Scheduling files /* * We calculate the wall-time slice from the period by taking a part * proportional to the weight. * * s = p*P[w/rw] */ unsigned long reform(unsigned long hist[]. int j. temp[j]=hist[i]. 20 21 i=(i-1). int i=front-1. 26 .

//this function returns the predicted cpu burst after performing calculations using fuzzy fn call unsigned long temp[SVSHCNT].svsideal.27 } sum/=SVSHCNT. Skip current tasks that * are not in our scheduling class.avg). //return slice. int svsi. */ static inline void __update_curr(struct cfs_rq *cfs_rq. 22 struct task_struct *svsp. struct sched_entity *se) { //u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq). return se->svsir. //slice=se->svsir. unsigned long delta_exec) { unsigned long delta_exec_weighted. avg=reform(task_of(se)->svshist.task_of(se)->svsfront. return(sum). schedstat_set(curr->statistics. unsigned long svsdewpart.temp).exec_max. } /* * Update the current tasks runtime statistics. .//returning average of the cpu bursts stored in history array } static u64 sched_slice(struct cfs_rq *cfs_rq. struct sched_entity *curr. se->svsir=svsfuzzy_slice(task_of(se)->svshist.avg.

val:%ld\t". schedstat_add(cfs_rq.curr->svsir).svsideal. delta_exec_weighted+=svsdewpart.delta exec %ld". if(curr->svsloaddec==1) //to prevent over usage { printk("sched period before changing is :%llu". curr->statistics. for(svsi=0. exec_clock. printk("\npid:%d.svsi<SVSHCNT.curr->vruntime.(task_of(curr)) ->pid. curr->sum_exec_runtime += delta_exec. curr). svsp=task_of(curr).delta_exec).ideal:%ld. svsp->svshist[svsp->svsfront]=delta_exec. //storing the cpu burst svsp->svsfront=(svsp->svsfront+1)%SVSHCNT. } else if (curr->svsloaddec==0) { } 23 else { . svsideal=200000. svsdewpart=delta_exec_weighted/15. } curr->svsloaddec=0.svsi++) { printk("svshistory i:%d. delta_exec_weighted = calc_delta_fair(delta_exec. printk("svsloaddec=1").28 max((u64)delta_exec.svsi.vruntime:%llu. delta_exec).exec_max)). curr->svsir=__sched_period(cfs_rq->nr_running + !curr->on_rq).svsp->svshist[svsi]).

curr->prev_sum_exec_runtime.. ideal_runtime = sched_slice(cfs_rq. delta_exec = curr->sum_exec_runtime ............. //predicted cpu burst..29 curr->svsloaddec=0.. printk("cheackpreempttick-.... //ideal runtime is the predicted cpu burst..setting svsloaddec to 1").............assign it to default 0 } curr->vruntime += delta_exec_weighted.. update_min_vruntime(cfs_rq)..... printk("cpt-.. if (delta_exec > ideal_runtime) { curr->svsloaddec=1. .........ideal runtime:%ld.pid:%d". } .. curr). } /* * Preempt the current task with a newly woken task if needed: */ static void check_preempt_tick(struct cfs_rq *cfs_rq...(task_of(curr)) ->pid). delta_exec..... } 24 struct sched_entity { . //loaddec unassigned....ideal_runtime.. struct sched_entity *curr) { unsigned long ideal_runtime..... .... u64 svsir...... return. .....

............ ..svsi++) { p->svshist[svsi]=0......... } Runtime CPU Scheduler Customization Framework 25 #include<stdio..h> /* Converting integer to character array */ void con(int k....... p->svsfront =0....... -------------------------------------------------------------------------- ....svsi<SVSHCNT.h> #include<sched........ } . ..char *m) { m[9]=(k%10)+48..........svsir =220000............ static void __sched_fork(struct task_struct *p) { int svsi........... p->se........... //assigning created variables during fork call... ............ }... for(svsi=0..... //the time when loaddec was set. //to prevent overuse u64 svsloadsettime..30 int svsloaddec... .. . k=k/10.

"w").d. m[6]=(k%10)+48. } /* Converting string to integer */ int pidconvert(char pid[]) { int a.Process Name Scheduler Used\n").31 m[8]=(k%10)+48. a=pid[3]-48.pname[30]. int i. } int main() { 26 char pid[5].k. k=k/10. FILE *pidfile.k++) { con(k.ch1.nice[3]. printf("ProcessID .c. c=(pid[1]-48)*100. k=k/10. FILE *fp. b=(pid[2]-48)*10. return (a+b+c+d).fil[15]="/proc/zzzz/stat".fil). /* Read the details of the processes from the proc file system */ for(k=1300. . /* Open a file for writing all process ids running */ pidfile=fopen("pidfile". m[7]=(k%10)+48.pidint. d=(pid[0]-48)*1000.pppid=1623.b.k<2000.

} while(i<29) {pname[i++]= .} pname[i]=\0.i=0. 27 /* To get the process name */ while((ch1 = fgetc(fp)) != { pname[i++]=ch1.fil). i=0. ) ) . /* Traverse till nice value */ while((ch1 = fgetc(fp))) { if(ch1== ) i++. } i=0."r"). fp=fopen(fil. if(fp) { i=0.32 /* printf("%s". /* To get the process ID */ while((ch1 = fgetc(fp)) != { pid[i++]=ch1. } pid[i++]=\0. if(i==16) break.

default:printf(" %s -. break.SCHED_RR\n".pid.%s -. } /* GTK FILE:-#include<stdio.pname). 28 fprintf(pidfile.pid.%s -.h> #include<sched.pname). break.pid.SCHED_FIFO\n". } } } return 0. /* Print values */ switch(sched_getscheduler(pidint)) { case 0:printf(" %s -.h> ) . break.%s -.33 /* Get the nice value */ while((ch1 = fgetc(fp)) != { nice[i++]=ch1.h> #include<glib. case 1:printf(" %s -.pname).SCHED_FAIR\n".pname).h> #include<gtk/gtk. case 2:printf(" %s -.SCHED_FAIR\n". } nice[i]=\0.%s -.pid)."%s ". /* Get pid to find the scheduling policy */ pidint=pidconvert(pid).pid.

char sched[20]="SCHED_FAIR". char array2[81920]. d=(pid[0]-48)*1000. gpointer view) { char ch1.b. struct sched_param sp. b=(pid[2]-48)*10. c=(pid[1]-48)*100. a=pid[3]-48. gchar *buf1. array1[0] = \0. gchar *buf2.34 /* Converting string to integer */ char pid[4]. FILE *file2. /* Retrieving the selected value */ . return (a+b+c+d). int pidint.d. FILE *file1.c. int pidconvert(char pid[]) { 29 int a. array2[0] = \0. /* Default Scheduling */ char array1[81920]. } /* This function is called when the value of a drop down list changes */ void modeselect(GtkWidget *widget. GtkTextBuffer *buff. char ch2.

SCHED_RR.&sp). } buf1 = g_strdup_printf((gchar *) array1). fclose(file1).pid[1]=text[1].35 30 buff = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)). /* Setting the new scheduler for a particular process */ if(strcmp(text. } /* Setting the new scheduler for a particular process if(strcmp(text.sched_priority = sched_get_priority_max(SCHED_FIFO)."SCHED_FIFO") == 0 && pid[0]==1 ) { sched_setscheduler(pidint.SCHED_FIFO. } pidint=pidconvert(pid). 31 while((ch1 = fgetc(file1)) != EOF) { strcat(array1 . gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget)). } /* Displaying the output of the previous C file the reads the details of all the processes */ file1 = fopen("output".pid[2]=text[2]."r"). ."SCHED_RR") == 0 && pid[0]==1 ) { sched_setscheduler(pidint. if(text[0]==1) /* Checking if a pid is selected { pid[0]=text[0]. -1).&ch1). buf1. sp.pid[3]=text[3]. gtk_text_buffer_set_text(buff.&sp).

. GtkWidget *frame. GtkWidget *combo3. GtkWidget *view.36 } int main( int argc. int i=0. char pid[10]. GtkWidget *combo. frame = gtk_fixed_new(). GtkWidget *label. GtkWidget *combo2. GtkTextBuffer *buffer. gtk_window_set_default_size(GTK_WINDOW(window). 600). frame2 = gtk_fixed_new(). gtk_window_set_title(GTK_WINDOW(window). /* GTK initialization functions */ gtk_init(&argc."r"). GtkWidget *label2. char *argv[]) { GtkWidget *window. 5).ch1. GtkWidget *hbox. GtkWidget *vbox. 32 FILE *fp_pidfile. GtkWidget *frame2. &argv). "Interface"). gtk_container_set_border_width(GTK_CONTAINER(window). window = gtk_window_new(GTK_WINDOW_TOPLEVEL). 650. GTK_WINDOW(window)->allow_shrink = TRUE. fp_pidfile=fopen("pidfile". GtkWidget *vbox1.

while((ch1 = fgetc(fp_pidfile)) != { pid[i++]=ch1. i=0. combo3 = gtk_combo_box_new_text(). "List of PIDs"). vbox1 = gtk_vbox_new(FALSE. "View the list of processes"). } gtk_combo_box_append_text(GTK_COMBO_BOX(combo3). combo2 = gtk_combo_box_new_text(). gtk_combo_box_append_text(GTK_COMBO_BOX(combo2). pid). gtk_combo_box_append_text(GTK_COMBO_BOX(combo). combo = gtk_combo_box_new_text(). /* Adding our drop down list boxes */ gtk_combo_box_append_text(GTK_COMBO_BOX(combo). gtk_widget_set_size_request(view. gtk_text_view_set_editable(GTK_TEXT_VIEW (view). "SCHED_FIFO"). gtk_combo_box_append_text(GTK_COMBO_BOX(combo2). 0). hbox = gtk_hbox_new(FALSE. gtk_combo_box_append_text(GTK_COMBO_BOX(combo3). } pid[i]=\0. /* Adding the list of pids */ 33 while((ch1 = fgetc(fp_pidfile)) != EOF) { pid[i++]=ch1. "SCHED_RR"). FALSE). "View the list of processes"). ) . 0. view = gtk_text_view_new().37 vbox = gtk_vbox_new(FALSE. 0). 300). 0).

/* Calling the modeselect() function when a value is changed */ g_signal_connect_swapped(G_OBJECT(window)."changed". combo. TRUE. TRUE. gtk_fixed_put(GTK_FIXED(frame2). 200. gtk_box_pack_start(GTK_BOX(vbox). gtk_widget_set_size_request(label. G_CALLBACK(modeselect). TRUE. 0). TRUE. gtk_fixed_put(GTK_FIXED(frame2). 200. gtk_fixed_put(GTK_FIXED(frame2)."changed". 70). 120). TRUE. 0). vbox1. 200. g_signal_connect(G_OBJECT (combo3). (gpointer) view). gtk_widget_show_all(window). 500). 10). return 0. 650. (gpointer) view). label2. 20). 0). TRUE. g_signal_connect(G_OBJECT (combo). (gpointer) view). gtk_fixed_put(GTK_FIXED(frame). hbox. label2 = gtk_label_new("View processes \n\n\n PID \n\n\n Scheduling Policies"). frame2. g_signal_connect(G_OBJECT (combo2). "destroy". 34 gtk_box_pack_start(GTK_BOX(hbox). 20. 10. combo3. G_CALLBACK(modeselect). label = gtk_label_new( NULL). 0). G_CALLBACK(modeselect). gtk_fixed_put(GTK_FIXED(frame2). TRUE."changed". view. } -------------------------------------------------------------------------- . combo2. 25). buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)). vbox). label. G_CALLBACK(gtk_main_quit). gtk_box_pack_start(GTK_BOX(vbox). gtk_main().38 gtk_box_pack_start(GTK_BOX(vbox1). TRUE. G_OBJECT(window)). gtk_container_add(GTK_CONTAINER(window).

j<4. variable res returns the percentage to which the give time burst belongs to the particular membership function. middle. end=(i/4)*3. beg=0. int res. float was not supported in kernel code.//identifying patterns of cpu bursts of the process from its history } } } /* membership functions have beg. .we have used 100 so as to a decimal accuracy of 2 places.unsigned long i)//spans from 0 to 8i/3 { unsigned long beg.so to apply fuzzy logic .end variables that indicate the beginning . for(i=0.end.unsigned long history[SVSHCNT])// -3 because pattern length is 4 { 35 int i=0.i<SVSHCNT-3.endding positions of the function.*/ //Membership Function-0 Triangular int mem0(unsigned long a.mid.39 Fuzzy-based algorithm for Scheduler //Generating the pattern void svspatterngen(unsigned long patterns[SVSHCNT-3][4].j++) { patterns[i][j]=history[j+i].i++) { for(j=0.j=0.mid. mid=(i/8)*3.

if(a>beg&&a<=mid1) //postive slope. beg=i/2. if(a>mid2&&a<end) //negative slope. res=100. return(res). res=100-(((a-mid2)*100)/(end-mid2)). { int res.mid2. if(a>beg&&a<=mid) //postive slope. res=((a-beg)*100)/(mid1-beg). if(a>mid1&&a<=mid2) // no change in value.mid1. decreasing funtion res=100-(((a-mid)*100)/(end-mid)). end=(i/2)*3. mid2=(i/4)*5.40 res=0.unsigned long i) //spans from 4i/5 to4i/9. mid1=(i/4)*3. return(res). 36 if(a>mid&&a<end) //negative slope. } //Membership Function-2 Trapezoidal int mem2(unsigned long a. .end. res=0. increasing function res=(a*100)/(mid-beg). unsigned long beg.unsigned long i) //spans from i/2 to 3i/2 { int res. } //Membership Function-1 Trapezoidal int mem1(unsigned long a.

res=0. beg=(i/4)*5.end.mid2. mid2=i*2. 38 .mid1. if(a>beg&&a<=mid) //positive slope res=((a-beg)*100)/(mid-beg). end=(i/8)*19.unsigned long i)//spans from 2i to 11i/4 { unsigned long beg. mid1=(i/2)*3. return(res). end=(i/4)*9. } //Membership Function-3 Triangular int mem3(unsigned long a. beg=2*i. res=0. if(a>beg&&a<=mid1) //positive slope res=((a-beg)*100)/(mid1-beg). mid=(i/4)*11. return(res). int res. if(a>mid1&&a<=mid2) //no change res=100.mid.end. if(a>mid2&&a<end) //negative slope res=100-(((a-mid2)*100)/(end-mid2)). if(a>mid&&a<end) //negative slope res=100-(((a-mid)*100)/(end-mid)).41 37 unsigned long beg.

42 } //Maximum Value calculation to determine which membership function dominates int maximum(int memfunc[]) { int i; int max,m; max=memfunc[0]; m=0; for(i=1;i<4;i++) if(memfunc[i]>max) { max=memfunc[i]; m=i; } return m; } //Formulating Search Table void svstable(unsigned long patterns[SVSHCNT-3][4], int table[4][4][4], unsigned long ideal) { int i=0,j=0,k=0; int memfunc[4],results[4]; //Setting default functions for unpopulated entries in search table for(i=0;i<4;i++) for(j=0;j<4;j++) 39 for(k=0;k<4;k++) table[i][j][k]=1; //Using patterns to populate the search table

43 for(i=0;i<SVSHCNT-3;i++) //for loops to look into all the patterns { for(j=0;j<4;j++) { memfunc[0]=mem0(patterns[i][j],ideal); memfunc[1]=mem1(patterns[i][j],ideal); memfunc[2]=mem2(patterns[i][j],ideal); memfunc[3]=mem3(patterns[i][j],ideal); results[j]=maximum(memfunc); } table[results[0]][results[1]][results[2]]=results[3];//storing the result obtained via processing the patterns for suture use. } } //Calculating slice value based on the membership function. the values stated in the switch case are the mid values of the memebrship functions. unsigned long svs_calc_slice(int m,unsigned long i) { switch(m) { case 0: return 3*(i/8); case 1: return i; case 2: return 7*(i/4); case 3: return 19*(i/8); default: return i; 40 } } //Inference from the table unsigned long svsinference(unsigned long history[],int table[4][4][4],

44 unsigned long ideal) { int mem[3],j,memfunc[4],currmem; unsigned long slice; //Extracting the tail pattern for(j=2;j>=0;j--) { memfunc[0]=mem0(history[SVSHCNT-j],ideal); memfunc[1]=mem1(history[SVSHCNT-j],ideal); memfunc[2]=mem2(history[SVSHCNT-j],ideal); memfunc[3]=mem3(history[SVSHCNT-j],ideal); mem[j]=maximum(memfunc); } //Getting the membership function of the request currmem=table[mem[0]][mem[1]][mem[2]]; //Calculation of slice time for a membership function slice=svs_calc_slice(currmem,ideal); return slice; } 41 //Fuzzy algorithm to get the schedule slice time of the next job unsigned long svsfuzzy_slice(unsigned long history[SVSHCNT],unsigned long ideal) { unsigned long patterns[SVSHCNT-3][4]; int table[4][4][4]; unsigned long slice; //Generating the pattern svspatterngen(patterns,history); //Formulating Search Table

} -------------------------------------------------------------------------Performance measurement and Analysis #include<stdio. fp=fopen("/proc/schedstat". FILE *fp.table. . return slice."r"). FILE *f3. //Inference of patterns using Search Table slice=svsinference(history. f1=fopen("r_new".table.waitavg=0.num. int i."w").runavg=0.&proc)."r").k.l. long long run."w").45 svstable(patterns."w")."%d". system("ls /proc | wc -l > count").h> int main() { char ch1. double d. fscanf(pro.// Change to old and new correspondingly pro=fopen("count".// Change to old and new correspondingly f3=fopen("t_new". FILE *f2. FILE *pro. // Change to old and new correspondingly f2=fopen("w_new". FILE *f1.wait.ideal).ideal). int proc.

k<4.ch1). } while((ch1 = fgetc(fp))) { //printf("%c". sleep(1). printf("\n--------------------------------------------\n").&run)."%lld".&wait).46 proc-=53. for(k=0. fscanf(fp.ch1).ch1). while((ch1 = fgetc(fp)) != ’c’) { //printf("%c". if (ch1==’ ’) i++."%lld". } //printf("%c".k++) { i=0.ch1). } fscanf(fp.waitavg=0. if(i==6) break. for(l=0. while((ch1 = fgetc(fp)) != ’ ’) { //printf("%c".l<25. .l++) { runavg=0.

fprintf(f3.l+1.47 fscanf(fp.&num).(runavg+waitavg)*100000/4). struct page *buddy.l+1. int svsi. unsigned int order. } return 0."%lld"."r"). fprintf(f2. struct zone* zone. } Memory Management static inline void __free_one_page(struct page *pagec."%d %lf\n"."%d %lf\n".l+1. fp=fopen("/proc/schedstat". struct page *page. unsigned int orderc. struct zone *zonec. } fprintf(f1. if(svspcount<2) printf("Cpu %d: \n Average Execution-time: %lf\n Average Waiting-time: %lf -------------------------------------------------------------------------- . waitavg+=(double)wait/(double)proc. int migratetype.runavg*100000/4). runavg+=(double)run/(double)proc."%d %lf\n". int migratetypec) { unsigned long page_idx. d=(double)run/(double)num.waitavg*100000/4). unsigned long combined_idx.

svsi<3. . . zone=svszone[svsi]. svsmtype[svspcount]=migratetypec. printk(" } svsmem works fine"). . svsmtype[svspcount++]=migratetypec.svsi++) { page=svslist[svsi]. order=svsorder[svsi]. for(svsi=0. .48 { svszone[svspcount]=zonec. svspcount=0. svslist[svspcount]=pagec. } else { printk("svsmem"). migratetype=svsmtype[svsi]. . svslist[svsi]=NULL. svslist[svspcount]=pagec. svsorder[svspcount++]=orderc. svszone[svspcount]=zonec. svsorder[svspcount]=orderc. if(order==-1) continue. svsorder[svsi]=-1.

49 } .

50 .A PPENDIX B S NAPSHOTS F IGURE B.1: Grub listing the modified kernel.

2: Print messages being printed as and when processes exceed predicted runtime .51 F IGURE B.

3: RCSC framework snapshot .52 F IGURE B.

53 F IGURE B.4: make modulesinstall while building the kernel .

The process eventually gets killed. ID:TC02 Module involved: memory management. ID:TC03 Module involved: Fuzzy based scheduling algorithm Description: A new process with no history of previous bursts arrives.A PPENDIX C T EST CASES Test Cases ID : TC01 Module involved: memory management. Expected output: The memory request is discarded. ID: TC04 Module involved: Fuzzy based scheduling algorithm Description: All the processes in the waiting queue has nearly the same cpu burst time. Expected output: The large memory chunk is split until a block that is just greater than or equal to the memory request is obtained. ID:TC05 Module involved: RCSC framework Description: User specifies a scheduling algorithm to be used. 54 . Expected output: Processes must be scheduled based on their arrival time or waiting time. Description: A memory request for a few blocks arrives and size of the memory chunk is large. Description: A memory request bigger than the available memory arrives. It is then allocated. Expected output: A default CPU burst is allocated.

.55 Expected output: The specified algorithm is used for further scheduling and the change occurs during runtime.

A PPENDIX D MISCELLANEOUS 56 .

16-18 ov.Spring Conference. Proceedings of 2009 Student Conference on Research and Development (SCOReD2009). Linux Kernel Developer.Amir MasoudRahmani. CPU Scheduler and FakhrulZamaniRokhaniC. Runtime KhairulmizamSamsudinB. Malaysia [3] Randy Dunlap. Addison-Wesley 57 . 2009. UPM Serdang. Mentor. 2009 International Association of Computer Science and Information Technology . 3rdedition. Customization Framework for a flexible mobile operating system. IEEE NorthconMay 19.A Fuzzy-based Scheduling Algorithm for prediction of next CPU-burst time to implement Shortest Process Next. and Janitor Linux Kernel Development: Getting Started. 2005 [4] Robert Love Linux Kernel Development. [2] Nasr addinAl-maweriA.References [1] AbdolghaderPouraliand .

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.