This project explores cache coherence protocols in parallel architectures by simulating a 4-processor system. The simulator is designed to evaluate and compare the MESI and MOESI coherence protocols. I plan to extend this for other Bus and Directory-based protocols as well. The implementation tracks key statistics such as cache hits, misses, memory transactions, and coherence signals, providing insights into the performance and efficiency of these protocols.
- Develop a simulator to evaluate cache coherence protocols in a multiprocessor system.
- Analyze performance metrics including cache hits, misses, memory transactions, and invalidations.
- Compare the optimizations offered by MESI and MOESI protocols in reducing memory and bus transactions.
The project directory is organized as follows:
src/- Contains the starter source code:cache.cc: Implements basic cache behavior.cache.h: Defines cache parameters and methods.main.cc: Contains the main program logic.Makefile: Compilation instructions.
trace/- Memory access traces.val/- Validation outputs for provided traces.outputs/- Terminal outputs for better debugging.
The simulator models a system where each processor has an infinite-size L1 cache with a block size of 64 bytes. The provided starter code includes the following components:
The Cache class simulates the behavior of a single cache. It implements basic cache methods and states. To support coherence, new methods such as Access() and Snoop() can be introduced or modified as required.
Memory traces represent transactions by processors and include:
- Processor ID (0-3)
- Operation (
rfor read,wfor write) - Address (in hexadecimal)
Example:
5 w 0xabcd
This indicates processor 5 is writing to address 0xabcd. The cache must handle this request and maintain coherence.
Two sample traces are provided:
canneal.04t.debug(10,000 trace)canneal.04t.longTrace(500,000 trace)
The simulator outputs the following statistics:
- Number of reads
- Number of read misses
- Number of writes
- Number of write misses
- Number of write hits
- Number of read hits
- Total miss rate
- Number of memory accesses (excluding writebacks)
- Number of invalidations
- Number of flushes
- Total program execution time
You can edit the class structure and add support for more statistics as you please. Take a deeper look at src/cache.h
Navigate to the src/ directory and compile the code using the provided Makefile:
make clean # Clean previous builds
make # Compile the simulatorRun the following commands to execute the simulator:
make test_mesi: Run the MESI protocol simulation.make test_moesi: Run the MOESI protocol simulation.
Both commands are preconfigured for experimentation. Modify the traces for debugging or extended tests as needed. Also feel free to create your own traces. (highly recommended)
- Thoroughly study the starter code, especially
cache.ccandcache.h. - Implement the MESI and MOESI protocols by overriding or extending the
Access()method. - Use protocol-specific counters, states, and methods for tracking coherence.
- Define an array of caches to represent the multi-processor system.
- Optimize the implementation to reduce memory and bus transactions.
- Validate results against the provided outputs in the
val/directory usingmake val. (this hasn't been implemented yet. just manually compare outputs for now) - Depending on your implementation, the metrics can have different values. The best stats I could achieve are recorded in the
outputs/folder. Do let me know if you manage to optimize the numbers further.
This project provides a hands-on approach to understanding cache coherence protocols in parallel systems. By implementing and analyzing coherence protocols, the simulator highlights the trade-offs between memory and bus optimizations. The results offer valuable insights into designing efficient cache systems for modern parallel architectures.
- Source Code:
src/ - Traces: Memory traces for debugging and testing.
- Validation: Pre-computed outputs for result comparison.
- Outputs: My personal best metrics achieved.
Feel free to contribute to this project or use it as a reference for exploring cache coherence protocols.