hle(host_posix): a Sleep of 100 ms or more must not consume title time while the host holds a thread (sleep hold) #646

Closed
opened 2026-11-28 21:37:02 +00:00 by github-bot · 3 comments
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 21:34 UTC · original

What

Sleep (crates/victory-hle/src/host_posix.rs:133) is a plain thread::sleep. The title's boot watchdog counts time while the host is slow: the 18 s int3 at image+0x4dcbc9d runs on time (its iterations), not frames (docs/native-host.md, "The int3 at image+0x4dcbc9d"), with 23k pipeline-creation calls and 70k WaitForSingleObject in those 18 s.

MacBox/XCL hit the same class of failure on GTA VI: a retail title's own stall check — a thread that ticks once a second with Sleep and ends the process after 30 ticks without a sign of its main thread — fired while the driver built the pipelines of its world (XCL #509, #232). XCL #1288's sleep hold fixed it: a Sleep of 100 ms or more is taken in steps of at most 20 ms, and the time the host holds one of the title's threads (a pipeline bind in progress, pso_async::title_held) is not subtracted from the sleep; shorter sleeps (polling, streaming, sound) pass through unchanged, XCL_SLEEP_HOLD=0 restores the plain host Sleep. With the hold, a loading run stayed alive to its 900-second bound instead of dying at the title's watchdog (MacBox tests/results/macos-launch-2026-11-25.json).

What this changes

  • a held() signal from the pipeline-creation path (and any other host stall that holds a title thread) into host_posix::Sleep;
  • Sleep(ms >= 100) sleeps in steps, not consuming the requested time while held();
  • VICTORY_SLEEP_HOLD=<ms> sets the threshold (0 disables), as XCL does.

How it was tested

  • unit test on the step accounting (a pure function, as XCL's title_sleep);
  • a game run once the data finishes downloading, watching whether the 18 s wall moves.

Sources: MacBox (github.com/aykhanium/MacBox) crates/xcl/src/hle/kernelx.rs:1440-1495, XCL #1288, #509, #232. Comparison note: their stack is CrossOver + D3DMetal; the transferable part is the title-behaviour finding, not the code.

**@⁠AnastasisKon** on GitHub · 2026-11-28 21:34 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/642) ## What `Sleep` (`crates/victory-hle/src/host_posix.rs:133`) is a plain `thread::sleep`. The title's boot watchdog counts time while the host is slow: the 18 s int3 at image+0x4dcbc9d runs on time (its iterations), not frames (docs/native-host.md, "The int3 at image+0x4dcbc9d"), with 23k pipeline-creation calls and 70k `WaitForSingleObject` in those 18 s. MacBox/XCL hit the same class of failure on GTA VI: a retail title's own stall check — a thread that ticks once a second with `Sleep` and ends the process after 30 ticks without a sign of its main thread — fired while the driver built the pipelines of its world (XCL #509, #232). XCL #1288's sleep hold fixed it: a `Sleep` of 100 ms or more is taken in steps of at most 20 ms, and the time the host holds one of the title's threads (a pipeline bind in progress, `pso_async::title_held`) is not subtracted from the sleep; shorter sleeps (polling, streaming, sound) pass through unchanged, `XCL_SLEEP_HOLD=0` restores the plain host Sleep. With the hold, a loading run stayed alive to its 900-second bound instead of dying at the title's watchdog (MacBox tests/results/macos-launch-2026-11-25.json). ## What this changes - a `held()` signal from the pipeline-creation path (and any other host stall that holds a title thread) into `host_posix::Sleep`; - `Sleep(ms >= 100)` sleeps in steps, not consuming the requested time while `held()`; - `VICTORY_SLEEP_HOLD=<ms>` sets the threshold (0 disables), as XCL does. ## How it was tested - unit test on the step accounting (a pure function, as XCL's `title_sleep`); - a game run once the data finishes downloading, watching whether the 18 s wall moves. Sources: MacBox (github.com/aykhanium/MacBox) crates/xcl/src/hle/kernelx.rs:1440-1495, XCL #1288, #509, #232. Comparison note: their stack is CrossOver + D3DMetal; the transferable part is the title-behaviour finding, not the code.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 21:37:02 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 21:59 UTC · original

/claim

**@⁠AnastasisKon** on GitHub · 2026-11-28 21:59 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/642#issuecomment-7246420191) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 21:59 UTC · original

Claimed by @⁠AnastasisKon. Open a draft pull request with Refs #642 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-28 21:59 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/642#issuecomment-7246421917) Claimed by @⁠AnastasisKon. Open a draft pull request with `Refs #642` in its description within 24 hours, or the claim expires.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 22:11 UTC · original

Done — landed on the fork's main as commit 512c43ee (hle(host_posix): hold the host's pipeline-compile time back from the title's Sleep).

  • victory-backend grew a hold seam: title_held() plus a Hold guard (a counter in the one crate both victory-metal and victory-hle see).
  • victory-metal's convert_uncached — the converter call every uncached pipeline build funnels through, seconds on a title thread — takes the guard.
  • Sleep(ms >= VICTORY_SLEEP_HOLD, default 100 ms, 0 the plain host Sleep) now moves in steps of at most 20 ms, and while a converter call holds a title thread the steps are 5 ms polls that consume none of the requested time, so a title's stall check fed by Sleep does not count the host's compiles as the title's. Shorter sleeps pass on unchanged. The accounting is a pure function (title_sleep) with unit tests; documented in docs/native-host.md's switch list.

Gate green in isolation: cargo test -p victory-hle -p victory -p victory-shader -p victory-gpu -p victory-backend -p xtask, the same suite and cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory (where host_posix compiles; the sleep tests run there), clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -D warnings, cargo xtask policy, all tools/macos/tests/*.sh.

Game run: not possible yet (data still downloading) — this is the step-1 change the issue scoped. What to watch on the next run: whether the 18 s int3 at image+0x4dcbc9d (runs on time, not frames, behind 23k pipeline creations) moves or goes; VICTORY_SLEEP_HOLD=0 restores the old behaviour for A/B. The larger follow-up, async pipeline builds (#647), stays measure-first.

**@⁠AnastasisKon** on GitHub · 2026-11-28 22:11 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/642#issuecomment-7246557910) Done — landed on the fork's main as commit 512c43ee (hle(host_posix): hold the host's pipeline-compile time back from the title's Sleep). - victory-backend grew a hold seam: title_held() plus a Hold guard (a counter in the one crate both victory-metal and victory-hle see). - victory-metal's convert_uncached — the converter call every uncached pipeline build funnels through, seconds on a title thread — takes the guard. - Sleep(ms >= VICTORY_SLEEP_HOLD, default 100 ms, 0 the plain host Sleep) now moves in steps of at most 20 ms, and while a converter call holds a title thread the steps are 5 ms polls that consume none of the requested time, so a title's stall check fed by Sleep does not count the host's compiles as the title's. Shorter sleeps pass on unchanged. The accounting is a pure function (title_sleep) with unit tests; documented in docs/native-host.md's switch list. Gate green in isolation: cargo test -p victory-hle -p victory -p victory-shader -p victory-gpu -p victory-backend -p xtask, the same suite and cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory (where host_posix compiles; the sleep tests run there), clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -D warnings, cargo xtask policy, all tools/macos/tests/*.sh. Game run: not possible yet (data still downloading) — this is the step-1 change the issue scoped. What to watch on the next run: whether the 18 s int3 at image+0x4dcbc9d (runs on time, not frames, behind 23k pipeline creations) moves or goes; VICTORY_SLEEP_HOLD=0 restores the old behaviour for A/B. The larger follow-up, async pipeline builds (#647), stays measure-first.
This discussion has been locked. Commenting is limited to contributors.
No description provided.