Skip to content

Commit

Permalink
i#5843 scheduler: Fix assert to allow 0 time
Browse files Browse the repository at this point in the history
Fixes a < assert from PR #6458 to be <=, to allow the pre-syscall
timestamp to equal the post-syscall timestamp.

Adds a test that fails without the fix.

Issue: #5843
  • Loading branch information
derekbruening committed Nov 17, 2023
1 parent 5990405 commit a69fad0
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clients/drcachesim/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ scheduler_tmpl_t<RecordType, ReaderType>::syscall_incurs_switch(input_info_t *in
return input->processing_maybe_blocking_syscall;
}
assert(input->pre_syscall_timestamp > 0);
assert(input->pre_syscall_timestamp < post_time);
assert(input->pre_syscall_timestamp <= post_time);
uint64_t latency = post_time - input->pre_syscall_timestamp;
VPRINT(this, 3, "input %d %ssyscall latency: %" PRIu64 "\n", input->index,
input->processing_maybe_blocking_syscall ? "maybe-blocking " : "", latency);
Expand Down
110 changes: 110 additions & 0 deletions clients/drcachesim/tests/scheduler_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,12 +1653,122 @@ test_synthetic_with_syscalls_precise()
assert(res);
}

static void
test_synthetic_with_syscalls_latencies()
{
std::cerr << "\n----------------\nTesting syscall latency switches\n";
static constexpr memref_tid_t TID_A = 42;
static constexpr memref_tid_t TID_B = 99;
static constexpr int SYSNUM = 202;
std::vector<trace_entry_t> refs_A = {
/* clang-format off */
make_thread(TID_A),
make_pid(1),
make_version(TRACE_ENTRY_VERSION),
make_timestamp(20),
make_instr(10),
// Test 0 latency.
make_timestamp(120),
make_marker(TRACE_MARKER_TYPE_SYSCALL, SYSNUM),
make_timestamp(120),
make_instr(10),
// Test large but too-short latency.
make_timestamp(200),
make_marker(TRACE_MARKER_TYPE_SYSCALL, SYSNUM),
make_timestamp(699),
make_instr(10),
// Test just large enough latency, with func markers in between.
make_timestamp(1000),
make_marker(TRACE_MARKER_TYPE_SYSCALL, SYSNUM),
make_marker(TRACE_MARKER_TYPE_MAYBE_BLOCKING_SYSCALL, 0),
make_marker(TRACE_MARKER_TYPE_FUNC_ID, 100),
make_marker(TRACE_MARKER_TYPE_FUNC_ARG, 42),
make_timestamp(1100),
make_marker(TRACE_MARKER_TYPE_CPU_ID, 1),
make_marker(TRACE_MARKER_TYPE_FUNC_ID, 100),
make_marker(TRACE_MARKER_TYPE_FUNC_RETVAL, 0),
make_instr(12),
make_exit(TID_A),
/* clang-format on */
};
std::vector<trace_entry_t> refs_B = {
/* clang-format off */
make_thread(TID_B),
make_pid(1),
make_version(TRACE_ENTRY_VERSION),
make_timestamp(2000),
make_instr(20),
make_instr(21),
make_exit(TID_B),
/* clang-format on */
};
std::vector<scheduler_t::input_reader_t> readers;
readers.emplace_back(std::unique_ptr<mock_reader_t>(new mock_reader_t(refs_A)),
std::unique_ptr<mock_reader_t>(new mock_reader_t()), TID_A);
readers.emplace_back(std::unique_ptr<mock_reader_t>(new mock_reader_t(refs_B)),
std::unique_ptr<mock_reader_t>(new mock_reader_t()), TID_B);
std::vector<scheduler_t::input_workload_t> sched_inputs;
sched_inputs.emplace_back(std::move(readers));
scheduler_t::scheduler_options_t sched_ops(scheduler_t::MAP_TO_ANY_OUTPUT,
scheduler_t::DEPENDENCY_TIMESTAMPS,
scheduler_t::SCHEDULER_DEFAULTS,
/*verbosity=*/4);
scheduler_t scheduler;
if (scheduler.init(sched_inputs, 1, sched_ops) != scheduler_t::STATUS_SUCCESS)
assert(false);
auto *stream = scheduler.get_stream(0);
memref_t memref;
std::vector<memref_t> refs;
for (scheduler_t::stream_status_t status = stream->next_record(memref);
status != scheduler_t::STATUS_EOF; status = stream->next_record(memref)) {
if (status == scheduler_t::STATUS_WAIT)
continue;
assert(status == scheduler_t::STATUS_OK);
refs.push_back(memref);
}
std::vector<trace_entry_t> entries;
int idx = 0;
bool res = true;
res = res &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_VERSION) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_INSTR) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_SYSCALL) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_INSTR) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_SYSCALL) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_INSTR) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_SYSCALL) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER,
TRACE_MARKER_TYPE_MAYBE_BLOCKING_SYSCALL) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_FUNC_ID) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_FUNC_ARG) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_CPU_ID) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_FUNC_ID) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_FUNC_RETVAL) &&
// Shouldn't switch until after all the syscall's markers.
check_ref(refs, idx, TID_B, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_VERSION) &&
check_ref(refs, idx, TID_B, TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP) &&
check_ref(refs, idx, TID_B, TRACE_TYPE_INSTR) &&
check_ref(refs, idx, TID_B, TRACE_TYPE_INSTR) &&
check_ref(refs, idx, TID_B, TRACE_TYPE_THREAD_EXIT) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_INSTR) &&
check_ref(refs, idx, TID_A, TRACE_TYPE_THREAD_EXIT);
assert(res);
}

static void
test_synthetic_with_syscalls()
{
test_synthetic_with_syscalls_multiple();
test_synthetic_with_syscalls_single();
test_synthetic_with_syscalls_precise();
test_synthetic_with_syscalls_latencies();
}

#if (defined(X86_64) || defined(ARM_64)) && defined(HAS_ZIP)
Expand Down

0 comments on commit a69fad0

Please sign in to comment.