Daniel Carvalho has uploaded this change for review. (
https://gem5-review.googlesource.com/8886
Change subject: mem-cache: Create Skewed Assoc placement policy
......................................................................
mem-cache: Create Skewed Assoc placement policy
Create a class that implements the skewed associative placement policy.
extractSet is removed as a necessity for the BaseTags class, and is
implemented only in the placement policies that need them, as a private
function.
Change-Id: Ibc77edffd8128114a8b200cec5d8deedfb5105cb
---
M src/mem/cache/cache.cc
M src/mem/cache/tags/SConscript
M src/mem/cache/tags/Tags.py
M src/mem/cache/tags/base.hh
M src/mem/cache/tags/fa_lru.hh
M src/mem/cache/tags/set_assoc.hh
A src/mem/cache/tags/skewed_assoc.cc
A src/mem/cache/tags/skewed_assoc.hh
8 files changed, 190 insertions(+), 17 deletions(-)
diff --git a/src/mem/cache/cache.cc b/src/mem/cache/cache.cc
index 40eb24c..16c7cea 100644
--- a/src/mem/cache/cache.cc
+++ b/src/mem/cache/cache.cc
@@ -1904,7 +1904,6 @@
// current request and then get rid of it
assert(!tempBlock->isValid());
blk = tempBlock;
- tempBlock->set = tags->extractSet(addr);
tempBlock->tag = tags->extractTag(addr);
if (is_secure) {
tempBlock->status |= BlkSecure;
diff --git a/src/mem/cache/tags/SConscript b/src/mem/cache/tags/SConscript
index b14bd42..15c36bb 100644
--- a/src/mem/cache/tags/SConscript
+++ b/src/mem/cache/tags/SConscript
@@ -36,3 +36,4 @@
Source('base_set_assoc.cc')
Source('fa_lru.cc')
Source('set_assoc.cc')
+Source('skewed_assoc.cc')
diff --git a/src/mem/cache/tags/Tags.py b/src/mem/cache/tags/Tags.py
index 28bc18b..309aab4 100644
--- a/src/mem/cache/tags/Tags.py
+++ b/src/mem/cache/tags/Tags.py
@@ -82,3 +82,7 @@
class SetAssoc(BaseSetAssoc):
type = 'SetAssoc'
cxx_header = "mem/cache/tags/set_assoc.hh"
+
+class SkewedAssoc(BaseSetAssoc):
+ type = 'SkewedAssoc'
+ cxx_header = "mem/cache/tags/skewed_assoc.hh"
diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh
index 778fffe..62be5bb 100644
--- a/src/mem/cache/tags/base.hh
+++ b/src/mem/cache/tags/base.hh
@@ -290,8 +290,6 @@
*/
virtual ReplacementCandidates getCandidates(Addr addr) const = 0;
- virtual int extractSet(Addr addr) const = 0;
-
virtual void forEachBlk(CacheBlkVisitor &visitor) = 0;
};
diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh
index e4fd277..5dd8fa5 100644
--- a/src/mem/cache/tags/fa_lru.hh
+++ b/src/mem/cache/tags/fa_lru.hh
@@ -151,8 +151,7 @@
* @}
*/
-public:
-
+ public:
typedef FALRUParams Params;
/**
@@ -230,16 +229,6 @@
}
/**
- * Return the set of an address. Only one set in a fully associative
cache.
- * @param addr The address to get the set from.
- * @return 0.
- */
- int extractSet(Addr addr) const override
- {
- return 0;
- }
-
- /**
* Regenerate the block address from the tag.
*
* @param block The block.
@@ -273,7 +262,6 @@
return;
}
}
-
};
#endif // __MEM_CACHE_TAGS_FA_LRU_HH__
diff --git a/src/mem/cache/tags/set_assoc.hh
b/src/mem/cache/tags/set_assoc.hh
index 82bb5e7..5f33e52 100644
--- a/src/mem/cache/tags/set_assoc.hh
+++ b/src/mem/cache/tags/set_assoc.hh
@@ -86,13 +86,14 @@
*/
Addr regenerateBlkAddr(const CacheBlk* blk) const override;
+ private:
/**
* 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;
+ int extractSet(Addr addr) const;
};
#endif //__MEM_CACHE_TAGS_SET_ASSOC_HH__
diff --git a/src/mem/cache/tags/skewed_assoc.cc
b/src/mem/cache/tags/skewed_assoc.cc
new file mode 100644
index 0000000..14562d2
--- /dev/null
+++ b/src/mem/cache/tags/skewed_assoc.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2018 Inria
+ * 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.
+ *
+ * Authors: Daniel Carvalho
+ */
+
+/**
+ * @file
+ * Definitions of a skewed associative placement policy.
+ */
+
+#include "mem/cache/tags/skewed_assoc.hh"
+
+SkewedAssoc::SkewedAssoc(const Params *p)
+ : BaseSetAssoc(p)
+{
+}
+
+unsigned
+SkewedAssoc::extractSet(Addr addr, unsigned way) const
+{
+ // @todo use better hash function
+ return ((addr >> setShift) ^ way) & setMask;
+}
+
+Addr
+SkewedAssoc::regenerateBlkAddr(const CacheBlk* blk) const
+{
+ return ((blk->tag << tagShift) |
+ ((((Addr)blk->set ^ blk->way) & setMask) << setShift));
+}
+
+ReplacementCandidates
+SkewedAssoc::getCandidates(Addr addr) const
+{
+ ReplacementCandidates cands;
+
+ // Parse all ways
+ for (int way = 0; way < assoc; ++way) {
+ // Apply hash to get set
+ int set = extractSet(addr, way);
+
+ // Get all entries in the working set
+ cands.push_back(sets[set].blks[way]);
+ }
+
+ return cands;
+}
+
+SkewedAssoc *
+SkewedAssocParams::create()
+{
+ return new SkewedAssoc(this);
+}
diff --git a/src/mem/cache/tags/skewed_assoc.hh
b/src/mem/cache/tags/skewed_assoc.hh
new file mode 100644
index 0000000..fc61ec5
--- /dev/null
+++ b/src/mem/cache/tags/skewed_assoc.hh
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2018 Inria
+ * 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.
+ *
+ * Authors: Daniel Carvalho
+ */
+
+/**
+ * @file
+ * Declaration of a base set associative tag store.
+ */
+
+#ifndef __MEM_CACHE_TAGS_SKEWED_ASSOC_HH__
+#define __MEM_CACHE_TAGS_SKEWED_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/SkewedAssoc.hh"
+
+/**
+ * A SkewedAssoc cache tag store.
+ * @todo add to \ref gem5MemorySystem "gem5 Memory System"
+ *
+ * The SkewedAssoc placement policy divides the cache into s sets of w
+ * cache lines (ways). A cache line has a different set mapping for each
way.
+ */
+class SkewedAssoc : public BaseSetAssoc
+{
+ public:
+ /** Convenience typedef. */
+ typedef SkewedAssocParams Params;
+
+ /**
+ * Construct and initialize this tag store.
+ */
+ SkewedAssoc(const Params *p);
+
+ /**
+ * Destructor
+ */
+ ~SkewedAssoc() {};
+
+ /**
+ * 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;
+
+ private:
+ /**
+ * Apply a hash function to calculate address set given a way.
+ * Currently uses a simple XOR on the way being used. could be modified
+ * to use better mapping funtions.
+ *
+ * @param addr The address to calculate the set for.
+ * @param way The way to get the set from.
+ * @return The set index for given combination of address and way.
+ */
+ unsigned extractSet(Addr addr, unsigned way) const;
+};
+
+#endif //__MEM_CACHE_TAGS_SKEWED_ASSOC_HH__
--
To view, visit https://gem5-review.googlesource.com/8886
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: Ibc77edffd8128114a8b200cec5d8deedfb5105cb
Gerrit-Change-Number: 8886
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