mem-cache: Create tags initialization function

Having the blocks initialized in the constructor makes it harder
to apply inheritance in the tags classes. This patch decouples
the block initialization functionality from the constructor by
using an init() function. It also sets the parent cache.

Change-Id: I0da7fdaae492b1177c7cc3bda8639f79921fbbeb
Reviewed-on: https://gem5-review.googlesource.com/c/11509
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
Daniel R. Carvalho
2018-06-21 16:57:37 +02:00
committed by Daniel Carvalho
parent 86a54d9193
commit 99a6c94e58
8 changed files with 61 additions and 8 deletions

View File

@@ -115,7 +115,7 @@ BaseCache::BaseCache(const BaseCacheParams *p, unsigned blk_size)
tempBlock = new TempCacheBlk(blkSize);
tags->setCache(this);
tags->init(this);
if (prefetcher)
prefetcher->setCache(this);
}

View File

@@ -154,6 +154,13 @@ class BaseTags : public ClockedObject
* @}
*/
/**
* Set the parent cache back pointer.
*
* @param _cache Pointer to parent cache.
*/
void setCache(BaseCache *_cache);
public:
typedef BaseTagsParams Params;
BaseTags(const Params *p);
@@ -164,10 +171,11 @@ class BaseTags : public ClockedObject
virtual ~BaseTags() {}
/**
* Set the parent cache back pointer.
* Initialize blocks and set the parent cache back pointer.
*
* @param _cache Pointer to parent cache.
*/
void setCache(BaseCache *_cache);
virtual void init(BaseCache *_cache) = 0;
/**
* Register local statistics.

View File

@@ -73,7 +73,15 @@ BaseSetAssoc::BaseSetAssoc(const Params *p)
setShift = floorLog2(blkSize);
setMask = numSets - 1;
tagShift = setShift + floorLog2(numSets);
}
void
BaseSetAssoc::init(BaseCache* cache)
{
// Set parent cache
setCache(cache);
// Initialize blocks
unsigned blkIndex = 0; // index into blks array
for (unsigned i = 0; i < numSets; ++i) {
sets[i].assoc = assoc;

View File

@@ -120,6 +120,13 @@ class BaseSetAssoc : public BaseTags
*/
virtual ~BaseSetAssoc() {};
/**
* Initialize blocks and set the parent cache back pointer.
*
* @param _cache Pointer to parent cache.
*/
void init(BaseCache *_cache) override;
/**
* This function updates the tags when a block is invalidated. It also
* updates the replacement data.

View File

@@ -69,6 +69,18 @@ FALRU::FALRU(const Params *p)
fatal("Cache Size must be power of 2 for now");
blks = new FALRUBlk[numBlocks];
}
FALRU::~FALRU()
{
delete[] blks;
}
void
FALRU::init(BaseCache* cache)
{
// Set parent cache
setCache(cache);
head = &(blks[0]);
head->prev = nullptr;
@@ -97,11 +109,6 @@ FALRU::FALRU(const Params *p)
cacheTracking.init(head, tail);
}
FALRU::~FALRU()
{
delete[] blks;
}
void
FALRU::regStats()
{

View File

@@ -68,6 +68,7 @@
// TrackedCaches class
//#define FALRU_DEBUG
class BaseCache;
class ReplaceableEntry;
// A bitmask of the caches we are keeping track of. Currently the
@@ -150,6 +151,13 @@ class FALRU : public BaseTags
FALRU(const Params *p);
~FALRU();
/**
* Initialize blocks and set the parent cache back pointer.
*
* @param _cache Pointer to parent cache.
*/
void init(BaseCache *_cache) override;
/**
* Register the stats for this object.
*/

View File

@@ -67,6 +67,13 @@ SectorTags::SectorTags(const SectorTagsParams *p)
fatal_if(!isPowerOf2(numBlocksPerSector),
"# of blocks per sector must be non-zero and a power of 2");
fatal_if(assoc <= 0, "associativity must be greater than zero");
}
void
SectorTags::init(BaseCache* cache)
{
// Set parent cache
setCache(cache);
// Initialize all sets
unsigned sec_blk_index = 0; // index into sector blks array

View File

@@ -43,6 +43,7 @@
#include "mem/cache/tags/base.hh"
#include "params/SectorTags.hh"
class BaseCache;
class BaseReplacementPolicy;
class ReplaceableEntry;
@@ -113,6 +114,13 @@ class SectorTags : public BaseTags
*/
virtual ~SectorTags() {};
/**
* Initialize blocks and set the parent cache back pointer.
*
* @param _cache Pointer to parent cache.
*/
void init(BaseCache *_cache) override;
/**
* This function updates the tags when a block is invalidated but does
* not invalidate the block itself. It also updates the replacement data.