Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#6662 public traces, part 2: encoding_filter #6663

Merged
merged 61 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c4106e0
i#6662 public traces, part 1: encoding_filter
edeiana Feb 21, 2024
66a29a2
Merge branch 'master' into i6662-public-record-filter
edeiana Apr 15, 2024
710a5d3
Saving previous work.
edeiana Apr 24, 2024
7d16393
Reverted back to not changing trace_entry_t length and pc.
edeiana Apr 25, 2024
d0f102c
Reverted back workaround for virtual register remapping.
edeiana Apr 25, 2024
38c2c60
Merge branch 'master' into i6662-public-record-filter
edeiana Apr 25, 2024
3653ee4
Added -encoding_filter_enabled flag, which also (indirectly) disables…
edeiana Apr 25, 2024
8263e76
Removed unnecessary headers.
edeiana Apr 25, 2024
8a121b4
We now use dynamorio encoding functionality, so we need to link it
edeiana Apr 25, 2024
cedc3bc
Fixing static dynamorio linking to client not working on mac.
edeiana Apr 25, 2024
064697f
Added TODO.
edeiana Apr 25, 2024
edb3d55
Fixed warning as error on windows.
edeiana Apr 25, 2024
8825a91
Minor comment improvement.
edeiana Apr 25, 2024
d4eb820
Another fix of warning as error on windows.
edeiana Apr 25, 2024
8924620
Now modifying the file_type of the trace to regdeps ISA.
edeiana Apr 29, 2024
9a8cd02
Improved comments.
edeiana Apr 29, 2024
f1fdd2c
Moved is_any_instr_type() to trace_entry.h.
edeiana Apr 29, 2024
0ef52fa
Refactoring: renaming of generic encoding_filter to
edeiana Apr 30, 2024
09c4d15
Renaming class encoding_filter_t to encodings2regdeps_t.
edeiana Apr 30, 2024
96d0925
Fixed memory leak.
edeiana Apr 30, 2024
3ebaf39
Added encodings2regdeps test (note: record_filter is tested
edeiana Apr 30, 2024
bfbe022
Fixed opcode_mix analyzer to work with DR_ISA_REGDEPS
edeiana Apr 30, 2024
6950c7b
Removed unnecessary space.
edeiana Apr 30, 2024
241819c
Indentation fix.
edeiana Apr 30, 2024
33e3bf0
Formatting fixed.
edeiana Apr 30, 2024
b61c5b7
Code cleanup.
edeiana Apr 30, 2024
05abd7e
clang-format pass.
edeiana Apr 30, 2024
454aac2
Templatex for new encodings2regdeps test. To fix.
edeiana Apr 30, 2024
84fa480
Improved comments.
edeiana Apr 30, 2024
4c7c201
Added OP_UNDECODED and interface between record_filter and its filters.
edeiana May 1, 2024
599fb04
Addressed minor PR feedback.
edeiana May 1, 2024
19c06a6
Updated version.
edeiana May 1, 2024
f31811c
Fix arm warning as error.
edeiana May 1, 2024
5fcc6c1
Fixed doxygen link in release doc.
edeiana May 1, 2024
201df94
From -encodings2regdeps to -filter_encodings2regdeps in test.
edeiana May 1, 2024
a31cd26
Doxygen could not resolve links.
edeiana May 1, 2024
d763c30
Fixed test, using existing infrastructure.
edeiana May 1, 2024
1fe93cb
Testing arm fix for opcode name.
edeiana May 1, 2024
7d40b2a
Fixed tests.
edeiana May 1, 2024
86bd2f8
Fixed encodings2regdeps opcode_mix analyzer test.
edeiana May 1, 2024
831d0a6
Reverted changed to OP_UNDECODED name for arm.
edeiana May 1, 2024
91fca5f
Moved include to its correct place, not the top of the file like clangd
edeiana May 1, 2024
f12c3a8
Addressing PR feedback.
edeiana May 2, 2024
807df45
Attempt to fix doxygen.
edeiana May 2, 2024
0e5d075
Attempt to fix doxygen 2.
edeiana May 2, 2024
8f483e9
Handling opcode name of OP_INVALID and OP_UNDECODED for x86.
edeiana May 2, 2024
fc50942
Fixed doxygen comment.
edeiana May 2, 2024
0e0a9b9
Added test entries to check different conditions.
edeiana May 2, 2024
3c416cb
Attempt to fix macos build.
edeiana May 2, 2024
db81af6
Attempt to fix macos build 2.
edeiana May 2, 2024
5b20bb5
Now using configure_DynamoRIO_standalone() for drmemtrace_record_filter.
edeiana May 2, 2024
b35faf4
Build fix, use before def in cmakelist.
edeiana May 2, 2024
2509adf
Fixed chunking in encodings2regdeps unit test.
edeiana May 2, 2024
fc0a744
Fixed test_encodings2regdeps_filter().
edeiana May 3, 2024
7a04272
Updated comment on chunk_footer, whose value is the chunk ordinal.
edeiana May 3, 2024
0f76ec8
Fixed doxygen comment on chunk_footer.
edeiana May 3, 2024
6b95e4d
Removed comment on marker value of TRACE_MARKER_TYPE_CHUNK_FOOTER.
edeiana May 5, 2024
4ffe2d1
Added memset for result reproducibility.
edeiana May 6, 2024
3d617ab
Added test for when real ISA encoding has more (or less)
edeiana May 6, 2024
bc7e4a0
Renaming encodings2regdeps* to encodings2regdeps_filter*
edeiana May 6, 2024
82a113b
Merge branch 'master' into i6662-public-record-filter
edeiana May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions api/docs/release.dox
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ changes:
- Changed the type of the AArch64 #dr_mcontext_t members svep and ffr to #dr_svep_t.
This breaks binary compatibility with clients that were built against versions of
DynamoRIO before this change.
- Changed dynamorio::drmemtrace::record_filter_t::record_filter_func_t
- Changed #dynamorio::drmemtrace::record_filter_t::record_filter_func_t
parallel_shard_filter() interface. Added a new parameter of type
dynamorio::drmemtrace::record_filter_t::record_filter_info_t that allows record_filter
to share data with its filters.
#dynamorio::drmemtrace::record_filter_t::record_filter_info_t that allows
#dynamorio::drmemtrace::record_filter_t to share data with its filters.

Further non-compatibility-affecting changes include:
- Added DWARF-5 support to the drsyms library by linking in 4 static libraries
Expand Down Expand Up @@ -230,6 +230,10 @@ Further non-compatibility-affecting changes include:
purpose of preserving register dependencies.
- Added instr_convert_to_isa_regdeps() API that converts an #instr_t from a real ISA
(e.g., #DR_ISA_AMD64) to the #DR_ISA_REGDEPS synthetic ISA.
- Added encodings2regdeps_t filter to #dynamorio::drmemtrace::record_filter_t to generate
#DR_ISA_REGDEPS traces.
- Added #dynamorio::drmemtrace::OFFLINE_FILE_TYPE_ARCH_REGDEPS file type for
#DR_ISA_REGDEPS traces.
derekbruening marked this conversation as resolved.
Show resolved Hide resolved

**************************************************
<hr>
Expand Down
5 changes: 4 additions & 1 deletion clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,14 @@ add_exported_library(drmemtrace_simulator STATIC
)

add_exported_library(drmemtrace_record_filter STATIC
tools/filter/record_filter.h
tools/filter/record_filter.cpp
tools/filter/cache_filter.h
tools/filter/cache_filter.cpp
tools/filter/type_filter.h
tools/filter/encodings2regdeps.h
tools/filter/null_filter.h)
target_link_libraries(drmemtrace_record_filter drmemtrace_simulator)
target_link_libraries(drmemtrace_record_filter drmemtrace_simulator dynamorio)
edeiana marked this conversation as resolved.
Show resolved Hide resolved

add_exported_library(directory_iterator STATIC common/directory_iterator.cpp)
add_dependencies(directory_iterator api_headers)
Expand Down Expand Up @@ -358,6 +359,8 @@ install_client_nonDR_header(drmemtrace simulator/cache_simulator_create.h)
install_client_nonDR_header(drmemtrace simulator/tlb_simulator_create.h)
install_client_nonDR_header(drmemtrace tools/view_create.h)
install_client_nonDR_header(drmemtrace tools/func_view_create.h)
install_client_nonDR_header(drmemtrace tools/filter/record_filter_create.h)
install_client_nonDR_header(drmemtrace tools/filter/record_filter.h)
# TODO i#6412: Create a separate directory for non-tracer headers so that
# we can more cleanly separate tracer and raw2trace code.
install_client_nonDR_header(drmemtrace tracer/raw2trace.h)
Expand Down
2 changes: 1 addition & 1 deletion clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ droption_t<std::string>
droption_t<bool> op_encodings2regdeps(
DROPTION_SCOPE_FRONTEND, "filter_encodings2regdeps", false,
"Enable converting the encoding of instructions to synthetic ISA DR_ISA_REGDEPS.",
"This option is intended to be used with record_filter. When present, it converts "
"This option is for -simulator_type " RECORD_FILTER ". When present, it converts "
"the encoding of instructions from a real ISA to the DR_ISA_REGDEPS synthetic ISA.");

droption_t<uint64_t> op_trim_before_timestamp(
Expand Down
5 changes: 4 additions & 1 deletion clients/drcachesim/common/trace_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ type_is_instr(const trace_type_t type)
/**
* Returns whether \p type represents any type of instruction record whether an
* instruction fetch or operation hint. This is a superset of type_is_instr() and includes
* TRACE_TYPE_INSTR_NO_FETCH.
* #TRACE_TYPE_INSTR_NO_FETCH.
*/
static inline bool
is_any_instr_type(const trace_type_t type)
Expand Down Expand Up @@ -979,6 +979,9 @@ typedef enum {
OFFLINE_FILE_TYPE_CORE_SHARDED = 0x10000,
/**
* Trace filtered by the record_filter tool using -filter_encodings2regdeps.
edeiana marked this conversation as resolved.
Show resolved Hide resolved
* The encodings2regdeps filter replaces real ISA encodings with #DR_ISA_REGDEPS
* encodings. Note that these encoding changes do not update the instruction length,
* hence encoding size and instruction fetch size may not match.
*/
OFFLINE_FILE_TYPE_ARCH_REGDEPS = 0x20000,
edeiana marked this conversation as resolved.
Show resolved Hide resolved
/**
Expand Down
12 changes: 6 additions & 6 deletions clients/drcachesim/reader/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ reader_t::process_input_entry()
++cur_instr_count_;
// Look for encoding bits that belong to this instr.
if (last_encoding_.size > 0) {
/* OFFLINE_FILE_TYPE_ARCH_REGDEPS traces have encodings with
* size != ifetch. It's a design choice, not an error, hence
* we avoid this sanity check.
*/
if (!TESTANY(OFFLINE_FILE_TYPE_ARCH_REGDEPS, filetype_) &&
(last_encoding_.size != cur_ref_.instr.size)) {
if (last_encoding_.size != cur_ref_.instr.size &&
/* OFFLINE_FILE_TYPE_ARCH_REGDEPS traces have encodings with
* size != ifetch. It's a design choice, not an error, hence
* we avoid this sanity check for these traces.
*/
!TESTANY(OFFLINE_FILE_TYPE_ARCH_REGDEPS, filetype_)) {
ERRMSG(
"Encoding size %zu != instr size %zu for PC 0x%zx at ord %" PRIu64
" instr %" PRIu64 " last_timestamp=0x%" PRIx64 "\n",
Expand Down
14 changes: 14 additions & 0 deletions clients/drcachesim/tests/record_filter_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,20 @@ test_encodings2regdeps_filter()
{ { TRACE_TYPE_ENCODING, 4, { 0xe78948 } }, true, { false } },
{ { TRACE_TYPE_ENCODING, 8, { 0x0006090600010011 } }, false, { true } },
edeiana marked this conversation as resolved.
Show resolved Hide resolved
{ { TRACE_TYPE_INSTR, 3, { 0x7f6fdd3ec360 } }, true, { true } },
// Same instr same chunk.
{ { TRACE_TYPE_INSTR, 3, { 0x7f6fdd3ec360 } }, true, { true } },
// Unit header.
{ { TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP, { 0xc } }, true, { true } },
{ { TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_CPU_ID, { 0xd } }, true, { true } },
// Duplicated encoding across chunk boundary.
edeiana marked this conversation as resolved.
Show resolved Hide resolved
{ { TRACE_TYPE_ENCODING, 4, { 0xe78948 } }, true, { false } },
{ { TRACE_TYPE_ENCODING, 8, { 0x0006090600010011 } }, false, { true } },
{ { TRACE_TYPE_INSTR, 3, { 0x7f6fdd3ec360 } }, true, { true } },
// Unit header.
{ { TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_TIMESTAMP, { 0xe } }, true, { true } },
{ { TRACE_TYPE_MARKER, TRACE_MARKER_TYPE_CPU_ID, { 0xf } }, true, { true } },
// Same instr in different chunk.
{ { TRACE_TYPE_INSTR, 3, { 0x7f6fdd3ec360 } }, true, { true } },
// Trace shard footer.
{ { TRACE_TYPE_FOOTER, 0, { 0x0 } }, true, { true } },
};
Expand Down
4 changes: 2 additions & 2 deletions clients/drcachesim/tools/filter/encodings2regdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class encodings2regdeps_t : public record_filter_t::record_filter_func_t {
static_cast<trace_marker_type_t>(entry.size);
if (marker_type == TRACE_MARKER_TYPE_FILETYPE) {
uint64_t marker_value = static_cast<uint64_t>(entry.addr);
marker_value = add_to_filetype(marker_value);
marker_value = update_filetype(marker_value);
entry.addr = static_cast<addr_t>(marker_value);
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ class encodings2regdeps_t : public record_filter_t::record_filter_func_t {
}

uint64_t
add_to_filetype(uint64_t filetype) override
update_filetype(uint64_t filetype) override
{
filetype &= ~OFFLINE_FILE_TYPE_ARCH_ALL;
filetype |= OFFLINE_FILE_TYPE_ARCH_REGDEPS;
Expand Down
4 changes: 2 additions & 2 deletions clients/drcachesim/tools/filter/record_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ record_filter_t::process_chunk_encodings(per_shard_t *per_shard, trace_entry_t &
// to the stop point, so a partial remove that does not change
// the filetype? For now we do not support that, and we re-add
// encodings at chunk boundaries regardless. Note that filters that modify
// encodings (even if they add or remove trace_entry_t records) do not incurr in
// encodings (even if they add or remove trace_entry_t records) do not incur in
// this problem and we don't need support for partial removal of encodings in this
// case. An example of such filters is encodings2regdeps_t.
if (TESTANY(OFFLINE_FILE_TYPE_ENCODINGS, per_shard->filetype) &&
Expand Down Expand Up @@ -651,7 +651,7 @@ record_filter_t::process_delayed_encodings(per_shard_t *per_shard, trace_entry_t
// Output if we have encodings that haven't yet been output, and
// there is no filter removing all encodings (we don't support
// partial encoding removal). Note that filters that modify encodings (even if
// they add or remove trace_entry_t records) do not incurr in this problem and we
// they add or remove trace_entry_t records) do not incur in this problem and we
// don't need support for partial removal of encodings in this case. An example
// of such filters is encodings2regdeps_t.
// We check prev_was_output to rule out filtered-out encodings
Expand Down
18 changes: 11 additions & 7 deletions clients/drcachesim/tools/filter/record_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class record_filter_t : public record_analysis_tool_t {
* Interface for the record_filter to share data with its filters.
*/
struct record_filter_info_t {
/**
* Stores the encoding of an instructions, which may be split among more than one
* #trace_entry_t, hence the vector.
*/
std::vector<trace_entry_t> *last_encoding;
edeiana marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down Expand Up @@ -93,10 +97,10 @@ class record_filter_t : public record_analysis_tool_t {
/**
* Invoked for each #trace_entry_t in the shard. It returns
* whether or not this \p entry should be included in the result
* trace. \p shard_data is same as what was returned by
* parallel_shard_init(). The given \p entry is included in the result
* trace iff all provided #record_filter_func_t return true. The
* \p entry parameter can also be modified by the record_filter_func_t.
* trace. \p shard_data is same as what was returned by parallel_shard_init().
* The given \p entry is included in the result trace iff all provided
* #dynamorio::drmemtrace::record_filter_t::record_filter_func_t return true.
* The \p entry parameter can also be modified by the record_filter_func_t.
* The passed \p entry is not guaranteed to be the original one from
* the trace if other filter tools are present, and may include changes
* made by other tools.
Expand Down Expand Up @@ -127,10 +131,10 @@ class record_filter_t : public record_analysis_tool_t {
/**
* If a filter modifies the file type of a trace, its changes should be made here,
* so they are visible to the record_filter even if the #trace_entry_t containing
* the file type marker is not modified.
* the file type marker is not modified directly by the filter.
*/
virtual uint64_t
add_to_filetype(uint64_t filetype)
update_filetype(uint64_t filetype)
{
return filetype;
}
Expand Down Expand Up @@ -277,7 +281,7 @@ class record_filter_t : public record_analysis_tool_t {
/* If filters modify the file type, add their changes here.
*/
for (auto &filter : filters_) {
filetype = filter->add_to_filetype(filetype);
filetype = filter->update_filetype(filetype);
}
return filetype;
}
Expand Down
3 changes: 2 additions & 1 deletion clients/drcachesim/tools/filter/record_filter_create.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ namespace drmemtrace {
* up to its first timestamp whose value is greater or equal to this parameter.
* @param[in] trim_after_timestamp Trim records after the trace's first timestamp
* whose value is greater than this parameter.
* @param[in] encodings2regdeps If true, converts instruction encodings from the real ISA
* @param[in] encodings2regdeps If true, converts instruction encodings from the real ISA
* of the input trace to the #DR_ISA_REGDEPS synthetic ISA.
* @param[in] verbose Verbosity level for notifications.
*/
record_analysis_tool_t *
record_filter_tool_create(const std::string &output_dir, uint64_t stop_timestamp,
Expand Down
2 changes: 1 addition & 1 deletion clients/drcachesim/tools/record_filter_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static droption_t<uint64_t> op_trim_after_timestamp(
droption_t<bool> op_encodings2regdeps(
DROPTION_SCOPE_FRONTEND, "filter_encodings2regdeps", false,
"Enable converting the encoding of instructions to synthetic ISA DR_ISA_REGDEPS.",
"This option is intended to be used with record_filter. When present, it converts "
"This option is for -simulator_type record_filter. When present, it converts "
"the encoding of instructions from a real ISA to the DR_ISA_REGDEPS synthetic ISA.");
} // namespace

Expand Down
7 changes: 7 additions & 0 deletions core/ir/x86/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,13 @@ const char *
decode_opcode_name(int opcode)
{
const instr_info_t *info = op_instr[opcode];
if (info == NULL) {
switch (opcode) {
case OP_INVALID: return "<invalid>";
case OP_UNDECODED: return "<undecoded>";
default: return "<unknown>";
}
}
return info->name;
}

Expand Down
2 changes: 1 addition & 1 deletion core/ir/x86/decode_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
const instr_info_t * const op_instr[] =
{
/* OP_INVALID */ NULL,
/* OP_UNDECODED */ (instr_info_t[]){{1, 0xffffff, 0, "<undecoded>", 0, 0, 0, 0, 0, 0, 0, 0}},
/* OP_UNDECODED */ NULL,
/* OP_CONTD */ NULL,
/* OP_LABEL */ NULL,

Expand Down
Loading