Skip to content

Commit

Permalink
i#6712: Add record_scheduler_t support for replay-as-traced
Browse files Browse the repository at this point in the history
Adds record_scheduler_t (for the record_filter tool) support for
replaying as-traced.  The key change here is having record_reader_t
increment the instruction ordinal on an encoding record instead of an
instruction record.  This avoids splitting encodings from instructions
when operating at instrution boundaries in the scheduler (during
replay, but this would also affect skipping for scheduler regions of
interest).

Adds a test of record_filter on the checked-in threadsig trace in
as-traced replay mode.

Fixes #6712
  • Loading branch information
derekbruening committed Mar 19, 2024
1 parent b2e6177 commit 924445a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
13 changes: 12 additions & 1 deletion clients/drcachesim/reader/record_file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ class record_reader_t : public std::iterator<std::input_iterator_tag, trace_entr
UNUSED(res);
if (!eof_) {
++cur_ref_count_;
if (type_is_instr(static_cast<trace_type_t>(cur_entry_.type)))
// We increment the instr count at the encoding as that avoids multiple
// problems with separating encodings from instrs when skipping (including
// for scheduler regions of interest) and when replaying schedules: anything
// using instr ordinals as boundaries.
if (!prev_record_was_encoding_ &&
(cur_entry_.type == TRACE_TYPE_ENCODING ||
type_is_instr(static_cast<trace_type_t>(cur_entry_.type))))
++cur_instr_count_;
else if (cur_entry_.type == TRACE_TYPE_MARKER) {
switch (cur_entry_.size) {
Expand Down Expand Up @@ -177,6 +183,10 @@ class record_reader_t : public std::iterator<std::input_iterator_tag, trace_entr
break;
}
}
if (cur_entry_.type == TRACE_TYPE_ENCODING)
prev_record_was_encoding_ = true;
else
prev_record_was_encoding_ = false;
}
return *this;
}
Expand Down Expand Up @@ -273,6 +283,7 @@ class record_reader_t : public std::iterator<std::input_iterator_tag, trace_entr
uint64_t cur_instr_count_ = 0;
uint64_t last_timestamp_ = 0;
uint64_t first_timestamp_ = 0;
bool prev_record_was_encoding_ = false;

// Remember top-level headers for the memtrace_stream_t interface.
uint64_t version_ = 0;
Expand Down
7 changes: 5 additions & 2 deletions clients/drcachesim/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,9 @@ scheduler_tmpl_t<RecordType, ReaderType>::clear_input_queue(input_info_t &input)
// skip it all when skipping ahead in the input stream.
int i = 0;
while (!input.queue.empty()) {
assert(i == 0 || !record_type_is_instr(input.queue.front()));
assert(i == 0 ||
(!record_type_is_instr(input.queue.front()) &&
!record_type_is_encoding(input.queue.front())));
++i;
input.queue.pop_front();
}
Expand All @@ -1809,7 +1811,8 @@ scheduler_tmpl_t<RecordType, ReaderType>::skip_instructions(output_ordinal_t out
// For a skip of 0 we still need to clear non-instrs from the queue, but
// should not have an instr in there.
assert(skip_amount > 0 || input.queue.empty() ||
!record_type_is_instr(input.queue.front()));
(!record_type_is_instr(input.queue.front()) &&
!record_type_is_encoding(input.queue.front())));
clear_input_queue(input);
input.reader->skip_instructions(skip_amount);
if (*input.reader == *input.reader_end) {
Expand Down
6 changes: 6 additions & 0 deletions clients/drcachesim/tests/record_filter_as_traced.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Output .* entries from .* entries.
Schedule stats tool results:
.*
Core #0 schedule: .*
Core #1 schedule: .*
Core #2 schedule: .*
18 changes: 17 additions & 1 deletion suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4661,8 +4661,8 @@ if (BUILD_CLIENTS)
"schedule_stats")
endif ()

# Test the trim filter.
if (X86 AND X64 AND ZLIB_FOUND)
# Test the trim filter.
set(zip_path
"${PROJECT_SOURCE_DIR}/clients/drcachesim/tests/drmemtrace.allasm_x86_64.trace.zip")
set(outdir ${PROJECT_BINARY_DIR}/trim_filter)
Expand All @@ -4680,6 +4680,22 @@ if (BUILD_CLIENTS)
"${drcachesim_path}@-simulator_type@record_filter@-trim_before_timestamp@13352268558646120@-trim_after_timestamp@13352268558646661@-indir@${srcdir}@-outdir@${outdir}")
set(tool.drcacheoff.trim_basedir "${PROJECT_SOURCE_DIR}/clients/drcachesim/tests")
set(tool.drcacheoff.trim_rawtemp ON) # no preprocessor

# Test the record_filter in as-traced mode.
set(trace_dir
"${PROJECT_SOURCE_DIR}/clients/drcachesim/tests/drmemtrace.threadsig.x64.tracedir")
set(sched_file "${trace_dir}/cpu_schedule.bin.zip")
set(outdir ${CMAKE_CURRENT_BINARY_DIR}/filter_as_traced)
file(MAKE_DIRECTORY ${outdir})
torunonly_api(tool.record_filter_as_traced "${drcachesim_path}"
"record_filter_as_traced"
"" "-simulator_type;schedule_stats;-indir;${outdir}" OFF OFF)
set(tool.record_filter_as_traced_runcmp "${CMAKE_CURRENT_SOURCE_DIR}/runmulti.cmake")
set(tool.record_filter_as_traced_precmd
"${drcachesim_path}@-simulator_type@record_filter@-cpu_schedule_file@${sched_file}@-core_sharded@-cores@7@-indir@${trace_dir}@-outdir@${outdir}")
set(tool.record_filter_as_traced_basedir
"${PROJECT_SOURCE_DIR}/clients/drcachesim/tests")
set(tool.record_filter_as_traced_rawtemp ON) # no preprocessor
endif ()

if (AARCH64)
Expand Down

0 comments on commit 924445a

Please sign in to comment.