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
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.

2 participants