mem-cache: Use CircularQueue in PIF prefetcher
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Sun, 29 Dec 2019 17:43:47 +0000 (18:43 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Fri, 1 May 2020 13:38:16 +0000 (13:38 +0000)
Use CircularQueue for PIF's history buffer, and change the indexing
storage to a CQ iterator.

Change-Id: I75bbb75a6be41bd063f662baedbd4c9de33644de
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24540
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/pif.cc
src/mem/cache/prefetch/pif.hh

index 8491062887869e9a35b84f690a4c80befc447f7a..6a2983b1b39e308519ac29fe7595d396e246a70d 100644 (file)
@@ -41,12 +41,11 @@ PIF::PIF(const PIFPrefetcherParams *p)
       precSize(p->prec_spatial_region_bits),
       succSize(p->succ_spatial_region_bits),
       maxCompactorEntries(p->compactor_entries),
-      maxStreamAddressBufferEntries(p->stream_address_buffer_entries),
       historyBuffer(p->history_buffer_size),
-      historyBufferTail(0),
       index(p->index_assoc, p->index_entries, p->index_indexing_policy,
             p->index_replacement_policy),
-      streamAddressBuffer(), listenersPC()
+      streamAddressBuffer(p->stream_address_buffer_entries),
+      listenersPC()
 {
 }
 
@@ -169,8 +168,8 @@ PIF::notifyRetiredInst(const Addr pc)
             // updating the trigger address and resetting the vector bits
             if (!is_in_temporal_compactor) {
                 // Insert the spatial entry into the history buffer and update
-                // the 'index' table to point to the new entry
-                historyBuffer[historyBufferTail] = spatialCompactor;
+                // the 'iterator' table to point to the new entry
+                historyBuffer.push_back(spatialCompactor);
 
                 IndexEntry *idx_entry =
                     index.findEntry(spatialCompactor.trigger, false);
@@ -182,12 +181,8 @@ PIF::notifyRetiredInst(const Addr pc)
                     index.insertEntry(spatialCompactor.trigger, false,
                                       idx_entry);
                 }
-                idx_entry->historyIndex = historyBufferTail;
-
-                historyBufferTail++;
-                if (historyBufferTail == historyBuffer.size()) {
-                    historyBufferTail = 0;
-                }
+                idx_entry->historyIt =
+                    historyBuffer.getIterator(historyBuffer.tail());
 
                 // Reset the spatial compactor fields with the new address
                 spatialCompactor = CompactorEntry(pc, precSize, succSize);
@@ -206,13 +201,7 @@ PIF::calculatePrefetch(const PrefetchInfo &pfi,
     // comparing the access against the active Stream Address Buffers
     for (auto &sabEntry : streamAddressBuffer) {
         if (sabEntry->hasAddress(addr, lBlkSize)) {
-            // Advance to the next entry (first check if we have reached the
-            // end of the history buffer)
-            if (sabEntry == &(historyBuffer[historyBuffer.size() - 1])) {
-                sabEntry = &(historyBuffer[0]);
-            } else {
-                sabEntry++;
-            }
+            sabEntry++;
             sabEntry->getPredictedAddresses(lBlkSize, addresses);
             // We are done
             return;
@@ -227,13 +216,9 @@ PIF::calculatePrefetch(const PrefetchInfo &pfi,
         index.accessEntry(idx_entry);
         // Trigger address from the 'index' table and index to the history
         // buffer
-        const unsigned int hb_entry = idx_entry->historyIndex;
-        CompactorEntry *entry = &historyBuffer[hb_entry];
+        auto entry = idx_entry->historyIt;
 
         // Track the block in the Stream Address Buffer
-        if (streamAddressBuffer.size() == maxStreamAddressBufferEntries) {
-            streamAddressBuffer.pop_front();
-        }
         streamAddressBuffer.push_back(entry);
 
         entry->getPredictedAddresses(lBlkSize, addresses);
index 9fef2968c538fbad60d4239727c48c687fc46e0f..e3d34fbebed4ad053862fb88d485ebf5b458a069 100644 (file)
@@ -40,6 +40,7 @@
 #include <deque>
 #include <vector>
 
+#include "base/circular_queue.hh"
 #include "mem/cache/prefetch/associative_set.hh"
 #include "mem/cache/prefetch/queued.hh"
 
@@ -55,8 +56,6 @@ class PIF : public Queued
         const unsigned int succSize;
         /** Number of entries used for the temporal compactor */
         const unsigned int maxCompactorEntries;
-        /** Max number of entries to be used in the Stream Address Buffer */
-        const unsigned int maxStreamAddressBufferEntries;
 
         /**
          * The compactor tracks retired instructions addresses, leveraging the
@@ -127,12 +126,12 @@ class PIF : public Queued
          * History buffer is a circular buffer that stores the sequence of
          * retired instructions in FIFO order.
          */
-        std::vector<CompactorEntry> historyBuffer;
-        unsigned int historyBufferTail;
+        using HistoryBuffer = CircularQueue<CompactorEntry>;
+        HistoryBuffer historyBuffer;
 
         struct IndexEntry : public TaggedEntry
         {
-            unsigned int historyIndex;
+            HistoryBuffer::iterator historyIt;
         };
         /**
          * The index table is a small cache-like structure that facilitates
@@ -146,7 +145,7 @@ class PIF : public Queued
          * history buffer, initiallly set to the pointer taken from the index
          * table
          */
-        std::deque<CompactorEntry*> streamAddressBuffer;
+        CircularQueue<HistoryBuffer::iterator> streamAddressBuffer;
 
         /**
          * Updates the prefetcher structures upon an instruction retired