Skip to content

Commit

Permalink
i#4014 dr$sim phys: Handle page-spanning accesses (#5536)
Browse files Browse the repository at this point in the history
Adds handling of page-spanning instruction fetch and data accesses.
For offline traces these are heuristics as we do not know the precise
sizes at tracing time.  Since an extra physical page value is not
harmful, the heuristics emit a second page if there is any decent
chance that it is reached.

Adds a data page span test by switching the drcacheoff.phys test to
use allasm_repstr and adding such an access there.  An instruction
cross is more difficult to synthesize.

Issue: #4014
  • Loading branch information
derekbruening authored Jun 18, 2022
1 parent 3f1d9f5 commit 1152e64
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 128 deletions.
12 changes: 6 additions & 6 deletions clients/drcachesim/tests/allasm-repstr-basic-counts.templatex
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Adios world!
---- <application exited with code 0> ----
Basic counts tool results:
Total counts:
95 total \(fetched\) instructions
23 total unique \(fetched\) instructions
98 total \(fetched\) instructions
26 total unique \(fetched\) instructions
4 total non-fetched instructions
0 total prefetches
5 total data loads
7 total data loads
5 total data stores
0 total icache flushes
0 total dcache flushes
Expand All @@ -28,11 +28,11 @@ Total counts:
0 total function return value markers
4 total other markers
Thread [0-9]* counts:
95 \(fetched\) instructions
23 unique \(fetched\) instructions
98 \(fetched\) instructions
26 unique \(fetched\) instructions
4 non-fetched instructions
0 prefetches
5 data loads
7 data loads
5 data stores
0 icache flushes
0 dcache flushes
Expand Down
12 changes: 12 additions & 0 deletions clients/drcachesim/tests/allasm_repstr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ _start:
cld
rep movsb

// Test page-spanning accesses.
lea rcx, page_str
// Somehow the GNU assembler 2.38 is adding the load size (4 here) to
// whatever displacement is listed (!!!), so these end up as -3 and -1.
mov eax, DWORD [-7+rcx]
mov eax, DWORD [-5+rcx]

// Print a message in a loop for testing tracing windows.
mov ebx, 10 // Loop count.
repeat:
Expand All @@ -76,3 +83,8 @@ hello_str:
.string "Hello world!\n"
bye_str:
.string "Adios\n"
// Push .data onto a 2nd page to test page-spanning accesses.
// We assume 4K pages here.
.align 4096
page_str:
.word 0
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Adios world!
Adios world!
Basic counts tool results:
Total counts:
95 total \(fetched\) instructions
23 total unique \(fetched\) instructions
98 total \(fetched\) instructions
26 total unique \(fetched\) instructions
4 total non-fetched instructions
0 total prefetches
5 total data loads
7 total data loads
5 total data stores
0 total icache flushes
0 total dcache flushes
Expand All @@ -27,11 +27,11 @@ Total counts:
0 total function return value markers
4 total other markers
Thread [0-9]* counts:
95 \(fetched\) instructions
23 unique \(fetched\) instructions
98 \(fetched\) instructions
26 unique \(fetched\) instructions
4 non-fetched instructions
0 prefetches
5 data loads
7 data loads
5 data stores
0 icache flushes
0 dcache flushes
Expand Down
36 changes: 17 additions & 19 deletions clients/drcachesim/tests/offline-phys.templatex
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Adios world!
Adios world!
Adios world!
Adios world!
Adios world!
Adios world!
Adios world!
Adios world!
Adios world!
Adios world!
Output format:
<record#>: T<tid> <record details>
------------------------------------------------------------
Expand All @@ -25,6 +19,10 @@ Output format:
6: T[0-9]+ <marker: tid [0-9]+ on core [0-9]+>
7: T[0-9]+ <marker: physical address for following virtual: 0x[0-9a-f][0-9a-f]+>
8: T[0-9]+ <marker: virtual address for prior physical: 0x[0-9a-f][0-9a-f]+>
9: T[0-9]+ <marker: timestamp [0-9]+>
10: T[0-9]+ <marker: tid [0-9]+ on core [0-9]+>
11: T[0-9]+ ifetch .*
9: T[0-9]+ <marker: physical address for following virtual: 0x[0-9a-f][0-9a-f]+>
10: T[0-9]+ <marker: virtual address for prior physical: 0x[0-9a-f][0-9a-f]+>
11: T[0-9]+ <marker: physical address for following virtual: 0x[0-9a-f][0-9a-f]+>
12: T[0-9]+ <marker: virtual address for prior physical: 0x[0-9a-f][0-9a-f]+>
13: T[0-9]+ <marker: timestamp [0-9]+>
14: T[0-9]+ <marker: tid [0-9]+ on core [0-9]+>
15: T[0-9]+ ifetch .*
18 changes: 9 additions & 9 deletions clients/drcachesim/tests/offline-windows-asm.templatex
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Adios world!
Hit tracing window #5 limit: disabling tracing.
Basic counts tool results:
Total counts:
50 total \(fetched\) instructions
18 total unique \(fetched\) instructions
53 total \(fetched\) instructions
21 total unique \(fetched\) instructions
4 total non-fetched instructions
0 total prefetches
5 total data loads
7 total data loads
5 total data stores
0 total icache flushes
0 total dcache flushes
Expand All @@ -40,11 +40,11 @@ Total counts:
11 total other markers
Total windows: 7
Window #0:
12 window \(fetched\) instructions
12 window unique \(fetched\) instructions
15 window \(fetched\) instructions
15 window unique \(fetched\) instructions
4 window non-fetched instructions
0 window prefetches
5 window data loads
7 window data loads
5 window data stores
0 window icache flushes
0 window dcache flushes
Expand Down Expand Up @@ -152,11 +152,11 @@ Window #6:
0 window function return value markers
1 window other markers
Thread [0-9]* counts:
12 \(fetched\) instructions
12 unique \(fetched\) instructions
15 \(fetched\) instructions
15 unique \(fetched\) instructions
4 non-fetched instructions
0 prefetches
5 data loads
7 data loads
5 data stores
0 icache flushes
0 dcache flushes
Expand Down
5 changes: 4 additions & 1 deletion clients/drcachesim/tracer/physaddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ physaddr_t::physaddr_t()
, fd_(-1)
, v2p_(nullptr)
, count_(0)
, num_hit_cache_(0)
, num_hit_table_(0)
, num_miss_(0)
#endif
{
#ifdef LINUX
Expand Down Expand Up @@ -246,7 +249,7 @@ physaddr_t::virtual2physical(void *drcontext, addr_t virt, OUT addr_t *phys,
NOTIFY(3, "v2p: %p => entry " HEX64_FORMAT_STRING " @ offs " INT64_FORMAT_STRING "\n",
vpage, entry, offs);
if (!TESTALL(PAGEMAP_VALID, entry) || TESTANY(PAGEMAP_SWAP, entry)) {
NOTIFY(1, "v2p failure: entry is invalid for %p\n", vpage);
NOTIFY(1, "v2p failure: entry %p is invalid for %p\n", vpage);
return false;
}
addr_t ppage = (addr_t)((entry & PAGEMAP_PFN) << page_bits_);
Expand Down
Loading

0 comments on commit 1152e64

Please sign in to comment.