04-04-09-Cache

From Msim

Jump to: navigation, search

This refers to the fixes to cache.c and cache.h to adjust cache_access to return an unsigned long long, and remove the need for the BOUND_POS macro


In cache.h, the cache_access prototype now returns unsigned long long instead of unsigned int:

unsigned int                      /* latency of access in cycles */
cache_access(mem_cmd cmd,               /* access type, Read or Write */

Now:

unsigned long long                      /* latency of access in cycles */
cache_access(mem_cmd cmd,               /* access type, Read or Write */

In cache.c, the appropriate changes were made: Old:

unsigned int cache_t::cache_access(mem_cmd cmd,

New:

unsigned long long cache_t::cache_access(mem_cmd cmd,

Old:

int lat = 0;

New:

long long lat = 0;

The following also removes the BOUND_POS macro (#define BOUND_POS(N) ((int)(MIN(MAX(0, (N)), 2147483647))). This is no longer needed since the overflow issue can be handled by long long.
Write-on-eviction is always a write to the next level cache, it should never be able to be a read.
Old:

 //write back replaced block data
if(repl->status & CACHE_BLK_VALID)
{
 replacements++;
 
 if(repl_addr)
  *repl_addr = CACHE_MK_BADDR(this, repl->tag, set);
 
 //don't replace the block until outstanding misses are satisfied
 lat += BOUND_POS(repl->ready - now);
 
 //stall until the bus to next level of memory is available
 lat += BOUND_POS(bus_free - (now + lat));
 
 //track bus resource usage
 bus_free = MAX(bus_free, (now + lat)) + 1;
 
 if(repl->status & CACHE_BLK_DIRTY)
 {
  //write back the cache block
  writebacks++;
  lat += blk_access_fn(cmd, CACHE_MK_BADDR(this, repl->tag, set), bsize, repl, now+lat, context_id);
 }
}

New:

//write back replaced block data
if(repl->status & CACHE_BLK_VALID)
{
 replacements++;
 
 if(repl_addr)
  *repl_addr = CACHE_MK_BADDR(this, repl->tag, set);
 
 //don't replace the block until outstanding misses are satisfied
 lat += MAX(0, repl->ready - now);
 
 //stall until the bus to next level of memory is available
 lat += MAX(0, bus_free - (now + lat));
 
 //track bus resource usage
 bus_free = 1 + MAX(bus_free, (tick_t)(now + lat));
 
 if(repl->status & CACHE_BLK_DIRTY)
 {
  //write back the cache block
  writebacks++;
  lat += blk_access_fn(Write, CACHE_MK_BADDR(this, repl->tag, set), bsize, repl, now+lat, context_id);
 }
}
Personal tools