Cache is setup as a vector of Sets, each set is a vector of CacheBlock.
CacheBlock stores the attributes of validBit, dirtyBit, tagBits and its Index in the Set.
Sets along with the CacheBlock vector, store data relevant for implementation of eviction strategies.
• number of sets in the cache (a positive power-of-2)
• number of blocks in each set (a positive power-of-2)
• number of bytes in each block (a positive power-of-2, at least 4 )
• write-allocate or no-write-allocate
• write-through or write-back
• lru (least-recently-used) or fifo evictions
- Compulsory Load Misses require readFromMemory.
- Load Misses are allocated memory in Cache based on eviction strategy.
- Load Misses requiring to write over a CacheBlock that has dirtyBit set as true requires writeToMemory.
- Store Hits in case of writeThrough requires a writeToMemory.
- Store Hits in case of writeBacck requires only setting dirtyBit.
- Store Misses with no-write-allocate does a writeToMemory.
- Store Misses with write-allocate works with both write-through and write-back.
- fifo uses a simple queue storing index information for each Set.
- LRU is implemented using linked-list and unordered_map that are maintained for each CacheBlock in all Sets.
- fifo and LRU implementation in store and load remains similar.
- after all lines of the program are over, cache is checked for any dirty-bits remaining which are pushed into the memory when found. This ensures no data-hazards occur due to mismatch of data in cache and main memory.
-
In case of a load/store hit with that particular CacheBlock having dirtyBit, data is not written in Memory at that time to save cycles.
-
LRU uses linked-list approach of a queue like data-structure.
To compile and create executable:
make
To run the executable with cache parameters (change the parameters and input file as required):
./cacheSim 256 64 16 write-allocate write-through fifo < testgen.txt
To clean the object and executable files:
make clean
This implementation of CacheSimulator has been rigorously tested with simple hand-written testcases as well as automated Big-Test-Cases.
All trace-files have also been run.