Homework 1
(handin instructions)

Use the SUN Cereal machines in Hill 248 to run all the programs.


(A) Cache measurements


(1) Write a C program to measure the size of L1 and L2 caches - using capacity misses.

(2) Write a C program to measure the size of L1 cache - using conflict misses. What are the assumptions under which your program finds the correct size?

(3) Determine the L1 and L2 cache miss penalties (by modifying one of the above programs).

Hint


(B) Implementing a shell


Write a simple Unix shell program that 

(It should also handle white space between components in a single command line correctly. i.e. "cmd | more", "cmd|  more", "   cmd |more", "cmd|more   " should all work.)

Hint

You may want to check man pages for the following system calls: fork, exec, wait, dup, signal, pipe etc.


(C) Page Fault Measurements


Write C programs to measure the time taken to service a page fault (segmentation violation). This should be measured in two ways:

(1) Protect a page using mprotect, and then try to access it. In the handler for segmentation violation, unprotect it.

(2) Use a null pointer and try to access it. In the signal handler, skip the faulting instruction by incrementing the program counter, which you can find on the stack. The following code fragment gets the program counter from the stack.

signal_handler(int t) {
    int *p = &t + 42; /* program counter available at *(&t + 42) */
}

Hint

You may have to handle multiple page faults, before unprotecting the faulting page (to get an accurate estimate of the handling time).