CPU Scheduling Simulator v1.0 DESGIN DOCUMENTATION FOR CPU SCHEDULING ALGORITHM By Nghia Ngoc Phan Summer 2005 Class: CS 440 Nghia Phan Page 1 2/12/2016 CPU Scheduling Simulator v1.0 1. Introduction In order to make the computer more productive in multiprogramming, the operating system needs to switch the CPU among processes. It must provides the basic algorithm to determine which process is allowed to get the CPU at the current time, and whether that process is allowed to finish its execution comparing to other processes in the system. Therefore, CPU scheduling algorithms such as First Come First Served (FCFS), Shortest Job First (SJF), Shortest Remaining Job (SRJ), Round-Robin (RR), and Priority are among possible solutions for multiprogrammed operating system. Students in operating system class should be familiar with these algorithms and be able to analyze these algorithms. Usually, students manually compute the waiting times and turnaround times of these algorithms to compare their performances. Consequently, the computation is inefficient and prone to error. 2. Goals and Objective The CPU Scheduling Simulator is an automation that provides efficient and errorless computation of waiting times and turnaround times of FCFS, SJF, SRJ, RR, and Priority. The system provides the students a clean and convenient way to test their given data or do the analysis of the CPU scheduling algorithms mentioned above. 3. Requirements a. User’s Level: i. For the purpose of analysis, the system allows the user to specify number of datasets and number of processes in each dataset. ii. For the purpose of testing, a user is allowed to enter the information of processes in his/her dataset. For each process, the following information can be entered by a user: arrival time, burst time, and priority. iii. FCFS, SJF, SRJ, RR, and Priority can be computed, and output is in appropriate format for readability. b. System’s Level: Nghia Phan i. Graphical User Interfaces (GUIs) will be provided for user friendly. ii. Temporary storage is provided for datasets Page 2 2/12/2016 CPU Scheduling Simulator v1.0 iii. Dataset has no size limit. iv. Each process has its own properties and functions. v. Data will be generated for non-users’ datasets with the following constraints: 0 <= Burst Time <= 20 0 <= Arrival Time <= 20 0 <= Priority <= 20 Time quantum is a list of values 1, 2, and 3. vi. For each CPU scheduling algorithm, average waiting time and average turnaround time will be computed for each and all datasets. vii. System will catch and handle any errors caused by the system or user. 4. Specifications a. Processes Diagrams: i. Context Diagram Student CPU Scheduling Simulator Faculty Nghia Phan Page 3 2/12/2016 CPU Scheduling Simulator v1.0 ii. 1st Level Data Flow Diagram (DFD) User Requests (1) Scheduler (2) Display Input Form 1 Invokes Previous Datasets Generates Next (3) Display Input Form 2 Previous Next (4) Display Selection Form iii. 2nd Level DFD Selects Closes Selects Closes (4) Display Selection From Selects Closes Selects Closes Selects Closes Nghia Phan Page 4 (5) Implements First Come First Served (FCFS) Output (6) Implements Shortest Job First (SJF) Output (7) Implements Priority Output (8) Implements Shortest Remaining Job (SRJ) Output (9) Implements Round-Robin (RR) Output 2/12/2016 CPU Scheduling Simulator v1.0 b. Modules Descriptions: i. MainClass.java This is the first class that will be called to run the system. Method Summary void main(String[] args) Create an object of Scheduler class. ii. Scheduler.java This class are handling users’ input/selection and generating datasets. Extends JFrame Implements ActionListener interface Field Summary int Number_Of_Process Value will inputted by a user. This will tell the system how many processes in each dataset that the system needs to generate. int Number_Of_Set Value will inputted by a user. This will tell the system how many datasets that the system needs to generate. int [][] Array_Process_ID Use to store the IDs of processes in the datasets. int [][] Array_Process_Burst_Time Use to store the burst times of processes in the datasets. int [][] Array_Process_Priority Use to store the priority numbers of processes in the datasets. int [][] Array_Process_Arrival_Time Use to store the arrival times of processes in the datasets. Constructor Summary Scheduler() Create frames, add components onto frames, and display first input form for the user to input number of datasets and number of processes in each dataset. Nghia Phan Page 5 2/12/2016 CPU Scheduling Simulator v1.0 Method Summary WelcomeFrame_Add_Shared_Components() void Add shared components such as menu bar, menu items, buttons onto welcome frame, which is the first input form (See Processes Diagrams) void InputFrame_Add_Shared_Components() Similar to WelcomeFrame_Add_Shared_Components(). void SelectionFrame_Add_Shared_Components() Similar to WelcomeFrame_Add_Shared_Components(). void actionPerformed(ActionEvent e) Handling events such as button clicked or menu item selected. void System_Generates_Data() Generates datasets which will be stored in the arrays of process id, arrival time, burst time, and priority. iii. SchedulingAlgorithm.java This class will handle the implementations of the following CPU scheduling algorithms: a. FCFS b. SJF c. Priority d. SRJ e. RR Extends JFrame Implements ActionListener Field Summary ProcessQueue [] ProcessQueue [] ProcessQueue [] double [] double [] Nghia Phan WaitingQueue Array contains list of objects belong to ProcessQueue class. Each element of an array is a dataset in waiting state. ReadyQueue Array contains list of objects belong to ProcessQueue class. Each element of an array is a dataset in ready state. FinishQueue Array contains list of objects belong to ProcessQueue class. Each element of an array is a dataset in finished state. QueueAverageWaitingTime Each member of an array is an average waiting time of one dataset in the system. QueueAverageTurnaroundTime Each member of an array is an average turnaround time of one dataset in the system. Page 6 2/12/2016 CPU Scheduling Simulator v1.0 int TimeCounter Use to specify the terminate time of a process. Constructor Summary SchedulingAlgorithm(int Array_Process_ID[][],int Array_Process_Burst_Time[][], int Array_Process_Priority[][], int Array_Process_Arrival_Time[][]) Create display frame and add components onto it. Create datasets and processes in each data set. Each dataset is an object of ProcessQueue class. Each process is an object or Process class. Method Summary ProcessQueue SortQueue(ProcessQueue p_queue, int sortID) Sorts a dataset bases on sortID. sortID = 1 refers to sorted by CPU Burst Time sortID = 2 refers to sorted by CPU Arrival Time sortID = 3 refers to sorted by CPU Priority int [] SwapArrayElement(int [] array, int index1, int index2) Swap element at index1 with element at index 2 of an array. void Implement_FCFS_SJF_Priority(int AlgorithmID) Implements and displays output of the following CPU scheduling algorithm: 1. AlgorithmID = 1 implies implementation of First Come First Served Algorithm 2. AlgorithmID = 2 implies implementation of Shortest Job First Algorithm 3. AlgorithmID = 3 implies implementation of Priority Algorithm void Implement_SRJ() Implements and displays output of SRJ. void Implement_RR(int [] TimeQuantum) Implements and displays output of RR with different time quantum of an array TimeQuantum. void RestoreData() Restore original data of datasets. void DisplaySummary(String FooterStr) Displays summary data such as average waiting time and average turnaround time of all datasets. Nghia Phan Page 7 2/12/2016 CPU Scheduling Simulator v1.0 iv. Process.java Object of this class can store its id, burst time, arrival time, priority and performs operations such as calculate arrival time, calculate turnaround time, and etc. A process in the dataset is an object of this class. Field Summary int BurstTime int CurrentBurstTime int Priority int ArrivalTime int TurnaroundTime int WaitingTime int TerminatedTime int ProcessID Constructor Summary Process(int PID, int BTime, int P, int ATime) Initializes all variables. Method Summary int GetBurstTime() int GetCurrentBurstTime() int GetPriority() int GetArrivalTime() int GetTurnaroundTime() int GetWaitingTime() int GetTerminatedTime() int GetProcessID() void setArrivalTime(int ATime) void SetCurrentBurstTime(int BTime) void SetTerminatedTime(int TTime) void CalculateTurnaroundTime() void CalculateWaitingTime() v. ProcessQueue.java A java class for queue ADT. It is an array-based implementation. An object of this class is a dataset that contains a list of processes used for the implementation of CPU scheduling algorithms. Nghia Phan Page 8 2/12/2016 CPU Scheduling Simulator v1.0 Field Summary int first int last int size int capacity Object [] ObjArray Constructor Summary ProcessQueue() Default contructor. ProcessQueue(int capacityElement) Contructor with specified capacity of the queue. Method Summary int GetCapacity() Return capacity of the the queue int GetSize() Return number of elements in the queue boolean IsEmpty() Return true if the queue is empty. false otherwise. Object Object GetFront() Inspect the element at the front of the queue. Return element at the front of the queue, if exception occurs, return error message. Object GetLast() Inspect the element at the end of the queue. Return element at the front of the queue, if exception occurs, return error message. void EnQueue(Object element) Insert an element at the rear of the queue. Object Object DeQueue() Remove and return the element at the front of the queue. If exception occurs, return error message. int getLast() int getFirst() Nghia Phan Page 9 2/12/2016