Repository navigation
startup: resume threads that fault on a host-cpu site another thread rewrote - #2197
Merged
Merged
Conversation
…rewrote With X2W_HOST_CPU=1 the debugger rewrites a missing instruction on its first fault. A second thread that ran the same instruction before the rewrite reports its fault after it: the site then holds the replacement, nothing is rewritten again, and the fault went to the title as a second chance. Such a thread is now continued once and runs the replacement; a fault that stays is still reported. The probe runs 32 RDPID sites that eight threads reach together; without the change the check stops at an illegal instruction on a host without RDPID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
reviewed
Nov 25, 2026
tedin7
left a comment
Collaborator
There was a problem hiding this comment.
Review of head 6429104adc5c9a2c29afa8042b63c2615dd94a4d (comment only).
Summary: the change is small and sound. A thread that faulted on a host-cpu site before another thread rewrote it is continued once, so it runs the replacement. No P1/P2 findings.
Checked:
tools/startup/debug_launch.py:rewrite_for_hostandsha_for_hostare tried first, so a fresh site is always handled the old way. Only an already-rewritten address that nobody can rewrite again reaches the new branch. The(site, tid)set bounds it to one resume per thread, so a fault that persists after the replacement is still reported and not looped on.- SHA sites are never added to the rewritten set (they are performed per hit), so they are not affected.
- The summary line is only printed when something was resumed, so existing output is unchanged otherwise.
- Probe: 32 distinct RDPID sites (the
+Nkeeps the linker from merging them) and a spin barrier before each site make every thread reach the site together. The check assertsrdpid threads 8 of 8.
Commands executed locally (Linux):
git diff --stat origin/main...HEAD: 3 files, +62/-3python3 tests/docs_links_check.py: self-test passed, 18 files, 405 linkspython3 tests/bidi_controls_check.py: 1480 files, no bidirectional controlsgit diff --check origin/main...HEAD: cleanpython3 -I -m py_compile tools/startup/debug_launch.py tests/startup_host_cpu_debug_check.py: ok- Mutation (removed the
(ex_addr, tid) not in host_cpu_resumedguard): the check needs the Windows probe binary (IndexErroron argv on Linux), so it cannot kill or confirm the mutation here. Reverted withgit checkout -- .. python3 x2w_pipe.py win2025 2197 --targets startup_host_cpu_probe --regex startup_host_cpu --wait 3300: dev 2/2 passed (startup_host_cpu,startup_host_cpu_debug), release 2/2 passed, exit 0.- CI: Linux checks, gfx1013 fixtures and Windows build/test all pass; mergeable; title is neutral.
Nits (non-blocking):
- N1
tests/startup_host_cpu_debug_check.py: on a host that has RDPID nothing is rewritten, so the resume branch is not exercised and8 of 8passes trivially. It only guards the fix on hosts without RDPID. Worth a comment, or asserting the resumed count whensummarymentions rdpid. - N2
tests/startup_host_cpu_debug_check.py: the resumed count is reported but not asserted. It is timing dependent, so this is a reasonable choice; the8 of 8assert is the real guard.
AI-assisted; commands listed were executed locally.
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
With
X2W_HOST_CPU=1the startup debugger rewrites a missing instruction on its first fault. A second thread that ran the same instruction before the rewrite reports its fault afterwards. Until now that fault went to the process as a second chance, and the run stopped. Fixes #2196.tools/startup/debug_launch.pynow records the sites it rewrote. A first-chance illegal instruction at such a site, where nothing is left to rewrite, is continued once per thread, so the thread runs the replacement. A fault that stays at the site is still reported. The summary prints how many threads were resumed.tests/startup_host_cpu_probe.cppadds 32 RDPID sites. A barrier before each site makes eight threads reach it together.startup_host_cpu_debugnow also requires all eight threads to finish.Related, but a different mechanism: #1281 and its PRs #1408 and #1951 (hooked-function breakpoints).
Verification
Commit
6429104aona116c379, Windows 10 22H2 (build 19045), i7-4790K (no RDPID, no SHA), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7.Negative control, the new probe without the
debug_launch.pychange, 3 runs:With the change, 5 runs:
CTest:
A full startup run with this change (and #1277 for Windows 10) rewrote the same sites as before (
clflushopt-nop x1, clwb x1, clwb-nop x4, clzero x5, insertq x2, monitorx x1, mwaitx x1). The race did not occur in that run, so nothing was resumed.Evidence and follow-up
Checklist
AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.
🤖 Generated with Claude Code