gem5  v20.1.0.0
stack_dist_calc.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __MEM_STACK_DIST_CALC_HH__
39 #define __MEM_STACK_DIST_CALC_HH__
40 
41 #include <limits>
42 #include <map>
43 #include <vector>
44 
45 #include "base/types.hh"
46 
172 {
173 
174  private:
175 
176  struct Node;
177 
178  typedef std::map<uint64_t, Node*> IndexNodeMap;
179  typedef std::map<Addr, uint64_t> AddressIndexMap;
181 
196  uint64_t getSum(Node* node, bool from_left, uint64_t sum_from_below,
197  uint64_t stack_dist, uint64_t level) const;
198 
207  uint64_t getSumsLeavesToRoot(Node* node) const;
208 
224  uint64_t updateSum(Node* node,
225  bool from_left, uint64_t sum_from_below, uint64_t level,
226  uint64_t stack_dist, bool discard_node);
227 
237  uint64_t updateSumsLeavesToRoot(Node* node, bool is_new_leaf);
238 
249  void updateTree();
250 
261  void sanityCheckTree(const Node* node, uint64_t level = 0) const;
262 
270  uint64_t getIndex() const { return index; }
271 
279  uint64_t getTreeDepth() const { return tree.size() - 1; }
280 
287  void printStack(int n = 5) const;
288 
301  uint64_t verifyStackDist(const Addr r_address,
302  bool update_stack = false);
303 
304  public:
305  StackDistCalc(bool verify_stack = false);
306 
307  ~StackDistCalc();
308 
312  static constexpr uint64_t Infinity = std::numeric_limits<uint64_t>::max();
313 
314 
326  bool mark = false);
327 
341  bool addNewNode = true);
342 
343  private:
344 
348  struct Node{
349  // Sum of the left children
350  uint64_t sumLeft;
351 
352  // Sum of the right children
353  uint64_t sumRight;
354 
355  // Flag to indicate that sumLeft has gone from non-zero value to 0
357 
358  // Flag to indicate that sumRight has gone from non-zero value to 0
360 
361  // Index of the current element in the Map
362  uint64_t nodeIndex;
363 
364  // Pointer to the parent
366 
367  // Flag to mark the node as the right/left child
369 
374  bool isMarked;
375 
380  Node() : sumLeft(0), sumRight(0), discardLeft(false),
381  discardRight(false), nodeIndex(0),
382  parent(nullptr), isLeftNode(true), isMarked(false)
383  { }
384  };
385 
394  uint64_t index;
395 
396  // Binary tree of partial sums
398 
399  // Hash map which returns last seen index of each address
401 
402  // Keeps count of number of the next unique index for each
403  // level in the tree
405 
406  // Dummy Stack for verification
408 
409  // Flag to enable verification of stack. (Slows down the simulation)
410  const bool verifyStack;
411 };
412 
413 
414 #endif //__STACK_DIST_CALC_HH__
StackDistCalc::StackDistCalc
StackDistCalc(bool verify_stack=false)
Definition: stack_dist_calc.cc:45
StackDistCalc::getSumsLeavesToRoot
uint64_t getSumsLeavesToRoot(Node *node) const
Gets the sum from the leaf node specified.
Definition: stack_dist_calc.cc:234
StackDistCalc::Node::parent
Node * parent
Definition: stack_dist_calc.hh:365
StackDistCalc::IndexNodeMap
std::map< uint64_t, Node * > IndexNodeMap
Definition: stack_dist_calc.hh:176
StackDistCalc::~StackDistCalc
~StackDistCalc()
Definition: stack_dist_calc.cc:72
StackDistCalc::Node::discardLeft
bool discardLeft
Definition: stack_dist_calc.hh:356
StackDistCalc::Node::nodeIndex
uint64_t nodeIndex
Definition: stack_dist_calc.hh:362
StackDistCalc::TreeType
std::vector< IndexNodeMap > TreeType
Definition: stack_dist_calc.hh:180
StackDistCalc::calcStackDist
std::pair< uint64_t, bool > calcStackDist(const Addr r_address, bool mark=false)
Process the given address.
Definition: stack_dist_calc.cc:459
StackDistCalc::sanityCheckTree
void sanityCheckTree(const Node *node, uint64_t level=0) const
This method is used for verification purposes It recursively traverses upwards from the given node ti...
Definition: stack_dist_calc.cc:512
std::vector< IndexNodeMap >
StackDistCalc::Node::isMarked
bool isMarked
Flag to indicate if this address is marked.
Definition: stack_dist_calc.hh:374
StackDistCalc::Node::sumRight
uint64_t sumRight
Definition: stack_dist_calc.hh:353
StackDistCalc::tree
TreeType tree
Definition: stack_dist_calc.hh:397
StackDistCalc::updateTree
void updateTree()
updateTree is a tree balancing operation, which maintains the binary tree structure.
Definition: stack_dist_calc.cc:248
StackDistCalc::updateSumsLeavesToRoot
uint64_t updateSumsLeavesToRoot(Node *node, bool is_new_leaf)
Updates the leaf nodes and nodes above.
Definition: stack_dist_calc.cc:186
StackDistCalc::index
uint64_t index
Internal counter for address accesses (unique and non-unique) This counter increments everytime the c...
Definition: stack_dist_calc.hh:394
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
StackDistCalc::Node::isLeftNode
bool isLeftNode
Definition: stack_dist_calc.hh:368
StackDistCalc::stack
std::vector< uint64_t > stack
Definition: stack_dist_calc.hh:407
StackDistCalc::getSum
uint64_t getSum(Node *node, bool from_left, uint64_t sum_from_below, uint64_t stack_dist, uint64_t level) const
Gets sum from the node upwards recursively till the root.
Definition: stack_dist_calc.cc:211
StackDistCalc::Node
Node which takes form of Leaf, INode or Root.
Definition: stack_dist_calc.hh:348
StackDistCalc::Node::sumLeft
uint64_t sumLeft
Definition: stack_dist_calc.hh:350
StackDistCalc::Node::discardRight
bool discardRight
Definition: stack_dist_calc.hh:359
StackDistCalc::verifyStackDist
uint64_t verifyStackDist(const Addr r_address, bool update_stack=false)
This is an alternative implementation of the stack-distance in a naive way.
Definition: stack_dist_calc.cc:532
StackDistCalc::calcStackDistAndUpdate
std::pair< uint64_t, bool > calcStackDistAndUpdate(const Addr r_address, bool addNewNode=true)
Process the given address:
Definition: stack_dist_calc.cc:357
std::pair
STL pair class.
Definition: stl.hh:58
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
StackDistCalc::updateSum
uint64_t updateSum(Node *node, bool from_left, uint64_t sum_from_below, uint64_t level, uint64_t stack_dist, bool discard_node)
Updates the nodes upwards recursively till the root.
Definition: stack_dist_calc.cc:97
StackDistCalc::Infinity
static constexpr uint64_t Infinity
A convenient way of refering to infinity.
Definition: stack_dist_calc.hh:312
StackDistCalc
The stack distance calculator is a passive object that merely observes the addresses pass to it.
Definition: stack_dist_calc.hh:171
StackDistCalc::getTreeDepth
uint64_t getTreeDepth() const
Query depth of the tree (tree[0] represents leaf layer while tree[treeDepth] represents the root laye...
Definition: stack_dist_calc.hh:279
X86ISA::level
Bitfield< 20 > level
Definition: intmessage.hh:47
types.hh
StackDistCalc::Node::Node
Node()
The discard flags are false by default they become true if the node is reached again in a future look...
Definition: stack_dist_calc.hh:380
StackDistCalc::verifyStack
const bool verifyStack
Definition: stack_dist_calc.hh:410
StackDistCalc::getIndex
uint64_t getIndex() const
Return the counter for address accesses (unique and non-unique).
Definition: stack_dist_calc.hh:270
StackDistCalc::printStack
void printStack(int n=5) const
Print the last n items on the stack.
Definition: stack_dist_calc.cc:563
StackDistCalc::nextIndex
std::vector< uint64_t > nextIndex
Definition: stack_dist_calc.hh:404
StackDistCalc::AddressIndexMap
std::map< Addr, uint64_t > AddressIndexMap
Definition: stack_dist_calc.hh:179
StackDistCalc::aiMap
AddressIndexMap aiMap
Definition: stack_dist_calc.hh:400

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17