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

Manually merged
github merged 1 commit from github-bot/gh-3938 into gh-pr/3938/base 2026-12-03 14:22:16 +00:00 AGit
Owner

@⁠triggered02 on GitHub · 2026-12-03 13:53 UTC · original
triggered02:feat/3897-probe-counters → main · +278 −8 · 5 files · 1 commits · merged 2026-12-03 14:19 UTC

Refs #3899. 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.

**@⁠triggered02** on GitHub · 2026-12-03 13:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3938) `triggered02:feat/3897-probe-counters` → `main` · +278 −8 · 5 files · 1 commits · merged 2026-12-03 14:19 UTC Refs #3899. **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.
Native draws serialise on the exclusive draw lock and readable-memory page
probes take most of the hold (issue #3897), but the log cannot separate a
probe that faults on first touch from one that pays a per-range guard
re-arm: there is no probe counter. This adds the counter half only, not the
per-draw phase timers.

probe_readable now publishes four counters next to faults_avoided in
src/startup_stubs/local_log.h:

* probe_calls: probes that got past the range guard (a null, low, high,
  empty or wrapping range never looks at memory and is not counted).
* probe_bytes_requested: the sum of the bytes argument of those probes.
* probe_pages_touched: one per touch the loop attempts, counted before the
  access, so the page a probe faults on (guard or no-access) counts. This
  is the number to compare with process page faults.
* probe_ticks: raw QueryPerformanceCounter ticks from entry to the guard
  re-arm, gated behind X2W_PROBE_ACCOUNTING (read once; unset or 0 off).
  Off, the probe reads one cached bool and calls no clock. The three
  counters are always on: three Interlocked operations, well below the
  cost of the pages the probe touches.

The render totals line prints them after the existing "reads refused
before a fault" count, with that wording unchanged:

  probes <n> (bytes requested <n>, pages touched <n>, ticks <n> when
  X2W_PROBE_ACCOUNTING=1)

tests/startup_local_log_check.cpp pins exact deltas for hand-computed
ranges: one page at different offsets, 0xF00 + 0x2200 across four pages,
a PAGE_NOACCESS truncation (2 readable pages plus the faulting page = 3
touches), an unaligned PAGE_NOACCESS range, a PAGE_GUARD trip and the
re-armed trip (2 touches each), 1,000 batched four-page probes (4,000
touches), 4 threads x 100 probes for the atomic sums, and a mapped page
before a verified-free tail (1 touch, one avoided fault). The new
--phase probe-accounting-off child (ctest
startup_local_log_accounting_off) asserts that with the switch off the
counts still advance and the tick total stays 0.

Refs #3897
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 13:55:12 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-03 13:54 UTC · original · edited 2026-12-03 14:00 UTC

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-03 13:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3938#issuecomment-7380567508) · edited 2026-12-03 14:00 UTC <!-- 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>
github-bot changed target branch from main to gh-pr/3938/base 2026-12-03 14:22:01 +00:00
github manually merged commit 0822b7146e into gh-pr/3938/base 2026-12-03 14:22:15 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 14:19 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-12-03 14:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3938#pullrequestreview-6171575091) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.