Skip to content

Commit

Permalink
need to refactor the abort system since it is causing too many edge c…
Browse files Browse the repository at this point in the history
…ases
  • Loading branch information
matthewfl committed Jul 29, 2016
1 parent cc80611 commit c0341d8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef REDMAGIC_CONFIG_H_
#define REDMAGIC_CONFIG_H_

// used for debugging
//#define CONF_COMPILE_IN_PARENT

#define CONF_NUMBER_OF_JUMPS_BEFORE_TRACE 10
// using 10 will cause ipython to crash, TODO: find the bug...
#define CONF_NUMBER_OF_JUMPS_BEFORE_TRACE 100

#define CONF_VERBOSE

//#define CONF_VERBOSE

#define CONF_GLOBAL_ABORT

Expand Down
1 change: 1 addition & 0 deletions src/jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace redmagic {
void *starting_point = nullptr;
bool disabled = false;
int64_t traced_instruction_count = 0;
int64_t longest_trace_instruction_count = 0;
int sub_branches = 0;
int finish_traces = 0; // number of branched traces that reached the end (not merged blocked back)
uint64_t *trace_loop_counter = nullptr;
Expand Down
25 changes: 17 additions & 8 deletions src/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void* Manager::backwards_branch(void *id, void *ret_addr) {
//return NULL;
auto head = get_tracer_head();
if(head->is_traced) {
assert(head->tracer);
assert(head->tracer || head->did_abort);
if(id == head->trace_id) {
auto info = &branches[id];
#ifdef CONF_GLOBAL_ABORT
Expand Down Expand Up @@ -362,9 +362,12 @@ void* Manager::backwards_branch(void *id, void *ret_addr) {
// then we should make a new tracer and jump to that
auto info = &branches[id];
if(info->starting_point) {
assert(!info->tracer); // that we are done with this
head->tracer->JumpToNestedLoop(id);
assert(!info->tracer || info->tracer->did_abort); // that we are done with this
auto new_head = push_tracer_stack();
if(head->tracer && !head->tracer->did_abort)
head->tracer->JumpToNestedLoop(id);
else
new_head->did_abort = !!head->tracer;
new_head->is_compiled = true;
new_head->is_traced = true;
new_head->trace_id = id;
Expand Down Expand Up @@ -596,6 +599,9 @@ bool Manager::should_trace_method(void *id) {
return true;
}

namespace redmagic {
extern long global_icount;
}

void Manager::print_info() {
UnprotectMalloc upm;
Expand All @@ -612,7 +618,7 @@ void Manager::print_info() {


if(a.second->trace_loop_counter != nullptr && b.second->trace_loop_counter != nullptr) {
if(a.second->traced_instruction_count * (*a.second->trace_loop_counter) > b.second->traced_instruction_count * (*b.second->trace_loop_counter))
if(a.second->longest_trace_instruction_count * (*a.second->trace_loop_counter) > b.second->longest_trace_instruction_count * (*b.second->trace_loop_counter))
return true;
else
return false;
Expand All @@ -626,27 +632,30 @@ void Manager::print_info() {

});

red_printf("Global icount: %ld\n", global_icount);

int cnt = 0;
for(auto b : bi) {
if(cnt % 30 == 0) {
red_printf("%3s|%16s|%16s|%10s|%10s|%12s|%10s\n", "#", "trace id", "trace location", "loop count", "icount", "sub branches", "finish traces");
red_printf("===============================================================================================\n");
red_printf("%3s|%16s|%16s|%10s|%10s|%10s|%12s|%10s\n", "#", "trace id", "trace location", "loop count", "sum icount", "max icount", "sub branches", "finished traces");
red_printf("=======================================================================================================\n");
}
cnt++;
if(cnt > 200) break;
red_printf("%3i|%#016lx|%#016lx|%10lu|%10lu|%12i|%10i\n",
red_printf("%3i|%#016lx|%#016lx|%10lu|%10lu|%10lu|%12i|%10i\n",
cnt,
b.first,
b.second->starting_point,
(b.second->trace_loop_counter ? *b.second->trace_loop_counter : 0),
b.second->traced_instruction_count,
b.second->longest_trace_instruction_count,
b.second->sub_branches,
b.second->finish_traces);
}

red_printf("thread tracers\n");
red_printf("%3s|E|C|%16s|%16s|%16s|%16s|%16s\n", "#", "trace id", "tracing from", "tracing pc", "generated pc", "trace icount");
red_printf("======================================================================================\n");
red_printf("=======================================================================================================\n");
for(int i = threadl_tracer_stack.size() - 1; i >= 0; i--) {
auto info = &threadl_tracer_stack[i];
red_printf("%3i|%1i|%1i|%#016lx|%#016lx|%#016lx|%#016lx|%10lu\n",
Expand Down
6 changes: 6 additions & 0 deletions src/redmagic.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class redmagic_disable {
~redmagic_disable() { redmagic_temp_enable(); }
};

class redmagic_merge {
public:
redmagic_merge () { redmagic_begin_merge_block(); }
~redmagic_merge() { redmagic_end_merge_block(); }
};

#endif


Expand Down
15 changes: 13 additions & 2 deletions src/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ extern "C" void red_resume_trace(mem_loc_t target_rip, mem_loc_t write_jump_addr
assert(ret != NULL);

#ifdef CONF_VERBOSE
red_printf("======================\nresume trace: %#016lx %x\n", target_rip, head->trace_id);
red_printf("======================\nresume trace: %#016lx %#016lx\n", target_rip, head->trace_id);
#endif

//protected_malloc = true;
Expand Down Expand Up @@ -230,7 +230,7 @@ extern "C" void* red_end_trace(mem_loc_t normal_end_address) {
new_head->resume_addr = nullptr;
} else {
#ifdef CONF_GLOBAL_ABORT
assert(!global_abort());
assert(!global_abort() || ret == (void*)normal_end_address);
#endif
}
} else {
Expand Down Expand Up @@ -556,6 +556,8 @@ void* Tracer::EndTraceFallthrough() {
auto info = &manager->branches[head->trace_id];
info->traced_instruction_count += icount;
info->finish_traces++;
if(info->longest_trace_instruction_count < icount)
info->longest_trace_instruction_count = icount;

buffer->setOffset(last_call_generated_op);
SimpleCompiler compiler(buffer);
Expand Down Expand Up @@ -593,6 +595,8 @@ void* Tracer::EndTraceLoop() {
assert(loop_location);
info->traced_instruction_count += icount;
info->finish_traces++;
if(info->longest_trace_instruction_count < icount)
info->longest_trace_instruction_count = icount;

buffer->setOffset(last_call_generated_op);
SimpleCompiler compiler(buffer);
Expand Down Expand Up @@ -738,6 +742,9 @@ void* Tracer::EndMergeBlock() {
auto info = &manager->branches[head->trace_id];
assert(info->tracer == this);
head->tracer = info->tracer = nullptr;
info->traced_instruction_count += icount;
if(info->longest_trace_instruction_count < icount)
info->longest_trace_instruction_count = icount;

// auto head = manger->get_tracer_head();
// assert(head->trace_id);
Expand All @@ -753,6 +760,10 @@ void* Tracer::EndMergeBlock() {
delete this;
}

#ifdef CONF_VERBOSE
red_printf("merge block closing back to parent: %#016lx\n", head->trace_id);
#endif

return (void*)resume_a;
} else {
mem_loc_t merge_addr = buffer->getRawBuffer() + buffer->getOffset();
Expand Down
3 changes: 3 additions & 0 deletions tools/gdb-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# load using source tools/gdb-helper.py
# helpful to set: set pagination off

# for gdb attach
# echo 0 > /proc/sys/kernel/yama/ptrace_scope

import gdb
import time
import traceback
Expand Down

0 comments on commit c0341d8

Please sign in to comment.