mem-cache: Fixed a bug in MRU replacement policy
authorMingyuan <xiang_my@outlook.com>
Mon, 2 Sep 2019 22:43:59 +0000 (17:43 -0500)
committerMingyuan Xiang <mxiang6@wisc.edu>
Sat, 12 Oct 2019 20:50:48 +0000 (20:50 +0000)
The lastTouchTick is set to 0 when instantiate. This will cause the
candidate[0] to get evicted over and over again in MRU replacement
policy. To resolve this, break the search loop whenever it finds a
cold cache line.

Change-Id: I33aa57ebe0efca15986f62c3ae10a146bd2b779f
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20881
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com>
src/mem/cache/replacement_policies/mru_rp.cc

index b2e019f9ad6b7e7cc146a8a9f44273a2b083c118..534fb52f09195b0d3b2081568fe678674655f0c1 100644 (file)
@@ -74,9 +74,14 @@ MRURP::getVictim(const ReplacementCandidates& candidates) const
     // Visit all candidates to find victim
     ReplaceableEntry* victim = candidates[0];
     for (const auto& candidate : candidates) {
-        // Update victim entry if necessary
-        if (std::static_pointer_cast<MRUReplData>(
-                    candidate->replacementData)->lastTouchTick >
+        std::shared_ptr<MRUReplData> candidate_replacement_data =
+            std::static_pointer_cast<MRUReplData>(candidate->replacementData);
+
+        // Stop searching entry if a cache line that doesn't warm up is found.
+        if (candidate_replacement_data->lastTouchTick == 0) {
+            victim = candidate;
+            break;
+        } else if (candidate_replacement_data->lastTouchTick >
                 std::static_pointer_cast<MRUReplData>(
                     victim->replacementData)->lastTouchTick) {
             victim = candidate;