text stringlengths 0 1.99k |
|---|
which 8-byte "qwords" within the segment are active. |
3. Level 3 (bytes): For each active qword, an 8-bit mask specifies which |
individual bytes are being tracked (byte-select mask). |
Once you have that hierarchy, you compute the smallest 2^N block covering |
all active bits: |
[ Full page: 0...31 ] |
| |
+--------+---------+ |
| | |
[0...15] [16...31] |
| | |
used?->yes used?->no |
| | |
select [0...15] back to root |
| |
repeat split on [0...15] |
If the optimal block still contains gaps or would occupy more than one |
hardware slot, we recursively split the range into two halves and test |
each for activity. This continues until we either: |
- Narrow to a single power-of-two block covering all active bytes, or |
- Fill all four slots with disjoint blocks that together cover the entire |
tracked region with minimal overhead. |
--------------------------------------------------------------------------- |
Here are four concrete examples on a 16 KB page at base 0x16bd7c000 |
--------------------------------------------------------------------------- |
Example 1: Aligned 8-Byte Range |
Tracked bytes: 0x16bd7c0a0-0x16bd7c0a7 |
Offset range: 0xa0-0xa7, already 8 Bytes power-of-two block |
Byte-select mask: 0b11111111 |
> single watchpoint: [0xa0-0xa7] |
--------------------------------------------------------------------------- |
Example 2: Two-Byte Selection in an 8-Byte Block |
Tracked bytes: 0x16bd7c0a0-0x16bd7c0a1 |
Aligned 8 Bytes block: 0xa0-0xa7 |
Byte-select mask: 0b00000011 |
> single watchpoint covering [0xa0-0xa7] with 2 byte-select |
--------------------------------------------------------------------------- |
Example 3: Unaligned 8-Byte Range |
Tracked bytes: 0x16bd7c00b-0x16bd7c012 |
Offset span: 0x0b-0x12 (8 B) crosses two 8 B blocks |
> minimal cover: 32 B block [0x00-0x1f] |
> algorithm may choose: |
- one 32 B watchpoint [0x00-0x1f] |
- two 8 B watchpoints [0x08-0x0f] & [0x10-0x17] |
based on available free watchpoint slots |
Note: a single 16 B watchpoint [0x08-0x17] is invalid |
because the CPU enforces power-of-two size and address alignment |
--------------------------------------------------------------------------- |
Example 4: Multiple Disjoint Ranges |
Tracked bytes: |
- 0x16bd7c0a0-0x16bd7c0a7 (8 B) |
- 0x16bd7c200-0x16bd7c207 (8 B) |
- 0x16bd7c500-0x16bd7c51f (32 B) |
> Three Watchpoints assignments: |
[1] 8 B @ 0xa0-0xa7, byte-select mask=0b11111111 |
[2] 8 B @ 0x200-0x207, byte-select mask=0b11111111 |
[3] 32 B @ 0x500-0x51f |
Note: Gaps > power-of-two aligned sizes force separate blocks |
--------------------------------------------------------------------------- |
Dynamic switching adds another layer of economy: on each page-fault or |
access trap, record the recently accessed address, then recompute the four |
watchpoints to favour that area (so the next few accesses fire the minimum |
number of context switches). In practice this means you only ever reprogram |
the debug registers when the exceptions "jumps" outside the current watched |
blocks, keeping overhead near zero during tight loops over the same region. |
.-----------. on WP fault at address X |
| CPU Core |----> recompute up to 4 WPs covering X +/- delta |
'-----------' reprogram DBGWCR0-3 with new ranges | resume execution |
By weaving bitmaps, recursive splitting, and fault-driven reconfiguration, |
you transform limited hardware watchpoints into a finely tuned tracking |
engine that precisely covers only the memory bytes and addresses you care |
about, while maximizing unwatched gaps to avoid irrelevant memory-access |
exceptions, eliminating floods of excessive page faults. |
To accomplish this, we designed and evaluated several watchpoint |
allocation strategies, each targeting different trade-offs between |
precision and performance. Early attempts included a naive uniform |
splitter that divided the page into evenly sized regions, regardless of |
access patterns. We then explored a greedy segment-based strategy that |
prioritized denser areas of tracked memory, followed by a refinement-aware |
approach that recursively split only when significant coverage reduction |
was observed. |
Ultimately, we settled on a strategy that consistently outperformed the |
others in practice: Strict Recent Access Bias. This strategy aggressively |
favors regions near the most recently faulting address, allocating more of |
the watchpoint budget toward areas that are likely to be accessed again |
soon. Instead of passively observing the bitmap distribution, it actively |
reshapes the coverage to follow the faulting instruction. This focus on |
locality means that memory loops and bursty access patterns remain within |
the same set of watchpoints for extended periods, minimizing debug |
register reprogramming and avoiding unnecessary traps. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.