From cda34c68a8ab3e6f999bfce893f52e9728bf9ed3 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Thu, 18 Jul 2024 14:30:12 +0100 Subject: [PATCH 1/2] base: Store a pointer to a debug flag in the AssociativeCache This will allow to print debug information for the associative cache depending on its usage Change-Id: Ia64e1cd7cb31fcbac27d031c38cd448ea64c5b4d Signed-off-by: Giacomo Travaglini --- src/base/cache/associative_cache.hh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/base/cache/associative_cache.hh b/src/base/cache/associative_cache.hh index f4771d1214..64690b847c 100644 --- a/src/base/cache/associative_cache.hh +++ b/src/base/cache/associative_cache.hh @@ -81,6 +81,8 @@ class AssociativeCache : public Named /** The entries */ std::vector entries; + const ::gem5::debug::SimpleFlag* debugFlag = nullptr; + private: void @@ -120,7 +122,8 @@ class AssociativeCache : public Named associativity(associativity_), replPolicy(repl_policy), indexingPolicy(indexing_policy), - entries(num_entries, init_val) + entries(num_entries, init_val), + debugFlag(nullptr) { initParams(num_entries, associativity); } @@ -162,6 +165,12 @@ class AssociativeCache : public Named initParams(num_entries, associativity); } + void + setDebugFlag(const ::gem5::debug::SimpleFlag& flag) + { + debugFlag = &flag; + } + /** * Do an access to the entry if it exists. * This is required to update the replacement information data. From 399f85223dc0f514dd308f5edd783e498b6704fc Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Thu, 18 Jul 2024 15:18:59 +0100 Subject: [PATCH 2/2] base: Add print when inserting/evicting an AssociativeCache entry We are adding two debug prints in the AssociativeCache: 1) Inserting print 2) Evicting print Among those, the evicting one is probably the most important This is because while the DPRINTF can be added in the Entry::insert implementation (called during insertion), the AssociativeCache does not reference any evict method. Instead, the findVictim is transparently invalidating the victim, which makes it impossible for the client code to understand whether the victim was a valid entry or not. Change-Id: I4fee59cc63c6b0e14c5b02bcf3ba5f58aa21ef9f Signed-off-by: Giacomo Travaglini --- src/base/cache/associative_cache.hh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/base/cache/associative_cache.hh b/src/base/cache/associative_cache.hh index 64690b847c..eb6d243e62 100644 --- a/src/base/cache/associative_cache.hh +++ b/src/base/cache/associative_cache.hh @@ -232,6 +232,12 @@ class AssociativeCache : public Named auto victim = static_cast(replPolicy->getVictim(candidates)); + if (debugFlag && debugFlag->tracing() && victim->isValid()) { + ::gem5::trace::getDebugLogger()->dprintf_flag( + curTick(), name(), debugFlag->name(), + "Replacing entry: %s\n", victim->print()); + } + invalidate(victim); return victim; @@ -257,6 +263,12 @@ class AssociativeCache : public Named virtual void insertEntry(const KeyType &key, Entry *entry) { + if (debugFlag && debugFlag->tracing()) { + ::gem5::trace::getDebugLogger()->dprintf_flag( + curTick(), name(), debugFlag->name(), + "Inserting entry: %s\n", entry->print()); + } + entry->insert(key); replPolicy->reset(entry->replacementData); }