Getting Started
This lab is a pair-programming project. The code you write must run
on wilkes.cs.hmc.edu, a 64-bit x86-64 architecture machine. You
may work elsewhere, but you will need to ensure that your code runs
on wilkes and that it passes all tests there.
Getting the Starter Code
The starter code for this lab is already available on the server in
the directory /cs/cs105/labs/lab7-cachelab. The first step is to
get your own copy of the code to work on.
Run
mkdir -p ~/cs105
to create a cs105 directory to work in (skip if you already have one).
Then run
cd ~/cs105
cp -ai /cs/cs105/labs/lab7-cachelab .
cd lab7-cachelab
Familiarize Yourself with the Starter Code
For this lab you will be modifying one file, csim.c, which will contain your implementation of the cache simulator.
The included Makefile builds csim for you when you run make.
The provided code includes the following files:
README- An overview of the contents of the
tararchive. traces/(directory)- Contains a collection of memory trace files you'll use with your cache simulator.
cachelab.candcachelab.h- Required helper functions and header file.
csim-ref- A reference implementation of the cache simulator.
test-csim- A testing program for your cache simulator.
driver.py- The driver program that runs
test-csim driver.py- A testing program for
the assignment (it runs
test-csim).
(There are also a few other helper files (e.g., a Makefile); see
the README for more.)
Reference Trace Files
To test and debug the cache simulator you will build, you can run it
using the reference trace files in the traces directory. These
files will also be used to evaluate the correctness of your
simulator.
Each trace file describes the memory references made when a program was run. They were generated by the memory-debugging program Valgrind, which you may have used in CS 70.
Memory Trace Files
Valgrind memory traces have the following form:
I 0400d7d4,8
M 0421c7f0,4
L 04f6b868,8
S 7ff0005c8,8
Each line denotes one or two memory accesses; the format is
operation address ,size
The field denotes the type of memory access:
I |
instruction load |
L |
data load |
S |
data store |
M |
data modify (data load, then data store) |
Notice that while there is no space character () at the start of
instruction-load (I) lines, the other operations always have a
space character at the start of the line.
The field specifies a 64-bit hexadecimal memory
address.
The field specifies the number of bytes accessed by the
operation.
Generating Trace Files
Trace files are created with a set of special arguments to
valgrind that use its lackey tool to trace memory and log it to
stdout.
As an example, running Valgrind as
valgrind --log-fd=1 --tool=lackey -v --trace-mem=yes ls -l
causes Valgrind to send its output to stdout (--log-fd=1); then
runs lackey in verbose mode (--tool=lackey -v), telling it to
trace memory (--trace-mem=yes) on the program ls with its -l
flag.
Adding > tracefile.txt puts the output into the file
tracefile.txt that you can then use with your cache simulator.
(When logged in, completion status appears here.)