summaryrefslogtreecommitdiff
path: root/src/mem/ruby/structures/CacheMemory.cc
diff options
context:
space:
mode:
authorJingQuJQ <jqu32@wisc.edu>2019-06-13 21:29:56 -0500
committerMingyuan Xiang <mxiang6@wisc.edu>2019-10-11 03:29:29 +0000
commit211869ea950f3cc3116655f06b1d46d3fa39fb3a (patch)
tree9a72e6d9797f0c98835514bdb2dbad44f96251ee /src/mem/ruby/structures/CacheMemory.cc
parentdd2b3bde4c3d067af68e1f2d10db81d9d0af9cb5 (diff)
downloadgem5-211869ea950f3cc3116655f06b1d46d3fa39fb3a.tar.xz
mem-ruby: Allow Ruby to use all replacement policies in Classic
Add support in Ruby to use all replacement policies in Classic. Furthermore, if new replacement policies are added to the Classic system, the Ruby system will recognize new policies without any other changes in Ruby system. The following list all the major changes: * Make Ruby cache entries (AbstractCacheEntry) inherit from Classic cache entries (ReplaceableEntry). By doing this, replacement policies can use cache entries from Ruby caches. AccessPermission and print function are moved from AbstractEntry to AbstractCacheEntry, so AbstractEntry is no longer needed. * DirectoryMemory and all SLICC files are changed to use AbstractCacheEntry as their cache entry interface. So do the python files in mem/slicc/ast which check the entry interface. * "main='false'" argument is added to the protocol files where the DirectoryEntry is defined. This change helps differentiate DirectoryEntry from CacheEntry because they are both the instances of AbstractCacheEntry now. * Use BaseReplacementPolicy in Ruby caches instead of AbstractReplacementPolicy so that Ruby caches will recognize the replacement policies from Classic. * Add getLastAccess() and useOccupancy() function to Classic system so that Ruby caches can use them. Move lastTouchTick to ReplacementData struct because it's needed by getLastAccess() to return the correct value. * Add a 2-dimensional array of ReplacementData in Ruby caches to store information for different replacement policies. Note that, unlike Classic caches, where policy information is stored in cache entries, the policy information needs to be stored in a new 2-dimensional array. This is due to Ruby caches deleting the cache entry every time the corresponding cache line get evicted. Change-Id: Idff6fdd2102a552c103e9d5f31f779aae052943f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20879 Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Maintainer: Jason Lowe-Power <jason@lowepower.com> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/mem/ruby/structures/CacheMemory.cc')
-rw-r--r--src/mem/ruby/structures/CacheMemory.cc75
1 files changed, 51 insertions, 24 deletions
diff --git a/src/mem/ruby/structures/CacheMemory.cc b/src/mem/ruby/structures/CacheMemory.cc
index 5dc346388..a7aa6370b 100644
--- a/src/mem/ruby/structures/CacheMemory.cc
+++ b/src/mem/ruby/structures/CacheMemory.cc
@@ -65,11 +65,12 @@ CacheMemory::CacheMemory(const Params *p)
m_cache_size = p->size;
m_cache_assoc = p->assoc;
m_replacementPolicy_ptr = p->replacement_policy;
- m_replacementPolicy_ptr->setCache(this);
m_start_index_bit = p->start_index_bit;
m_is_instruction_only_cache = p->is_icache;
m_resource_stalls = p->resourceStalls;
m_block_size = p->block_size; // may be 0 at this point. Updated in init()
+ m_use_occupancy = dynamic_cast<WeightedLRUPolicy*>(
+ m_replacementPolicy_ptr) ? true : false;
}
void
@@ -85,6 +86,15 @@ CacheMemory::init()
m_cache.resize(m_cache_num_sets,
std::vector<AbstractCacheEntry*>(m_cache_assoc, nullptr));
+ replacement_data.resize(m_cache_num_sets,
+ std::vector<ReplData>(m_cache_assoc, nullptr));
+ // instantiate all the replacement_data here
+ for (int i = 0; i < m_cache_num_sets; i++) {
+ for ( int j = 0; j < m_cache_assoc; j++) {
+ replacement_data[i][j] =
+ m_replacementPolicy_ptr->instantiateEntry();
+ }
+ }
}
CacheMemory::~CacheMemory()
@@ -170,7 +180,8 @@ CacheMemory::tryCacheAccess(Addr address, RubyRequestType type,
if (loc != -1) {
// Do we even have a tag match?
AbstractCacheEntry* entry = m_cache[cacheSet][loc];
- m_replacementPolicy_ptr->touch(cacheSet, loc, curTick());
+ m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]);
+ m_cache[cacheSet][loc]->setLastAccess(curTick());
data_ptr = &(entry->getDataBlk());
if (entry->m_Permission == AccessPermission_Read_Write) {
@@ -198,7 +209,8 @@ CacheMemory::testCacheAccess(Addr address, RubyRequestType type,
if (loc != -1) {
// Do we even have a tag match?
AbstractCacheEntry* entry = m_cache[cacheSet][loc];
- m_replacementPolicy_ptr->touch(cacheSet, loc, curTick());
+ m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]);
+ m_cache[cacheSet][loc]->setLastAccess(curTick());
data_ptr = &(entry->getDataBlk());
return m_cache[cacheSet][loc]->m_Permission !=
@@ -252,7 +264,7 @@ CacheMemory::cacheAvail(Addr address) const
}
AbstractCacheEntry*
-CacheMemory::allocate(Addr address, AbstractCacheEntry *entry, bool touch)
+CacheMemory::allocate(Addr address, AbstractCacheEntry *entry)
{
assert(address == makeLineAddress(address));
assert(!isTagPresent(address));
@@ -278,13 +290,11 @@ CacheMemory::allocate(Addr address, AbstractCacheEntry *entry, bool touch)
address);
set[i]->m_locked = -1;
m_tag_index[address] = i;
- entry->setSetIndex(cacheSet);
- entry->setWayIndex(i);
-
- if (touch) {
- m_replacementPolicy_ptr->touch(cacheSet, i, curTick());
- }
-
+ set[i]->setPosition(cacheSet, i);
+ // Call reset function here to set initial value for different
+ // replacement policies.
+ m_replacementPolicy_ptr->reset(replacement_data[cacheSet][i]);
+ set[i]->setLastAccess(curTick());
return entry;
}
}
@@ -300,6 +310,7 @@ CacheMemory::deallocate(Addr address)
int64_t cacheSet = addressToCacheSet(address);
int loc = findTagInSet(cacheSet, address);
if (loc != -1) {
+ m_replacementPolicy_ptr->invalidate(replacement_data[cacheSet][loc]);
delete m_cache[cacheSet][loc];
m_cache[cacheSet][loc] = NULL;
m_tag_index.erase(address);
@@ -314,8 +325,16 @@ CacheMemory::cacheProbe(Addr address) const
assert(!cacheAvail(address));
int64_t cacheSet = addressToCacheSet(address);
- return m_cache[cacheSet][m_replacementPolicy_ptr->getVictim(cacheSet)]->
- m_Address;
+ std::vector<ReplaceableEntry*> candidates;
+ for (int i = 0; i < m_cache_assoc; i++) {
+ // Pass the value of replacement_data to the cache entry so that we
+ // can use it in the getVictim() function.
+ m_cache[cacheSet][i]->replacementData = replacement_data[cacheSet][i];
+ candidates.push_back(static_cast<ReplaceableEntry*>(
+ m_cache[cacheSet][i]));
+ }
+ return m_cache[cacheSet][m_replacementPolicy_ptr->
+ getVictim(candidates)->getWay()]->m_Address;
}
// looks an address up in the cache
@@ -347,16 +366,19 @@ CacheMemory::setMRU(Addr address)
int64_t cacheSet = addressToCacheSet(address);
int loc = findTagInSet(cacheSet, address);
- if (loc != -1)
- m_replacementPolicy_ptr->touch(cacheSet, loc, curTick());
+ if (loc != -1) {
+ m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]);
+ m_cache[cacheSet][loc]->setLastAccess(curTick());
+ }
}
void
CacheMemory::setMRU(const AbstractCacheEntry *e)
{
- uint32_t cacheSet = e->getSetIndex();
- uint32_t loc = e->getWayIndex();
- m_replacementPolicy_ptr->touch(cacheSet, loc, curTick());
+ uint32_t cacheSet = e->getSet();
+ uint32_t loc = e->getWay();
+ m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]);
+ m_cache[cacheSet][loc]->setLastAccess(curTick());
}
void
@@ -366,13 +388,17 @@ CacheMemory::setMRU(Addr address, int occupancy)
int loc = findTagInSet(cacheSet, address);
if (loc != -1) {
- if (m_replacementPolicy_ptr->useOccupancy()) {
- (static_cast<WeightedLRUPolicy*>(m_replacementPolicy_ptr))->
- touch(cacheSet, loc, curTick(), occupancy);
+ // m_use_occupancy can decide whether we are using WeightedLRU
+ // replacement policy. Depending on different replacement policies,
+ // use different touch() function.
+ if (m_use_occupancy) {
+ static_cast<WeightedLRUPolicy*>(m_replacementPolicy_ptr)->touch(
+ replacement_data[cacheSet][loc], occupancy);
} else {
m_replacementPolicy_ptr->
- touch(cacheSet, loc, curTick());
+ touch(replacement_data[cacheSet][loc]);
}
+ m_cache[cacheSet][loc]->setLastAccess(curTick());
}
}
@@ -413,9 +439,10 @@ CacheMemory::recordCacheContents(int cntrl, CacheRecorder* tr) const
}
if (request_type != RubyRequestType_NULL) {
+ Tick lastAccessTick;
+ lastAccessTick = m_cache[i][j]->getLastAccess();
tr->addRecord(cntrl, m_cache[i][j]->m_Address,
- 0, request_type,
- m_replacementPolicy_ptr->getLastAccess(i, j),
+ 0, request_type, lastAccessTick,
m_cache[i][j]->getDataBlk());
warmedUpBlocks++;
}