-
Notifications
You must be signed in to change notification settings - Fork 566
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#7113 decode cache: Add analyzer library for decode_cache_t #7114
base: master
Are you sure you want to change the base?
Conversation
Adds a new library to cache information about decoded instructions. This can be used by analysis tools that need to decode the instr encodings in the trace. The library allows the tools to specify what information they need to cache. Refactors the invariant checker tool to use this library. Issue: #7113
Decided to try out an alternate way to support module-mapper-decoding in instr_decode_cache_t that came out of offline discussion. Okay to hold off on the re-review until then (Cannot undo re-request review) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank review to reset the requested review state.
…upport to instr_decode_cache_t
Almost all concerns from the review and offline discussions have been addressed, so this is ready for a re-review. Added a TODO for a couple items: dr_set_isa_mode for regdeps, and the Windows test-only i#5960. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a large diff. Did not make it through all the files yet but sending comments so far. May be delayed on finishing as have other work to get to.
* An \p decode_cache_t for testing which uses a \p test_module_mapper_t. | ||
*/ | ||
template <class DecodeInfo> | ||
class test_decode_cache_t : public decode_cache_t<DecodeInfo> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be in this header? Shouldn't this be in the test file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemed convenient to have the test class available at a common location. But sure, it'll be better to find a new test-only common location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually test_module_mapper_t also lives in raw2trace_shared.h. Do we want to update all such test classes to be in their own separate header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest of files. Maybe main points are that optimizations in opcode_mix (worker instead of shard data; further caching) are being thrown out: seems like we want to keep at least the worker data.
pair.memref.instr.encoding_is_new = true; | ||
if (!set_only_instr_addr) { | ||
memcpy(pair.memref.instr.encoding, &decode_buf[offset], instr_size); | ||
pair.memref.instr.encoding_is_new = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is your code assuming encoding_is_new is always initialized? E.g., "if (!use_module_mapper_ && memref_instr.encoding_is_new) {" in decode_cache.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that condition, encoding_is_new will be read only if the user didn't ask to use the module mapper, in which case the init() time check will ensure the trace filetype supports embedded-encodings, in which case encoding_is_new will be set.
// XXX: We could potentially use instr_decode_cache_t here (i#7113) and avoid the | ||
// repeated instr decoding logic. However, we want to preserve the legacy view | ||
// tool output format which uses disassemble_to_buffer, and disassemble_to_buffer | ||
// does the decoding on its own internally, while adding a bunch of non-trival |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to update the view tool separately (this PR is already large), so long as we know it won't require interface changes to this library. If it used instr_disassemle(), and the library sets ISA regdeps, will it all work out?
Location for test_decode_cache_t and providing raw instr encoding for view_t need more discussion; resolved other threads. Ready for re-review. Though no rush because of the holidays. |
Adds a new drmemtrace_decode_cache library to cache information about decoded instructions using decode_cache_t. This can be used by analysis tools that need to decode the instr encodings in the trace, to avoid overhead of redundant decodings which can get expensive.
The library allows the tools to specify what information they need to cache. Also, it uses instr_noalloc_t when possible to reduce heap usage and allocation/deallocation overhead.
If the trace does not include embedded encodings or if the user wants to get encodings from the app binaries using module_mapper_t instead, they can provide the module file path to the init API on the decode_cache_t object. decode_cache_t keeps a single initialized module_mapper_t at any time, which is shared between all decode_cache_t objects (even the ones of different template types); this is done by tracking the count of active objects using the module mapper.
decode_cache_t provides the clear_cache() API which can be used in parallel_shard_exit() to keep memory consumption in check by free-ing up cached decoding info that may not be needed for result computation in later print_results() which has to wait until all shards are done.
Refactors the invariant checker and opcode mix tools to use this library.
Modifies add_encodings_to_memrefs to support a mode where encodings are not set in the generated test memref but only the instr addr and size fields are set.
Makes the opcode cache in opcode_mix_t per-shard instead of per-worker. Decodings must not be cached per-worker as that may cause stale encodings for non-first shards processed by the worker. This means the worker init and worker exit APIs can be removed now from opcode_mix_t.
Adds decode_cache_test and opcode_mix_test unit tests that verify operation of the decode_cache_t.
Issue: #7113