Skip to content

Stubs: record R8/R9 argument registers of stub calls in the report - #2722

Open
amazedturnip wants to merge 1 commit into
xcl-dev:mainfrom
amazedturnip:xcl/stubs-record-r8-r9-argument-registers-081516
Open

amazedturnip wants to merge 1 commit into
xcl-dev:mainfrom
amazedturnip:xcl/stubs-record-r8-r9-argument-registers-081516

Conversation

@amazedturnip

@amazedturnip amazedturnip commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Record the 3rd/4th Win64 argument registers (R8/R9) at stub-thunk call time and surface them in report.json as first_args/last_args per called stub, to diagnose which console slots actually receive which values. Args are kept in a side table keyed by the StubInfo pointer so no StubInfo fields or thunk bytes change (avoids overlap with open #936/#1155). Tests pin first/last/call-count and serde on/off; verified on the AMD Radeon iGPU retail build.

What is in it

  • crates/xcl/src/stubs.rs: stub_report now takes (r8, r9) and records first/last R8/R9 per stub in a side-table keyed by the StubInfo pointer (no StubInfo field changes, no thunk-bytes changes).
  • crates/xcl/src/report.rs: StubCall gains optional first_args/last_args (hex, serde default + skip_serializing_if empty); build() emits them from stub_args.
  • crates/xcl/src/stubs_args_tests.rs (new sibling test module): thunk call records first/last R8/R9 and call count; argless record_call leaves the side table empty; StubCall with args serializes them, without args omits them.

Tested

Regression run
main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon(TM) Graphics
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1473 (PresentX 1473)
presents per 2 s (last 3): 60 44 0
device removals: 0
crashes: 0
peak commit: 13978 MB

PR:

xcl-smoke v1
commit: 315e3f85e2eb51a490643560fca3e91c52d3c6be
gpu: AMD Radeon(TM) Graphics
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1552 (PresentX 1552)
presents per 2 s (last 3): 4 59 60
device removals: 0
crashes: 0
peak commit: 14106 MB

Not tested

  • NVIDIA wave32 GPU (verified on AMD Radeon native wave64)

AI use

  • Local AI (thinkingmachines_inkling-2-mini) assisted with diagnosis, implementation, tests, review, and description; all tests executed locally on AMD Radeon (native wave64).
  • Claude Code (Claude Opus 5.5) edited this description: removed an internal note, and put in the test counts and both smoke blocks rerun on the current head.

@luckyteagirl luckyteagirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a concurrency issue in the new R8/R9 diagnostics at head 77158b0 (base b49be18). This is a source-derived review; I did not run a native concurrent title test.

record_call_with_args assigns the call ordinal with fetch_add and stores first_caller before taking the ARGS mutex. If call A gets ordinal 0 and pauses during first-call logging, call B can get ordinal 1 and insert B's arguments into the empty side table. A then acquires the mutex and overwrites the last arguments. After both calls, the report can say first_caller=A, first_args=B, and last_args=A. Neither argument pair matches the ordinal implied by its label.

Could the side table record the first/last ordinal alongside the arguments and update each field only when the incoming ordinal is earlier/later, or otherwise serialize ordinal assignment with the table update? A two-thread fixture that forces the first caller to enter the table second would cover the first and last fields. Logging and hooks can remain outside the mutex.

AI assistance: GPT-6.2 Sol identified the interleaving; GPT-6.2 Astra independently checked the exact-head source and wording.

@amazedturnip

Copy link
Copy Markdown
Contributor Author

Fixed per the review: the ARGS side table now records (first_ord, last_ord, first_r8, first_r9, last_r8, last_r9) per info and updates each field only when the incoming ordinal is strictly earlier/later. Ordinal assignment still happens via fetch_add before the ARGS mutex (logging/hooks remain outside), but no field is overwritten by an out-of-order caller now. A two-thread fixture (ordinal_first_caller_arriving_late_still_records_as_first_and_last) forces caller A (ordinal 0) into the table second via a test-only pause hook; the test asserts A's args land as first_args and B's as last_args. All stubs tests pass (9/9).

@amazedturnip
amazedturnip force-pushed the xcl/stubs-record-r8-r9-argument-registers-081516 branch from 77158b0 to 315e3f8 Compare November 26, 2026 09:54
@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2722 at 315e3f85e2eb51a490643560fca3e91c52d3c6be (exact parent origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)

Targeted Win11 / RTX 4060 release unit tests (315e3f85)

  • cargo test --release -p xcl --lib stubs_args_tests:: -- --nocapture: 4 passed, 0 failed, 0 ignored (0.00 s, exit 0), covering ordinal_first_caller_arriving_late_still_records_as_first_and_last, thunk_records_first_and_last_r8_r9_args, record_call_without_args_leaves_side_table_empty, and stub_call_serializes_args_only_when_present.
  • cargo test --release -p xcl --lib stubs_args_tests:: -- --test-threads=4 (3 consecutive parallel stress passes): 4 passed, 0 failed, 0 ignored × 3 (0.00 s each, exit 0).
  • cargo test --release -p xcl --lib stubs:: -- --test-threads=4: 7 passed, 0 failed, 0 ignored (0.02 s, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib report:: -- --test-threads=4: 1 passed, 0 failed, 0 ignored (0.10 s, 0 skipped, exit 0).

Observations

  • The updated ARGS side-table ordering fix (ordinal_first_caller_arriving_late_still_records_as_first_and_last) and all stubs_args_tests::, stubs::, and report:: tests passed cleanly in --release on native Windows 11 26200, including 3 consecutive parallel --test-threads=4 stress runs with zero flake.
  • Live report.json verification on the 60 s retail smoke: called_stubs recorded 9 entries total, with 1 thunk-captured entry cleanly serializing both first_args and last_args (two hex R8/R9 values each) and the other 8 entries omitting both fields as expected.
  • Quiet 60 s retail smoke ran cleanly (exit: 0x0, 1545 frames shown, 60 60 60 steady-state presents per 2 s, 0 device removals, 0 crashes, 14014 MB peak commit vs parent b49be183's 14018 MB / 1518 frames).

Paired 60 s RTX 4060 smoke (b49be183 vs 315e3f85)

Parent origin/main (b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR #2722 head (315e3f85):

xcl-smoke v1
commit: 315e3f85e2eb51a490643560fca3e91c52d3c6be
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1545 (PresentX 1545)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14014 MB

Limits of coverage

  • Full workspace test suite was not re-run on 315e3f85 (only targeted stubs_args_tests::, stubs::, and report:: release tests plus paired quiet 60 s smoke).
  • Native Windows 11 (26200) / x86-64 RTX 4060 only; no Wine/Linux run on this host.

AI use

Ran the targeted release unit tests, paired quiet 60 s smoke runs, and report.json field check with assistance from Google Antigravity (Gemini 4 Neon); all test counts, report.json statistics, and smoke blocks were taken directly from cargo test, report.json, and scripts/smoke.ps1 outputs.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants