mem-cache: Fix invalidation of prefetchers
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Sat, 18 Jan 2020 15:19:53 +0000 (16:19 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Tue, 21 Jan 2020 08:07:05 +0000 (08:07 +0000)
Add an invalidation function to the AssociativeSet, so that entries
can be properly invalidated by also invalidating their replacement
data.

Both setInvalid and reset have been merged into invalidate to
indicate users that they are using an incorrect approach by
generating compilation errors, and to match CacheBlk's naming
convention.

Change-Id: I568076a3b5adda8b1311d9498b086c0dab457a14
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24529
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/cache/prefetch/access_map_pattern_matching.hh
src/mem/cache/prefetch/associative_set.hh
src/mem/cache/prefetch/associative_set_impl.hh
src/mem/cache/prefetch/delta_correlating_prediction_tables.cc
src/mem/cache/prefetch/delta_correlating_prediction_tables.hh
src/mem/cache/prefetch/indirect_memory.cc
src/mem/cache/prefetch/indirect_memory.hh
src/mem/cache/prefetch/irregular_stream_buffer.hh
src/mem/cache/prefetch/signature_path.hh
src/mem/cache/prefetch/spatio_temporal_memory_streaming.cc
src/mem/cache/prefetch/spatio_temporal_memory_streaming.hh

index 397bc788a937e05c7e1c77e9ae430c8d1a8f6552..6e2e194c7c90a512e1d1e0122c239e491cf2cfae 100644 (file)
@@ -89,12 +89,15 @@ class AccessMapPatternMatching : public ClockedObject
         /** vector containing the state of the cachelines in this zone */
         std::vector<AccessMapState> states;
 
-        AccessMapEntry(size_t num_entries) : states(num_entries, AM_INIT)
-        {}
+        AccessMapEntry(size_t num_entries)
+          : TaggedEntry(), states(num_entries, AM_INIT)
+        {
+        }
 
-        /** Reset the entries to their initial values */
-        void reset() override
+        void
+        invalidate() override
         {
+            TaggedEntry::invalidate();
             for (auto &entry : states) {
                 entry = AM_INIT;
             }
index e4e1b0428265877d0986dd73b485ec5fe81b077c..6228fe4da220f84eb5bd939abe206573213e3cf7 100644 (file)
@@ -66,10 +66,10 @@ class TaggedEntry : public ReplaceableEntry {
         valid = true;
     }
 
-    /**
-     * Sets the entry to invalid
-     */
-    void setInvalid() {
+    /** Invalidates the entry. */
+    virtual void
+    invalidate()
+    {
         valid = false;
     }
 
@@ -108,14 +108,6 @@ class TaggedEntry : public ReplaceableEntry {
     {
         secure = s;
     }
-
-    /**
-     * Resets the entry, this is called when an entry is evicted to allocate
-     * a new one. Types inheriting this class should provide its own
-     * implementation
-     */
-    virtual void reset () {
-    }
 };
 
 /**
@@ -196,6 +188,13 @@ class AssociativeSet {
      */
     void insertEntry(Addr addr, bool is_secure, Entry* entry);
 
+    /**
+     * Invalidate an entry and its respective replacement data.
+     *
+     * @param entry Entry to be invalidated.
+     */
+    void invalidate(Entry* entry);
+
     /** Iterator types */
     using const_iterator = typename std::vector<Entry>::const_iterator;
     using iterator = typename std::vector<Entry>::iterator;
index cc547e2dcd8a460d14fe0f97cebc13603483d375..8acae62690ab159997e462cb6525584a6c826ada 100644 (file)
@@ -87,7 +87,7 @@ AssociativeSet<Entry>::findVictim(Addr addr)
     Entry* victim = static_cast<Entry*>(replacementPolicy->getVictim(
                             selected_entries));
     // There is only one eviction for this replacement
-    victim->reset();
+    invalidate(victim);
     return victim;
 }
 
@@ -117,4 +117,12 @@ AssociativeSet<Entry>::insertEntry(Addr addr, bool is_secure, Entry* entry)
    replacementPolicy->reset(entry->replacementData);
 }
 
+template<class Entry>
+void
+AssociativeSet<Entry>::invalidate(Entry* entry)
+{
+    entry->invalidate();
+    replacementPolicy->invalidate(entry->replacementData);
+}
+
 #endif//__CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
index 4dbd596a2b949cea67f2f755a36fce96d156ed98..8f7041f2b9867e62f070ad513d67e33aa15e580e 100644 (file)
@@ -44,8 +44,10 @@ DeltaCorrelatingPredictionTables::DeltaCorrelatingPredictionTables(
 }
 
 void
-DeltaCorrelatingPredictionTables::DCPTEntry::reset()
+DeltaCorrelatingPredictionTables::DCPTEntry::invalidate()
 {
+    TaggedEntry::invalidate();
+
     for (auto &delta : deltas) {
         delta = 0;
     }
index 86cf9574cc841b67837a531cf3bc5d4c4580f5e2..e4c466c7542a3217fac51be4565cce396ce5dcc4 100644 (file)
@@ -75,12 +75,12 @@ class DeltaCorrelatingPredictionTables : public SimObject
          * Constructor
          * @param num_deltas number of deltas stored in the entry
          */
-        DCPTEntry(unsigned int num_deltas) : lastAddress(0), deltaPointer(0),
-            deltas(num_deltas)
-        {}
+        DCPTEntry(unsigned int num_deltas)
+          : TaggedEntry(), lastAddress(0), deltaPointer(0), deltas(num_deltas)
+        {
+        }
 
-        /** Reset callback called when invalidating the entry */
-        void reset() override;
+        void invalidate() override;
 
         /**
          * Adds an address to the entry, if the entry already existed, a delta
index 703105166eef4e6abf74eec9ca536927b727185f..0fd72cc62aebc8120e5209b0f24057db94eed6c9 100644 (file)
@@ -183,7 +183,7 @@ IndirectMemoryPrefetcher::allocateOrUpdateIPDEntry(
         } else {
             // Third access! no pattern has been found so far,
             // release the IPD entry
-            ipd_entry->reset();
+            ipd.invalidate(ipd_entry);
             ipdEntryTrackingMisses = nullptr;
         }
     } else {
@@ -237,7 +237,7 @@ IndirectMemoryPrefetcher::trackMissIndex2(Addr miss_addr)
                 pt_entry->enabled = true;
                 pt_entry->indirectCounter.reset();
                 // Release the current IPD Entry
-                entry->reset();
+                ipd.invalidate(entry);
                 // Do not track more misses
                 ipdEntryTrackingMisses = nullptr;
                 return;
index f177c5c06f1057ea7495704038568417020cbcd6..07f3cb5cae281ab09a0f76b6356668d51fdcdc03 100644 (file)
@@ -101,7 +101,10 @@ class IndirectMemoryPrefetcher : public QueuedPrefetcher
               increasedIndirectCounter(false)
         {}
 
-        void reset() override {
+        void
+        invalidate() override
+        {
+            TaggedEntry::invalidate();
             address = 0;
             secure = false;
             streamCounter = 0;
@@ -136,16 +139,20 @@ class IndirectMemoryPrefetcher : public QueuedPrefetcher
 
         IndirectPatternDetectorEntry(unsigned int num_addresses,
                                      unsigned int num_shifts)
-          : idx1(0), idx2(0), secondIndexSet(false), numMisses(0),
+          : TaggedEntry(), idx1(0), idx2(0), secondIndexSet(false),
+            numMisses(0),
             baseAddr(num_addresses, std::vector<Addr>(num_shifts))
-        {}
+        {
+        }
 
-        void reset() override {
+        void
+        invalidate() override
+        {
+            TaggedEntry::invalidate();
             idx1 = 0;
             idx2 = 0;
             secondIndexSet = false;
             numMisses = 0;
-            setInvalid();
         }
     };
     /** Indirect Pattern Detector (IPD) table */
index c97fde84db48b28e68010cca6740fa9f80052616..fefebc5d29057e0607340da6568a6795a1fae7d8 100644 (file)
@@ -79,13 +79,18 @@ class IrregularStreamBufferPrefetcher : public QueuedPrefetcher
      * Maps a set of contiguous addresses to another set of (not necessarily
      * contiguos) addresses, with their corresponding confidence counters
      */
-    struct AddressMappingEntry : public TaggedEntry {
+    struct AddressMappingEntry : public TaggedEntry
+    {
         std::vector<AddressMapping> mappings;
         AddressMappingEntry(size_t num_mappings, unsigned counter_bits)
-            : mappings(num_mappings, counter_bits)
-        {}
-        void reset() override
+          : TaggedEntry(), mappings(num_mappings, counter_bits)
+        {
+        }
+
+        void
+        invalidate() override
         {
+            TaggedEntry::invalidate();
             for (auto &entry : mappings) {
                 entry.address = 0;
                 entry.counter.reset();
index 3bf4dd29319a6631c1380fbca19c0dea3f7c912c..d2464e27a2b99c8b146f95993ae1a32d6a4f0eb3 100644 (file)
@@ -99,12 +99,16 @@ class SignaturePathPrefetcher : public QueuedPrefetcher
         /** use counter, used by SPPv2 */
         SatCounter counter;
         PatternEntry(size_t num_strides, unsigned counter_bits)
-            : strideEntries(num_strides, counter_bits), counter(counter_bits)
-        {}
+          : TaggedEntry(), strideEntries(num_strides, counter_bits),
+            counter(counter_bits)
+        {
+        }
 
         /** Reset the entries to their initial values */
-        void reset() override
+        void
+        invalidate() override
         {
+            TaggedEntry::invalidate();
             for (auto &entry : strideEntries) {
                 entry.counter.reset();
                 entry.stride = 0;
index cf6144a64f9773308ee7174d242dcfb476dfef6a..2bcd2feea77c26af345a6377050d513275bde992 100644 (file)
@@ -96,7 +96,7 @@ STeMSPrefetcher::checkForActiveGenerationsEnd() {
                 // this also sets the values of the entry
                 pst_entry->update(agt_entry);
                 // Free the AGT entry
-                agt_entry.setInvalid();
+                activeGenerationTable.invalidate(&agt_entry);
             }
         }
     }
index 34cf5d12a121056525e4884e866b8a21a5cbaac1..725fa38dbf66f6b5b8d3c84ba18067cc957ee680 100644 (file)
@@ -86,12 +86,16 @@ class STeMSPrefetcher : public QueuedPrefetcher
         /** Sequence of accesses */
         std::vector<SequenceEntry> sequence;
 
-        ActiveGenerationTableEntry(int num_positions) : paddress(0), pc(0),
+        ActiveGenerationTableEntry(int num_positions)
+          : TaggedEntry(), paddress(0), pc(0),
             seqCounter(0), sequence(num_positions)
-        {}
+        {
+        }
 
-        void reset() override
+        void
+        invalidate() override
         {
+            TaggedEntry::invalidate();
             paddress = 0;
             pc = 0;
             seqCounter = 0;