mem-cache: Add match functions to QueueEntry
[gem5.git] / src / mem / stack_dist_calc.cc
index c273ee7f4dff6c361bd9b56120c92865ae78601b..886e539777ed539029022bfce87b03587256f57f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 ARM Limited
+ * Copyright (c) 2014-2015 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
  * Authors: Kanishk Sugand
  */
 
+#include "mem/stack_dist_calc.hh"
+
+#include "base/chunk_generator.hh"
 #include "base/intmath.hh"
 #include "base/trace.hh"
 #include "debug/StackDist.hh"
-#include "mem/stack_dist_calc.hh"
 
-StackDistCalc::StackDistCalc(const StackDistCalcParams* p) :
-    SimObject(p), index(0), verifyStack(p->verify),
-    disableLinearHists(p->disable_linear_hists),
-    disableLogHists(p->disable_log_hists)
+StackDistCalc::StackDistCalc(bool verify_stack)
+    : index(0),
+      verifyStack(verify_stack)
 {
     // Instantiate a new root and leaf layer
     // Map type variable, representing a layer in the tree
@@ -91,38 +92,6 @@ StackDistCalc::~StackDistCalc()
     stack.clear();
 }
 
-void
-StackDistCalc::update(const MemCmd& cmd, Addr addr)
-{
-    // only capturing read and write requests (which allocate in the
-    // cache)
-    if (cmd.isRead() || cmd.isWrite()) {
-        auto returnType = calcStackDistAndUpdate(addr);
-
-        uint64_t stackDist = returnType.first;
-
-        if (stackDist != Infinity) {
-            // Sample the stack distance of the address in linear bins
-            if (!disableLinearHists) {
-                if (cmd.isRead())
-                    readLinearHist.sample(stackDist);
-                else
-                    writeLinearHist.sample(stackDist);
-            }
-
-            if (!disableLogHists) {
-                int stackDistLog2 = stackDist == 0 ? 1 : floorLog2(stackDist);
-
-                // Sample the stack distance of the address in log bins
-                if (cmd.isRead())
-                    readLogHist.sample(stackDistLog2);
-                else
-                    writeLogHist.sample(stackDistLog2);
-            }
-        }
-    }
-}
-
 // The updateSum method is a recursive function which updates
 // the node sums till the root. It also deletes the nodes that
 // are not used anymore.
@@ -247,13 +216,13 @@ StackDistCalc::getSum(Node* node, bool from_left, uint64_t sum_from_below,
     ++level;
     // Variable stack_dist is updated only
     // when arriving from Left.
-    if(from_left) {
+    if (from_left) {
         stack_dist += node->sumRight;
     }
 
     // Recursively call the getSum operation till the
     // root node is reached
-    if(node->parent) {
+    if (node->parent) {
         stack_dist = getSum(node->parent, node->isLeftNode,
                             node->sumLeft + node->sumRight,
                             stack_dist, level);
@@ -390,8 +359,6 @@ std::pair< uint64_t, bool>
 StackDistCalc::calcStackDistAndUpdate(const Addr r_address, bool addNewNode)
 {
     Node* newLeafNode;
-    // Return index if the address was already present in stack
-    uint64_t r_index = index;
 
     auto ai = aiMap.lower_bound(r_address);
 
@@ -411,7 +378,7 @@ StackDistCalc::calcStackDistAndUpdate(const Addr r_address, bool addNewNode)
         // key already exists
         // save the index counter value when this address was
         // encountered before and update it to the current index value
-        r_index = ai->second;
+        uint64_t r_index = ai->second;
 
         if (addNewNode) {
             // Update aiMap aiMap(Address) = current index
@@ -493,8 +460,6 @@ StackDistCalc::calcStackDistAndUpdate(const Addr r_address, bool addNewNode)
 std::pair< uint64_t, bool>
 StackDistCalc::calcStackDist(const Addr r_address, bool mark)
 {
-    // Return index if the address was already present in stack
-    uint64_t r_index = index;
     // Default value of isMarked flag for each node.
     bool _mark = false;
 
@@ -511,7 +476,7 @@ StackDistCalc::calcStackDist(const Addr r_address, bool mark)
         // key already exists
         // save the index counter value when this address was
         // encountered before
-        r_index = ai->second;
+        uint64_t r_index = ai->second;
 
         // Get the value of mark flag if previously marked
         _mark = tree[0][r_index]->isMarked;
@@ -600,7 +565,6 @@ void
 StackDistCalc::printStack(int n) const
 {
     Node* node;
-    uint64_t r_index;
     int count = 0;
 
     DPRINTF(StackDist, "Printing last %d entries in tree\n", n);
@@ -609,7 +573,7 @@ StackDistCalc::printStack(int n) const
     for (auto it = tree[0].rbegin(); (count < n) && (it != tree[0].rend());
          ++it, ++count) {
         node = it->second;
-        r_index = node->nodeIndex;
+        uint64_t r_index = node->nodeIndex;
 
         // Lookup aiMap using the index returned by the leaf iterator
         for (auto ai = aiMap.rbegin(); ai != aiMap.rend(); ++ai) {
@@ -632,39 +596,3 @@ StackDistCalc::printStack(int n) const
         }
     }
 }
-
-void
-StackDistCalc::regStats()
-{
-    using namespace Stats;
-
-    readLinearHist
-        .init(params()->linear_hist_bins)
-        .name(name() + ".readLinearHist")
-        .desc("Reads linear distribution")
-        .flags(disableLinearHists ? nozero : pdf);
-
-    readLogHist
-        .init(params()->log_hist_bins)
-        .name(name() + ".readLogHist")
-        .desc("Reads logarithmic distribution")
-        .flags(disableLogHists ? nozero : pdf);
-
-    writeLinearHist
-        .init(params()->linear_hist_bins)
-        .name(name() + ".writeLinearHist")
-        .desc("Writes linear distribution")
-        .flags(disableLinearHists ? nozero : pdf);
-
-    writeLogHist
-        .init(params()->log_hist_bins)
-        .name(name() + ".writeLogHist")
-        .desc("Writes logarithmic distribution")
-        .flags(disableLogHists ? nozero : pdf);
-}
-
-StackDistCalc*
-StackDistCalcParams::create()
-{
-    return new StackDistCalc(this);
-}