cache-lab/README.org

3.1 KiB
Raw Permalink Blame History

cachelab

Writing a Cache Simulator

In Part A you will write a cache simulator in csim.c that takes a valgrind memory trace as input, simulates the hit/miss behavior of a cache memory on this trace, and outputs the total number of hits, misses, and evictions. We have provided you with the binary executable of a reference cache simulator, called csim-ref, that simulates the behavior of a cache with arbitrary size and associativity on a valgrind trace file. It uses the LRU (least-recently used) replacement policy when choosing which cache line to evict. The reference simulator takes the following command-line arguments:

  Usage: ./csim-ref [-hv] -s <s> -E <E> -b <b> -t <tracefile>
  • -h: Optional help flag that prints usage info
  • -v: Optional verbose flag that displays trace info
  • -s <s>: Number of set index bits (S = 2 s is the number of sets)
  • -E <E>: Associativity (number of lines per set)
  • -b <b>: Number of block bits (B = 2 b is the block size)
  • -t <tracefile>: Name of the valgrind trace to replay

The command-line arguments are based on the notation (s, E, and b) from the textbook. For example:

  $> ./csim-ref -s 4 -E 1 -b 4 -t traces/yi.trace
  hits:4 misses:5 evictions:3

The same example in verbose mode:

  $> ./csim-ref -v -s 4 -E 1 -b 4 -t traces/yi.trace
  L 10,1 miss
  M 20,1 miss hit
  L 22,1 hit
  S 18,1 hit
  L 110,1 miss eviction
  L 210,1 miss eviction
  M 12,1 miss eviction hit
  hits:4 misses:5 evictions:3

Your job for Part A is to fill in the csim.c file so that it takes the same command line arguments and produces the identical output as the reference simulator. Notice that this file is almost completely empty. Youll need to write it from scratch.

Programming Rules for Part A

  • Include the name of each group member in the header comment for csim.c.
  • Your csim.c file must compile without warnings in order to receive credit.
  • Your simulator must work correctly for arbitrary s, E, and b. This means that you will need to allocate storage for your simulators data structures using the malloc function. Type “man malloc” for information about this function.
  • For this lab, we are interested only in data cache performance, so your simulator should ignore all instruction cache accesses (lines starting with “I”). Recall that valgrind always puts “I” in the first column (with no preceding space), and “M”, “L”, and “S” in the second column (with a preceding space). This may help you parse the trace.
  • To receive credit for Part A, you must call the function printSummary, with the total number of hits, misses, and evictions, at the end of your main function: printSummary(hit_count, miss_count, eviction_count);
  • For this this lab, you should assume that memory accesses are aligned properly, such that a single memory access never crosses block boundaries. By making this assumption, you can ignore the request sizes in the valgrind traces.