summaryrefslogtreecommitdiff
path: root/src/mem
diff options
context:
space:
mode:
authorDaniel R. Carvalho <odanrc@yahoo.com.br>2018-03-09 15:04:20 +0100
committerDaniel Carvalho <odanrc@yahoo.com.br>2018-10-10 18:17:42 +0000
commitd204e56b2b9b8ad561fc258ebdc50ae8365159e1 (patch)
tree52783a7a32db7d055cb85e5454e6512c22cb2b1c /src/mem
parent99a6c94e58b6375c0d524530cab2a27b6ea0f2bc (diff)
downloadgem5-d204e56b2b9b8ad561fc258ebdc50ae8365159e1.tar.xz
mem-cache: Use possible locations to find block
Use possible locations to find block to make it placement policy independent. Change-Id: I4c9d9e1e1ff91ce12e85ca1970f927d8f4f5a93b Reviewed-on: https://gem5-review.googlesource.com/c/8884 Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Maintainer: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src/mem')
-rw-r--r--src/mem/cache/tags/base.cc29
-rw-r--r--src/mem/cache/tags/base.hh20
-rw-r--r--src/mem/cache/tags/base_set_assoc.cc17
-rw-r--r--src/mem/cache/tags/base_set_assoc.hh48
-rw-r--r--src/mem/cache/tags/sector_tags.cc29
-rw-r--r--src/mem/cache/tags/sector_tags.hh24
-rw-r--r--src/mem/cache/tags/skewed_assoc.cc13
-rw-r--r--src/mem/cache/tags/skewed_assoc.hh25
8 files changed, 120 insertions, 85 deletions
diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc
index 7f848e0d8..9358652bf 100644
--- a/src/mem/cache/tags/base.cc
+++ b/src/mem/cache/tags/base.cc
@@ -78,6 +78,35 @@ BaseTags::setCache(BaseCache *_cache)
cache = _cache;
}
+std::vector<ReplaceableEntry*>
+BaseTags::getPossibleLocations(const Addr addr) const
+{
+ panic("Unimplemented getPossibleLocations for tags subclass");
+}
+
+CacheBlk*
+BaseTags::findBlock(Addr addr, bool is_secure) const
+{
+ // Extract block tag
+ Addr tag = extractTag(addr);
+
+ // Find possible locations for the given address
+ const std::vector<ReplaceableEntry*> locations =
+ getPossibleLocations(addr);
+
+ // Search for block
+ for (const auto& location : locations) {
+ CacheBlk* blk = static_cast<CacheBlk*>(location);
+ if ((blk->tag == tag) && blk->isValid() &&
+ (blk->isSecure() == is_secure)) {
+ return blk;
+ }
+ }
+
+ // Did not find block
+ return nullptr;
+}
+
void
BaseTags::insertBlock(const Addr addr, const bool is_secure,
const int src_master_ID, const uint32_t task_ID,
diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh
index 385d25c9f..7badc46c2 100644
--- a/src/mem/cache/tags/base.hh
+++ b/src/mem/cache/tags/base.hh
@@ -161,6 +161,18 @@ class BaseTags : public ClockedObject
*/
void setCache(BaseCache *_cache);
+ /**
+ * Find all possible block locations for insertion and replacement of
+ * an address. Should be called immediately before ReplacementPolicy's
+ * findVictim() not to break cache resizing.
+ * Returns blocks in all ways belonging to the set of the address.
+ *
+ * @param addr The addr to a find possible locations for.
+ * @return The possible locations.
+ */
+ virtual std::vector<ReplaceableEntry*> getPossibleLocations(
+ const Addr addr) const;
+
public:
typedef BaseTagsParams Params;
BaseTags(const Params *p);
@@ -199,9 +211,13 @@ class BaseTags : public ClockedObject
std::string print();
/**
- * Find a block using the memory address
+ * Finds the block in the cache without touching it.
+ *
+ * @param addr The address to look for.
+ * @param is_secure True if the target memory space is secure.
+ * @return Pointer to the cache block.
*/
- virtual CacheBlk * findBlock(Addr addr, bool is_secure) const = 0;
+ virtual CacheBlk *findBlock(Addr addr, bool is_secure) const;
/**
* Find a block given set and way.
diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc
index 8bd65e03b..05712ec8f 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -84,14 +84,12 @@ BaseSetAssoc::init(BaseCache* cache)
// Initialize blocks
unsigned blkIndex = 0; // index into blks array
for (unsigned i = 0; i < numSets; ++i) {
- sets[i].assoc = assoc;
-
- sets[i].blks.resize(assoc);
+ sets[i].resize(assoc);
// link in the data blocks
for (unsigned j = 0; j < assoc; ++j) {
// Select block within the set to be linked
- BlkType*& blk = sets[i].blks[j];
+ BlkType*& blk = sets[i][j];
// Locate next cache block
blk = &blks[blkIndex];
@@ -128,19 +126,10 @@ BaseSetAssoc::invalidate(CacheBlk *blk)
replacementPolicy->invalidate(blk->replacementData);
}
-CacheBlk*
-BaseSetAssoc::findBlock(Addr addr, bool is_secure) const
-{
- Addr tag = extractTag(addr);
- unsigned set = extractSet(addr);
- BlkType *blk = sets[set].findBlk(tag, is_secure);
- return blk;
-}
-
ReplaceableEntry*
BaseSetAssoc::findBlockBySetAndWay(int set, int way) const
{
- return sets[set].blks[way];
+ return sets[set][way];
}
BaseSetAssoc *
diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh
index a3826499f..26cc6bcf0 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -59,7 +59,6 @@
#include "mem/cache/blk.hh"
#include "mem/cache/replacement_policies/base.hh"
#include "mem/cache/tags/base.hh"
-#include "mem/cache/tags/cacheset.hh"
#include "params/BaseSetAssoc.hh"
/**
@@ -76,7 +75,7 @@ class BaseSetAssoc : public BaseTags
/** Typedef the block type used in this tag store. */
typedef CacheBlk BlkType;
/** Typedef the set type used in this tag store. */
- typedef CacheSet<CacheBlk> SetType;
+ typedef std::vector<CacheBlk*> SetType;
protected:
/** The associativity of the cache. */
@@ -106,6 +105,25 @@ class BaseSetAssoc : public BaseTags
/** Replacement policy */
BaseReplacementPolicy *replacementPolicy;
+ /**
+ * Find all possible block locations for insertion and replacement of
+ * an address. Should be called immediately before ReplacementPolicy's
+ * findVictim() not to break cache resizing.
+ * Returns blocks in all ways belonging to the set of the address.
+ *
+ * @param addr The addr to a find possible locations for.
+ * @return The possible locations.
+ */
+ std::vector<ReplaceableEntry*> getPossibleLocations(const Addr addr) const
+ override
+ {
+ std::vector<ReplaceableEntry*> locations;
+ for (const auto& blk : sets[extractSet(addr)]) {
+ locations.push_back(static_cast<ReplaceableEntry*>(blk));
+ }
+ return locations;
+ }
+
public:
/** Convenience typedef. */
typedef BaseSetAssocParams Params;
@@ -187,16 +205,6 @@ class BaseSetAssoc : public BaseTags
}
/**
- * Finds the given address in the cache, do not update replacement data.
- * i.e. This is a no-side-effect find of a block.
- *
- * @param addr The address to find.
- * @param is_secure True if the target memory space is secure.
- * @return Pointer to the cache block if found.
- */
- CacheBlk* findBlock(Addr addr, bool is_secure) const override;
-
- /**
* Find a block given set and way.
*
* @param set The set of the block.
@@ -218,7 +226,7 @@ class BaseSetAssoc : public BaseTags
std::vector<CacheBlk*>& evict_blks) const override
{
// Get possible locations for the victim block
- std::vector<CacheBlk*> locations = getPossibleLocations(addr);
+ std::vector<ReplaceableEntry*> locations = getPossibleLocations(addr);
// Choose replacement victim from replacement candidates
CacheBlk* victim = static_cast<CacheBlk*>(replacementPolicy->getVictim(
@@ -235,20 +243,6 @@ class BaseSetAssoc : public BaseTags
}
/**
- * Find all possible block locations for insertion and replacement of
- * an address. Should be called immediately before ReplacementPolicy's
- * findVictim() not to break cache resizing.
- * Returns blocks in all ways belonging to the set of the address.
- *
- * @param addr The addr to a find possible locations for.
- * @return The possible locations.
- */
- virtual const std::vector<CacheBlk*> getPossibleLocations(Addr addr) const
- {
- return sets[extractSet(addr)].blks;
- }
-
- /**
* Insert the new block into the cache and update replacement data.
*
* @param addr Address of the block.
diff --git a/src/mem/cache/tags/sector_tags.cc b/src/mem/cache/tags/sector_tags.cc
index 988fda540..ef3fec2b9 100644
--- a/src/mem/cache/tags/sector_tags.cc
+++ b/src/mem/cache/tags/sector_tags.cc
@@ -194,10 +194,14 @@ SectorTags::accessBlock(Addr addr, bool is_secure, Cycles &lat)
return blk;
}
-const std::vector<SectorBlk*>
-SectorTags::getPossibleLocations(Addr addr) const
+std::vector<ReplaceableEntry*>
+SectorTags::getPossibleLocations(const Addr addr) const
{
- return sets[extractSet(addr)];
+ std::vector<ReplaceableEntry*> locations;
+ for (const auto& blk : sets[extractSet(addr)]) {
+ locations.push_back(static_cast<ReplaceableEntry*>(blk));
+ }
+ return locations;
}
void
@@ -238,11 +242,12 @@ SectorTags::findBlock(Addr addr, bool is_secure) const
const Addr offset = extractSectorOffset(addr);
// Find all possible sector locations for the given address
- const std::vector<SectorBlk*> locations = getPossibleLocations(addr);
+ const std::vector<ReplaceableEntry*> locations =
+ getPossibleLocations(addr);
// Search for block
for (const auto& sector : locations) {
- auto blk = sector->blks[offset];
+ auto blk = static_cast<SectorBlk*>(sector)->blks[offset];
if (blk->getTag() == tag && blk->isValid() &&
blk->isSecure() == is_secure) {
return blk;
@@ -264,16 +269,17 @@ SectorTags::findVictim(Addr addr, const bool is_secure,
std::vector<CacheBlk*>& evict_blks) const
{
// Get all possible locations of this sector
- const std::vector<SectorBlk*> sector_locations =
+ const std::vector<ReplaceableEntry*> sector_locations =
getPossibleLocations(addr);
// Check if the sector this address belongs to has been allocated
Addr tag = extractTag(addr);
SectorBlk* victim_sector = nullptr;
- for (const auto& sector : sector_locations){
- if ((tag == sector->getTag()) && sector->isValid() &&
- (is_secure == sector->isSecure())){
- victim_sector = sector;
+ for (const auto& sector : sector_locations) {
+ SectorBlk* sector_blk = static_cast<SectorBlk*>(sector);
+ if ((tag == sector_blk->getTag()) && sector_blk->isValid() &&
+ (is_secure == sector_blk->isSecure())){
+ victim_sector = sector_blk;
break;
}
}
@@ -282,8 +288,7 @@ SectorTags::findVictim(Addr addr, const bool is_secure,
if (victim_sector == nullptr){
// Choose replacement victim from replacement candidates
victim_sector = static_cast<SectorBlk*>(replacementPolicy->getVictim(
- std::vector<ReplaceableEntry*>(
- sector_locations.begin(), sector_locations.end())));
+ sector_locations));
}
// Get the location of the victim block within the sector
diff --git a/src/mem/cache/tags/sector_tags.hh b/src/mem/cache/tags/sector_tags.hh
index 7a2cddae9..c3c3bc8f9 100644
--- a/src/mem/cache/tags/sector_tags.hh
+++ b/src/mem/cache/tags/sector_tags.hh
@@ -100,6 +100,18 @@ class SectorTags : public BaseTags
/** Mask out all bits that aren't part of the set index. */
const unsigned setMask;
+ /**
+ * Find all possible block locations for insertion and replacement of
+ * an address. Should be called immediately before ReplacementPolicy's
+ * findVictim() not to break cache resizing.
+ * Returns sector blocks in all ways belonging to the set of the address.
+ *
+ * @param addr The addr to a find possible locations for.
+ * @return The possible locations.
+ */
+ std::vector<ReplaceableEntry*> getPossibleLocations(const Addr addr) const
+ override;
+
public:
/** Convenience typedef. */
typedef SectorTagsParams Params;
@@ -143,18 +155,6 @@ class SectorTags : public BaseTags
CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override;
/**
- * Find all possible block locations for insertion and replacement of
- * an address. Should be called immediately before ReplacementPolicy's
- * findVictim() not to break cache resizing.
- * Returns sector blocks in all ways belonging to the set of the address.
- *
- * @param addr The addr to a find possible locations for.
- * @return The possible locations.
- */
- virtual const std::vector<SectorBlk*> getPossibleLocations(Addr addr)
- const;
-
- /**
* Insert the new block into the cache and update replacement data.
*
* @param addr Address of the block.
diff --git a/src/mem/cache/tags/skewed_assoc.cc b/src/mem/cache/tags/skewed_assoc.cc
index b3945d0c4..89ab61588 100644
--- a/src/mem/cache/tags/skewed_assoc.cc
+++ b/src/mem/cache/tags/skewed_assoc.cc
@@ -204,15 +204,15 @@ SkewedAssoc::regenerateBlkAddr(const CacheBlk* blk) const
return (blk->tag << tagShift) | (set << setShift);
}
-const std::vector<CacheBlk*>
-SkewedAssoc::getPossibleLocations(Addr addr) const
+std::vector<ReplaceableEntry*>
+SkewedAssoc::getPossibleLocations(const Addr addr) const
{
- std::vector<CacheBlk*> locations;
+ std::vector<ReplaceableEntry*> locations;
// Parse all ways
for (int way = 0; way < assoc; ++way) {
// Apply hash to get set, and get way entry in it
- locations.push_back(sets[extractSet(addr, way)].blks[way]);
+ locations.push_back(sets[extractSet(addr, way)][way]);
}
return locations;
@@ -225,10 +225,11 @@ SkewedAssoc::findBlock(Addr addr, bool is_secure) const
Addr tag = extractTag(addr);
// Find possible locations for the given address
- std::vector<CacheBlk*> locations = getPossibleLocations(addr);
+ std::vector<ReplaceableEntry*> locations = getPossibleLocations(addr);
// Search for block
- for (const auto& blk : locations) {
+ for (const auto& location : locations) {
+ CacheBlk* blk = static_cast<CacheBlk*>(location);
if ((blk->tag == tag) && blk->isValid() &&
(blk->isSecure() == is_secure)) {
return blk;
diff --git a/src/mem/cache/tags/skewed_assoc.hh b/src/mem/cache/tags/skewed_assoc.hh
index 9fc39e297..597c32fcd 100644
--- a/src/mem/cache/tags/skewed_assoc.hh
+++ b/src/mem/cache/tags/skewed_assoc.hh
@@ -120,6 +120,19 @@ class SkewedAssoc : public BaseSetAssoc
*/
unsigned extractSet(Addr addr, unsigned way) const;
+ protected:
+ /**
+ * Find all possible block locations for insertion and replacement of
+ * an address. Should be called immediately before ReplacementPolicy's
+ * findVictim() not to break cache resizing.
+ * Returns blocks in all ways belonging to the set of the address.
+ *
+ * @param addr The addr to a find possible locations for.
+ * @return The possible locations.
+ */
+ std::vector<ReplaceableEntry*> getPossibleLocations(const Addr addr) const
+ override;
+
public:
/** Convenience typedef. */
typedef SkewedAssocParams Params;
@@ -135,18 +148,6 @@ class SkewedAssoc : public BaseSetAssoc
~SkewedAssoc() {};
/**
- * Find all possible block locations for insertion and replacement of
- * an address. Should be called immediately before ReplacementPolicy's
- * findVictim() not to break cache resizing.
- * Returns blocks in all ways belonging to the set of the address.
- *
- * @param addr The addr to a find possible locations for.
- * @return The possible locations.
- */
- const std::vector<CacheBlk*> getPossibleLocations(Addr addr) const
- override;
-
- /**
* Finds the given address in the cache, do not update replacement data.
* i.e. This is a no-side-effect find of a block.
*