CSC 112 Experiment and Assignment "How To Be Nice" *** GENERAL WARNING: *** When running experiments for this assignment, make sure your system is running as few processes as possible. In particular, make sure that no web browser is running. Type "who" to see if someone else is logged on to your machine. When taking timing samples, do not move the mouse or touch the keyboard! Minimize other windows before executing a program. Run each experiment at least three times to obtain an average. All this is VERY important. I will assume you were in class for my demonstrations before doing this assignment. If you missed class, it's your responsibility to find out what you need to know. This assignment may be completed with one (but only one) partner. ************************ This assignment asks you do device some simulations of cpu-bound and io-bound processes, and use Unix system utilities to measure how they run. This assignment is to be conducted on Hofstra Solaris systems using the C programming language. 1. Download the program "utils.c" from the class homepage. Look at its contents, specifically the "busywait" function. This function is designed to simulate a CPU burst for a given duration. The first thing you need to do is to re-calibrate the constant SECONDTIME, so that the following program runs for exactly (or as close to as possible) one second on your machine. #include "utils.c" int main(int argc, char* argv[]) { busywait(1.0); exit(0); } Type "gcc (or cc) sourcefile -o executable" to compile the program. Use the "time" command to measure the time. Take the average of at least three runs. Since this process involves no IO, the cpu-time should be the same as real time (turnaround time). You may need to re-do this if you move to a different machine. The command "/opt/SUNWspro/bin/fpversion" will give you information as to the speed of your processor. Once you calibrate the SECONDTIME constant, the busywait function can be called for the cpu to loop for any given number of seconds (in cpu time). 2. In the utils.c file you will also find a function "sleepwait". This is the counterpart to busywait: it suspends the process for a given amount of time. Now, use busywait and sleepwait to write two programs: a. A cpu-bound process that alternately bursts for 0.5 seconds and suspends for 0.05 seconds. It should thus alternate 10 times. The program should take a command line argument to identify itself. Add the follwing line to the end of your program (before the "exit(0)"!): printf("cpu-bound process %s exiting\n",argv[1]); Measure the undisturbed turnaround time (real time) of this program. Note that there will be a slight difference in the turnaround time and user time. Be sure to pass the program a command line argument when running it, as in "time ./cpubound A". b. An io-bound process that alternately bursts for .05 seconds and suspends for .05 seconds. It should thus alternate enough times so that the turnaround time is approximately equal to that of the cpu-bound program. Note that, for this program, user time will be drastically different from turnaround time. Be sure to also add a line to indicate when a process exits: printf("io-bound process %s exiting\n",argv[1]); 3. Assume "cpubound" and "iobound" are the names of your executables. Run and time both concurrently with: time ./cpubound A & ; time ./iobound B You may have to hit return at the end for both timing results to be displayed. The second set of timings reported should be the one for process "A". The turnaround time for the cpu bound process should be longer than for the io-bound process. Note these times. Calculate the faster speed of the io-bound process as a percentage of the cpu-bound process. For example, if the cpu-bound process has a turnaround time of 10 seconds, and the io-bound process has one of 9 seconds, then the percentage speedup is 10%. 4. The nice command can be used to adjust the priority of processes. For example, "nice +5 ./a.out" will lower the priority of the a.out process by 5 units. (Only system administrators can raise the priority of processes, for obvious reasons). Although we're not administrators, we can still use "nice" to adjust the *relative* priority of processes. The nice number you can use is between +1 and +19. What we want to do is to quantify the relationship between the "niceness" of a process and its turnaround time while running concurrently with another process. a. First run two cpubound processes concurrently at the same (or no) niceness level, run the processes at different niceness levels, for each niceness setting, run the experiment 3 times to obtain an average. For example, "time nice +3 ./cpubound A &; time nice +1 ./cpubound B" will give you the effect of a niceness difference of two. Obtain and record the results for niceness differences of 0, 3, 6, 9 12, 15, and 18 units. Compute the percentage difference in speed between the nicer process and the not-so-nice process. Graph the percentages (be neat). Can you draw some generalizations? Is there a "niceness threshold" that needs to be met before there is a real difference in performance? b. Perform the same experiment for two concurrent iobound processes c. Perform the same experiment for an iobound and a cpubound process. How nice does the iobound process have to be so that the scheduling algorithm will nolonger favor the iobound process? d. Draw conclusions from your experiments - be thoughtful. Turn in source code, timing tables and graphs. This assignment is due 2/22/2002.