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#4328 AArch64 prefetch and flush instrs: Add trace types for prefetch instructions #4341

Merged
merged 29 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b91c19d
i#4328 AArch64 prefetch and flush instrs: Add trace types for AArch64…
abhinav92003 Jun 29, 2020
6852dba
Skip test with __builtin_prefetch when it is not defined.
abhinav92003 Jun 29, 2020
fe516e3
Execute prfm/prfum instructions in prefetch test only for AArch64
abhinav92003 Jun 29, 2020
d4338aa
Install missing cross compiler for DYNAMORIO_A64_ON_X86_ONLY.
abhinav92003 Jun 29, 2020
f24ef79
Skip all AArch64 asm code for non-AArch64 builds.
abhinav92003 Jun 29, 2020
66fa911
Fix prefetch counts for 32-bit x86 tests.
abhinav92003 Jun 29, 2020
6209472
Fix typo in macro in test file.
abhinav92003 Jun 29, 2020
9057549
Replace alternative operator for logical 'and' with the primary one.
abhinav92003 Jun 30, 2020
18c2a9d
Clear status flag for stdout in before_install.
abhinav92003 Jun 30, 2020
141ff2f
Revert "Clear status flag for stdout in before_install."
abhinav92003 Jul 2, 2020
b0febf2
Reviewer suggested readability fixes.
abhinav92003 Jul 5, 2020
036e446
Move app setup local to their tests and move test code to drcachesim/
abhinav92003 Jul 6, 2020
efcdbe1
Add test that uses a checked-in offline trace with prefetches collect…
abhinav92003 Jul 6, 2020
03559fd
Run offline trace test only if zlib is present.
abhinav92003 Jul 6, 2020
d6e3ae5
Update trace_type_names to reflect the new trace types.
abhinav92003 Jul 6, 2020
3bb8648
Add pure asm test with custom analyzer to verify prefetch operation c…
abhinav92003 Jul 10, 2020
84e6943
Update expected counts for online test and fix formatting.
abhinav92003 Jul 10, 2020
2ee8c57
Use explicit switch statements to translate prefetch instrs to trace …
abhinav92003 Jul 10, 2020
8005b97
Restrict AArch64 prefetch test to AArch64.
abhinav92003 Jul 10, 2020
dc04eb9
Fix formatting.
abhinav92003 Jul 10, 2020
8d20f5a
Mark some of the new trace types as aliases of the x86 specific ones.
abhinav92003 Jul 10, 2020
9059643
Update expected order of prefetch operation counts in test.
abhinav92003 Jul 10, 2020
f8ef515
Skip __builtin_prefetch tests only for MSVC
abhinav92003 Jul 15, 2020
3f66a3c
Add missing newline at end of file.
abhinav92003 Jul 15, 2020
58d051c
Add more comments to trace entry enum types.
abhinav92003 Jul 15, 2020
676dddd
Fix formatting error.
abhinav92003 Jul 15, 2020
f591fc4
Return generic TRACE_TYPE_PREFETCH in release builds for misc prefetc…
abhinav92003 Jul 15, 2020
0968101
Add comment explaining the debug-build-only assert.
abhinav92003 Jul 16, 2020
c010305
Merge branch 'master' into i4328-drmemtrace-handle-aarch64-prefetch
abhinav92003 Jul 20, 2020
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
18 changes: 18 additions & 0 deletions clients/drcachesim/common/trace_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@ const char *const trace_type_names[] = {
"non-fetched instr",
"maybe-fetched instr",
"sysenter",
"prefetch_pldl1keep",
"prefetch_pldl1strm",
"prefetch_pldl2keep",
"prefetch_pldl2strm",
"prefetch_pldl3keep",
"prefetch_pldl3strm",
"prefetch_plil1keep",
"prefetch_plil1strm",
"prefetch_plil2keep",
"prefetch_plil2strm",
"prefetch_plil3keep",
"prefetch_plil3strm",
"prefetch_pstl1keep",
"prefetch_pstl1strm",
"prefetch_pstl2keep",
"prefetch_pstl2strm",
"prefetch_pstl3keep",
"prefetch_pstl3strm",
};
45 changes: 45 additions & 0 deletions clients/drcachesim/common/trace_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,49 @@ typedef enum {
*/
TRACE_TYPE_INSTR_SYSENTER,

/** AArch64 specific prefetch trace entries.
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
* Relative order of these enum values is relevant to the handling of AArch64
* prefetch instructions.
*/
TRACE_TYPE_PREFETCH_PLDL1KEEP, /**< An AArch64 load prefetch to level 1 of the cache.
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
*/
TRACE_TYPE_PREFETCH_PLDL1STRM, /**< An AArch64 streaming load prefetch to level 1 of
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
the cache. */
TRACE_TYPE_PREFETCH_PLDL2KEEP, /**< An AArch64 load prefetch to level 2 of the cache.
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
*/
TRACE_TYPE_PREFETCH_PLDL2STRM, /**< An AArch64 streaming load prefetch to level 2 of
the cache. */
TRACE_TYPE_PREFETCH_PLDL3KEEP, /**< An AArch64 load prefetch to level 3 of the cache.
*/
TRACE_TYPE_PREFETCH_PLDL3STRM, /**< An AArch64 streaming load prefetch to level 3 of
the cache. */

TRACE_TYPE_PREFETCH_PLIL1KEEP, /**< An AArch64 instruction prefetch to level 1 of the
cache. */
TRACE_TYPE_PREFETCH_PLIL1STRM, /**< An AArch64 streaming instruction prefetch to level
1 of the cache. */
TRACE_TYPE_PREFETCH_PLIL2KEEP, /**< An AArch64 instruction prefetch to level 2 of the
cache. */
TRACE_TYPE_PREFETCH_PLIL2STRM, /**< An AArch64 streaming instruction prefetch to level
2 of the cache. */
TRACE_TYPE_PREFETCH_PLIL3KEEP, /**< An AArch64 instruction prefetch to level 3 of the
cache. */
TRACE_TYPE_PREFETCH_PLIL3STRM, /**< An AArch64 streaming instruction prefetch to level
3 of the cache. */

TRACE_TYPE_PREFETCH_PSTL1KEEP, /**< An AArch64 store prefetch to level 1 of the cache.
*/
TRACE_TYPE_PREFETCH_PSTL1STRM, /**< An AArch64 streaming store prefetch to level 1 of
the cache. */
TRACE_TYPE_PREFETCH_PSTL2KEEP, /**< An AArch64 store prefetch to level 2 of the cache.
*/
TRACE_TYPE_PREFETCH_PSTL2STRM, /**< An AArch64 streaming store prefetch to level 2 of
the cache. */
TRACE_TYPE_PREFETCH_PSTL3KEEP, /**< An AArch64 store prefetch to level 3 of the cache.
*/
TRACE_TYPE_PREFETCH_PSTL3STRM, /**< An AArch64 streaming store prefetch to level 3 of
the cache. */

// Update trace_type_names[] when adding here.
} trace_type_t;

Expand Down Expand Up @@ -277,6 +320,8 @@ static inline bool
type_is_prefetch(const trace_type_t type)
{
return (type >= TRACE_TYPE_PREFETCH && type <= TRACE_TYPE_PREFETCH_INSTR) ||
(type >= TRACE_TYPE_PREFETCH_PLDL1KEEP &&
type <= TRACE_TYPE_PREFETCH_PSTL3STRM) ||
type == TRACE_TYPE_HARDWARE_PREFETCH;
}

Expand Down
18 changes: 18 additions & 0 deletions clients/drcachesim/reader/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ reader_t::operator++()
case TRACE_TYPE_PREFETCH_READ:
case TRACE_TYPE_PREFETCH_WRITE:
case TRACE_TYPE_PREFETCH_INSTR:
case TRACE_TYPE_PREFETCH_PLDL1KEEP:
case TRACE_TYPE_PREFETCH_PLDL1STRM:
case TRACE_TYPE_PREFETCH_PLDL2KEEP:
case TRACE_TYPE_PREFETCH_PLDL2STRM:
case TRACE_TYPE_PREFETCH_PLDL3KEEP:
case TRACE_TYPE_PREFETCH_PLDL3STRM:
case TRACE_TYPE_PREFETCH_PLIL1KEEP:
case TRACE_TYPE_PREFETCH_PLIL1STRM:
case TRACE_TYPE_PREFETCH_PLIL2KEEP:
case TRACE_TYPE_PREFETCH_PLIL2STRM:
case TRACE_TYPE_PREFETCH_PLIL3KEEP:
case TRACE_TYPE_PREFETCH_PLIL3STRM:
case TRACE_TYPE_PREFETCH_PSTL1KEEP:
case TRACE_TYPE_PREFETCH_PSTL1STRM:
case TRACE_TYPE_PREFETCH_PSTL2KEEP:
case TRACE_TYPE_PREFETCH_PSTL2STRM:
case TRACE_TYPE_PREFETCH_PSTL3KEEP:
case TRACE_TYPE_PREFETCH_PSTL3STRM:
have_memref = true;
assert(cur_tid_ != 0 && cur_pid_ != 0);
cur_ref_.data.pid = cur_pid_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Hello, world!
Basic counts tool results:
Total counts:
.* total \(fetched\) instructions
.* total unique \(fetched\) instructions
.* total non-fetched instructions
62 total prefetches
.* total data loads
.* total data stores
1 total threads
.* total scheduling markers
.* total transfer markers
.* total function id markers
.* total function return address markers
.* total function argument markers
.* total function return value markers
.* total other markers
Thread .* counts:
.* \(fetched\) instructions
.* unique \(fetched\) instructions
.* non-fetched instructions
62 prefetches
.* data loads
.* data stores
.* scheduling markers
.* transfer markers
.* function id markers
.* function return address markers
.* function argument markers
.* function return value markers
.* other markers
43 changes: 43 additions & 0 deletions clients/drcachesim/tests/offline-prefetch-basic-counts.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Hello, world!
Basic counts tool results:
Total counts:
.* total \(fetched\) instructions
.* total unique \(fetched\) instructions
.* total non-fetched instructions
#if defined(AARCH64)
34 total prefetches
#elif defined(X86) && !defined(X64)
0 total prefetches
#else
8 total prefetches
#endif
.* total data loads
.* total data stores
1 total threads
.* total scheduling markers
.* total transfer markers
.* total function id markers
.* total function return address markers
.* total function argument markers
.* total function return value markers
.* total other markers
Thread .* counts:
.* \(fetched\) instructions
.* unique \(fetched\) instructions
.* non-fetched instructions
#if defined(AARCH64)
34 prefetches
#elif defined(X86) && !defined(X64)
0 prefetches
#else
8 prefetches
#endif
.* data loads
.* data stores
.* scheduling markers
.* transfer markers
.* function id markers
.* function return address markers
.* function argument markers
.* function return value markers
.* other markers
32 changes: 32 additions & 0 deletions clients/drcachesim/tests/prefetch-aarch64-basic-counts.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Hello, world!
---- <application exited with code 0> ----
Basic counts tool results:
Total counts:
.* total \(fetched\) instructions
.* total unique \(fetched\) instructions
.* total non-fetched instructions
62 total prefetches
.* total data loads
.* total data stores
1 total threads
.* total scheduling markers
.* total transfer markers
.* total function id markers
.* total function return address markers
.* total function argument markers
.* total function return value markers
.* total other markers
Thread .* counts:
.* \(fetched\) instructions
.* unique \(fetched\) instructions
.* non-fetched instructions
62 prefetches
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
.* data loads
.* data stores
.* scheduling markers
.* transfer markers
.* function id markers
.* function return address markers
.* function argument markers
.* function return value markers
.* other markers
44 changes: 44 additions & 0 deletions clients/drcachesim/tests/prefetch-basic-counts.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Hello, world!
---- <application exited with code 0> ----
Basic counts tool results:
Total counts:
.* total \(fetched\) instructions
.* total unique \(fetched\) instructions
.* total non-fetched instructions
#if defined(AARCH64)
34 total prefetches
#elif defined(X86) && !defined(X64)
0 total prefetches
#else
8 total prefetches
#endif
.* total data loads
.* total data stores
1 total threads
.* total scheduling markers
.* total transfer markers
.* total function id markers
.* total function return address markers
.* total function argument markers
.* total function return value markers
.* total other markers
Thread .* counts:
.* \(fetched\) instructions
.* unique \(fetched\) instructions
.* non-fetched instructions
#if defined(AARCH64)
34 prefetches
#elif defined(X86) && !defined(X64)
0 prefetches
#else
8 prefetches
#endif
.* data loads
.* data stores
.* scheduling markers
.* transfer markers
.* function id markers
.* function return address markers
.* function argument markers
.* function return value markers
.* other markers
51 changes: 51 additions & 0 deletions clients/drcachesim/tracer/instru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,51 @@ instru_t::instr_to_instr_type(instr_t *instr, bool repstr_expanded)
return TRACE_TYPE_INSTR;
}

#ifdef AARCH64
unsigned short
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
get_aarch64_prefetch_target_policy(ptr_int_t prfop)
{
// Least significant three bits of prfop represent prefetch target and
// policy [... b2 b1 b0]
//
// b2 b1 : prefetch target
// 0b00 - L1 cache, 0b01 - L2 cache, 0b10 - L3 cache
//
// b0 : prefetch policy
// 0b0 - temporal prefetch, 0b1 - streaming (non-temporal) prefetch
return prfop & 0b111;
}

unsigned short
get_aarch64_prefetch_op_type(ptr_int_t prfop)
{
// Bits at position 3 and 4 in prfop represent prefetch operation type
// [... b4 b3 ...]
// 0b00 - prefetch for load
// 0b01 - prefetch for instruction
// 0b10 - prefetch for store
return (prfop >> 3) & 0b11;
}

unsigned short
get_aarch64_prefetch_type(ptr_int_t prfop)
{
unsigned short target_policy = get_aarch64_prefetch_target_policy(prfop);
unsigned short op_type = get_aarch64_prefetch_op_type(prfop);
DR_ASSERT_MSG(target_policy < 6 && op_type < 3,
"Unsupported AArch64 prefetch operation.");
switch (op_type) {
case 0: // prefetch for load
return TRACE_TYPE_PREFETCH_PLDL1KEEP + target_policy;
case 1: // prefetch for instruction
return TRACE_TYPE_PREFETCH_PLIL1KEEP + target_policy;
case 2: // prefetch for store
return TRACE_TYPE_PREFETCH_PSTL1KEEP + target_policy;
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
}
return TRACE_TYPE_PREFETCH; // unreachable.
}
#endif

unsigned short
instru_t::instr_to_prefetch_type(instr_t *instr)
{
Expand All @@ -94,6 +139,12 @@ instru_t::instr_to_prefetch_type(instr_t *instr)
case OP_pld: return TRACE_TYPE_PREFETCH_READ;
case OP_pldw: return TRACE_TYPE_PREFETCH_WRITE;
case OP_pli: return TRACE_TYPE_PREFETCH_INSTR;
#endif
#ifdef AARCH64
case OP_prfm:
return get_aarch64_prefetch_type(opnd_get_immed_int(instr_get_src(instr, 0)));
case OP_prfum:
return get_aarch64_prefetch_type(opnd_get_immed_int(instr_get_src(instr, 0)));
#endif
default: return TRACE_TYPE_PREFETCH;
}
Expand Down
4 changes: 2 additions & 2 deletions core/ir/aarch64/instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ instr_is_mov_constant(instr_t *instr, ptr_int_t *value)
bool
instr_is_prefetch(instr_t *instr)
{
/* FIXME i#1569: NYI */
return false;
int opcode = instr_get_opcode(instr);
return opcode == OP_prfm || opcode == OP_prfum;
}

bool
Expand Down
32 changes: 32 additions & 0 deletions suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,20 @@ set(ci_shared_app simple_app)
set(ci_shared_app_src client-interface/${ci_shared_app}.c)
add_exe(${ci_shared_app} ${ci_shared_app_src})

if (CMAKE_COMPILER_IS_GNUCC)
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
# An app with prefetch instructions.
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
set(ci_prefetch_app prefetch_app)
set(ci_prefetch_app_src client-interface/${ci_prefetch_app}.c)
add_exe(${ci_prefetch_app} ${ci_prefetch_app_src})
endif ()

if (AARCH64)
# An AArch64 app with prefetch instructions.
set(ci_prefetch_aarch64_app prefetch_aarch64_app)
set(ci_prefetch_aarch64_app_src client-interface/${ci_prefetch_aarch64_app}.c)
add_exe(${ci_prefetch_aarch64_app} ${ci_prefetch_aarch64_app_src})
endif ()

function(setup_test_client_dll_basics test)
configure_DynamoRIO_client(${test})
append_property_string(TARGET ${test} LINK_FLAGS "${ARCH_DEBUG}")
Expand Down Expand Up @@ -3108,6 +3122,15 @@ if (CLIENT_INTERFACE)

torunonly_drcachesim(instr-only-trace ${ci_shared_app} "-instr_only_trace" "")

if (CMAKE_COMPILER_IS_GNUCC)
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
torunonly_drcachesim(prefetch-basic-counts ${ci_prefetch_app} "-simulator_type basic_counts" "")
unset(tool.drcachesim.prefetch-basic-counts_rawtemp) # use preprocessor
endif ()

if (AARCH64)
torunonly_drcachesim(prefetch-aarch64-basic-counts ${ci_prefetch_aarch64_app} "-simulator_type basic_counts" "")
endif ()

torunonly_drcachesim(delay-simple ${ci_shared_app}
"-trace_after_instrs 20000 -exit_after_tracing 10000" "")

Expand Down Expand Up @@ -3331,6 +3354,15 @@ if (CLIENT_INTERFACE)
torunonly_drcacheoff(instr-only-trace ${ci_shared_app} "-instr_only_trace" "" "")
torunonly_drcacheoff(filter-and-instr-only-trace ${ci_shared_app} "-instr_only_trace -L0_filter" "" "")

if (CMAKE_COMPILER_IS_GNUCC)
torunonly_drcacheoff(prefetch-basic-counts ${ci_prefetch_app} "" "@-simulator_type@basic_counts" "")
unset(tool.drcacheoff.prefetch-basic-counts_rawtemp) # use preprocessor
endif ()

if (AARCH64)
torunonly_drcacheoff(prefetch-aarch64-basic-counts ${ci_prefetch_aarch64_app} "" "@-simulator_type@basic_counts" "")
endif ()

# We run common.decode-bad to test markers for faults
if (X86) # decode-bad is x86-only
# Do not cap the trace size (done to shorten tests) b/c it will then miss
Expand Down
Loading