summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel R. Carvalho <odanrc@yahoo.com.br>2018-04-25 14:41:23 +0200
committerDaniel Carvalho <odanrc@yahoo.com.br>2018-04-26 12:51:58 +0000
commit685cf2d1f8ae2f2ca3168a650efa1d36120783fe (patch)
tree8777aa38ddbcaa9b2c70b555e962fd3723f5fa1a /src
parentee2ffdc0fdb489767768e5273a4ccd7b51735c7c (diff)
downloadgem5-685cf2d1f8ae2f2ca3168a650efa1d36120783fe.tar.xz
mem-cache: Use block iteration in BaseSetAssoc
Use block iteration instead of numSets and assoc in print(), cleanupRefs() and computeStats(). This makes these functions rely solely on what they are used for: printing and calculating stats of blocks. With the addition of Sectors an extra indirection level is added, and thus these functions would be skipping blocks. Change-Id: I0006f82736cce02ba3e501ffafe9236f748daf32 Reviewed-on: https://gem5-review.googlesource.com/10143 Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com> Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Diffstat (limited to 'src')
-rw-r--r--src/mem/cache/tags/base_set_assoc.cc32
-rw-r--r--src/mem/cache/tags/base_set_assoc.hh4
2 files changed, 16 insertions, 20 deletions
diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc
index ac0e06f95..f0ee2a5d8 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -124,14 +124,10 @@ BaseSetAssoc::findBlockBySetAndWay(int set, int way) const
std::string
BaseSetAssoc::print() const {
std::string cache_state;
- for (unsigned i = 0; i < numSets; ++i) {
- // link in the data blocks
- for (unsigned j = 0; j < assoc; ++j) {
- BlkType *blk = sets[i].blks[j];
- if (blk->isValid())
- cache_state += csprintf("\tset: %d block: %d %s\n", i, j,
- blk->print());
- }
+ for (const CacheBlk& blk : blks) {
+ if (blk.isValid())
+ cache_state += csprintf("\tset: %d way: %d %s\n", blk.set,
+ blk.way, blk.print());
}
if (cache_state.empty())
cache_state = "no valid tags\n";
@@ -141,9 +137,9 @@ BaseSetAssoc::print() const {
void
BaseSetAssoc::cleanupRefs()
{
- for (unsigned i = 0; i < numSets*assoc; ++i) {
- if (blks[i].isValid()) {
- totalRefs += blks[i].refCount;
+ for (const CacheBlk& blk : blks) {
+ if (blk.isValid()) {
+ totalRefs += blk.refCount;
++sampledRefs;
}
}
@@ -159,12 +155,12 @@ BaseSetAssoc::computeStats()
}
}
- for (unsigned i = 0; i < numSets * assoc; ++i) {
- if (blks[i].isValid()) {
- assert(blks[i].task_id < ContextSwitchTaskId::NumTaskId);
- occupanciesTaskId[blks[i].task_id]++;
- assert(blks[i].tickInserted <= curTick());
- Tick age = curTick() - blks[i].tickInserted;
+ for (const CacheBlk& blk : blks) {
+ if (blk.isValid()) {
+ assert(blk.task_id < ContextSwitchTaskId::NumTaskId);
+ occupanciesTaskId[blk.task_id]++;
+ assert(blk.tickInserted <= curTick());
+ Tick age = curTick() - blk.tickInserted;
int age_index;
if (age / SimClock::Int::us < 10) { // <10us
@@ -178,7 +174,7 @@ BaseSetAssoc::computeStats()
} else
age_index = 4; // >10ms
- ageTaskId[blks[i].task_id][age_index]++;
+ ageTaskId[blk.task_id][age_index]++;
}
}
}
diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh
index ed9997608..024fda157 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -304,8 +304,8 @@ class BaseSetAssoc : public BaseTags
* \param visitor Visitor to call on each block.
*/
void forEachBlk(CacheBlkVisitor &visitor) override {
- for (unsigned i = 0; i < numSets * assoc; ++i) {
- if (!visitor(blks[i]))
+ for (CacheBlk& blk : blks) {
+ if (!visitor(blk))
return;
}
}