43 #include "debug/StackDist.hh" 47 verifyStack(verify_stack)
57 tree.push_back(tree_level);
66 tree.push_back(tree_level);
75 for (
auto& layer :
tree) {
76 for (
auto& index_node : layer) {
78 delete index_node.second;
98 uint64_t sum_from_below, uint64_t
level,
99 uint64_t stack_dist,
bool discard_node)
105 uint64_t node_sum_l = node->
sumLeft;
106 uint64_t node_sum_r = node->
sumRight;
121 panic_if(node_sum_l > (1 << (level - 1)),
122 "Error in sum left of level %ul, node index %ull, " 123 "Sum = %ull \n", level, node_n_index, node_sum_l);
125 panic_if(node_sum_r > (1 << (level - 1)),
126 "Error in sum right of level %ul, node index %ull, " 127 "Sum = %ull \n", level, node_n_index, node_sum_r);
135 node_sum_l = sum_from_below;
136 stack_dist += node_sum_r;
139 node_sum_r = sum_from_below;
143 if (discard_node && !sum_from_below) {
145 node_discard_left =
true;
147 node_discard_right =
true;
159 if (node_discard_left && node_discard_right &&
160 discard_node && node_parent_ptr && !sum_from_below) {
167 discard_node =
false;
172 if (node_parent_ptr) {
173 stack_dist =
updateSum(node_parent_ptr, node_left,
174 node_sum_l + node_sum_r,
175 level, stack_dist, discard_node);
189 uint64_t stack_dist = 0;
202 level, stack_dist,
true);
212 uint64_t stack_dist, uint64_t
level)
const 280 tree.push_back(treeLevel);
325 if ((
index % (1 << i)) == 0) {
361 auto ai =
aiMap.lower_bound(r_address);
375 if (ai !=
aiMap.end() && !(
aiMap.key_comp()(r_address, ai->first))) {
379 uint64_t r_index = ai->second;
385 aiMap.erase(r_address);
392 newLeafNode =
tree[0][r_index];
396 tree[0].erase(r_index);
409 if (
index % 2 == 0) {
419 newLeafNode =
new Node();
440 panic_if(verify_stack_dist != stack_dist,
441 "Expected stack-distance for address \ 442 %#lx is %#lx but found %#lx",
443 r_address, verify_stack_dist, stack_dist);
452 return (std::make_pair(stack_dist, _mark));
464 auto ai =
aiMap.lower_bound(r_address);
467 uint64_t stack_dist = 0;
473 if (ai !=
aiMap.end() && !(
aiMap.key_comp()(r_address, ai->first))) {
477 uint64_t r_index = ai->second;
480 _mark =
tree[0][r_index]->isMarked;
482 tree[0][r_index]->isMarked = mark;
498 panic_if(verify_stack_dist != stack_dist,
499 "Expected stack-distance for address \ 500 %#lx is %#lx but found %#lx",
501 r_address, verify_stack_dist, stack_dist);
506 return std::make_pair(stack_dist, _mark);
517 next_up = next_up->
parent;
518 panic_if(!next_up,
"Sanity check failed for node %ull \n",
535 uint64_t stack_dist = 0;
538 for (;
a !=
stack.rend(); ++
a) {
539 if (*
a == r_address) {
556 stack.push_back(r_address);
568 DPRINTF(StackDist,
"Printing last %d entries in tree\n", n);
571 for (
auto it =
tree[0].rbegin(); (count <
n) && (it !=
tree[0].rend());
577 for (
auto ai =
aiMap.rbegin(); ai !=
aiMap.rend(); ++ai) {
578 if (ai->second == r_index) {
579 DPRINTF(StackDist,
"Tree leaves, Rightmost-[%d] = %#lx\n",
589 DPRINTF(StackDist,
"Printing Last %d entries in VerifStack \n", n);
591 for (
auto a =
stack.rbegin(); (count <
n) && (
a !=
stack.rend());
593 DPRINTF(StackDist,
"Verif Stack, Top-[%d] = %#lx\n", count, *
a);
std::pair< uint64_t, bool > calcStackDistAndUpdate(const Addr r_address, bool addNewNode=true)
Process the given address:
uint64_t getTreeDepth() const
Query depth of the tree (tree[0] represents leaf layer while tree[treeDepth] represents the root laye...
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.
Node which takes form of Leaf, INode or Root.
StackDistCalc(bool verify_stack=false)
std::vector< uint64_t > stack
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.
static constexpr uint64_t Infinity
A convenient way of refering to infinity.
void updateTree()
updateTree is a tree balancing operation, which maintains the binary tree structure.
bool isPowerOf2(const T &n)
std::map< uint64_t, Node * > IndexNodeMap
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
std::vector< uint64_t > nextIndex
void printStack(int n=5) const
Print the last n items on the stack.
uint64_t index
Internal counter for address accesses (unique and non-unique) This counter increments everytime the c...
uint64_t getSumsLeavesToRoot(Node *node) const
Gets the sum from the leaf node specified.
bool isMarked
Flag to indicate if this address is marked.
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...
Declaration and inline definition of ChunkGenerator object.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
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.