startup: count probe calls, requested bytes and page touches on the totals line #3938

Merged
triggered02 merged 1 commit from upstream-pr/3938 into main 2026-12-03 14:19:39 +00:00
triggered02 commented 2026-12-03 13:53:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-12-03T13:53:45Z.


Refs #3897. Counter half only — not the per-draw phase timers, which the issue's reporter has a draft series for.

Native draws hold the exclusive draw lock for most of their wall time and readable-memory probes take most of that hold, but the log could not say what a probe actually did: whether the ~1 fault per probe in the slow phase is a pressure page-in or a per-range guard re-arm. This makes the probe measurable.

What is counted (around probe_readable, behaviour unchanged):

  • calls — one per probe that gets past the existing range guard (null, below 64 KiB, above the user limit, empty and wrapping ranges count nothing: they never look at memory, and a wrapping bytes is not a byte count).
  • bytes requested — the request, not the readable prefix.
  • pages touched — one per touch the loop attempts, incremented before the access, so the page that faults counts. That is deliberate: it is the number to compare against process page faults, so pages_touched ≈ faults means pressure page-ins while faults ≈ probes ≪ pages means per-range guard re-arm.
  • ticks — raw QueryPerformanceCounter from entry through the guard re-arm, gated behind X2W_PROBE_ACCOUNTING.

All four print on the render totals line immediately after reads refused before a fault, whose wording is unchanged.

Why only the clock is gated. The three counters cost three interlocked operations (tens of nanoseconds) against the ~90 µs a probe can cost under pressure, and they are worthless if they default off. A QueryPerformanceCounter pair costs roughly as much as a fast cached probe and would distort the hold it is meant to measure, so a run that wants timing opts in and every other run pays one cached bool.

Tests. startup_local_log_check pins exact, hand-computed deltas: 16 bytes at +0x10 → (1, 16, 1); an unaligned 4-page span → (1, 0x3EDD, 3); PAGE_NOACCESS on page 2 → (1, 0x4000, 3) with 3 pages touched including the faulting one; PAGE_GUARD re-arm; a free tail refused without a touch (faults_avoided +1); 1,000 batched probes → (1000, 0x400000, 4000) with monotone ticks; 4 threads × 100 probes → exactly (400, 6400, 400); and every refused range → (0, 0, 0). A new startup_local_log_accounting_off ctest asserts the counts still advance with ticks exactly 0 when the switch is off.

Verified here — Debian, clang-cl 19.1.7, xwin SDK 10.0.26100, main 7b3212a9:

cmake --build out/build/clang --target startup_local_log_check d3d12_xs_shim -j 8   -> both link, exit 0
startup_local_log_check under Wine      -> 140 cases, all 36 new ones pass
startup_local_log_check --phase probe-accounting-off -> 0 of 7 FAILED

One case fails: the pre-existing concurrent-logging case. I checked rather than assumed — stashing this diff, rebuilding unmodified main and re-running the same command reproduces it identically, and it also fails in a fresh Wine prefix and under the system wine. It is a Wine FILE_APPEND_DATA limitation of that older test, not this change.

Not established: Windows ctest, an MSVC build with the real /W4 /WX flags, and — the point of the change — a title-scene run on the Windows test PC with X2W_PROBE_ACCOUNTING=1. That run is the only way to attribute the 1.3–1.65k faults per present, and no fps or hold-time number is claimed from Wine.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5627860874 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3938). Originally posted by [triggered02](https://github.com/triggered02) on 2026-12-03T13:53:45Z. --- Refs #3897. **Counter half only** — not the per-draw phase timers, which the issue's reporter has a draft series for. Native draws hold the exclusive draw lock for most of their wall time and readable-memory probes take most of that hold, but the log could not say what a probe actually did: whether the ~1 fault per probe in the slow phase is a pressure page-in or a per-range guard re-arm. This makes the probe measurable. **What is counted** (around `probe_readable`, behaviour unchanged): - **calls** — one per probe that gets past the existing range guard (null, below 64 KiB, above the user limit, empty and wrapping ranges count nothing: they never look at memory, and a wrapping `bytes` is not a byte count). - **bytes requested** — the request, not the readable prefix. - **pages touched** — one per touch the loop *attempts*, incremented before the access, so the page that faults counts. That is deliberate: it is the number to compare against process page faults, so `pages_touched ≈ faults` means pressure page-ins while `faults ≈ probes ≪ pages` means per-range guard re-arm. - **ticks** — raw `QueryPerformanceCounter` from entry through the guard re-arm, **gated behind `X2W_PROBE_ACCOUNTING`**. All four print on the render totals line immediately after `reads refused before a fault`, whose wording is unchanged. **Why only the clock is gated.** The three counters cost three interlocked operations (tens of nanoseconds) against the ~90 µs a probe can cost under pressure, and they are worthless if they default off. A `QueryPerformanceCounter` pair costs roughly as much as a fast cached probe and would distort the hold it is meant to measure, so a run that wants timing opts in and every other run pays one cached bool. **Tests.** `startup_local_log_check` pins exact, hand-computed deltas: 16 bytes at +0x10 → (1, 16, 1); an unaligned 4-page span → (1, 0x3EDD, 3); `PAGE_NOACCESS` on page 2 → (1, 0x4000, 3) with 3 pages touched including the faulting one; `PAGE_GUARD` re-arm; a free tail refused without a touch (`faults_avoided` +1); 1,000 batched probes → (1000, 0x400000, 4000) with monotone ticks; 4 threads × 100 probes → exactly (400, 6400, 400); and every refused range → (0, 0, 0). A new `startup_local_log_accounting_off` ctest asserts the counts still advance with **ticks exactly 0** when the switch is off. **Verified here** — Debian, clang-cl 19.1.7, xwin SDK 10.0.26100, `main` 7b3212a9: ``` cmake --build out/build/clang --target startup_local_log_check d3d12_xs_shim -j 8 -> both link, exit 0 startup_local_log_check under Wine -> 140 cases, all 36 new ones pass startup_local_log_check --phase probe-accounting-off -> 0 of 7 FAILED ``` One case fails: the **pre-existing** concurrent-logging case. I checked rather than assumed — stashing this diff, rebuilding unmodified `main` and re-running the same command reproduces it identically, and it also fails in a fresh Wine prefix and under the system wine. It is a Wine `FILE_APPEND_DATA` limitation of that older test, not this change. **Not established:** Windows ctest, an MSVC build with the real `/W4 /WX` flags, and — the point of the change — a title-scene run on the Windows test PC with `X2W_PROBE_ACCOUNTING=1`. That run is the only way to attribute the 1.3–1.65k faults per present, and no fps or hold-time number is claimed from Wine.
chatgpt-codex-connector[bot] commented 2026-12-03 13:54:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-12-03T13:54:02Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T14:00:36.922182Z 0822b71 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7380567508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3938#issuecomment-7380567508). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-12-03T13:54:02Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"0822b7146ee5b611aeb8f30de7fdbeacc5a43209","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-12-03T14:00:36.922182Z">2026-12-03T14:00:36.922182Z</relative-time> | `0822b71` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
R0Y00 commented 2026-12-03 14:19:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T14:19:29Z.

Review: APPROVED


Independently reviewed 0822b714. The counter increments follow probe admission and count each attempted page touch, including protected pages. QPC timing stays behind the cached opt-in, and the totals field uses atomic snapshots. Windows MSVC Debug: ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^startup_local_log($|_)' passed 10/10. Removing the page increment made 11 probe accounting assertions fail, including the four-thread case, and also failed the timing-off case. Restoring the increment made both controls pass.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6171575091 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3938#pullrequestreview-6171575091). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T14:19:29Z. **Review:** APPROVED --- Independently reviewed 0822b714. The counter increments follow probe admission and count each attempted page touch, including protected pages. QPC timing stays behind the cached opt-in, and the totals field uses atomic snapshots. Windows MSVC Debug: `ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^startup_local_log($|_)'` passed 10/10. Removing the page increment made 11 probe accounting assertions fail, including the four-thread case, and also failed the timing-off case. Restoring the increment made both controls pass.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3938
No description provided.