Skip to content

Commit

Permalink
i#2645 delayed burst, part 2: add -exit_after_tracing (#2687)
Browse files Browse the repository at this point in the history
Adds a new drmemtrace feature -exit_after_tracing N which exits the process
after tracing N memory references.  Extends the -trace_after_instr test to
include -exit_after_tracing.

We would prefer -detach_after_tracing but we need i#2644 for that and we
leave it for future work.

Fixes #2645 

Xref: #2644
  • Loading branch information
derekbruening authored and fhahn committed Dec 4, 2017
1 parent ba2602e commit 1c2071b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ droption_t<bytesize_t> op_trace_after_instrs
"executions are observed. At that point, regular tracing is put into place. Use "
"-max_trace_size to set a limit on the subsequent trace length.");

droption_t<bytesize_t> op_exit_after_tracing
(DROPTION_SCOPE_CLIENT, "exit_after_tracing", 0,
"Exit the process after tracing N references",
"If non-zero, after tracing the specified number of references, the process is "
"exited with an exit code of 0. The reference count is approximate.");

droption_t<bool> op_online_instr_types
(DROPTION_SCOPE_CLIENT, "online_instr_types", false,
"Whether online traces should distinguish instr types",
Expand Down
1 change: 1 addition & 0 deletions clients/drcachesim/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extern droption_t<bool> op_use_physical;
extern droption_t<unsigned int> op_virt2phys_freq;
extern droption_t<bytesize_t> op_max_trace_size;
extern droption_t<bytesize_t> op_trace_after_instrs;
extern droption_t<bytesize_t> op_exit_after_tracing;
extern droption_t<bool> op_online_instr_types;
extern droption_t<std::string> op_replace_policy;
extern droption_t<std::string> op_data_prefetcher;
Expand Down
2 changes: 1 addition & 1 deletion clients/drcachesim/tests/drcachesim-delay-simple.templatex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Hit delay threshold: enabling tracing.
Hello, world!
Exiting process after ~1.... references.
---- <application exited with code 0> ----
Cache simulation results:
Core #0 \(1 thread\(s\)\)
Expand Down
22 changes: 21 additions & 1 deletion clients/drcachesim/tracer/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ static instru_t *instru;
static client_id_t client_id;
static void *mutex; /* for multithread support */
static uint64 num_refs; /* keep a global memory reference count */
static uint64 num_refs_racy; /* racy global memory reference count */
static volatile bool exited_process;

/* virtual to physical translation */
static bool have_phys;
Expand Down Expand Up @@ -308,6 +310,7 @@ memtrace(void *drcontext, bool skip_size_cap)
byte *pipe_start, *pipe_end, *redzone;
bool do_write = true;
size_t header_size = buf_hdr_slots_size;
uint num_refs = 0;

buf_ptr = BUF_PTR(data->seg_base);
// We may get called with nothing to write: e.g., on a syscall for -L0_filter.
Expand Down Expand Up @@ -336,7 +339,7 @@ memtrace(void *drcontext, bool skip_size_cap)
if (do_write) {
for (mem_ref = data->buf_base + header_size; mem_ref < buf_ptr;
mem_ref += instru->sizeof_entry()) {
data->num_refs++;
num_refs++;
if (have_phys && op_use_physical.get_value()) {
trace_type_t type = instru->get_entry_type(mem_ref);
if (type != TRACE_TYPE_THREAD &&
Expand Down Expand Up @@ -381,6 +384,7 @@ memtrace(void *drcontext, bool skip_size_cap)
if ((buf_ptr - pipe_start) > (ssize_t)buf_hdr_slots_size)
atomic_pipe_write(drcontext, pipe_start, buf_ptr);
}
data->num_refs += num_refs;
}

if (do_write && file_ops_func.handoff_buf != NULL) {
Expand All @@ -398,6 +402,22 @@ memtrace(void *drcontext, bool skip_size_cap)
}
}
BUF_PTR(data->seg_base) = data->buf_base + buf_hdr_slots_size;
num_refs_racy += num_refs;
if (op_exit_after_tracing.get_value() > 0 &&
num_refs_racy > op_exit_after_tracing.get_value()) {
dr_mutex_lock(mutex);
if (!exited_process) {
exited_process = true;
dr_mutex_unlock(mutex);
// XXX i#2644: we would prefer detach_after_tracing rather than exiting
// the process but that requires a client-triggered detach so for now
// we settle for exiting.
NOTIFY(0, "Exiting process after ~" UINT64_FORMAT_STRING" references.\n",
num_refs_racy);
dr_exit_process(0);
}
dr_mutex_unlock(mutex);
}
}

/* clean_call sends the memory reference info to the simulator */
Expand Down
3 changes: 2 additions & 1 deletion suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,8 @@ if (CLIENT_INTERFACE)

torunonly_ci(tool.drcachesim.delay ${ci_shared_app} drcachesim
"drcachesim-delay-simple.c" # for templatex basename
"-ipc_name ${IPC_PREFIX}drtestdelay -trace_after_instrs 50000" "" "")
"-ipc_name ${IPC_PREFIX}drtestdelay -trace_after_instrs 50000 -exit_after_tracing 10000"
"" "")
set(tool.drcachesim.delay_toolname "drcachesim")
set(tool.drcachesim.delay_basedir
"${PROJECT_SOURCE_DIR}/clients/drcachesim/tests")
Expand Down

0 comments on commit 1c2071b

Please sign in to comment.