mem-cache: Add match functions to QueueEntry
[gem5.git] / src / mem / physical.cc
index 05881b2248a76b05c62b5bf182501ba30c0398a5..afe5f7aa8897768687e6cf8274eebf0aaf2cc46b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2014 ARM Limited
+ * Copyright (c) 2012, 2014, 2018 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
  * Authors: Andreas Hansson
  */
 
+#include "mem/physical.hh"
+
+#include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/user.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <zlib.h>
 
@@ -54,7 +56,6 @@
 #include "debug/AddrRanges.hh"
 #include "debug/Checkpoint.hh"
 #include "mem/abstract_mem.hh"
-#include "mem/physical.hh"
 
 /**
  * On Linux, MAP_NORESERVE allow us to simulate a very large memory
@@ -73,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");
@@ -235,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.find(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
@@ -291,32 +278,18 @@ void
 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.find(addr);
-        assert(m != addrMap.end());
-        m->second->access(pkt);
-    }
+    const auto& m = addrMap.contains(pkt->getAddrRange());
+    assert(m != addrMap.end());
+    m->second->access(pkt);
 }
 
 void
 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.find(addr);
-        assert(m != addrMap.end());
-        m->second->functionalAccess(pkt);
-    }
+    const auto& m = addrMap.contains(pkt->getAddrRange());
+    assert(m != addrMap.end());
+    m->second->functionalAccess(pkt);
 }
 
 void
@@ -405,7 +378,7 @@ PhysicalMemory::unserialize(CheckpointIn &cp)
     UNSERIALIZE_CONTAINER(lal_addr);
     UNSERIALIZE_CONTAINER(lal_cid);
     for (size_t i = 0; i < lal_addr.size(); ++i) {
-        const auto& m = addrMap.find(lal_addr[i]);
+        const auto& m = addrMap.contains(lal_addr[i]);
         m->second->addLockedAddr(LockedAddr(lal_addr[i], lal_cid[i]));
     }