Performance Improvement in Operating System: Sundhar Ram P R 20072225 Vignesh A 20072235 Vigneshwarasabarinath S 20072236
Performance Improvement in Operating System: Sundhar Ram P R 20072225 Vignesh A 20072235 Vigneshwarasabarinath S 20072236
by
BACHELOR OF ENGINEERING
in
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ANNA UNIVERSITY CHENNAI CHENNAI - 600025 April 2011
CERTIFICATE
Certied that this project report titled Performance Improvement of Ubuntu is the bonade work of SUNDHAR RAM P R (20072225), VIGNESH A (20072235),VIGNESHWARASABRINATH S (20072236) who carried out the project work under my supervision, for the fulllment of the requirements for the award of the degree of Bachelor of Engineering in Computer Science and Engineering. Certied 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.
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
ABSTRACT
Operating systems are a must in all the computers used today, may it be at home, school or work. Our aim is to improve the performance of the operating system thereby providing faster running of the operating system. The main areas of the operating system are the scheduler and the memory management unit. We are aimed at improving the scheduling algorithm and the memory management techniques 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. A Runtime CPU Scheduler Customization Framework that helps in dynamically changing the scheduling policies of the processes currently running, displaying the details of all the processes and the scheduling policies used. 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. 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
Contents
Certicate Acknowledgements Abstract(English) Abstract(Tamil) List of Figures 1 Introduction 1.1 Problem Domain . 1.2 Scope of the Project 1.3 Literature Review . 1.4 Problem Denition 1.5 Contributions . . . 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
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Requirements Analysis 2.1 Functional Requirements . . . . . . . . . . . . . . . . 2.2 Non-Functional Requirements . . . . . . . . . . . . . 2.2.1 User Interface . . . . . . . . . . . . . . . . . . 2.2.2 Hardware Considerations . . . . . . . . . . . . 2.2.3 Performance Characteristics . . . . . . . . . . 2.2.3.1 Memory Module . . . . . . . . . . . 2.2.3.2 RCSC Framework . . . . . . . . . . 2.2.3.3 Fuzzy based Scheduling algorithm: . 2.3 Constraints and Assumptions . . . . . . . . . . . . . . 2.4 System Models . . . . . . . . . . . . . . . . . . . . . 2.4.1 Scenarios and Use Case Model . . . . . . . . . 2.4.2 Domain Model and System Sequence diagrams
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
3.2
Module Descriptions . . . . . . . . . . 3.2.1 Algorithms and Explanation . . 3.2.2 Modules . . . . . . . . . . . . 3.2.2.1 Process Scheduling . 3.2.2.2 Memory Management 3.2.3 Complexity analysis . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
11 11 12 12 12 14 16 16 17 17 19 19 21 24 24 25
System Development 4.1 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . 4.2 Test Report and Analysis . . . . . . . . . . . . . . . . . . . . . . 4.3 Performance Studies . . . . . . . . . . . . . . . . . . . . . . . . Results and Discussions 5.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Problems And Issues . . . . . . . . . . . . . . . . . . . . . . . . Conclusion 6.1 Overall conclusion . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Future work and extensions . . . . . . . . . . . . . . . . . . . . .
26 50 54 56
References
57
vi
List of Figures
2.1 2.2 3.1 3.2 3.3 3.4 3.5 4.1 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 Use case Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . System Sequence diagram . . . . . . . . . . . . . . . . . . . . . System Architecture . . . . . . . . . . . . . . . . . . . . . Runtime CPU Scheduler Customization Framework . . . . Runtime CPU Scheduler Customization Framework-DFD0 Runtime CPU Scheduler Customization Framework-DFD1 Proposed Datastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 9 10 12 13 14 15 17 19 20 20 21 21 22 22 23 23 50 51 52 53
System Conguration . . . . . . . . . . . . . . . . . . . . . . . . Running the Benchmark program. . Sample pi Comparison. . . . . . . . Running the Benchmark program2. . Byte Program Comparison 1. . . . . Byte Program Comparison 2. . . . . Nqueens program comparison. . . . Sudoku Program Comparison. . . . Stream Program Comparison 1. . . . Stream Program Comparison 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B.1 Grub listing the modied kernel. . . . . . . . . . . . . . B.2 Print messages being printed as and when processes predicted runtime . . . . . . . . . . . . . . . . . . . . . B.3 RCSC framework snapshot . . . . . . . . . . . . . . . . B.4 make modulesinstall while building the kernel . . . . . .
. . . . . exceed . . . . . . . . . . . . . . .
vii
C HAPTER 1
I NTRODUCTION
In general, performance of the operating system is mainly affected by the scheduling policy adopted by the CPU-scheduler and memory management technique. In Ubuntu operating system, CPU-scheduler uses any one of the scheduling policies to schedule the processes in the system irrespective of the working environment. Each scheduling policy suits well for a particular working environment, a change in working environment leads to performance degradation. In real time working environment changes dynamically, thereby reducing the performance of the system. This project aims at enhancing performance of the Ubuntu operating system.
1.1
Problem Domain
The domain of our project is Operating System. Operating systems is
a platform to run user applications .It is used in many places like in servers that take millions of requests from internet users, by normal personal computers that are used by millions of people around the world, in super computers, in embedded systems and in many more such areas. Since the scope of the operating system is varied the performance measures are also widely varied and are subject to constant changes.The scheduling module in particular is subject to constant changes as there is no xed algorithm that provides best results in all environments.
1.2
enhanced service to the product users.We develop an operating system that could dynamically change the scheduling policy to improve the performance.We will develop a memory management technique for quick,reliable and highly- efcient processing.The project improves the performance of Linux kernel. Any operating system using Linux core like ubuntu, redhat, cent os can benet from this change. Thus the scope of the project is immense, as any user with a desktop and a Linux kernel driven operating system can experience the outcome of our project.
1.3
Literature Review
[1] AbdolghaderPouraliand Amir MasoudRahmaniA Fuzzy-based Scheduling Algorithm for prediction of next CPU-burst time to implement Shortest Process Next, 2009 International Association of Computer Science and Information Technology - Spring Conference.
[2] Nasr addinAl-maweriA, KhairulmizamSamsudinB, and FakhrulZamaniRokhaniC Runtime CPU Scheduler Customization Framework for a flexible mobile operating system Proceedings of 2009 Student Conference on Research and Development (SCOReD2009),16-18 ov. 2009, UPM Serdang, Malaysia
[3] Randy Dunlap, Linux Kernel Developer, Mentor, and JanitorLinux Kernel
1.4
Problem Denition
Performance of the Ubuntu operating system is affected by the static
CPU scheduler and memory management technique. The objective is to provide enhanced service to the product users. 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,reliable and highly- efcient processing. A scheduling algorithm that predicts the next time slice of all runnable processes thereby reducing context switches
1.5
Contributions
We develop a CPU Scheduling algorithm based on fuzzy logic. A
fuzzy system is a knowledge-based rule system .The heart of this system is a database which was formed with if-then rules. Fuzzy if-then rule is a phrase that some words were marked by membership functions.
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.1 Functional Requirements
NEW SCHEDULING POLICY A pattern generating module that generates patterns based on the history of CPU bursts. A search table populating module that populates the search table using the patterns based on a logic. A inference module which predicts the next cpu burst based on the search table values. RUNTIME CPU SCHEDULING FRAMEWORK a module to list the processes , scheduling policies available. a module to inict the change and display the result. Memory Management Denition of the new data structure proposed for the list of free blocks. Functions for allocating and de-allocating memory using the new data structure. 5
2.2
2.2.1
Non-Functional Requirements
User Interface
The operating system is the user interface.any linux kernel driven operating system could serve the purpose. 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.
2.2.2
Hardware Considerations
Any simple desktop conguration that is t enough to run Ubuntu operating system would sufce.For good performance we suggest a desktop with alteast intel Pentium 4 processor,2 GB ram and 80 GB hard disk space.
2.2.3
2.2.3.1
Performance Characteristics
Memory Module
Booting time- This is an indirect measure of the memory management efciency. During booting period many memory blocks get allocated. Although booting time involves scheduling and processing elements too, keeping them constant (as that part of the code is left unchanged) the booting time will be a measure of the memory management techniques efciency. Amount of time spent in the memory
7 management code: This is a direct measure. This can be achieved by using printk() and checking the time the messages appear in the log.
2.2.3.2
RCSC Framework
Number of scheduling policies available for swapping. Time taken for the switch. Efciency in selecting the correct scheduling policy for a given working environment.
2.2.3.3
Turnaround time of the process. Difference between the predicted CPU burst of a process and the actual CPU burst.
2.3
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. Or one must possess the knowledge to add the patch to the existing kernel.
2.4
2.4.1
System Models
Scenarios and Use Case Model
2.4.2
C HAPTER 3
S YSTEM D ESIGN
3.1 System Architecture
F IGURE 3.1: System Architecture
10
11
3.2
3.2.1
Module Descriptions
Algorithms and Explanation
Scheduling algorithm It is a fuzzy based scheduling algorithm that uses if then rules. Modules. 1.pattern extraction-It uses the history of cpu bursts to generate the pattern.A set of patterns are generated. 2.search table population-Search table population is based on membership functions. Two triangular and two trapezoidal membership functions are used in this case. 3.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. 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. Effect change this modules changes the scheduling policy and intimates the user of the same.
12
3.2.2
3.2.2.1
Modules
Process Scheduling
CPU scheduler relies on a particular scheduling algorithm (policy), for example FIFO, Round Robin and SJF. But only one policy is used in a scheduler. When a scheduler needs to use another policy, the kernel needs to be restarted in order to account for it. The Run-time Scheduler Customization Framework helps in switching between the policies while the os is still running. 1. Retrieve policies 2. Change policy 3. Change scheduling classes 4. Switch scheduling policies in run-time
3.2.2.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.3: Runtime CPU Scheduler Customization Framework-DFD0
the programs running over the operating system when asked for. 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. 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.
14
F IGURE 3.4: Runtime CPU Scheduler Customization Framework-DFD1
3.2.3
Complexity analysis
Our algorithm is performed for every few microseconds during which the context switch takes place. So it is of atmost importance that it is optimised to the best possible level. Any fault in the algorithm could cause the kernel to crash leading to fatal errors.
15
C HAPTER 4
S YSTEM D EVELOPMENT
4.1 Implementation Details
The kernel is coded in c , hence the changes that we make are coded in C. The kernel does not support oat datatype,so we have altered our fuzzy algorithm and made it take values ranging from 0-100 instead of the usual 0-1.we have obtained 2 decimal place accuracy this way,the user interface for the runtime cpu scheduler framework is coded using gtk.
16
17
4.2
4.3
Performance Studies
Testing of the new kernel developed by modications in the
scheduler and the memory modules is done by using a tool called Phoronix Test Suite (http://www.phoronix-test-suite.com). The Phoronix Test Suite is the most comprehensive testing and benchmarking platform available for the Linux operating system. This software is designed to effectively carry out both
(pts-core) with each benchmark consisting of an XML-based prole with related resource scripts. The Phoronix Test Suite provides with a set of standard
benchmarking programs that can be used for testing the computer. The Phoronix Test Suite, once on specifying a program, runs the program in the computer and gives us the results of the run. The Phoronix Test Suite is used to test both the old and the new kernels and the results are specied in the following sections.
C HAPTER 5
19
20
F IGURE 5.2: Sample pi Comparison.
21
F IGURE 5.4: Byte Program Comparison 1.
5.2
The kernel wont boot if the algorithm that one coded is faulty,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.
22
23
C HAPTER 6
C ONCLUSION
6.1 Overall conclusion
RCSC A new runtime CPU scheduler customization framework is proposed due to the limitation of Linux CPU scheduler implementation. 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, applications and environment. Based on the study on the recent Linux kernel version 2.6.25, the current Linux CPU scheduler has adapted as the core for RCSC architecture. The RCSC architecture has been designed modularly with aim of reducing the complexity of the implementation. RCSC has been successfully implemented and currently is being evaluated and enhanced. 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. High exibility and desirable speed in
calculation are some advantages of fuzzy systems used in such time series prediction. The main advantage of the proposed algorithm is to forecast the execution time of a process (next CPU-burst time) based on past history. Therefore, 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. 24
25
6.2
Develop a new memory management technique. Develop better scheduling policies. Develop a runtime scheduler which could switch scheduling policies automatically based on the change in the working environment. Develop a scheduling policy that works good for real time systems.
A PPENDIX A
27 } sum/=SVSHCNT; return(sum);//returning average of the cpu bursts stored in history array } static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) { //u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq); //slice=se->svsir; //return slice; //this function returns the predicted cpu burst after performing calculations using fuzzy fn call unsigned long temp[SVSHCNT],avg; avg=reform(task_of(se)->svshist,task_of(se)->svsfront,temp); se->svsir=svsfuzzy_slice(task_of(se)->svshist,avg); return se->svsir; } /* * Update the current tasks runtime statistics. Skip current tasks that * are not in our scheduling class. */ static inline void __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr, unsigned long delta_exec) { unsigned long delta_exec_weighted,svsideal; unsigned long svsdewpart; int svsi; 22 struct task_struct *svsp; schedstat_set(curr->statistics.exec_max,
28 max((u64)delta_exec, curr->statistics.exec_max)); curr->sum_exec_runtime += delta_exec; schedstat_add(cfs_rq, exec_clock, delta_exec); delta_exec_weighted = calc_delta_fair(delta_exec, curr); svsdewpart=delta_exec_weighted/15; svsp=task_of(curr); svsp->svshist[svsp->svsfront]=delta_exec; //storing the cpu burst svsp->svsfront=(svsp->svsfront+1)%SVSHCNT; if(curr->svsloaddec==1) //to prevent over usage { printk("sched period before changing is :%llu",curr->svsir); curr->svsir=__sched_period(cfs_rq->nr_running + !curr->on_rq); printk("svsloaddec=1"); svsideal=200000; delta_exec_weighted+=svsdewpart; printk("\npid:%d,ideal:%ld,vruntime:%llu,delta exec %ld",(task_of(curr)) ->pid,svsideal,curr->vruntime,delta_exec); for(svsi=0;svsi<SVSHCNT;svsi++) { printk("svshistory i:%d,val:%ld\t",svsi,svsp->svshist[svsi]); } curr->svsloaddec=0; } else if (curr->svsloaddec==0) { } 23 else {
29 curr->svsloaddec=0; //loaddec unassigned.assign it to default 0 } curr->vruntime += delta_exec_weighted; update_min_vruntime(cfs_rq); } /* * Preempt the current task with a newly woken task if needed: */ static void check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) { unsigned long ideal_runtime, delta_exec; //ideal runtime is the predicted cpu burst. ideal_runtime = sched_slice(cfs_rq, curr); delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime; if (delta_exec > ideal_runtime) { curr->svsloaddec=1; printk("cpt-- ideal runtime:%ld,pid:%d",ideal_runtime,(task_of(curr)) ->pid); printk("cheackpreempttick-- setting svsloaddec to 1"); return; } ................... ................... } 24 struct sched_entity { ................... ................... u64 svsir; //predicted cpu burst.
30 int svsloaddec; //to prevent overuse u64 svsloadsettime; //the time when loaddec was set. ................... ................... }; static void __sched_fork(struct task_struct *p) { int svsi; ................... ................... //assigning created variables during fork call. p->svsfront =0; p->se.svsir =220000; for(svsi=0;svsi<SVSHCNT;svsi++) { p->svshist[svsi]=0; } ................... ................... } Runtime CPU Scheduler Customization Framework 25 #include<stdio.h> #include<sched.h> /* Converting integer to character array */ void con(int k,char *m) { m[9]=(k%10)+48; k=k/10;
--------------------------------------------------------------------------
31 m[8]=(k%10)+48; k=k/10; m[7]=(k%10)+48; k=k/10; m[6]=(k%10)+48; } /* Converting string to integer */ int pidconvert(char pid[]) { int a,b,c,d; a=pid[3]-48; b=(pid[2]-48)*10; c=(pid[1]-48)*100; d=(pid[0]-48)*1000; return (a+b+c+d); } int main() { 26 char pid[5],ch1,fil[15]="/proc/zzzz/stat",pname[30],nice[3]; int i,k,pidint,pppid=1623; FILE *fp; FILE *pidfile; /* Open a file for writing all process ids running */ pidfile=fopen("pidfile","w"); printf("ProcessID - Process Name Scheduler Used\n"); /* Read the details of the processes from the proc file system */ for(k=1300;k<2000;k++) { con(k,fil);
32 /* printf("%s",fil); fp=fopen(fil,"r"); if(fp) { i=0; /* To get the process ID */ while((ch1 = fgetc(fp)) != { pid[i++]=ch1; } pid[i++]=\0;i=0; 27 /* To get the process name */ while((ch1 = fgetc(fp)) != { pname[i++]=ch1; } while(i<29) {pname[i++]= ;} pname[i]=\0; i=0; /* Traverse till nice value */ while((ch1 = fgetc(fp))) { if(ch1== ) i++; if(i==16) break; } i=0; ) )
33 /* Get the nice value */ while((ch1 = fgetc(fp)) != { nice[i++]=ch1; } nice[i]=\0; /* Get pid to find the scheduling policy */ pidint=pidconvert(pid); 28 fprintf(pidfile,"%s ",pid); /* Print values */ switch(sched_getscheduler(pidint)) { case 0:printf(" %s -- %s -- SCHED_FAIR\n",pid,pname); break; case 1:printf(" %s -- %s -- SCHED_FIFO\n",pid,pname); break; case 2:printf(" %s -- %s -- SCHED_RR\n",pid,pname); break; default:printf(" %s -- %s -- SCHED_FAIR\n",pid,pname); } } } return 0; } /* GTK FILE:-#include<stdio.h> #include<gtk/gtk.h> #include<glib.h> #include<sched.h> )
34 /* Converting string to integer */ char pid[4]; int pidconvert(char pid[]) { 29 int a,b,c,d; a=pid[3]-48; b=(pid[2]-48)*10; c=(pid[1]-48)*100; d=(pid[0]-48)*1000; return (a+b+c+d); } /* This function is called when the value of a drop down list changes */ void modeselect(GtkWidget *widget, gpointer view) { char ch1; char sched[20]="SCHED_FAIR"; /* Default Scheduling */ char array1[81920]; gchar *buf1; FILE *file1; struct sched_param sp; FILE *file2; char ch2; gchar *buf2; char array2[81920]; int pidint; GtkTextBuffer *buff; array2[0] = \0; array1[0] = \0; /* Retrieving the selected value */
35 30 buff = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget)); if(text[0]==1) /* Checking if a pid is selected { pid[0]=text[0];pid[1]=text[1];pid[2]=text[2];pid[3]=text[3]; } pidint=pidconvert(pid); sp.sched_priority = sched_get_priority_max(SCHED_FIFO); /* Setting the new scheduler for a particular process */ if(strcmp(text,"SCHED_FIFO") == 0 && pid[0]==1 ) { sched_setscheduler(pidint,SCHED_FIFO,&sp); } /* Setting the new scheduler for a particular process if(strcmp(text,"SCHED_RR") == 0 && pid[0]==1 ) { sched_setscheduler(pidint,SCHED_RR,&sp); } /* Displaying the output of the previous C file the reads the details of all the processes */ file1 = fopen("output","r"); 31 while((ch1 = fgetc(file1)) != EOF) { strcat(array1 ,&ch1); } buf1 = g_strdup_printf((gchar *) array1); fclose(file1); gtk_text_buffer_set_text(buff, buf1, -1);
36 } int main( int argc, char *argv[]) { GtkWidget *window; GtkWidget *view; GtkWidget *frame; GtkWidget *frame2; GtkWidget *vbox; GtkWidget *vbox1; GtkWidget *hbox; GtkWidget *label; GtkWidget *label2; GtkWidget *combo; GtkWidget *combo2; GtkWidget *combo3; GtkTextBuffer *buffer; char pid[10],ch1; int i=0; 32 FILE *fp_pidfile; fp_pidfile=fopen("pidfile","r"); /* GTK initialization functions */ gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 650, 600); gtk_window_set_title(GTK_WINDOW(window), "Interface"); gtk_container_set_border_width(GTK_CONTAINER(window), 5); GTK_WINDOW(window)->allow_shrink = TRUE; frame = gtk_fixed_new(); frame2 = gtk_fixed_new();
37 vbox = gtk_vbox_new(FALSE, 0); vbox1 = gtk_vbox_new(FALSE, 0); hbox = gtk_hbox_new(FALSE, 0); combo = gtk_combo_box_new_text(); combo2 = gtk_combo_box_new_text(); combo3 = gtk_combo_box_new_text(); /* Adding our drop down list boxes */ gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "View the list of processes"); gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "View the list of processes"); gtk_combo_box_append_text(GTK_COMBO_BOX(combo2), "List of PIDs"); /* Adding the list of pids */ 33 while((ch1 = fgetc(fp_pidfile)) != EOF) { pid[i++]=ch1; while((ch1 = fgetc(fp_pidfile)) != { pid[i++]=ch1; } pid[i]=\0; gtk_combo_box_append_text(GTK_COMBO_BOX(combo2), pid); i=0; } gtk_combo_box_append_text(GTK_COMBO_BOX(combo3), "SCHED_FIFO"); gtk_combo_box_append_text(GTK_COMBO_BOX(combo3), "SCHED_RR"); view = gtk_text_view_new(); gtk_widget_set_size_request(view, 0, 300); gtk_text_view_set_editable(GTK_TEXT_VIEW (view), FALSE); )
38 gtk_box_pack_start(GTK_BOX(vbox1), view, TRUE, TRUE, 0); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); label = gtk_label_new( NULL); gtk_widget_set_size_request(label, 650, 500); label2 = gtk_label_new("View processes \n\n\n PID \n\n\n Scheduling Policies"); gtk_fixed_put(GTK_FIXED(frame), label, 10, 10); gtk_fixed_put(GTK_FIXED(frame2), label2, 20, 25); gtk_fixed_put(GTK_FIXED(frame2), combo, 200, 20); gtk_fixed_put(GTK_FIXED(frame2), combo2, 200, 70); gtk_fixed_put(GTK_FIXED(frame2), combo3, 200, 120); 34 gtk_box_pack_start(GTK_BOX(hbox), frame2, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); /* Calling the modeselect() function when a value is changed */ g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), G_OBJECT(window)); g_signal_connect(G_OBJECT (combo),"changed", G_CALLBACK(modeselect), (gpointer) view); g_signal_connect(G_OBJECT (combo2),"changed", G_CALLBACK(modeselect), (gpointer) view); g_signal_connect(G_OBJECT (combo3),"changed", G_CALLBACK(modeselect), (gpointer) view); gtk_widget_show_all(window); gtk_main(); return 0; }
--------------------------------------------------------------------------
39 Fuzzy-based algorithm for Scheduler //Generating the pattern void svspatterngen(unsigned long patterns[SVSHCNT-3][4],unsigned long history[SVSHCNT])// -3 because pattern length is 4 { 35 int i=0,j=0; for(i=0;i<SVSHCNT-3;i++) { for(j=0;j<4;j++) { patterns[i][j]=history[j+i];//identifying patterns of cpu bursts of the process from its history } } } /* membership functions have beg,mid,end variables that indicate the beginning , middle,endding positions of the function. float was not supported in kernel code.so to apply fuzzy logic ,we have used 100 so as to a decimal accuracy of 2 places. variable res returns the percentage to which the give time burst belongs to the particular membership function.*/ //Membership Function-0 Triangular int mem0(unsigned long a,unsigned long i)//spans from 0 to 8i/3 { unsigned long beg,mid,end; int res; beg=0; end=(i/4)*3; mid=(i/8)*3;
40 res=0; if(a>beg&&a<=mid) //postive slope. increasing function res=(a*100)/(mid-beg); 36 if(a>mid&&a<end) //negative slope. decreasing funtion res=100-(((a-mid)*100)/(end-mid)); return(res); } //Membership Function-1 Trapezoidal int mem1(unsigned long a,unsigned long i) //spans from i/2 to 3i/2 { int res; unsigned long beg,mid1,mid2,end; beg=i/2; mid1=(i/4)*3; mid2=(i/4)*5; end=(i/2)*3; res=0; if(a>beg&&a<=mid1) //postive slope. res=((a-beg)*100)/(mid1-beg); if(a>mid1&&a<=mid2) // no change in value. res=100; if(a>mid2&&a<end) //negative slope. res=100-(((a-mid2)*100)/(end-mid2)); return(res); } //Membership Function-2 Trapezoidal int mem2(unsigned long a,unsigned long i) //spans from 4i/5 to4i/9. { int res;
41 37 unsigned long beg,mid1,mid2,end; beg=(i/4)*5; mid1=(i/2)*3; mid2=i*2; end=(i/4)*9; res=0; if(a>beg&&a<=mid1) //positive slope res=((a-beg)*100)/(mid1-beg); if(a>mid1&&a<=mid2) //no change res=100; if(a>mid2&&a<end) //negative slope res=100-(((a-mid2)*100)/(end-mid2)); return(res); } //Membership Function-3 Triangular int mem3(unsigned long a,unsigned long i)//spans from 2i to 11i/4 { unsigned long beg,mid,end; int res; beg=2*i; end=(i/8)*19; mid=(i/4)*11; res=0; if(a>beg&&a<=mid) //positive slope res=((a-beg)*100)/(mid-beg); if(a>mid&&a<end) //negative slope res=100-(((a-mid)*100)/(end-mid)); return(res); 38
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.h> int main() { char ch1; long long run,wait,num; int proc; double d,runavg=0,waitavg=0; int i,k,l; FILE *fp; FILE *f1; FILE *f2; FILE *f3; FILE *pro; fp=fopen("/proc/schedstat","r"); f1=fopen("r_new","w"); // Change to old and new correspondingly f2=fopen("w_new","w");// Change to old and new correspondingly f3=fopen("t_new","w");// Change to old and new correspondingly pro=fopen("count","r"); system("ls /proc | wc -l > count"); fscanf(pro,"%d",&proc);
46 proc-=53; for(l=0;l<25;l++) { runavg=0;waitavg=0; printf("\n--------------------------------------------\n"); sleep(1); for(k=0;k<4;k++) { i=0; while((ch1 = fgetc(fp)) != c) { //printf("%c",ch1); } //printf("%c",ch1); while((ch1 = fgetc(fp)) != ) { //printf("%c",ch1); } while((ch1 = fgetc(fp))) { //printf("%c",ch1); if (ch1== ) i++; if(i==6) break; } fscanf(fp,"%lld",&run); fscanf(fp,"%lld",&wait);
47 fscanf(fp,"%lld",&num); d=(double)run/(double)num; runavg+=(double)run/(double)proc; waitavg+=(double)wait/(double)proc; } fprintf(f1,"%d %lf\n",l+1,runavg*100000/4); fprintf(f2,"%d %lf\n",l+1,waitavg*100000/4); fprintf(f3,"%d %lf\n",l+1,(runavg+waitavg)*100000/4); fp=fopen("/proc/schedstat","r"); } return 0; } Memory Management static inline void __free_one_page(struct page *pagec, struct zone *zonec, unsigned int orderc, int migratetypec) { unsigned long page_idx; unsigned long combined_idx; struct page *buddy; struct page *page; struct zone* zone; unsigned int order; int migratetype; int svsi; if(svspcount<2)
--------------------------------------------------------------------------
48 { svszone[svspcount]=zonec; svsmtype[svspcount]=migratetypec; svslist[svspcount]=pagec; svsorder[svspcount++]=orderc; } else { printk("svsmem"); svslist[svspcount]=pagec; svsorder[svspcount]=orderc; svszone[svspcount]=zonec; svsmtype[svspcount++]=migratetypec; svspcount=0; for(svsi=0;svsi<3;svsi++) { page=svslist[svsi]; order=svsorder[svsi]; zone=svszone[svsi]; migratetype=svsmtype[svsi]; svslist[svsi]=NULL; svsorder[svsi]=-1; if(order==-1) continue; . . . . printk(" } svsmem works fine");
49 }
A PPENDIX B
S NAPSHOTS
F IGURE B.1: Grub listing the modied kernel.
50
51
F IGURE B.2: Print messages being printed as and when processes exceed predicted runtime
52
F IGURE B.3: RCSC framework snapshot
53
F IGURE B.4: make modulesinstall while building the kernel
A PPENDIX C
T EST CASES
Test Cases ID : TC01 Module involved: memory management. Description: A memory request bigger than the available memory arrives. Expected output: The memory request is discarded. The process eventually gets killed. ID:TC02 Module involved: memory management. Description: A memory request for a few blocks arrives and size of the memory chunk is large. Expected output: The large memory chunk is split until a block that is just greater than or equal to the memory request is obtained. It is then allocated. ID:TC03 Module involved: Fuzzy based scheduling algorithm Description: A new process with no history of previous bursts arrives. Expected output: A default CPU burst is allocated. 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: Processes must be scheduled based on their arrival time or waiting time. ID:TC05 Module involved: RCSC framework Description: User species a scheduling algorithm to be used. 54
55 Expected output: The specied algorithm is used for further scheduling and the change occurs during runtime.
A PPENDIX D
MISCELLANEOUS
56
References
[1] AbdolghaderPouraliand ,Amir MasoudRahmani,A Fuzzy-based Scheduling Algorithm for prediction of next CPU-burst time to implement Shortest Process Next, 2009 International Association of Computer Science and Information Technology - Spring Conference. [2] Nasr addinAl-maweriA, Runtime KhairulmizamSamsudinB, CPU Scheduler and
FakhrulZamaniRokhaniC,
Customization
Framework for a exible mobile operating system, Proceedings of 2009 Student Conference on Research and Development (SCOReD2009),16-18 ov. 2009, UPM Serdang, Malaysia [3] Randy Dunlap, Linux Kernel Developer, Mentor, and Janitor Linux Kernel Development: Getting Started, IEEE NorthconMay 19, 2005 [4] Robert Love Linux Kernel Development, 3rdedition, Addison-Wesley
57