From 99a6c94e58b6375c0d524530cab2a27b6ea0f2bc Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Thu, 21 Jun 2018 16:57:37 +0200 Subject: [PATCH] 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 Reviewed-by: Nikos Nikoleris Maintainer: Jason Lowe-Power --- src/mem/cache/base.cc | 2 +- src/mem/cache/tags/base.hh | 12 ++++++++++-- src/mem/cache/tags/base_set_assoc.cc | 8 ++++++++ src/mem/cache/tags/base_set_assoc.hh | 7 +++++++ src/mem/cache/tags/fa_lru.cc | 17 ++++++++++++----- src/mem/cache/tags/fa_lru.hh | 8 ++++++++ src/mem/cache/tags/sector_tags.cc | 7 +++++++ src/mem/cache/tags/sector_tags.hh | 8 ++++++++ 8 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc index 6c79fd683..736f16761 100644 --- a/src/mem/cache/base.cc +++ b/src/mem/cache/base.cc @@ -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); } diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh index 30a7af72c..385d25c9f 100644 --- a/src/mem/cache/tags/base.hh +++ b/src/mem/cache/tags/base.hh @@ -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. diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc index 18da53273..8bd65e03b 100644 --- a/src/mem/cache/tags/base_set_assoc.cc +++ b/src/mem/cache/tags/base_set_assoc.cc @@ -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; diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh index dc0e04275..a3826499f 100644 --- a/src/mem/cache/tags/base_set_assoc.hh +++ b/src/mem/cache/tags/base_set_assoc.hh @@ -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. diff --git a/src/mem/cache/tags/fa_lru.cc b/src/mem/cache/tags/fa_lru.cc index 1b43e9892..d35e37c7b 100644 --- a/src/mem/cache/tags/fa_lru.cc +++ b/src/mem/cache/tags/fa_lru.cc @@ -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() { diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh index c8ccc66f3..0d9a8d440 100644 --- a/src/mem/cache/tags/fa_lru.hh +++ b/src/mem/cache/tags/fa_lru.hh @@ -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. */ diff --git a/src/mem/cache/tags/sector_tags.cc b/src/mem/cache/tags/sector_tags.cc index 76034e1ea..988fda540 100644 --- a/src/mem/cache/tags/sector_tags.cc +++ b/src/mem/cache/tags/sector_tags.cc @@ -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 diff --git a/src/mem/cache/tags/sector_tags.hh b/src/mem/cache/tags/sector_tags.hh index 109b9832b..7a2cddae9 100644 --- a/src/mem/cache/tags/sector_tags.hh +++ b/src/mem/cache/tags/sector_tags.hh @@ -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. -- 2.30.2