I am trying to design a cache simulator. To find there is a cache hit/miss for a block, I compare its index and offset with the blocks already present in the cache. In case of n-associative cache, I check only those entries of cache where that block can go.
Finding the number of hits and cold misses is then trivial. If the cache is full (or all the entries where the block can go are occupied), then we have a capacity miss.
Could someone please tell me how can I find the number of conflict misses? Definition of conflict miss says:
Conflict misses are those misses that could have been avoided,
had the cache not evicted an entry earlier
How can I determine if an entry, removed from the cache earlier, should or should not have been removed?
The value is expressed as a percentage: The miss rate is similar in form: the total cache misses divided by the total number of memory requests expressed as a percentage over a time interval. Note that the miss rate also equals 100 minus the hit rate.
Conflict Miss – It is also known as collision misses or interference misses. These misses occur when several blocks are mapped to the same set or block frame. These misses occur in the set associative or direct mapped block placement strategies.
Cache misses can be reduced by changing capacity, block size, and/or associativity. The first step to reducing the miss rate is to understand the causes of the misses. The misses can be classified as compulsory, capacity, and conflict.
Conceptually this is how you can measure the types of misses:
measure the number of misses (M) for the same code for the following caches:
then
When actually implementing these measurements in your simulator, you need not run three different simulations. The misses to a hash map as described by Leeor gives you M1. Now if you implement your hash map as a list(or some more efficient data structure) such that you never delete an entry, but whenever an access is made to address 'x' put 'x' in the front of the list. Whenever a reference is made and it hits in the first 'S' locations in your list(where S is the size of your cache), it can be counted as a HIT for cache number 1 and 2. The actual cache simulation (modeling N-way cache) gives you M3. So the actual cache model plus this list data structure gives you M1, M2, M3 in a single simulation run.
You can store all historical addresses in a hashmap and do lookups whenever you miss - if you miss the cache but hit in the hash - you evicted that line at some point.
This however can grow in size quite rapidly. In most cases though, it's more interesting to ask "could i have kept the line cached just a little while longer and avoid this miss?". For that, you could extend your cache simulation to have more ways (up to the history depth you determine is still realistic to keep lines at). You lookup your cache like before, and maintain the same LRU method you would have used, but if the way being hit is beyond the "real" way count in terms of LRU age - it's a conflict miss (i.e. - the line was there, but pushed back the LRU chain beyond a point it should have been evicted). Make sure your LRU mechanism can work this way - a true LRU should be ok as it keeps a strict order, age-value based ones are also fine, but other types like pseudo LRU trees might get tricky.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With