Warm-Up Assignment

All of the course projects for this class will involve measurement of some kind. This project will help you to get thinking about how to measure and evaluate a computer system. In addition, it should help you to better understand the relative costs of different activities in an operating system, ranging from a simple function call up to executing a complete program.

Below is a list of actions that you will time using the system clock. Most of these actions are much faster than the resolution of the system clock, so you will need to perform anywhere from a few hundred to a few billion events in a loop so that the test will take a measurable amount of time. Call gettimeofday before and after the loop and subtract to get the elpased time. For each test, experiment with the number of actions per loop until the test takes a a few seconds, then divide by the number of loops to yield the average time.

Of course, it is never enough to measure a value once: the measurement may be inherently variable, or the measuring equipment may have its own internal variation. For this work, you should repeat each test about ten times, and report the average and standard deviation.

To ensure consistency of results, everyone should conduct their experiments on the machines with author's names on the first floor of Fitzpatrick. You can either walk down to the lab, or SSH into the machines. (list of names here). Write each of these simple programs in C. If you are a little rusty on the details of Unix system calls, you should make good use of the online Unix manuals by invoking, for example, man 2 open to see all of the options for open().

  1. Measure the time to invoke an empty function that does nothing and returns.

  2. Measure the time to invoke the simple system call SYS_getpid.
    Hint: Invoke the getpid system call directly like this:
    #include <unistd.h>
    #include <syscall.h>
    int pid = syscall(SYS_getpid);

  3. Measure the time to invoke the library function getpid().
    Can you propose a reasonable hypothesis as to why this result is different from SYS_getpid?

  4. Measure the time to call gethostbyname("www.google.com").

  5. Measure the time to execute a program like system("/bin/date");.

  6. Measure the time to creat(), close(), and unlink() a file in /tmp.

  7. Measure the time to open() a file for writing, write ten megabytes to the file ONE BYTE at a time with many write()s, and then close() it.

  8. Repeat the previous experiment, keeping the total amount of data the same, but writing two bytes, four bytes, and so on. Produce a line graph with "Write Size (bytes)" on the X axis and "I/O Throughput (MB/s)" on the Y axis. Explain the shape of the graph.

  9. Learn how to use the program strace, which displays all of the system calls performed by a program. Apply it to a large program such as a web browser or a word processor, to obtain a very large sampling of system calls. Create a histogram of system calls by frequency, from most common to least common.

  10. List each type of system call used (open, close, mmap, etc) and give a one sentence description of what the call does.

  11. What is the most common system call? Is it what you expected? Why does it appear so frequently?
Carefully write up your results in a few pages. This assignment is to be completed individually, and is due at the beginning of class on Thursday, September 2.