Skip to content

Commit

Permalink
i#6938 sched migrate: Make initial_cur_time atomic
Browse files Browse the repository at this point in the history
Fixes a race in the drmemtrace scheduler by making
output_info_t.initial_cur_time atomic.

Tested on ThreadSanitizer on the internal test where this was first
reported.

Issue: #6938
  • Loading branch information
derekbruening committed Oct 15, 2024
1 parent a6af579 commit dfe9be4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions clients/drcachesim/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2784,7 +2784,8 @@ scheduler_tmpl_t<RecordType, ReaderType>::pop_from_ready_queue_hold_locks(
// For never-executed inputs we consider their last execution
// to be the very first simulation time, which we can't
// easily initialize until here.
res->last_run_time = outputs_[from_output].initial_cur_time;
res->last_run_time = outputs_[from_output].initial_cur_time->load(
std::memory_order_acquire);
}
VPRINT(this, 5,
"migration check %d to %d: cur=%" PRIu64 " last=%" PRIu64
Expand Down Expand Up @@ -3800,8 +3801,8 @@ scheduler_tmpl_t<RecordType, ReaderType>::next_record(output_ordinal_t output,
cur_time = 1 + outputs_[output].stream->get_output_instruction_ordinal() +
outputs_[output].idle_count;
}
if (outputs_[output].initial_cur_time == 0) {
outputs_[output].initial_cur_time = cur_time;
if (outputs_[output].initial_cur_time->load(std::memory_order_acquire) == 0) {
outputs_[output].initial_cur_time->store(cur_time, std::memory_order_release);
}
// Invalid values for cur_time are checked below.
outputs_[output].cur_time->store(cur_time, std::memory_order_release);
Expand Down
7 changes: 6 additions & 1 deletion clients/drcachesim/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,9 @@ template <typename RecordType, typename ReaderType> class scheduler_tmpl_t {
cur_time =
std::unique_ptr<std::atomic<uint64_t>>(new std::atomic<uint64_t>());
cur_time->store(0, std::memory_order_relaxed);
initial_cur_time =
std::unique_ptr<std::atomic<uint64_t>>(new std::atomic<uint64_t>());
initial_cur_time->store(0, std::memory_order_relaxed);
record_index = std::unique_ptr<std::atomic<int>>(new std::atomic<int>());
record_index->store(0, std::memory_order_relaxed);
}
Expand Down Expand Up @@ -1693,7 +1696,9 @@ template <typename RecordType, typename ReaderType> class scheduler_tmpl_t {
// Indirected so we can store it in our vector.
std::unique_ptr<std::atomic<uint64_t>> cur_time;
// The first simulation time passed to this output.
uint64_t initial_cur_time = 0;
// This is accessed by other outputs for stealing and rebalancing.
// Indirected so we can store it in our vector.
std::unique_ptr<std::atomic<uint64_t>> initial_cur_time;
// Used for MAP_TO_RECORDED_OUTPUT get_output_cpuid().
int64_t as_traced_cpuid = -1;
// Used for MAP_AS_PREVIOUSLY with live_replay_output_count_.
Expand Down

0 comments on commit dfe9be4

Please sign in to comment.