Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/8885

Change subject: mem-cache: Split BaseSetAssoc for placement policies
......................................................................

mem-cache: Split BaseSetAssoc for placement policies

Use BaseSetAssoc as an abstract base class and create a placement policy
that inherits from it.

This patch does not create a placement policy class.

Change-Id: I0838b41663f21eba0aeab7aeb7839e3703ca3324
---
M src/mem/cache/Cache.py
M src/mem/cache/tags/SConscript
M src/mem/cache/tags/Tags.py
M src/mem/cache/tags/base_set_assoc.cc
M src/mem/cache/tags/base_set_assoc.hh
A src/mem/cache/tags/set_assoc.cc
A src/mem/cache/tags/set_assoc.hh
7 files changed, 180 insertions(+), 51 deletions(-)



diff --git a/src/mem/cache/Cache.py b/src/mem/cache/Cache.py
index 544789b..f33cf7d 100644
--- a/src/mem/cache/Cache.py
+++ b/src/mem/cache/Cache.py
@@ -75,7 +75,7 @@
     prefetch_on_access = Param.Bool(False,
"Notify the hardware prefetcher on every access (not just misses)")

-    tags = Param.BaseTags(BaseSetAssoc(), "Tag store")
+    tags = Param.BaseTags(SetAssoc(), "Tag store")
repl_policy = Param.BaseReplacementPolicy(LRURP(), "Replacement policy")

     sequential_access = Param.Bool(False,
diff --git a/src/mem/cache/tags/SConscript b/src/mem/cache/tags/SConscript
index 9758b56..b14bd42 100644
--- a/src/mem/cache/tags/SConscript
+++ b/src/mem/cache/tags/SConscript
@@ -35,3 +35,4 @@
 Source('base.cc')
 Source('base_set_assoc.cc')
 Source('fa_lru.cc')
+Source('set_assoc.cc')
diff --git a/src/mem/cache/tags/Tags.py b/src/mem/cache/tags/Tags.py
index d211b2a..28bc18b 100644
--- a/src/mem/cache/tags/Tags.py
+++ b/src/mem/cache/tags/Tags.py
@@ -70,6 +70,7 @@

 class BaseSetAssoc(BaseTags):
     type = 'BaseSetAssoc'
+    abstract = True
     cxx_header = "mem/cache/tags/base_set_assoc.hh"
     assoc = Param.Int(Parent.assoc, "associativity")

@@ -77,3 +78,7 @@
     type = 'FALRU'
     cxx_class = 'FALRU'
     cxx_header = "mem/cache/tags/fa_lru.hh"
+
+class SetAssoc(BaseSetAssoc):
+    type = 'SetAssoc'
+    cxx_header = "mem/cache/tags/set_assoc.hh"
diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc
index bd39e1a..bab5bf7 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -195,10 +195,3 @@
         }
     }
 }
-
-BaseSetAssoc *
-BaseSetAssocParams::create()
-{
-    return new BaseSetAssoc(this);
-}
-
diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh
index 27a3734..739a21f 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -187,28 +187,6 @@
     CacheBlk* findBlock(Addr addr, bool is_secure) const override;

     /**
-     * Find all candidates for replacement. Returns blocks in all ways
-     * belonging to the set of the address.
-     * @param addr The addr to a find replacement candidates for.
-     * @return The replacement candidates.
-     */
-    ReplacementCandidates getCandidates(Addr addr) const override
-    {
-        ReplacementCandidates cands;
-
-        // Get working set
-        int set = extractSet(addr);
-
-        // Get all entries in the working set
-        for (auto it = sets[set].blks.begin();
-                  it != sets[set].blks.end(); ++it) {
-            cands.push_back(*it);
-        }
-
-        return cands;
-    }
-
-    /**
      * Insert the new block into the cache.
      * @param pkt Packet holding the address to update
      * @param blk The block to update.
@@ -289,27 +267,6 @@
     }

     /**
-     * Calculate the set index from the address.
-     * @param addr The address to get the set from.
-     * @return The set index of the address.
-     */
-    int extractSet(Addr addr) const override
-    {
-        return ((addr >> setShift) & setMask);
-    }
-
-    /**
-     * Regenerate the block address from the tag and set.
-     *
-     * @param block The block.
-     * @return the block address.
-     */
-    Addr regenerateBlkAddr(const CacheBlk* blk) const override
-    {
-        return ((blk->tag << tagShift) | ((Addr)blk->set << setShift));
-    }
-
-    /**
* Called at end of simulation to complete average block reference stats.
      */
     void cleanupRefs() override;
diff --git a/src/mem/cache/tags/set_assoc.cc b/src/mem/cache/tags/set_assoc.cc
new file mode 100644
index 0000000..57d3bcb
--- /dev/null
+++ b/src/mem/cache/tags/set_assoc.cc
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018 Inria
+ *
+ * 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.
+ *
+ * Authors: Daniel Carvalho
+ */
+
+/**
+ * @file
+ * Definitions of a set associative placement policy.
+ */
+
+#include "mem/cache/tags/set_assoc.hh"
+
+SetAssoc::SetAssoc(const Params *p)
+    : BaseSetAssoc(p)
+{
+}
+
+int
+SetAssoc::extractSet(Addr addr) const
+{
+    return (addr >> setShift) & setMask;
+}
+
+Addr
+SetAssoc::regenerateBlkAddr(const CacheBlk* blk) const
+{
+    return ((blk->tag << tagShift) | ((Addr)blk->set << setShift));
+}
+
+ReplacementCandidates
+SetAssoc::getCandidates(Addr addr) const
+{
+    ReplacementCandidates cands;
+
+    // Get working set
+    int set = extractSet(addr);
+
+    // Get all entries in the working set
+    for (auto it = sets[set].blks.begin();
+              it != sets[set].blks.end(); ++it) {
+        cands.push_back(*it);
+    }
+
+    return cands;
+}
+
+SetAssoc*
+SetAssocParams::create()
+{
+    return new SetAssoc(this);
+}
diff --git a/src/mem/cache/tags/set_assoc.hh b/src/mem/cache/tags/set_assoc.hh
new file mode 100644
index 0000000..82bb5e7
--- /dev/null
+++ b/src/mem/cache/tags/set_assoc.hh
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2018 Inria
+ *
+ * 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.
+ *
+ * Authors: Daniel Carvalho
+ */
+
+/**
+ * @file
+ * Declaration of a set associative placement policy.
+ */
+
+#ifndef __MEM_CACHE_TAGS_SET_ASSOC_HH__
+#define __MEM_CACHE_TAGS_SET_ASSOC_HH__
+
+#include <cassert>
+#include <cstring>
+#include <memory>
+#include <vector>
+
+#include "mem/cache/base.hh"
+#include "mem/cache/blk.hh"
+#include "mem/cache/tags/base_set_assoc.hh"
+#include "mem/cache/tags/cacheset.hh"
+#include "mem/packet.hh"
+#include "params/SetAssoc.hh"
+
+/**
+ * A SetAssoc cache placement policy.
+ * @sa  \ref gem5MemorySystem "gem5 Memory System"
+ *
+ * It dictates the possible placement locations for given addresses.
+ */
+class SetAssoc : public BaseSetAssoc
+{
+  public:
+    /** Convenience typedef. */
+     typedef SetAssocParams Params;
+
+    /**
+     * Construct and initialize this tag store.
+     */
+    SetAssoc(const Params *p);
+
+    /**
+     * Destructor
+     */
+    ~SetAssoc() {};
+
+    /**
+     * Find all candidates for replacement. Returns blocks in all ways
+     * belonging to the set of the address.
+     *
+     * @param addr The addr to a find replacement candidates for.
+     * @return The replacement candidates.
+     */
+    ReplacementCandidates getCandidates(Addr addr) const override;
+
+    /**
+     * Regenerate the block address from the tag, set and way.
+     *
+     * @param block The block.
+     * @return the block address.
+     */
+    Addr regenerateBlkAddr(const CacheBlk* blk) const override;
+
+    /**
+     * Apply a hash function to calculate address set.
+     *
+     * @param addr The address to calculate the set for.
+     * @return The set index for given combination of address and way.
+     */
+    int extractSet(Addr addr) const override;
+};
+
+#endif //__MEM_CACHE_TAGS_SET_ASSOC_HH__

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

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I0838b41663f21eba0aeab7aeb7839e3703ca3324
Gerrit-Change-Number: 8885
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to