mem-ruby: Fix missing RubySystem in PerfectCacheMemory's entries (#1864)

MOESI_CMP_directory protocol crashes with one of the several assertions
in NetDest.cc. It happens because the entry type used to instantiate a
PerfectCacheMemory object in MOESI_CMP_directory-L2cache.sm contains a
NetDest object, so it requires a RubySystem object to be manually set
for it.

Instead of just receiving the block size, change PerfectCacheMemory to
receive a RubySystem object and use it to set the block size and call
ENTRY::setRubySystem if the entries require it.
This commit is contained in:
Marleson Graf
2024-12-19 01:59:47 -03:00
committed by Bobby R. Bruce
parent 0fe31664f3
commit b6c941c9ca
2 changed files with 20 additions and 3 deletions

View File

@@ -41,11 +41,13 @@
#ifndef __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
#define __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
#include <type_traits>
#include <unordered_map>
#include "base/compiler.hh"
#include "mem/ruby/common/Address.hh"
#include "mem/ruby/protocol/AccessPermission.hh"
#include "mem/ruby/system/RubySystem.hh"
namespace gem5
{
@@ -74,7 +76,7 @@ class PerfectCacheMemory
public:
PerfectCacheMemory();
void setBlockSize(const int block_size) { m_block_size = block_size; }
void setRubySystem(RubySystem *rs);
// tests to see if an address is present in the cache
bool isTagPresent(Addr address) const;
@@ -111,7 +113,11 @@ class PerfectCacheMemory
// Data Members (m_prefix)
std::unordered_map<Addr, PerfectCacheLineState<ENTRY> > m_map;
RubySystem *m_ruby_system = nullptr;
int m_block_size = 0;
static constexpr bool entryRequiresRubySystem =
std::is_member_function_pointer_v<decltype(&ENTRY::setRubySystem)>;
};
template<class ENTRY>
@@ -129,6 +135,14 @@ PerfectCacheMemory<ENTRY>::PerfectCacheMemory()
{
}
template<class ENTRY>
inline
void PerfectCacheMemory<ENTRY>::setRubySystem(RubySystem *rs)
{
m_ruby_system = rs;
m_block_size = rs->getBlockSizeBytes();
}
// tests to see if an address is present in the cache
template<class ENTRY>
inline bool
@@ -153,6 +167,9 @@ PerfectCacheMemory<ENTRY>::allocate(Addr address)
PerfectCacheLineState<ENTRY> line_state;
line_state.m_permission = AccessPermission_Invalid;
line_state.m_entry = ENTRY();
if constexpr (entryRequiresRubySystem) {
line_state.m_entry.setRubySystem(m_ruby_system);
}
Addr line_addr = makeLineAddress(address, floorLog2(m_block_size));
m_map.emplace(line_addr, line_state);
}

View File

@@ -833,11 +833,11 @@ $c_ident::init()
# For objects that require knowing the cache line size,
# set the value here.
if vtype.c_ident in ("TBETable", "PerfectCacheMemory"):
if vtype.c_ident in ("TBETable"):
block_size_func = "m_ruby_system->getBlockSizeBytes()"
code(f"(*{vid}).setBlockSize({block_size_func});")
if vtype.c_ident in ("NetDest"):
if vtype.c_ident in ("NetDest", "PerfectCacheMemory"):
code(f"(*{vid}).setRubySystem(m_ruby_system);")
for param in self.config_parameters: