CS 537 - Programming Assignment 3 CS 537 Programming Assignment 3 Lottery Scheduling Due: April 14 at the start of class. Contents Introduction Running the Simulator System Overview Program Modification Files Coding Experiments Report Grading Handing In FAQ (be sure to read it!) Introduction We have written a program that simulates a short-term scheduler; with this program, you can experiment with various scheduling policies. Your assignment is to implement the Lottery scheduling policy, and compare it with the round-robin scheduling policy by running experiments. Running the Simulator The current version of the program simulates (non-preemptive) Round-Robin (RR) scheduling, but it is constructed to allow easy modification for other scheduling policies. The program expects the following command line: java Proj3 [-v...] [-t] data-file quantum Proj3: Name of the main class. -v, -v -v, etc.: Starts verbose mode for debugging. Verbose mode causes the simulator to print debugging output to the screen. The more v's in the command line, the greater the verbosity. -t: Starts trace mode. Trace mode causes the simulator to maintain a record of all significant events. data-file: Name of the file containing the trace data used in the simulation. quantum: Length of the time-slice currently used in the Round-Robin scheduling (in milliseconds). System Overview The Simulator essentially consists of Jobs, Devices, and Schedulers -- all coordinated by a single loop of code. A Job is a customer of services: it is a process that needs to use system resources during its execution. A Device represents a resource in the system. In this simulation, the devices available to a job are the CPU and the disk. There is also a clock device and a pseudo-device that interrupts whenever a new job arrives in the system. A Scheduler coordinates access to a device. It queues Jobs that are waiting to use a device and will choose which job is the next to access. The overall execution of the simulator occurs like this: Jobs arrive at the JobArrival device and are entered into the system. A job's lifetime consists of alternating periods of using the CPU (called a burst) and performing I/O. The Main Loop is responsible for moving jobs around the system. It sends them to a scheduler, takes the next job from a scheduler, and starts and stops jobs running on a device. The Disk Scheduler and the CPU Scheduler decide which job should be the next to run on their respective devices. They also buffer jobs that are waiting to run but have not yet been given access. The clock device is used to enable preemption (more on this later). For those who would like a more detailed description of the system (more than is necessary to do this assignment) there are pages describing all the interfaces in detail, additional documentation about the program, and, of course, comments in the code itself. Program Modification For this project, you focus on the CPU Scheduler object shown above. The provided simulator performs Round-Robin (RR) scheduling. You are to create a different version of the simulator to implement the Lottery Scheduling policy described below. Modify one copy of the program to simulate the Lottery Scheduling algorithm for fair share. In lottery scheduling, each process owns a number of tickets. At each time quantum, the CPU scheduler decides which process to run on the CPU based on the following principle: the probability that a process is chosen to run on the CPU is proportional to the number of tickets it has. Furthermore, (a) When a process first arrives at the system, it has 10 tickets. (b) When the process uses up its CPU quantum without blocking for I/O or terminating, the scheduler stops it, reduces its ticket by 1 except if the process has only 1 ticket, puts it back to the ready queue, and chooses a process to run on the CPU again. Note that it is possible that the same process will be selected again. (c) If the process blocks for I/O while running on the CPU, the CPU scheduler increases its ticket by 1 except if the process already has 20 tickets, and the ticket will be used to select the process when its I/O operation completes. (d) This policy is preemptive in the following sense: If a job becomes ready while another job is running, the running job is stopped with its ticket unchanged, and a new round of CPU scheduling starts again. You should have two versions of the simulation program when finished, the original (RR), one for Lottery Scheduling (Lot). Files The files you will need can be found in
~cs537-2/public/project3
They include all of the files for the simulator, several data files, and a Makefile. Copy all of these files into one of your directories and type make to run the Round-Robin version of the simulator. Coding The easiest way to work on this assignment is to modify a copy of the provided Round-Robin scheduler.
cp RRScheduler.java LotScheduler.java
Don't forget to change all occurrences of RRScheduler to LotScheduler in the copy and in Makefile. You should also change the line cpuScheduler = new RRScheduler(); in the file Sim.java to read cpuScheduler = new LotScheduler();. The methods in RRScheduler which you will have to modify for your assignment include: boolean add(Job newJob) adds a new job wanting service. This method should return true if the scheduler would like to preempt the current job. Job remove() returns the job that the scheduler would like to run next (and removes it from the queue) boolean reschedule(Job currentJob) returns true if there is a reason to stop the current job and start another. It is called by mainLoop on a clock interrupt and is essential to implementing preemption. If it returns true, the mainLoop will take the current running job off the CPU and return it to the CPU queue (by calling add) and then ask for another job to run by calling remove. You may also need to modify the Job class, for example to add a field to keep track of the job's priority. Experiments You need to compare the performance of two scheduling algorithms. You should also compare the performance for various values of the parameters quantum. Note that if quantum is very large, RR becomes First-Come-First-Served (FCFS). Run your simulator for each scheduling policy, with a variety of quantum values. For each version of the simulator, for each input data file, for each quantum value, plot the (a) completion time, (b) throughput, (c) average job elapsed time, (d) average job waiting time. From the data in part 1, determine (for each scheduling algorithm) the range of values for the quantum that have a noticeable effect on performance. In other words, what is the smallest and largest quantum that will effect performance? From the data in part 1, note any performance differences and similarities between the scheduling algorithms. Are the results consistent for different input data files? Are the results consistent for different quantum values? Is one algorithm always better than another? Try to figure out if these differences make sense to you and explain these differences and similarities. You should approach this portion of the assignment as you would approach a laboratory assignment in a physics course. Use the ``scientific method.'' You should form some hypotheses before you start experimenting and use the experiments to confirm or reject these hypotheses based on observed results. Give careful thought to the correct choice of parameters for the programs. Try a few trial runs with various parameters, print out the results, and go home and think about the results. These preliminary results should help you decide on better parameters for a second round of trials. Remember: It's not the quantity but the quality of data that dictates the quality of the experiments. If the program is not printing out all the statistics you would like to see, feel free to modify it to produce better output. You may find additional statistics-reporting code can help explain some of the behavior you observe. Report You are to prepare a report describing the results of your experiments. Again, approach this report as you would approach a physics laboratory experiment report. You should carefully describe what experiments you did and what the results showed you about the different scheduling policies. We want to see a correlation between the experiments you run and the conclusions you draw. You must supply quantitative data to support your conclusions. The report should be not more than three typewritten pages, excluding tables, graphs, etc. Grading You grade will be determined as follows: 40% - Report (experiments, conclusions, presentation) 60% - Implementation (correctness, style, documentation) You must work in two-person groups for this project. Handing In The handin procedure is similar to the previous two projects. The only difference is that you should bring a printed copy of your report to class. As stated above, the report should be at most three pages, not including graphs and tables. Don't forget to put the names of both partners on the printed report. Last modified: Copyright by Pei Cao and Marvin Solomon. All rights reserved.