Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master' into i5036-aarch64-scatt…
Browse files Browse the repository at this point in the history
…er-gather-multivector

Change-Id: Ia157d828be53d49cb2af574e72ac5c7d7bf6a775
  • Loading branch information
jackgallagher-arm committed Nov 20, 2023
2 parents b9ba140 + 63c701b commit 482432d
Show file tree
Hide file tree
Showing 284 changed files with 5,320 additions and 3,446 deletions.
4 changes: 2 additions & 2 deletions api/samples/bbsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void
event_exit(void);
static dr_emit_flags_t
event_bb_analysis(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
bool translating, OUT void **user_data);
bool translating, DR_PARAM_OUT void **user_data);

DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
Expand Down Expand Up @@ -110,7 +110,7 @@ event_exit(void)

static dr_emit_flags_t
event_bb_analysis(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
bool translating, OUT void **user_data)
bool translating, DR_PARAM_OUT void **user_data)
{
int cur_size = 0;

Expand Down
2 changes: 1 addition & 1 deletion api/samples/callstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ print_qualified_function_name(app_pc pc)
}

static void
wrap_pre(void *wrapcxt, OUT void **user_data)
wrap_pre(void *wrapcxt, DR_PARAM_OUT void **user_data)
{
dr_fprintf(STDERR, "%s called from:\n", trace_function.get_value().c_str());
// Get the context. The pc field is set by drwrap to the wrapped function
Expand Down
2 changes: 1 addition & 1 deletion api/samples/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ callback(app_pc addr, uint divisor)

/* If instr is unsigned division, return true and set *opnd to divisor. */
static bool
instr_is_div(instr_t *instr, OUT opnd_t *opnd)
instr_is_div(instr_t *instr, DR_PARAM_OUT opnd_t *opnd)
{
int opc = instr_get_opcode(instr);
#if defined(X86)
Expand Down
2 changes: 1 addition & 1 deletion api/samples/hot_bbcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ set_up_bb_dups(void *drbbdup_ctx, void *drcontext, void *tag, instrlist_t *bb,

static void
analyse_orig_bb(void *drcontext, void *tag, instrlist_t *bb, void *user_data,
IN void **orig_analysis_data)
DR_PARAM_IN void **orig_analysis_data)
{
/* Extract bb_pc and store it as analysis data. */
app_pc *bb_pc = dr_thread_alloc(drcontext, sizeof(app_pc));
Expand Down
34 changes: 0 additions & 34 deletions api/samples/memtrace_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ static int tls_idx;

#define MINSERT instrlist_meta_preinsert

#ifdef AARCH64
static bool reported_sg_warning = false;
#endif

static void
memtrace(void *drcontext)
{
Expand Down Expand Up @@ -320,43 +316,13 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *wher
for (i = 0; i < instr_num_srcs(instr_operands); i++) {
const opnd_t src = instr_get_src(instr_operands, i);
if (opnd_is_memory_reference(src)) {
#ifdef AARCH64
/* TODO i#5036: Memory references involving SVE registers are not
* supported yet. To be implemented as part of scatter/gather work.
*/
if (opnd_is_base_disp(src) &&
(reg_is_z(opnd_get_base(src)) || reg_is_z(opnd_get_index(src)))) {
if (!reported_sg_warning) {
dr_fprintf(STDERR,
"WARNING: Scatter/gather is not supported, results will "
"be inaccurate\n");
reported_sg_warning = true;
}
continue;
}
#endif
instrument_mem(drcontext, bb, where, src, false);
}
}

for (i = 0; i < instr_num_dsts(instr_operands); i++) {
const opnd_t dst = instr_get_dst(instr_operands, i);
if (opnd_is_memory_reference(dst)) {
#ifdef AARCH64
/* TODO i#5036: Memory references involving SVE registers are not
* supported yet. To be implemented as part of scatter/gather work.
*/
if (opnd_is_base_disp(dst) &&
(reg_is_z(opnd_get_base(dst)) || reg_is_z(opnd_get_index(dst)))) {
if (!reported_sg_warning) {
dr_fprintf(STDERR,
"WARNING: Scatter/gather is not supported, results will "
"be inaccurate\n");
reported_sg_warning = true;
}
continue;
}
#endif
instrument_mem(drcontext, bb, where, dst, true);
}
}
Expand Down
36 changes: 0 additions & 36 deletions api/samples/memval_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ static int tls_idx;
static drx_buf_t *write_buffer;
static drx_buf_t *trace_buffer;

#ifdef AARCH64
static bool reported_sg_warning = false;
#endif

/* Requires that hex_buf be at least as long as 2*memref->size + 1. */
static char *
write_hexdump(char *hex_buf, byte *write_base, mem_ref_t *mem_ref)
Expand Down Expand Up @@ -332,23 +328,6 @@ handle_post_write(void *drcontext, instrlist_t *ilist, instr_t *where, reg_id_t
DR_ASSERT_MSG(false, "Found inst with multiple memory destinations");
break;
}

#ifdef AARCH64
/* TODO i#5036: Memory references involving SVE registers are not
* supported yet. To be implemented as part of scatter/gather work.
*/
if (opnd_is_base_disp(dst) &&
(reg_is_z(opnd_get_base(dst)) || reg_is_z(opnd_get_index(dst)))) {
if (!reported_sg_warning) {
dr_fprintf(STDERR,
"WARNING: Scatter/gather is not supported, results "
"will be inaccurate\n");
reported_sg_warning = true;
}
continue;
}
#endif

seen_memref = true;
instrument_post_write(drcontext, ilist, where, dst, prev_instr, reg_addr);
}
Expand Down Expand Up @@ -404,21 +383,6 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *wher
DR_ASSERT_MSG(false, "Found inst with multiple memory destinations");
break;
}
#ifdef AARCH64
/* TODO i#5036: Memory references involving SVE registers are not
* supported yet. To be implemented as part of scatter/gather work.
*/
if (opnd_is_base_disp(dst) &&
(reg_is_z(opnd_get_base(dst)) || reg_is_z(opnd_get_index(dst)))) {
if (!reported_sg_warning) {
dr_fprintf(STDERR,
"WARNING: Scatter/gather is not supported, results "
"will be inaccurate\n");
reported_sg_warning = true;
}
continue;
}
#endif
data->reg_addr = instrument_pre_write(
drcontext, bb, where, data->last_opcode, instr_operands, dst);
seen_memref = true;
Expand Down
2 changes: 1 addition & 1 deletion api/samples/opcode_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ event_opcode_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *i

static dr_emit_flags_t
event_bb_analysis(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
bool translating, OUT void **user_data)
bool translating, DR_PARAM_OUT void **user_data)
{
intptr_t bb_size = (intptr_t)drx_instrlist_app_size(bb);
*user_data = (void *)bb_size;
Expand Down
8 changes: 4 additions & 4 deletions api/samples/ssljack.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@

/* OpenSSL and GnuTLS - shared wrappers */
static void
wrap_pre_SSL_write(void *wrapcxt, OUT void **user_data);
wrap_pre_SSL_write(void *wrapcxt, DR_PARAM_OUT void **user_data);
static void
wrap_pre_SSL_read(void *wrapcxt, OUT void **user_data);
wrap_pre_SSL_read(void *wrapcxt, DR_PARAM_OUT void **user_data);
static void
wrap_post_SSL_read(void *wrapcxt, void *user_data);

Expand Down Expand Up @@ -128,7 +128,7 @@ dr_init(client_id_t id)
}

static void
wrap_pre_SSL_write(void *wrapcxt, OUT void **user_data)
wrap_pre_SSL_write(void *wrapcxt, DR_PARAM_OUT void **user_data)
{
/* int SSL_write(SSL *ssl, const void *buf, int num);
*
Expand Down Expand Up @@ -161,7 +161,7 @@ wrap_pre_SSL_write(void *wrapcxt, OUT void **user_data)
}

static void
wrap_pre_SSL_read(void *wrapcxt, OUT void **user_data)
wrap_pre_SSL_read(void *wrapcxt, DR_PARAM_OUT void **user_data)
{
struct SSL_read_data *sd;

Expand Down
2 changes: 1 addition & 1 deletion api/samples/statecmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ error_callback(const char *msg, void *tag)

static dr_emit_flags_t
event_analysis(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
bool translating, OUT void **user_data)
bool translating, DR_PARAM_OUT void **user_data)
{

bool *side_effect_free = (bool *)dr_thread_alloc(drcontext, sizeof(bool));
Expand Down
4 changes: 2 additions & 2 deletions api/samples/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
static void
event_exit(void);
static void
wrap_pre(void *wrapcxt, OUT void **user_data);
wrap_pre(void *wrapcxt, DR_PARAM_OUT void **user_data);
static void
wrap_post(void *wrapcxt, void *user_data);

Expand Down Expand Up @@ -141,7 +141,7 @@ event_exit(void)
}

static void
wrap_pre(void *wrapcxt, OUT void **user_data)
wrap_pre(void *wrapcxt, DR_PARAM_OUT void **user_data)
{
/* malloc(size) or HeapAlloc(heap, flags, size) */
size_t sz = (size_t)drwrap_get_arg(wrapcxt, IF_WINDOWS_ELSE(2, 0));
Expand Down
13 changes: 13 additions & 0 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,9 @@ add_subdirectory(tools/external)
# We build larger executables here. All tests are added in suite/tests/ except unit tests.
# Be sure to give the targets qualified test names ("tool.drcache*...").

# XXX: Try to add a macro add_drcachesim_test() to share common pieces
# of these executables.

if (BUILD_TESTS)
add_executable(tool.reuse_distance.unit_tests tests/reuse_distance_test.cpp)
target_link_libraries(tool.reuse_distance.unit_tests drmemtrace_reuse_distance
Expand Down Expand Up @@ -907,6 +910,16 @@ if (BUILD_TESTS)
set_tests_properties(tool.drcachesim.invariant_checker_test PROPERTIES
TIMEOUT ${test_seconds})

add_executable(tool.drcachesim.schedule_stats_test tests/schedule_stats_test.cpp)
configure_DynamoRIO_standalone(tool.drcachesim.schedule_stats_test)
add_win32_flags(tool.drcachesim.schedule_stats_test)
target_link_libraries(tool.drcachesim.schedule_stats_test drmemtrace_schedule_stats
drmemtrace_static drmemtrace_analyzer test_helpers)
add_test(NAME tool.drcachesim.schedule_stats_test
COMMAND tool.drcachesim.schedule_stats_test)
set_tests_properties(tool.drcachesim.schedule_stats_test PROPERTIES
TIMEOUT ${test_seconds})

add_executable(tool.drcacheoff.view_test tests/view_test.cpp reader/file_reader.cpp)
configure_DynamoRIO_standalone(tool.drcacheoff.view_test)
add_win32_flags(tool.drcacheoff.view_test)
Expand Down
8 changes: 8 additions & 0 deletions clients/drcachesim/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ analyzer_tmpl_t<RecordType, ReaderType>::process_shard_exit(
{
VPRINT(this, 1, "Worker %d finished trace shard %s\n", worker->index,
worker->stream->get_stream_name().c_str());
worker->shard_data[shard_index].exited = true;
if (interval_microseconds_ != 0 &&
!process_interval(worker->shard_data[shard_index].cur_interval_index,
worker->shard_data[shard_index].cur_interval_init_instr_count,
Expand Down Expand Up @@ -560,6 +561,7 @@ analyzer_tmpl_t<RecordType, ReaderType>::process_tasks(analyzer_worker_data_t *w
tools_[i]->parallel_shard_init_stream(
shard_index, user_worker_data[i], worker->stream);
}
worker->shard_data[shard_index].shard_index = shard_index;
}
memref_tid_t tid;
if (worker->shard_data[shard_index].shard_id == 0) {
Expand Down Expand Up @@ -597,6 +599,12 @@ analyzer_tmpl_t<RecordType, ReaderType>::process_tasks(analyzer_worker_data_t *w
if (!process_shard_exit(worker, worker->index))
return;
}
for (const auto &keyval : worker->shard_data) {
if (!keyval.second.exited) {
if (!process_shard_exit(worker, keyval.second.shard_index))
return;
}
}
for (int i = 0; i < num_tools_; ++i) {
const std::string error = tools_[i]->parallel_worker_exit(user_worker_data[i]);
if (!error.empty()) {
Expand Down
6 changes: 4 additions & 2 deletions clients/drcachesim/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ template <typename RecordType, typename ReaderType> class analyzer_tmpl_t {

uint64_t cur_interval_index;
uint64_t cur_interval_init_instr_count;
// Identifier for the shard. Currently, shards map only to threads, so this is
// the thread id.
// Identifier for the shard (thread or core id).
int64_t shard_id;
// Ordinal for the shard.
int shard_index = 0;
std::vector<analyzer_tool_shard_data_t> tool_data;
bool exited = false;

private:
// Delete copy constructor and assignment operator to avoid overhead of
Expand Down
2 changes: 2 additions & 0 deletions clients/drcachesim/analyzer_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ analyzer_multi_t::init_dynamic_schedule()
sched_ops.quantum_duration = op_sched_quantum.get_value();
if (op_sched_time.get_value())
sched_ops.quantum_unit = scheduler_t::QUANTUM_TIME;
sched_ops.syscall_switch_threshold = op_sched_syscall_switch_us.get_value();
sched_ops.blocking_switch_threshold = op_sched_blocking_switch_us.get_value();
#ifdef HAS_ZIP
if (!op_record_file.get_value().empty()) {
record_schedule_zip_.reset(new zipfile_ostream_t(op_record_file.get_value()));
Expand Down
12 changes: 6 additions & 6 deletions clients/drcachesim/common/named_pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ typedef int ssize_t;
# endif
#endif

#ifndef OUT
# define OUT // nothing
#ifndef DR_PARAM_OUT
# define DR_PARAM_OUT // nothing
#endif
#ifndef IN
# define IN // nothing
#ifndef DR_PARAM_IN
# define DR_PARAM_IN // nothing
#endif

// Usage is as follows:
Expand Down Expand Up @@ -98,12 +98,12 @@ class named_pipe_t {
// Returns < 0 on EOF or an error.
// On success (or partial read) returns number of bytes read.
ssize_t
read(void *buf OUT, size_t sz);
read(void *buf DR_PARAM_OUT, size_t sz);

// Returns < 0 on an error.
// On success (or partial write) returns number of bytes written.
ssize_t
write(const void *buf IN, size_t sz);
write(const void *buf DR_PARAM_IN, size_t sz);

#ifdef UNIX
// On UNIX, rather than calling open_for_{read,write}, The caller
Expand Down
4 changes: 2 additions & 2 deletions clients/drcachesim/common/named_pipe_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ named_pipe_t::set_fd(int fd)
}

ssize_t
named_pipe_t::read(void *buf OUT, size_t sz)
named_pipe_t::read(void *buf DR_PARAM_OUT, size_t sz)
{
int res = -1;
while (true) {
Expand All @@ -211,7 +211,7 @@ named_pipe_t::read(void *buf OUT, size_t sz)
}

ssize_t
named_pipe_t::write(const void *buf IN, size_t sz)
named_pipe_t::write(const void *buf DR_PARAM_IN, size_t sz)
{
int res = -1;
while (true) {
Expand Down
4 changes: 2 additions & 2 deletions clients/drcachesim/common/named_pipe_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ named_pipe_t::maximize_buffer()
}

ssize_t
named_pipe_t::read(void *buf OUT, size_t sz)
named_pipe_t::read(void *buf DR_PARAM_OUT, size_t sz)
{
DWORD actual;
BOOL res = ReadFile(fd_, buf, (DWORD)sz, &actual, NULL);
Expand All @@ -156,7 +156,7 @@ named_pipe_t::read(void *buf OUT, size_t sz)
}

ssize_t
named_pipe_t::write(const void *buf IN, size_t sz)
named_pipe_t::write(const void *buf DR_PARAM_IN, size_t sz)
{
DWORD actual;
BOOL res = WriteFile(fd_, buf, (DWORD)sz, &actual, NULL);
Expand Down
13 changes: 13 additions & 0 deletions clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,19 @@ droption_t<bool> op_sched_order_time(DROPTION_SCOPE_ALL, "sched_order_time", tru
"Applies to -core_sharded and -core_serial. "
"Whether to honor recorded timestamps for ordering");

droption_t<uint64_t> op_sched_syscall_switch_us(
DROPTION_SCOPE_ALL, "sched_syscall_switch_us", 500,
"Minimum latency to consider any syscall as incurring a context switch.",
"Minimum latency in timestamp units (us) to consider any syscall as incurring "
"a context switch. Applies to -core_sharded and -core_serial. ");

droption_t<uint64_t> op_sched_blocking_switch_us(
DROPTION_SCOPE_ALL, "sched_blocking_switch_us", 100,
"Minimum latency to consider a maybe-blocking syscall as incurring a context switch.",
"Minimum latency in timestamp units (us) to consider any syscall that is marked as "
"maybe-blocking to incur a context switch. Applies to -core_sharded and "
"-core_serial. ");

#ifdef HAS_ZIP
droption_t<std::string> op_record_file(DROPTION_SCOPE_FRONTEND, "record_file", "",
"Path for storing record of schedule",
Expand Down
2 changes: 2 additions & 0 deletions clients/drcachesim/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ extern dynamorio::droption::droption_t<bool> op_core_serial;
extern dynamorio::droption::droption_t<int64_t> op_sched_quantum;
extern dynamorio::droption::droption_t<bool> op_sched_time;
extern dynamorio::droption::droption_t<bool> op_sched_order_time;
extern dynamorio::droption::droption_t<uint64_t> op_sched_syscall_switch_us;
extern dynamorio::droption::droption_t<uint64_t> op_sched_blocking_switch_us;
#ifdef HAS_ZIP
extern dynamorio::droption::droption_t<std::string> op_record_file;
extern dynamorio::droption::droption_t<std::string> op_replay_file;
Expand Down
Loading

0 comments on commit 482432d

Please sign in to comment.