mem: Use the caching in the AddrRangeMap class in PhysicalMemory
authorGabe Black <gabeblack@google.com>
Thu, 19 Oct 2017 04:16:37 +0000 (21:16 -0700)
committerNikos Nikoleris <nikos.nikoleris@arm.com>
Tue, 19 Jun 2018 14:24:25 +0000 (14:24 +0000)
Use it instead of custom implemented caching.

Change-Id: Ie21012a77a3cb6ce57f34f879fa391678913896a
Reviewed-on: https://gem5-review.googlesource.com/5244
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>

src/mem/physical.cc
src/mem/physical.hh

index c7dbb3bcb6e454529d007a03d7687e212c763e1b..fdc88a8c098cdc2f43d7fcade413300dbd5b2f88 100644 (file)
@@ -74,8 +74,7 @@ using namespace std;
 PhysicalMemory::PhysicalMemory(const string& _name,
                                const vector<AbstractMemory*>& _memories,
                                bool mmap_using_noreserve) :
-    _name(_name), rangeCache(addrMap.end()), size(0),
-    mmapUsingNoReserve(mmap_using_noreserve)
+    _name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve)
 {
     if (mmap_using_noreserve)
         warn("Not reserving swap space. May cause SIGSEGV on actual usage\n");
@@ -236,20 +235,7 @@ PhysicalMemory::~PhysicalMemory()
 bool
 PhysicalMemory::isMemAddr(Addr addr) const
 {
-    // see if the address is within the last matched range
-    if (rangeCache != addrMap.end() && rangeCache->first.contains(addr)) {
-        return true;
-    } else {
-        // lookup in the interval tree
-        const auto& r = addrMap.contains(addr);
-        if (r == addrMap.end()) {
-            // not in the cache, and not in the tree
-            return false;
-        }
-        // the range is in the tree, update the cache
-        rangeCache = r;
-        return true;
-    }
+    return addrMap.contains(addr) != addrMap.end();
 }
 
 AddrRangeList
@@ -293,15 +279,9 @@ PhysicalMemory::access(PacketPtr pkt)
 {
     assert(pkt->isRequest());
     Addr addr = pkt->getAddr();
-    if (rangeCache != addrMap.end() && rangeCache->first.contains(addr)) {
-        rangeCache->second->access(pkt);
-    } else {
-        // do not update the cache here, as we typically call
-        // isMemAddr before calling access
-        const auto& m = addrMap.contains(addr);
-        assert(m != addrMap.end());
-        m->second->access(pkt);
-    }
+    const auto& m = addrMap.contains(addr);
+    assert(m != addrMap.end());
+    m->second->access(pkt);
 }
 
 void
@@ -309,15 +289,9 @@ PhysicalMemory::functionalAccess(PacketPtr pkt)
 {
     assert(pkt->isRequest());
     Addr addr = pkt->getAddr();
-    if (rangeCache != addrMap.end() && rangeCache->first.contains(addr)) {
-        rangeCache->second->functionalAccess(pkt);
-    } else {
-        // do not update the cache here, as we typically call
-        // isMemAddr before calling functionalAccess
-        const auto& m = addrMap.contains(addr);
-        assert(m != addrMap.end());
-        m->second->functionalAccess(pkt);
-    }
+    const auto& m = addrMap.contains(addr);
+    assert(m != addrMap.end());
+    m->second->functionalAccess(pkt);
 }
 
 void
index cc733b2d67d14bb6d34bbfcf10de98d3a2c442c6..3fb3510b8de30d4855b6090e082b0e3c80f84c10 100644 (file)
@@ -118,11 +118,7 @@ class PhysicalMemory : public Serializable
     std::string _name;
 
     // Global address map
-    AddrRangeMap<AbstractMemory*> addrMap;
-
-    // a mutable cache for the last address map iterator that matched
-    // an address
-    mutable AddrRangeMap<AbstractMemory*>::const_iterator rangeCache;
+    AddrRangeMap<AbstractMemory*, 1> addrMap;
 
     // All address-mapped memories
     std::vector<AbstractMemory*> memories;