Nikos Nikoleris has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/30095 )

Change subject: mem-cache: Make indexing policies range-aware
......................................................................

mem-cache: Make indexing policies range-aware

Change-Id: Ibdee97be47f9bd4161d74c5625ab7d5036bad689
Signed-off-by: Nikos Nikoleris <nikos.nikole...@arm.com>
---
M src/mem/cache/tags/indexing_policies/IndexingPolicies.py
M src/mem/cache/tags/indexing_policies/base.cc
M src/mem/cache/tags/indexing_policies/base.hh
M src/mem/cache/tags/indexing_policies/set_associative.cc
M src/mem/cache/tags/indexing_policies/set_associative.hh
M src/mem/cache/tags/indexing_policies/skewed_associative.cc
M src/mem/cache/tags/indexing_policies/skewed_associative.hh
7 files changed, 85 insertions(+), 30 deletions(-)



diff --git a/src/mem/cache/tags/indexing_policies/IndexingPolicies.py b/src/mem/cache/tags/indexing_policies/IndexingPolicies.py
index 7414ddf..058a1c9 100644
--- a/src/mem/cache/tags/indexing_policies/IndexingPolicies.py
+++ b/src/mem/cache/tags/indexing_policies/IndexingPolicies.py
@@ -42,6 +42,10 @@
     # Get the associativity
     assoc = Param.Int(Parent.assoc, "associativity")

+    # Get the address range used by the parent (cache)
+    addr_ranges = VectorParam.AddrRange(Parent.addr_ranges,
+                                        "Address range used by the cache")
+
 class SetAssociative(BaseIndexingPolicy):
     type = 'SetAssociative'
     cxx_class = 'SetAssociative'
diff --git a/src/mem/cache/tags/indexing_policies/base.cc b/src/mem/cache/tags/indexing_policies/base.cc
index 6a799e6..25fd0d0 100644
--- a/src/mem/cache/tags/indexing_policies/base.cc
+++ b/src/mem/cache/tags/indexing_policies/base.cc
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018 Inria
- * Copyright (c) 2012-2014,2017 ARM Limited
+ * Copyright (c) 2012-2014,2017,2020 ARM Limited
  * All rights reserved.
  *
  * The license below extends only to copyright in the software and shall
@@ -48,6 +48,7 @@

 #include <cstdlib>

+#include "base/channel_addr.hh"
 #include "base/intmath.hh"
 #include "base/logging.hh"
 #include "mem/cache/replacement_policies/replaceable_entry.hh"
@@ -56,7 +57,8 @@
     : SimObject(p), assoc(p->assoc),
       numSets(p->size / (p->entry_size * assoc)),
setShift(floorLog2(p->entry_size)), setMask(numSets - 1), sets(numSets),
-      tagShift(setShift + floorLog2(numSets))
+      tagShift(setShift + floorLog2(numSets)),
+      range(p->addr_ranges)
 {
fatal_if(!isPowerOf2(numSets), "# of sets must be non-zero and a power " \
              "of 2");
@@ -95,5 +97,22 @@
 Addr
 BaseIndexingPolicy::extractTag(const Addr addr) const
 {
-    return (addr >> tagShift);
+    // addr is physical, tags are extracted from relative
+    ChannelAddr ch_addr(range, addr);
+    return Addr(ch_addr) >> tagShift;
+}
+
+std::vector<ReplaceableEntry*>
+BaseIndexingPolicy::getPossibleEntries(const Addr addr) const
+{
+    return getPossibleEntries(ChannelAddr(range, addr));
+}
+
+Addr
+BaseIndexingPolicy::regenerateAddr(const Addr tag,
+                                   const ReplaceableEntry* entry) const
+{
+    // _regenerateAddr returns an offset into the range
+    ChannelAddr ch_addr = getChannelAddr(tag, entry);
+    return ch_addr.getPA(range);
 }
diff --git a/src/mem/cache/tags/indexing_policies/base.hh b/src/mem/cache/tags/indexing_policies/base.hh
index 9a56b54..803ff61 100644
--- a/src/mem/cache/tags/indexing_policies/base.hh
+++ b/src/mem/cache/tags/indexing_policies/base.hh
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018 Inria
- * Copyright (c) 2012-2014,2017 ARM Limited
+ * Copyright (c) 2012-2014,2017,2020 ARM Limited
  * All rights reserved.
  *
  * The license below extends only to copyright in the software and shall
@@ -49,6 +49,7 @@

 #include <vector>

+#include "base/channel_addr.hh"
 #include "params/BaseIndexingPolicy.hh"
 #include "sim/sim_object.hh"

@@ -93,6 +94,33 @@
      */
     const int tagShift;

+    /**
+     * The range covered by this indexing policy's cache.
+     */
+    const AddrRange range;
+
+    /**
+     * Find all possible entries for insertion and replacement of a
+     * relative address in this range. Called by getPossibleEntries
+     * with a relative address.
+     *
+     * @param addr The addr to a find possible entries for.
+     * @return The possible entries.
+     */
+    virtual std::vector<ReplaceableEntry*> getPossibleEntries(
+        const ChannelAddr ch_addr) const = 0;
+
+    /**
+ * Regenerate an entry's address from its tag and assigned indexing bits.
+     * Called by regenerateAddr, should produce a relative address
+     *
+     * @param tag The tag bits.
+     * @param entry The entry.
+     * @return the entry's original address relative to the range.
+     */
+    virtual ChannelAddr getChannelAddr(
+        const Addr tag, const ReplaceableEntry* entry) const = 0;
+
   public:
     /**
      * Convenience typedef.
@@ -143,8 +171,7 @@
      * @param addr The addr to a find possible entries for.
      * @return The possible entries.
      */
- virtual std::vector<ReplaceableEntry*> getPossibleEntries(const Addr addr) - const = 0; + std::vector<ReplaceableEntry*> getPossibleEntries(const Addr addr) const;

     /**
* Regenerate an entry's address from its tag and assigned indexing bits.
@@ -153,8 +180,7 @@
      * @param entry The entry.
      * @return the entry's original address.
      */
- virtual Addr regenerateAddr(const Addr tag, const ReplaceableEntry* entry) - const = 0; + Addr regenerateAddr(const Addr tag, const ReplaceableEntry* entry) const;
 };

 #endif //__MEM_CACHE_INDEXING_POLICIES_BASE_HH__
diff --git a/src/mem/cache/tags/indexing_policies/set_associative.cc b/src/mem/cache/tags/indexing_policies/set_associative.cc
index 05b37dd..abed36a 100644
--- a/src/mem/cache/tags/indexing_policies/set_associative.cc
+++ b/src/mem/cache/tags/indexing_policies/set_associative.cc
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018 Inria
- * Copyright (c) 2012-2014,2017 ARM Limited
+ * Copyright (c) 2012-2014,2017,2020 ARM Limited
  * All rights reserved.
  *
  * The license below extends only to copyright in the software and shall
@@ -46,6 +46,7 @@

 #include "mem/cache/tags/indexing_policies/set_associative.hh"

+#include "base/channel_addr.hh"
 #include "mem/cache/replacement_policies/replaceable_entry.hh"

 SetAssociative::SetAssociative(const Params *p)
@@ -59,17 +60,17 @@
     return (addr >> setShift) & setMask;
 }

-Addr
-SetAssociative::regenerateAddr(const Addr tag, const ReplaceableEntry* entry) - const
+ChannelAddr
+SetAssociative::getChannelAddr(const Addr tag,
+                               const ReplaceableEntry* entry) const
 {
-    return (tag << tagShift) | (entry->getSet() << setShift);
+    return ChannelAddr((tag << tagShift) | (entry->getSet() << setShift));
 }

 std::vector<ReplaceableEntry*>
-SetAssociative::getPossibleEntries(const Addr addr) const
+SetAssociative::getPossibleEntries(const ChannelAddr addr) const
 {
-    return sets[extractSet(addr)];
+    return sets[extractSet(Addr(addr))];
 }

 SetAssociative*
diff --git a/src/mem/cache/tags/indexing_policies/set_associative.hh b/src/mem/cache/tags/indexing_policies/set_associative.hh
index e7126c3..eaef70d 100644
--- a/src/mem/cache/tags/indexing_policies/set_associative.hh
+++ b/src/mem/cache/tags/indexing_policies/set_associative.hh
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018 Inria
- * Copyright (c) 2012-2014,2017 ARM Limited
+ * Copyright (c) 2012-2014,2017,2020 ARM Limited
  * All rights reserved.
  *
  * The license below extends only to copyright in the software and shall
@@ -49,6 +49,7 @@

 #include <vector>

+#include "base/channel_addr.hh"
 #include "mem/cache/tags/indexing_policies/base.hh"
 #include "params/SetAssociative.hh"

@@ -103,6 +104,8 @@
      */
     ~SetAssociative() {};

+  protected:
+
     /**
* Find all possible entries for insertion and replacement of an address.
      * Should be called immediately before ReplacementPolicy's findVictim()
@@ -112,8 +115,8 @@
      * @param addr The addr to a find possible entries for.
      * @return The possible entries.
      */
- std::vector<ReplaceableEntry*> getPossibleEntries(const Addr addr) const - override;
+    std::vector<ReplaceableEntry*> getPossibleEntries(
+        const ChannelAddr addr) const override;

     /**
      * Regenerate an entry's address from its tag and assigned set and way.
@@ -122,8 +125,8 @@
      * @param entry The entry.
      * @return the entry's original addr value.
      */
- Addr regenerateAddr(const Addr tag, const ReplaceableEntry* entry) const - override;
+    ChannelAddr getChannelAddr(
+        const Addr tag, const ReplaceableEntry* entry) const override;
 };

 #endif //__MEM_CACHE_INDEXING_POLICIES_SET_ASSOCIATIVE_HH__
diff --git a/src/mem/cache/tags/indexing_policies/skewed_associative.cc b/src/mem/cache/tags/indexing_policies/skewed_associative.cc
index 57c389b..882774b 100644
--- a/src/mem/cache/tags/indexing_policies/skewed_associative.cc
+++ b/src/mem/cache/tags/indexing_policies/skewed_associative.cc
@@ -194,24 +194,24 @@
     return skew(addr >> setShift, way) & setMask;
 }

-Addr
-SkewedAssociative::regenerateAddr(const Addr tag,
+ChannelAddr
+SkewedAssociative::getChannelAddr(const Addr tag,
                                   const ReplaceableEntry* entry) const
 {
     const Addr addr_set = (tag << (msbShift + 1)) | entry->getSet();
-    return (tag << tagShift) |
-           ((deskew(addr_set, entry->getWay()) & setMask) << setShift);
+    const Addr set = deskew(addr_set, entry->getWay()) & setMask;
+    return ChannelAddr((tag << tagShift) | (set << setShift));
 }

 std::vector<ReplaceableEntry*>
-SkewedAssociative::getPossibleEntries(const Addr addr) const
+SkewedAssociative::getPossibleEntries(const ChannelAddr addr) const
 {
     std::vector<ReplaceableEntry*> entries;

     // Parse all ways
     for (uint32_t way = 0; way < assoc; ++way) {
         // Apply hash to get set, and get way entry in it
-        entries.push_back(sets[extractSet(addr, way)][way]);
+        entries.push_back(sets[extractSet(Addr(addr), way)][way]);
     }

     return entries;
diff --git a/src/mem/cache/tags/indexing_policies/skewed_associative.hh b/src/mem/cache/tags/indexing_policies/skewed_associative.hh
index cff3b3c..e913d56 100644
--- a/src/mem/cache/tags/indexing_policies/skewed_associative.hh
+++ b/src/mem/cache/tags/indexing_policies/skewed_associative.hh
@@ -149,6 +149,8 @@
      */
     ~SkewedAssociative() {};

+  protected:
+
     /**
* Find all possible entries for insertion and replacement of an address.
      * Should be called immediately before ReplacementPolicy's findVictim()
@@ -157,8 +159,8 @@
      * @param addr The addr to a find possible entries for.
      * @return The possible entries.
      */
- std::vector<ReplaceableEntry*> getPossibleEntries(const Addr addr) const - override;
+    std::vector<ReplaceableEntry*> getPossibleEntries(
+        const ChannelAddr addr) const override;

     /**
      * Regenerate an entry's address from its tag and assigned set and way.
@@ -168,8 +170,8 @@
      * @param entry The entry.
      * @return the entry's address.
      */
- Addr regenerateAddr(const Addr tag, const ReplaceableEntry* entry) const - override;
+    ChannelAddr getChannelAddr(
+        const Addr tag, const ReplaceableEntry* entry) const override;
 };

 #endif //__MEM_CACHE_INDEXING_POLICIES_SKEWED_ASSOCIATIVE_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/30095
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ibdee97be47f9bd4161d74c5625ab7d5036bad689
Gerrit-Change-Number: 30095
Gerrit-PatchSet: 1
Gerrit-Owner: Nikos Nikoleris <nikos.nikole...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to