Homework 1
W4118 Fall 2000
DUE: Monday, 9/25/2000 at the beginning of class

W4118 Fall 2000 - Homework 1

All non-programming and programming problems in this assignment are to be done by yourself. Group collaboration is not permitted for this assignment. Each of you should turn in one hardcopy for the non-programming problems and one hardcopy for the programming problems. Both hardcopies should have your name and email address clearly written on the first page.

Non-Programming Problems:

Exercise numbers refer to the course textbook. Each problem is worth 4 points unless otherwise indicated.

  1. Exercise 1.1

  2. Exercise 1.5

  3. Exercise 1.6

  4. Exercise 1.11

  5. Exercise 2.3

  6. Exercise 2.5

  7. Exercise 2.8

  8. Exercise 2.10

  9. Exercise 3.1

  10. Exercise 3.6

Programming Problems:

For all programming problems you will be required to submit source code, a README file documenting your files and code, and a test run of your programs. Refer to the homework submission page on the class web site for additional submission instructions.

  1. (10 pts) Using system calls, write a program in C that reads data from one file and copies it to another file. The program should take two file names as its arguments. The program should check for bad inputs and should work for files of arbritrary size.

  2. (10 pts) Write a trivial shell that reads a line from the standard input, splits the line into program name and arguments, and invokes the command after forking, with the arguments passed in the normal C manner. The shell waits until the program completes. You should write this in C. You can make reasonable assumptions about the maximum number of command line arguments.

  3. The Pentium II and AMD machines in the CLIC lab have a tsc hardware register that counts processor cycles. The register can be read using the rdtsc instruction, which can be used to provide very accurate timing measurements. The Intel document about this instruction is at http://developer.intel.com/software/idap/media/pdf/rdtscpm1.htm

    1. (15 pts) Write a function in C called gettsc that takes a pointer to a long long as an argument and has a return type of void. Test your function by using it in a program to measure the time it takes to execute each iteration of the following inner for loop:
      	for (i=0; i<100; i++) {
      	    for (j=0; j<N; j++) {  /* inner loop starts here */
      	    	k = i + j;
      	    }                      /* inner loop ends here */
      	}
      
      Report your results for N=10, 100, 1000, 10000, and 100000. Plot your results across the 100 iterations and report the average and standard deviation of your measurements for each value of N.

    2. (10 pts) Write another function in C called gettsctime that takes a long long tsc value as an argument and returns the equivalent long long in nanoseconds. Repeat the tests from part a, this time reporting the results in nanoseconds. Your function should be portable across machines, so it will need to determine the CPU speed of the machine on which it is being called. One way to do this in Linux is to parse the data contained in the file /proc/cpuinfo. The /proc filesystem (where /proc/cpuinfo resides), is a virtual filesystem that presents a way for userspace to communicate with the kernel and vice-versa. Various statistics can be read from the files in the /proc filesystem and /proc/cpuinfo, as its name suggests, contains information regarding the CPU.

    3. (5 pts) Use the system call gettimeofday to measure the performance of the same set of for loops. Compare and discuss any differences in the measurements between these results and those from part b.

    4. (10 pts) What is the execution time required by gettsc, gettsctime, and gettimeofday? Write a program to do determine this. You should be careful to do the measurement in such a way that the overhead of doing the measurement is negligible.