Daniel Carvalho has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/12764
Change subject: mem-cache: Substitute set and way by index
......................................................................
mem-cache: Substitute set and way by index
As of now we assume that all blocks belong to a set associative
cache. This isn't always the case, as other placement policies
can be implemented that are not aware of the concept of sets or
ways.
All replaceable entries belong to a table, so substitute these
variables by an index in this table.
Change-Id: If0e3dacf9ea2f523af9cface067469ccecf82648
---
M src/mem/cache/blk.hh
M src/mem/cache/replacement_policies/base.hh
M src/mem/cache/tags/base.cc
M src/mem/cache/tags/base_set_assoc.cc
M src/mem/cache/tags/base_set_assoc.hh
M src/mem/cache/tags/fa_lru.cc
M src/mem/cache/tags/sector_tags.cc
M src/mem/cache/tags/sector_tags.hh
M src/mem/cache/tags/skewed_assoc.cc
M src/mem/cache/tags/skewed_assoc.hh
10 files changed, 103 insertions(+), 33 deletions(-)
diff --git a/src/mem/cache/blk.hh b/src/mem/cache/blk.hh
index 3bb0317..cc6d905 100644
--- a/src/mem/cache/blk.hh
+++ b/src/mem/cache/blk.hh
@@ -108,12 +108,6 @@
/** Which curTick() will this block be accessible */
Tick whenReady;
- /**
- * The set and way this block belongs to.
- * @todo Move this into subclasses when we fix CacheTags to use them.
- */
- int set, way;
-
/** Number of references to this block since it was brought in. */
unsigned refCount;
diff --git a/src/mem/cache/replacement_policies/base.hh
b/src/mem/cache/replacement_policies/base.hh
index 0ce86d0..7897ba4 100644
--- a/src/mem/cache/replacement_policies/base.hh
+++ b/src/mem/cache/replacement_policies/base.hh
@@ -50,12 +50,33 @@
*/
class ReplaceableEntry
{
- public:
+ private:
/**
- * Replacement data associated to this entry.
- * It is instantiated by the replacement policy.
+ * Every entry has a correspondent position in a table. This index can
be
+ * decomposed into placement policy-specific information.
*/
- std::shared_ptr<ReplacementData> replacementData;
+ Addr _index;
+
+ public:
+ /**
+ * Replacement data associated to this entry.
+ * It is instantiated by the replacement policy.
+ */
+ std::shared_ptr<ReplacementData> replacementData;
+
+ /**
+ * Set index value. Should be set only once.
+ *
+ * @param index The index of this entry.
+ */
+ void setIndex(const Addr index) { _index = index; }
+
+ /**
+ * Get index value.
+ *
+ * @return The index of this entry.
+ */
+ Addr getIndex() const { return _index; }
};
/**
diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc
index 452388f..d786046 100644
--- a/src/mem/cache/tags/base.cc
+++ b/src/mem/cache/tags/base.cc
@@ -188,8 +188,7 @@
auto print_blk = [&str](CacheBlk &blk) {
if (blk.isValid())
- str += csprintf("\tset: %d way: %d %s\n", blk.set, blk.way,
- blk.print());
+ str += csprintf("\tindex: %x %s\n", blk.getIndex(),
blk.print());
};
forEachBlk(print_blk);
diff --git a/src/mem/cache/tags/base_set_assoc.cc
b/src/mem/cache/tags/base_set_assoc.cc
index 05712ec..0d74eb9 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -104,9 +104,8 @@
// hash table; won't matter because the block is invalid
blk->tag = j;
- // Set its set and way
- blk->set = i;
- blk->way = j;
+ // Set its index
+ blk->setIndex(blkIndex);
// Update block index
++blkIndex;
@@ -132,6 +131,12 @@
return sets[set][way];
}
+Addr
+BaseSetAssoc::getSetFromIndex(const Addr index) const
+{
+ return (index / assoc) & setMask;
+}
+
BaseSetAssoc *
BaseSetAssocParams::create()
{
diff --git a/src/mem/cache/tags/base_set_assoc.hh
b/src/mem/cache/tags/base_set_assoc.hh
index e3516ee..886c735 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -217,8 +217,8 @@
// There is only one eviction for this replacement
evict_blks.push_back(victim);
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for
replacement\n",
- victim->set, victim->way);
+ DPRINTF(CacheRepl, "index %x: selecting blk for replacement\n",
+ victim->getIndex());
return victim;
}
@@ -295,6 +295,14 @@
}
/**
+ * Get set given an entry index.
+ *
+ * @param index The index of the entry.
+ * @return The set to which this index belongs.
+ */
+ Addr getSetFromIndex(const Addr index) const;
+
+ /**
* Regenerate the block address from the tag and set.
*
* @param block The block.
@@ -302,7 +310,8 @@
*/
Addr regenerateBlkAddr(const CacheBlk* blk) const override
{
- return ((blk->tag << tagShift) | ((Addr)blk->set << setShift));
+ const Addr set = getSetFromIndex(blk->getIndex()) << setShift;
+ return ((blk->tag << tagShift) | set);
}
void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
diff --git a/src/mem/cache/tags/fa_lru.cc b/src/mem/cache/tags/fa_lru.cc
index 4abfae4..3739994 100644
--- a/src/mem/cache/tags/fa_lru.cc
+++ b/src/mem/cache/tags/fa_lru.cc
@@ -83,15 +83,13 @@
head = &(blks[0]);
head->prev = nullptr;
head->next = &(blks[1]);
- head->set = 0;
- head->way = 0;
+ head->setIndex(0);
head->data = &dataBlks[0];
for (unsigned i = 1; i < numBlocks - 1; i++) {
blks[i].prev = &(blks[i-1]);
blks[i].next = &(blks[i+1]);
- blks[i].set = 0;
- blks[i].way = i;
+ blks[i].setIndex(i);
// Associate a data chunk to the block
blks[i].data = &dataBlks[blkSize*i];
@@ -100,8 +98,7 @@
tail = &(blks[numBlocks - 1]);
tail->prev = &(blks[numBlocks - 2]);
tail->next = nullptr;
- tail->set = 0;
- tail->way = numBlocks - 1;
+ tail->setIndex(numBlocks - 1);
tail->data = &dataBlks[(numBlocks - 1) * blkSize];
cacheTracking.init(head, tail);
diff --git a/src/mem/cache/tags/sector_tags.cc
b/src/mem/cache/tags/sector_tags.cc
index 9bf5ea7..6a47db7 100644
--- a/src/mem/cache/tags/sector_tags.cc
+++ b/src/mem/cache/tags/sector_tags.cc
@@ -92,6 +92,9 @@
// Associate a replacement data entry to the sector
sec_blk->replacementData =
replacementPolicy->instantiateEntry();
+ // Set its index
+ sec_blk->setIndex(sec_blk_index);
+
// Initialize all blocks in this sector
sec_blk->blks.resize(numBlocksPerSector);
for (unsigned k = 0; k < numBlocksPerSector; ++k){
@@ -110,9 +113,8 @@
// Associate the sector replacement data to this block
blk->replacementData = sec_blk->replacementData;
- // Set its set, way and sector offset
- blk->set = i;
- blk->way = j;
+ // Set its index and sector offset
+ blk->setIndex(blk_index);
blk->setSectorOffset(k);
// Update block index
@@ -308,9 +310,8 @@
}
}
- DPRINTF(CacheRepl, "set %x, way %x, sector offset %x: %s\n",
- "selecting blk for replacement\n", victim->set, victim->way,
- victim->getSectorOffset());
+ DPRINTF(CacheRepl, "index %x, sector offset %x: selecting blk for " \
+ "replacement\n", victim->getIndex(),
victim->getSectorOffset());
return victim;
}
@@ -334,10 +335,17 @@
}
Addr
+SectorTags::getSetFromIndex(const Addr index) const
+{
+ return (index / assoc) & setMask;
+}
+
+Addr
SectorTags::regenerateBlkAddr(const CacheBlk* blk) const
{
const SectorSubBlk* blk_cast = static_cast<const SectorSubBlk*>(blk);
- return ((blk_cast->getTag() << tagShift) | ((Addr)blk->set <<
setShift) |
+ const Addr set =
getSetFromIndex(blk_cast->getSectorBlock()->getIndex());
+ return ((blk_cast->getTag() << tagShift) | (set << setShift) |
((Addr)blk_cast->getSectorOffset() << sectorShift));
}
diff --git a/src/mem/cache/tags/sector_tags.hh
b/src/mem/cache/tags/sector_tags.hh
index cae2d2d..6f34db3 100644
--- a/src/mem/cache/tags/sector_tags.hh
+++ b/src/mem/cache/tags/sector_tags.hh
@@ -222,6 +222,14 @@
int extractSectorOffset(Addr addr) const;
/**
+ * Get set given an entry index.
+ *
+ * @param index The index of the entry.
+ * @return The set to which this index belongs.
+ */
+ Addr getSetFromIndex(const Addr index) const;
+
+ /**
* Regenerate the block address from the tag and set.
*
* @param block The block.
diff --git a/src/mem/cache/tags/skewed_assoc.cc
b/src/mem/cache/tags/skewed_assoc.cc
index 6b4ece6..a92da3b 100644
--- a/src/mem/cache/tags/skewed_assoc.cc
+++ b/src/mem/cache/tags/skewed_assoc.cc
@@ -197,10 +197,23 @@
}
Addr
+SkewedAssoc::getSetFromIndex(const Addr index) const
+{
+ return (index / assoc) & setMask;
+}
+
+Addr
+SkewedAssoc::getWayFromIndex(const Addr index) const
+{
+ return index % assoc;
+}
+
+Addr
SkewedAssoc::regenerateBlkAddr(const CacheBlk* blk) const
{
- const Addr addr = (blk->tag << (msbShift + 1)) | blk->set;
- const Addr set = deskew(addr, blk->way) & setMask;
+ const Addr index = blk->getIndex();
+ const Addr addr = (blk->tag << (msbShift + 1)) |
getSetFromIndex(index);
+ const Addr set = deskew(addr, getWayFromIndex(index)) & setMask;
return (blk->tag << tagShift) | (set << setShift);
}
diff --git a/src/mem/cache/tags/skewed_assoc.hh
b/src/mem/cache/tags/skewed_assoc.hh
index 5ce0fe5..5865a6b 100644
--- a/src/mem/cache/tags/skewed_assoc.hh
+++ b/src/mem/cache/tags/skewed_assoc.hh
@@ -157,6 +157,22 @@
CacheBlk* findBlock(Addr addr, bool is_secure) const override;
/**
+ * Get set given an entry index.
+ *
+ * @param index The index of the entry.
+ * @return The set to which this index belongs.
+ */
+ Addr getSetFromIndex(const Addr index) const;
+
+ /**
+ * Get way given an entry index.
+ *
+ * @param index The index of the entry.
+ * @return The way to which this index belongs.
+ */
+ Addr getWayFromIndex(const Addr index) const;
+
+ /**
* Regenerate the block address from the tag, set and way. Uses the
* inverse of the skewing function.
*
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12764
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: If0e3dacf9ea2f523af9cface067469ccecf82648
Gerrit-Change-Number: 12764
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev