From 10206f06e2238a6cd5b30761b50b2f610161724c Mon Sep 17 00:00:00 2001 From: Philip Harr Date: Wed, 25 Sep 2019 09:25:14 +0200 Subject: [PATCH] feat: stack trace handling was implemented with boost graph library --- .../detectors/fasttrack/include/fasttrack.h | 2 +- .../detectors/fasttrack/include/stacktrace.h | 81 ++++++++++--------- .../detectors/fasttrack/src/fasttrack.cpp | 15 +--- 3 files changed, 46 insertions(+), 52 deletions(-) diff --git a/drace-client/detectors/fasttrack/include/fasttrack.h b/drace-client/detectors/fasttrack/include/fasttrack.h index e55dbba..4d89822 100644 --- a/drace-client/detectors/fasttrack/include/fasttrack.h +++ b/drace-client/detectors/fasttrack/include/fasttrack.h @@ -18,6 +18,7 @@ #define MAKE_OUTPUT true #define REGARD_ALLOCS false + namespace drace { namespace detector { @@ -27,7 +28,6 @@ namespace drace { typedef size_t tid_ft; typedef DrLock rwlock; - private: /// globals /// diff --git a/drace-client/detectors/fasttrack/include/stacktrace.h b/drace-client/detectors/fasttrack/include/stacktrace.h index 68f2779..1fb333c 100644 --- a/drace-client/detectors/fasttrack/include/stacktrace.h +++ b/drace-client/detectors/fasttrack/include/stacktrace.h @@ -1,87 +1,88 @@ +#ifndef _STACKTRAC_H_ +#define _STACKTRAC_H_ + #include "xvector.h" #include #include - +#include class StackTrace { + typedef boost::property VertexProperty; + typedef boost::adjacency_list stack_tree; + - xvector global_stack; //holds var_address, pc, stack_length - std::unordered_map> read_write; + std::unordered_map> read_write; + stack_tree local_stack; + stack_tree::vertex_descriptor ce; + std::list make_trace(std::pair data) + { + std::list this_stack; - xvector make_trace(std::pair data) { - xvector this_stack; - this_stack.push_back(data.first); - return this_stack; + stack_tree::vertex_descriptor act_item = data.second; - /* size_t len = data.second; - const auto begin = global_stack.begin(); - const auto end = begin + len; - xvector this_stack(global_stack); - - - unsigned int flag = 1; // contains_zero(*this_stack); - unsigned int last_pos = 1; - do{ - flag = 1; - for (auto it = this_stack.begin() ; it != this_stack.end(); it++) { - if (*it == 0 && this_stack.size() > 2) { - auto e_it = this_stack.begin(); - this_stack.erase(e_it + (last_pos - 1), e_it + (last_pos +1)); - //last_pos -= 2; - flag = 0; - break; - } - last_pos++; - } - } while (flag == 0 && this_stack.size() > 0); + this_stack.push_front(data.first); + auto map = boost::get(boost::vertex_name_t(), local_stack); + this_stack.push_front(map[act_item]); - this_stack.push_back(data.first); - return this_stack;*/ + + while (boost::out_degree(act_item, local_stack) != 0) { + auto edge = boost::out_edges(act_item, local_stack); + act_item = (boost::target(*(edge.first), local_stack)); + if (map[act_item] != 0) { + this_stack.push_front(map[act_item]); + } + } + + return this_stack; } public: + StackTrace():ce(boost::add_vertex(0, local_stack)){} + void pop_stack_element() { - global_stack.push_back(0); - + auto edge = boost::out_edges(ce, local_stack); + ce = (boost::target(*(edge.first), local_stack)); } void push_stack_element(size_t element) { - global_stack.push_back(element); + auto temp = boost::add_vertex(VertexProperty(element), local_stack); + boost::add_edge(temp, ce, local_stack); + ce = temp; } ///when a var is written or read, it copies the stack and adds the pc of the ///r/w operation to be able to return the stack trace if a race was detected void set_read_write(size_t addr, size_t pc) { - size_t len = global_stack.size(); if (read_write.find(addr) == read_write.end()) { - read_write.insert({ addr, {pc, len} }); + read_write.insert({ addr, {pc, ce} }); } else { - read_write.find(addr)->second = { pc, len }; + read_write.find(addr)->second = { pc, ce }; } } ///returns a stack trace of a clock for handing it over to drace - xvector return_stack_trace(size_t address) { + std::list return_stack_trace(size_t address) { auto it = read_write.find(address); if (it != read_write.end()) { auto data = it->second; - xvector t = make_trace(data); + std::list t = make_trace(data); return t; } else { //A read/write operation was not tracked correctly -> return empty stack trace - return xvector(0); + return std::list(0); } } }; +#endif diff --git a/drace-client/detectors/fasttrack/src/fasttrack.cpp b/drace-client/detectors/fasttrack/src/fasttrack.cpp index 09119ea..73c3297 100644 --- a/drace-client/detectors/fasttrack/src/fasttrack.cpp +++ b/drace-client/detectors/fasttrack/src/fasttrack.cpp @@ -23,7 +23,7 @@ namespace drace { size_t var, uint32_t clk1, uint32_t clk2) { - xvector stack1, stack2; + std::list stack1, stack2; { std::shared_ptr s1; std::shared_ptr s2; @@ -50,17 +50,11 @@ namespace drace { size_t var_size = 0; var_size = vars[var]->size; //size is const member -> thread safe - if (stack1.size() > 16) { - auto end_stack = stack1.end(); - auto begin_stack = stack1.end() - 16; - - stack1 = xvector(begin_stack, end_stack); + while(stack1.size() > 16) { + stack1.pop_front(); } if (stack2.size() > 16) { - auto end_stack = stack2.end(); - auto begin_stack = stack2.end() - 16; - - stack2 = xvector(begin_stack, end_stack); + stack2.pop_front(); } Detector::AccessEntry access1; @@ -92,7 +86,6 @@ namespace drace { race.first = access1; race.second = access2; - ((void(*)(const Detector::Race*))clb)(&race); }