From: Daniel R. Carvalho Date: Sun, 29 Dec 2019 17:43:47 +0000 (+0100) Subject: mem-cache: Use CircularQueue in PIF prefetcher X-Git-Tag: v20.0.0.0~73 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=feb2042cb1eb8e8a21c938cc28cdcd46d5d0523e;p=gem5.git mem-cache: Use CircularQueue in PIF prefetcher 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24540 Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris Tested-by: kokoro --- diff --git a/src/mem/cache/prefetch/pif.cc b/src/mem/cache/prefetch/pif.cc index 849106288..6a2983b1b 100644 --- a/src/mem/cache/prefetch/pif.cc +++ b/src/mem/cache/prefetch/pif.cc @@ -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); diff --git a/src/mem/cache/prefetch/pif.hh b/src/mem/cache/prefetch/pif.hh index 9fef2968c..e3d34fbeb 100644 --- a/src/mem/cache/prefetch/pif.hh +++ b/src/mem/cache/prefetch/pif.hh @@ -40,6 +40,7 @@ #include #include +#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 historyBuffer; - unsigned int historyBufferTail; + using HistoryBuffer = CircularQueue; + 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 streamAddressBuffer; + CircularQueue streamAddressBuffer; /** * Updates the prefetcher structures upon an instruction retired