Skip to content

Commit

Permalink
feat: stack trace handling was implemented with boost graph library
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-harr committed Sep 25, 2019
1 parent 37e570e commit 10206f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 52 deletions.
2 changes: 1 addition & 1 deletion drace-client/detectors/fasttrack/include/fasttrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define MAKE_OUTPUT true
#define REGARD_ALLOCS false


namespace drace {

namespace detector {
Expand All @@ -27,7 +28,6 @@ namespace drace {
typedef size_t tid_ft;
typedef DrLock rwlock;


private:

/// globals ///
Expand Down
81 changes: 41 additions & 40 deletions drace-client/detectors/fasttrack/include/stacktrace.h
Original file line number Diff line number Diff line change
@@ -1,87 +1,88 @@
#ifndef _STACKTRAC_H_
#define _STACKTRAC_H_

#include "xvector.h"
#include <unordered_map>
#include <ipc/DrLock.h>

#include <boost/graph/adjacency_list.hpp>

class StackTrace {
typedef boost::property<boost::vertex_name_t, size_t> VertexProperty;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProperty> stack_tree;


xvector<size_t> global_stack;
//holds var_address, pc, stack_length
std::unordered_map<size_t,
std::pair<size_t, size_t>> read_write;
std::unordered_map<size_t, std::pair<size_t,
stack_tree::vertex_descriptor>> read_write;

stack_tree local_stack;
stack_tree::vertex_descriptor ce;

std::list<size_t> make_trace(std::pair<size_t, stack_tree::vertex_descriptor> data)
{
std::list<size_t> this_stack;

xvector<size_t> make_trace(std::pair<size_t, size_t> data) {
xvector<size_t> 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<size_t> 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<size_t> return_stack_trace(size_t address) {
std::list<size_t> return_stack_trace(size_t address) {

auto it = read_write.find(address);
if (it != read_write.end()) {
auto data = it->second;
xvector<size_t> t = make_trace(data);
std::list<size_t> t = make_trace(data);
return t;
}
else {
//A read/write operation was not tracked correctly -> return empty stack trace
return xvector<size_t>(0);
return std::list<size_t>(0);
}

}
};
#endif
15 changes: 4 additions & 11 deletions drace-client/detectors/fasttrack/src/fasttrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace drace {
size_t var,
uint32_t clk1, uint32_t clk2)
{
xvector<size_t> stack1, stack2;
std::list<size_t> stack1, stack2;
{
std::shared_ptr<StackTrace> s1;
std::shared_ptr<StackTrace> s2;
Expand All @@ -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<size_t>(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<size_t>(begin_stack, end_stack);
stack2.pop_front();
}

Detector::AccessEntry access1;
Expand Down Expand Up @@ -92,7 +86,6 @@ namespace drace {
race.first = access1;
race.second = access2;


((void(*)(const Detector::Race*))clb)(&race);
}

Expand Down

0 comments on commit 10206f0

Please sign in to comment.