The main objective of this project is for you to learn about cache memories, their organization, and the impact of their design on program performance measured in terms of the memory subsystem. In this part, you will code a C program (cache.c), behaviorally simulating a single level cache. Your program will model a data cache with the following parameters
• S: the number of sets in the cache
• A: the associativity (or the number of entries in each set).
• B: the block size in bytes
• R: Replacement policy (R = 1 LRU, R=2 FIFO).
• W: Write policy (W = 1)
• -v Verbose
Your program will support the command line switches to create a cache of the specified parameters. For example,
loki> ./cache –S 512 –A 2 –B 32 –R 1 –W 1 -v
should create 8KB 2-way associative cache, with LRU replacement policy and print the cache (because of verbose switch).
Input: The input to your cache is a file containing memory trace of a C executable produced using the valgrind utility. For example, the following command should produce the trace for the program “ls”.
linux> valgrind --log-fd=1 --tool=lackey -v --trace-mem=yes ls -l
The memory trace file output by valgrind has the following format:
Each line is of the form:
The operation I: is an instruction load, L: a data load, S: a data store, and M: a data modify (i.e., a data load followed by a data store). There is never a space before an “I” and there is always a space before each “M”, “L”, and “S”. The address field specifies a 64-bit hex memory address and the size field specifies the number of bytes accessed by the operation.
Output: The program should print the cache in whatever format you choose when it is given a command line as described above.
The program should output the number of hits, misses and the number of evictions when it is given a valgrind trace with a –t switch as follows. Below, [url removed, login to view] is the trace file obtained using valgrind on some executable example.
linux> ./cache -S 16 -A 1 -B 4 –t [url removed, login to view]
hits:4 misses:5 evictions:3