changeset ea8bdb1d9f1e in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=ea8bdb1d9f1e
description:
        ruby: initialize replacement policies with their own simobjs

        this is in preparation for other replacement policies that take 
additional
        parameters.

diffstat:

 configs/ruby/MESI_Three_Level.py                      |    6 +-
 src/mem/ruby/structures/AbstractReplacementPolicy.cc  |   72 +++++++++++
 src/mem/ruby/structures/AbstractReplacementPolicy.hh  |   44 +-----
 src/mem/ruby/structures/Cache.py                      |    4 +-
 src/mem/ruby/structures/CacheMemory.cc                |   11 +-
 src/mem/ruby/structures/CacheMemory.hh                |    4 +-
 src/mem/ruby/structures/LRUPolicy.cc                  |   80 ++++++++++++
 src/mem/ruby/structures/LRUPolicy.hh                  |   53 +-------
 src/mem/ruby/structures/LRUReplacementPolicy.py       |   41 ++++++
 src/mem/ruby/structures/PseudoLRUPolicy.cc            |  113 ++++++++++++++++++
 src/mem/ruby/structures/PseudoLRUPolicy.hh            |   79 +-----------
 src/mem/ruby/structures/PseudoLRUReplacementPolicy.py |   35 +++++
 src/mem/ruby/structures/ReplacementPolicy.py          |   43 ++++++
 src/mem/ruby/structures/SConscript                    |    6 +
 14 files changed, 414 insertions(+), 177 deletions(-)

diffs (truncated from 767 to 300 lines):

diff -r a588fceeb834 -r ea8bdb1d9f1e configs/ruby/MESI_Three_Level.py
--- a/configs/ruby/MESI_Three_Level.py  Mon Jul 20 09:15:18 2015 -0500
+++ b/configs/ruby/MESI_Three_Level.py  Mon Jul 20 09:15:18 2015 -0500
@@ -95,10 +95,12 @@
             # First create the Ruby objects associated with this cpu
             #
             l0i_cache = L0Cache(size = '4096B', assoc = 1, is_icache = True,
-                start_index_bit = block_size_bits, replacement_policy="LRU")
+                start_index_bit = block_size_bits,
+                replacement_policy = LRUReplacementPolicy())
 
             l0d_cache = L0Cache(size = '4096B', assoc = 1, is_icache = False,
-                start_index_bit = block_size_bits, replacement_policy="LRU")
+                start_index_bit = block_size_bits,
+                replacement_policy = LRUReplacementPolicy())
 
             l0_cntrl = L0Cache_Controller(version = i*num_cpus_per_cluster + j,
                           Icache = l0i_cache, Dcache = l0d_cache,
diff -r a588fceeb834 -r ea8bdb1d9f1e 
src/mem/ruby/structures/AbstractReplacementPolicy.cc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mem/ruby/structures/AbstractReplacementPolicy.cc      Mon Jul 20 
09:15:18 2015 -0500
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Advanced Micro Devices, Inc
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Derek Hower
+ */
+
+#include "mem/ruby/structures/AbstractReplacementPolicy.hh"
+
+AbstractReplacementPolicy::AbstractReplacementPolicy(const Params * p)
+  : SimObject(p)
+{
+    m_num_sets = p->size/p->block_size/p->assoc;
+    m_assoc = p->assoc;
+    m_last_ref_ptr = new Tick*[m_num_sets];
+    for(unsigned i = 0; i < m_num_sets; i++){
+        m_last_ref_ptr[i] = new Tick[m_assoc];
+        for(unsigned j = 0; j < m_assoc; j++){
+            m_last_ref_ptr[i][j] = 0;
+        }
+    }
+}
+
+AbstractReplacementPolicy *
+ReplacementPolicyParams::create()
+{
+    fatal("Cannot create an AbstractReplacementPolicy");
+    return NULL;
+}
+
+
+
+AbstractReplacementPolicy::~AbstractReplacementPolicy()
+{
+    if (m_last_ref_ptr != NULL){
+        for (unsigned i = 0; i < m_num_sets; i++){
+            if (m_last_ref_ptr[i] != NULL){
+                delete[] m_last_ref_ptr[i];
+            }
+        }
+        delete[] m_last_ref_ptr;
+    }
+}
+
+Tick
+AbstractReplacementPolicy::getLastAccess(int64 set, int64 way)
+{
+    return m_last_ref_ptr[set][way];
+}
diff -r a588fceeb834 -r ea8bdb1d9f1e 
src/mem/ruby/structures/AbstractReplacementPolicy.hh
--- a/src/mem/ruby/structures/AbstractReplacementPolicy.hh      Mon Jul 20 
09:15:18 2015 -0500
+++ b/src/mem/ruby/structures/AbstractReplacementPolicy.hh      Mon Jul 20 
09:15:18 2015 -0500
@@ -30,11 +30,15 @@
 #define __MEM_RUBY_STRUCTURES_ABSTRACTREPLACEMENTPOLICY_HH__
 
 #include "base/types.hh"
+#include "mem/ruby/common/TypeDefines.hh"
+#include "params/ReplacementPolicy.hh"
+#include "sim/sim_object.hh"
 
-class AbstractReplacementPolicy
+class AbstractReplacementPolicy : public SimObject
 {
   public:
-    AbstractReplacementPolicy(int64 num_sets, int64 assoc);
+    typedef ReplacementPolicyParams Params;
+    AbstractReplacementPolicy(const Params * p);
     virtual ~AbstractReplacementPolicy();
 
     /* touch a block. a.k.a. update timestamp */
@@ -46,44 +50,12 @@
     /* get the time of the last access */
     Tick getLastAccess(int64 set, int64 way);
 
+    virtual bool useOccupancy() const { return false; }
+
   protected:
     unsigned m_num_sets;       /** total number of sets */
     unsigned m_assoc;          /** set associativity */
     Tick **m_last_ref_ptr;         /** timestamp of last reference */
 };
 
-inline
-AbstractReplacementPolicy::AbstractReplacementPolicy(int64 num_sets,
-                                                     int64 assoc)
-{
-    m_num_sets = num_sets;
-    m_assoc = assoc;
-    m_last_ref_ptr = new Tick*[m_num_sets];
-    for(unsigned i = 0; i < m_num_sets; i++){
-        m_last_ref_ptr[i] = new Tick[m_assoc];
-        for(unsigned j = 0; j < m_assoc; j++){
-            m_last_ref_ptr[i][j] = 0;
-        }
-    }
-}
-
-inline
-AbstractReplacementPolicy::~AbstractReplacementPolicy()
-{
-    if (m_last_ref_ptr != NULL){
-        for (unsigned i = 0; i < m_num_sets; i++){
-            if (m_last_ref_ptr[i] != NULL){
-                delete[] m_last_ref_ptr[i];
-            }
-        }
-        delete[] m_last_ref_ptr;
-    }
-}
-
-inline Tick
-AbstractReplacementPolicy::getLastAccess(int64 set, int64 way)
-{
-    return m_last_ref_ptr[set][way];
-}
-
 #endif // __MEM_RUBY_STRUCTURES_ABSTRACTREPLACEMENTPOLICY_HH__
diff -r a588fceeb834 -r ea8bdb1d9f1e src/mem/ruby/structures/Cache.py
--- a/src/mem/ruby/structures/Cache.py  Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/ruby/structures/Cache.py  Mon Jul 20 09:15:18 2015 -0500
@@ -29,6 +29,7 @@
 
 from m5.params import *
 from m5.proxy import *
+from PseudoLRUReplacementPolicy import PseudoLRUReplacementPolicy
 from m5.SimObject import SimObject
 
 class RubyCache(SimObject):
@@ -38,7 +39,8 @@
     size = Param.MemorySize("capacity in bytes");
     latency = Param.Cycles("");
     assoc = Param.Int("");
-    replacement_policy = Param.String("PSEUDO_LRU", "");
+    replacement_policy = Param.ReplacementPolicy(PseudoLRUReplacementPolicy(),
+                         "")
     start_index_bit = Param.Int(6, "index start, default 6 for 64-byte line");
     is_icache = Param.Bool(False, "is instruction only cache");
 
diff -r a588fceeb834 -r ea8bdb1d9f1e src/mem/ruby/structures/CacheMemory.cc
--- a/src/mem/ruby/structures/CacheMemory.cc    Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/ruby/structures/CacheMemory.cc    Mon Jul 20 09:15:18 2015 -0500
@@ -61,7 +61,7 @@
     m_cache_size = p->size;
     m_latency = p->latency;
     m_cache_assoc = p->assoc;
-    m_policy = p->replacement_policy;
+    m_replacementPolicy_ptr = p->replacement_policy;
     m_start_index_bit = p->start_index_bit;
     m_is_instruction_only_cache = p->is_icache;
     m_resource_stalls = p->resourceStalls;
@@ -76,15 +76,6 @@
     m_cache_num_set_bits = floorLog2(m_cache_num_sets);
     assert(m_cache_num_set_bits > 0);
 
-    if (m_policy == "PSEUDO_LRU")
-        m_replacementPolicy_ptr =
-            new PseudoLRUPolicy(m_cache_num_sets, m_cache_assoc);
-    else if (m_policy == "LRU")
-        m_replacementPolicy_ptr =
-            new LRUPolicy(m_cache_num_sets, m_cache_assoc);
-    else
-        assert(false);
-
     m_cache.resize(m_cache_num_sets);
     for (int i = 0; i < m_cache_num_sets; i++) {
         m_cache[i].resize(m_cache_assoc);
diff -r a588fceeb834 -r ea8bdb1d9f1e src/mem/ruby/structures/CacheMemory.hh
--- a/src/mem/ruby/structures/CacheMemory.hh    Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/ruby/structures/CacheMemory.hh    Mon Jul 20 09:15:18 2015 -0500
@@ -40,9 +40,8 @@
 #include "mem/ruby/common/DataBlock.hh"
 #include "mem/ruby/slicc_interface/AbstractCacheEntry.hh"
 #include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
+#include "mem/ruby/structures/AbstractReplacementPolicy.hh"
 #include "mem/ruby/structures/BankedArray.hh"
-#include "mem/ruby/structures/LRUPolicy.hh"
-#include "mem/ruby/structures/PseudoLRUPolicy.hh"
 #include "mem/ruby/system/CacheRecorder.hh"
 #include "params/RubyCache.hh"
 #include "sim/sim_object.hh"
@@ -163,7 +162,6 @@
     BankedArray tagArray;
 
     int m_cache_size;
-    std::string m_policy;
     int m_cache_num_sets;
     int m_cache_num_set_bits;
     int m_cache_assoc;
diff -r a588fceeb834 -r ea8bdb1d9f1e src/mem/ruby/structures/LRUPolicy.cc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mem/ruby/structures/LRUPolicy.cc      Mon Jul 20 09:15:18 2015 -0500
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2013 Advanced Micro Devices, Inc
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Derek Hower
+ */
+
+#include "mem/ruby/structures/LRUPolicy.hh"
+
+
+
+LRUPolicy::LRUPolicy(const Params * p)
+    : AbstractReplacementPolicy(p)
+{
+}
+
+
+LRUPolicy::~LRUPolicy()
+{
+}
+
+LRUPolicy *
+LRUReplacementPolicyParams::create()
+{
+    return new LRUPolicy(this);
+}
+
+
+void
+LRUPolicy::touch(int64 set, int64 index, Tick time)
+{
+    assert(index >= 0 && index < m_assoc);
+    assert(set >= 0 && set < m_num_sets);
+
+    m_last_ref_ptr[set][index] = time;
+}
+
+int64
+LRUPolicy::getVictim(int64 set) const
+{
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to