This project simulates a basic cache snooping protocol in a multiprocessor system. It demonstrates how multiple CPU cores with private caches interact with a shared memory through a bus, maintaining cache coherence.
- Memory.java: Represents the main memory as a map from addresses to data.
- CoreCache.java: Simulates a private cache for each core, storing cache lines as address-data pairs.
- Bus.java: Acts as the communication medium between caches and memory. It handles read and write transactions, checks caches for data, and updates memory and all caches on writes.
-
Read Operation:
- The bus checks all core caches for the requested address.
- If found in any cache, it returns the cached data.
- If not found, it reads from memory.
-
Write Operation:
- The bus writes the data to memory.
- It then updates all core caches with the new data for the given address, simulating a snooping protocol where all caches observe the write.
- Create a
Businstance with a transaction ID, data, address, and operation ("READ" or "WRITE"). - Add core caches to the bus using
addCoreCaches(coreId). - Use
checkOperation()to perform the transaction (read or write).
- This is a simplified simulation for educational purposes. It does not implement advanced cache coherence protocols (like MESI), but demonstrates the basic idea of snooping and cache updates.
- The simulation uses
Longfor addresses andbyte[]for data, but can be adapted for other types.
- Java 8 or higher
Compile all Java files:
javac CacheSnooping/*.java