gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Kanishk Sugand
38  * Andreas Hansson
39  */
40 
41 #ifndef __MEM_STACK_DIST_CALC_HH__
42 #define __MEM_STACK_DIST_CALC_HH__
43 
44 #include <limits>
45 #include <map>
46 #include <vector>
47 
48 #include "base/types.hh"
49 
175 {
176 
177  private:
178 
179  struct Node;
180 
181  typedef std::map<uint64_t, Node*> IndexNodeMap;
182  typedef std::map<Addr, uint64_t> AddressIndexMap;
184 
199  uint64_t getSum(Node* node, bool from_left, uint64_t sum_from_below,
200  uint64_t stack_dist, uint64_t level) const;
201 
210  uint64_t getSumsLeavesToRoot(Node* node) const;
211 
227  uint64_t updateSum(Node* node,
228  bool from_left, uint64_t sum_from_below, uint64_t level,
229  uint64_t stack_dist, bool discard_node);
230 
240  uint64_t updateSumsLeavesToRoot(Node* node, bool is_new_leaf);
241 
252  void updateTree();
253 
264  void sanityCheckTree(const Node* node, uint64_t level = 0) const;
265 
273  uint64_t getIndex() const { return index; }
274 
282  uint64_t getTreeDepth() const { return tree.size() - 1; }
283 
290  void printStack(int n = 5) const;
291 
304  uint64_t verifyStackDist(const Addr r_address,
305  bool update_stack = false);
306 
307  public:
308  StackDistCalc(bool verify_stack = false);
309 
310  ~StackDistCalc();
311 
315  static constexpr uint64_t Infinity = std::numeric_limits<uint64_t>::max();
316 
317 
329  bool mark = false);
330 
344  bool addNewNode = true);
345 
346  private:
347 
351  struct Node{
352  // Sum of the left children
353  uint64_t sumLeft;
354 
355  // Sum of the right children
356  uint64_t sumRight;
357 
358  // Flag to indicate that sumLeft has gone from non-zero value to 0
360 
361  // Flag to indicate that sumRight has gone from non-zero value to 0
363 
364  // Index of the current element in the Map
365  uint64_t nodeIndex;
366 
367  // Pointer to the parent
369 
370  // Flag to mark the node as the right/left child
372 
377  bool isMarked;
378 
383  Node() : sumLeft(0), sumRight(0), discardLeft(false),
384  discardRight(false), nodeIndex(0),
385  parent(nullptr), isLeftNode(true), isMarked(false)
386  { }
387  };
388 
397  uint64_t index;
398 
399  // Binary tree of partial sums
401 
402  // Hash map which returns last seen index of each address
404 
405  // Keeps count of number of the next unique index for each
406  // level in the tree
408 
409  // Dummy Stack for verification
411 
412  // Flag to enable verification of stack. (Slows down the simulation)
413  const bool verifyStack;
414 };
415 
416 
417 #endif //__STACK_DIST_CALC_HH__
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...
AddressIndexMap aiMap
STL pair class.
Definition: stl.hh:61
std::pair< uint64_t, bool > calcStackDistAndUpdate(const Addr r_address, bool addNewNode=true)
Process the given address:
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.
uint64_t updateSumsLeavesToRoot(Node *node, bool is_new_leaf)
Updates the leaf nodes and nodes above.
uint64_t verifyStackDist(const Addr r_address, bool update_stack=false)
This is an alternative implementation of the stack-distance in a naive way.
std::map< Addr, uint64_t > AddressIndexMap
Node which takes form of Leaf, INode or Root.
StackDistCalc(bool verify_stack=false)
std::vector< uint64_t > stack
Bitfield< 31 > n
Definition: miscregs.hh:1636
uint64_t getIndex() const
Return the counter for address accesses (unique and non-unique).
static constexpr uint64_t Infinity
A convenient way of refering to infinity.
Node()
The discard flags are false by default they become true if the node is reached again in a future look...
void updateTree()
updateTree is a tree balancing operation, which maintains the binary tree structure.
std::vector< IndexNodeMap > TreeType
std::map< uint64_t, Node * > IndexNodeMap
const bool verifyStack
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
The stack distance calculator is a passive object that merely observes the addresses pass to it...
std::vector< uint64_t > nextIndex
uint64_t index
Internal counter for address accesses (unique and non-unique) This counter increments everytime the c...
Bitfield< 20 > level
Definition: intmessage.hh:48
bool isMarked
Flag to indicate if this address is marked.
uint64_t getTreeDepth() const
Query depth of the tree (tree[0] represents leaf layer while tree[treeDepth] represents the root laye...
uint64_t getSumsLeavesToRoot(Node *node) const
Gets the sum from the leaf node specified.
void printStack(int n=5) const
Print the last n items on the stack.
std::pair< uint64_t, bool > calcStackDist(const Addr r_address, bool mark=false)
Process the given address.
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.

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6