fix(vcores): keep a thread that never had a mask on its ideal core #2368

Merged
HumanBean merged 2 commits from DuckNintendo/Longshot:fix/vcore-unmasked-ideal into main 2026-11-23 19:58:16 +00:00
Contributor

Summary

Follow-up to #327. That change made a raw mask 0 mean “no affinity”, but a thread that never called SetThreadCoreMask also has mask 0, so every such thread — including MainThread — started floating instead of staying on the core it was created for. This PR records whether a mask was ever set: only an explicit 0 floats, and a thread that was never masked stays on its ideal core, as the kernel and main did.

On the mobile Radeon 780M here the new-game movie runs at about 37 fps and Hyrule Field at about 10 fps; main and this PR are the same within the run spread. To see the bug on main, run python -I -B tests/test_vcore_mask0.py --source <main's host/hos_thread.c>: the never-masked checks fail because vc_allowed() returns every core and vc_free_for() floats such a thread. With this PR the fixture prints ok.

SetThreadCoreMask now publishes its ideal core, mask and mask_set under the scheduler lock, and the svc call returns the kernel's InvalidCombination for an empty mask instead of success. Read host/hos_thread.c’s vc_set_affinity(), mask_set, vc_allowed(), vc_free_for() and vc_pref_core() first; host/hos_svc.c’s SetThreadCoreMask case and the new cases in tests/test_vcore_mask0.py follow.

Testing

Tested: Linux, host-only fixture and the full game-free suite; and the game on the Radeon 780M, headless, with interleaved main/PR runs. python -I -B tests/test_vcore_mask0.py passes, including the never-masked and first-SetThreadCoreMask cases; the fixture fails on main at the new never-masked checks. python -I -B tests/run_all.py --jobs 8 gives 855 passed, 11 failed and 108 skipped; untouched 59f9632b gives 854 passed with the same 11 failures: tests/test_amd_subgroup_profiles.py, tests/test_dev_packs.py, tests/test_flat_map.py, tests/test_guest_holes.py, tests/test_pipeline_state_computes.py, tests/test_rdna2_mesh_only.py, tests/test_readback_timeout_source.py, tests/test_shader_profile_caps.py, tests/test_target_image_reuse.py, tests/test_vram_compact.py and tests/test_wb_spans.py. The touched host files compile with the build's flags. The new tests/test_svc_core_mask.py checks the empty-mask result and that the thread's affinity is unchanged. On the 780M, two interleaved runs of the title plus new-game movie and two of Hyrule Field showed no crash and no regression: movie 37.0 against 36.95 fps, Hyrule Field 9.83 against 9.97 fps; the details are below.

Still to test:

  • Native Windows: play with masked and unmasked threads active, expecting no crash, no hang, and no regression for a thread that never changes its mask (by hand).
  • Steam Deck or a low-core CPU: the same, expecting no regression (by hand).

Measurements

Verdict: the new fixture fails on main and passes here; the full game-free suite is unchanged; on the Radeon 780M the new-game movie and Hyrule Field runs are within run spread (movie 37.0 against 36.95 fps, field 9.83 against 9.97 fps).

Fixture and suite

Setup: Linux host-only; the fixture compiles the virtual-core block from host/hos_thread.c with a host harness, and the suite runs each tests/test_*.py in its own process. No game or GPU path is involved.

Before: main @ 59f9632b After: this PR @ e1aff25d
never-masked fixture FAIL: stays on its ideal core; FAIL: waits for its ideal core ok
full game-free suite 854 passed / 11 failed / 108 skipped 855 passed / 11 failed / 108 skipped

Main's new fixture output:

FAIL: a never-masked thread stays on its ideal core
FAIL: a never-masked thread waits for its ideal core
the virtual-core mask/TLS checks failed

This PR:

ok

Game runs on the Radeon 780M

Setup: Linux, AMD Zen 4 8-core/16-thread APU with Radeon 780M (RADV Phoenix), Mesa 26.0.2, 60 GB; headless offscreen 1920x1080, uncapped. A dev.py packs base at 59f9632b, with main and this PR as runtimes; two interleaved runs each, main/PR/main/PR. The movie run holds the title for 20 s, then measures 130 s of the new-game movie; Hyrule Field is the fixed save, 10 s warm-up and 60 s of scripted movement. Frame times from RX_VK_FRAME_LOG; scheduling from the 5 s vcores: lines.

Before: main @ 59f9632b After: this PR @ 65f2456f
title + new-game movie · fps mean 37.01 36.95
title + new-game movie · 1% low fps 27.7 27.7
title + new-game movie · frame median 27.13 ms 27.11 ms
title + new-game movie · p99 31.98 ms 31.98 ms
title + new-game movie · process CPU 211.5 s 210.3 s
Hyrule Field · fps mean 9.83 9.97
Hyrule Field · 1% low fps 6.05 6.74
Hyrule Field · frame median 99.2 ms 97.6 ms
Hyrule Field · p99 139.2 ms 137.5 ms
Hyrule Field · process CPU 105.1 s 107.4 s

The title screen runs at about 35 fps and the new-game movie at about 37 fps; Hyrule Field is GPU-bound at about 10 fps on the 780M. The scheduling counters in the final 5 s were: movie 100 us mean wait and 0 escapes on both; Hyrule Field 676/741 us mean wait on main and 635/769 us here, 0 over the long-wait threshold and 0 escapes on both. No crash in either side. Those two-run medians are at 65f2456f; on the final head e1aff25d a single pair measured movie 29.7 (main) / 30.4 (this PR) fps and Hyrule Field 9.8 / 9.8 fps, so the lock change did not move the game result.

The final 5 s lines (run 1 of each):

movie main: vcores: 49789 takes, 6470 waits (mean 103 us, longest 4.2 ms, 0 over HOS_VCORE_LOG_MS), 2311 kicks, 2206 yields, 0 starved grants, 0 escapes in 5 s
movie PR:   vcores: 49598 takes, 5923 waits (mean 96 us, longest 7.0 ms, 0 over HOS_VCORE_LOG_MS), 2153 kicks, 2037 yields, 0 starved grants, 0 escapes in 5 s
field main: vcores: 39659 takes, 9890 waits (mean 676 us, longest 21.4 ms, 0 over HOS_VCORE_LOG_MS), 5157 kicks, 5037 yields, 0 starved grants, 0 escapes in 5 s
field PR:   vcores: 45579 takes, 10156 waits (mean 635 us, longest 22.1 ms, 0 over HOS_VCORE_LOG_MS), 5182 kicks, 5087 yields, 0 starved grants, 0 escapes in 5 s

Risks

A thread that never called SetThreadCoreMask is pinned again, as on main; if the game relied on such a thread floating, that behaviour is lost. The explicit mask-0 path from #327 is unchanged. The svcSetThreadCoreMask(0) call is ignored as the real kernel does.

Turning it off: revert the commit; there is no switch. Saves, options, caches and the vk ABI are unchanged.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • The game-free suite passes (python -I -B tests/run_all.py --jobs 8), with the failures named above.
  • mise run test passes (the same failures named above also fail on main).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested.
  • Approved in review, every comment answered.
  • CI passes on the head.

Generated by opencode with deepseek-v4.1-flash-1017

## Summary Follow-up to #327. That change made a raw mask 0 mean “no affinity”, but a thread that never called `SetThreadCoreMask` also has mask 0, so every such thread — including `MainThread` — started floating instead of staying on the core it was created for. This PR records whether a mask was ever set: only an explicit 0 floats, and a thread that was never masked stays on its ideal core, as the kernel and main did. On the mobile Radeon 780M here the new-game movie runs at about 37 fps and Hyrule Field at about 10 fps; main and this PR are the same within the run spread. To see the bug on main, run `python -I -B tests/test_vcore_mask0.py --source <main's host/hos_thread.c>`: the never-masked checks fail because `vc_allowed()` returns every core and `vc_free_for()` floats such a thread. With this PR the fixture prints `ok`. `SetThreadCoreMask` now publishes its ideal core, mask and mask_set under the scheduler lock, and the svc call returns the kernel's InvalidCombination for an empty mask instead of success. Read `host/hos_thread.c`’s `vc_set_affinity()`, `mask_set`, `vc_allowed()`, `vc_free_for()` and `vc_pref_core()` first; `host/hos_svc.c`’s `SetThreadCoreMask` case and the new cases in `tests/test_vcore_mask0.py` follow. ## Testing **Tested:** Linux, host-only fixture and the full game-free suite; and the game on the Radeon 780M, headless, with interleaved main/PR runs. `python -I -B tests/test_vcore_mask0.py` passes, including the never-masked and first-`SetThreadCoreMask` cases; the fixture fails on main at the new never-masked checks. `python -I -B tests/run_all.py --jobs 8` gives 855 passed, 11 failed and 108 skipped; untouched `59f9632b` gives 854 passed with the same 11 failures: `tests/test_amd_subgroup_profiles.py`, `tests/test_dev_packs.py`, `tests/test_flat_map.py`, `tests/test_guest_holes.py`, `tests/test_pipeline_state_computes.py`, `tests/test_rdna2_mesh_only.py`, `tests/test_readback_timeout_source.py`, `tests/test_shader_profile_caps.py`, `tests/test_target_image_reuse.py`, `tests/test_vram_compact.py` and `tests/test_wb_spans.py`. The touched host files compile with the build's flags. The new `tests/test_svc_core_mask.py` checks the empty-mask result and that the thread's affinity is unchanged. On the 780M, two interleaved runs of the title plus new-game movie and two of Hyrule Field showed no crash and no regression: movie 37.0 against 36.95 fps, Hyrule Field 9.83 against 9.97 fps; the details are below. **Still to test:** - Native Windows: play with masked and unmasked threads active, expecting no crash, no hang, and no regression for a thread that never changes its mask (by hand). - Steam Deck or a low-core CPU: the same, expecting no regression (by hand). ## Measurements **Verdict:** the new fixture fails on main and passes here; the full game-free suite is unchanged; on the Radeon 780M the new-game movie and Hyrule Field runs are within run spread (movie 37.0 against 36.95 fps, field 9.83 against 9.97 fps). ### Fixture and suite Setup: Linux host-only; the fixture compiles the virtual-core block from `host/hos_thread.c` with a host harness, and the suite runs each `tests/test_*.py` in its own process. No game or GPU path is involved. | | Before: main @ 59f9632b | After: this PR @ e1aff25d | |---|---|---| | never-masked fixture | FAIL: stays on its ideal core; FAIL: waits for its ideal core | ok | | full game-free suite | 854 passed / 11 failed / 108 skipped | 855 passed / 11 failed / 108 skipped | Main's new fixture output: ``` FAIL: a never-masked thread stays on its ideal core FAIL: a never-masked thread waits for its ideal core the virtual-core mask/TLS checks failed ``` This PR: ``` ok ``` ### Game runs on the Radeon 780M Setup: Linux, AMD Zen 4 8-core/16-thread APU with Radeon 780M (RADV Phoenix), Mesa 26.0.2, 60 GB; headless offscreen 1920x1080, uncapped. A `dev.py packs` base at `59f9632b`, with main and this PR as runtimes; two interleaved runs each, main/PR/main/PR. The movie run holds the title for 20 s, then measures 130 s of the new-game movie; Hyrule Field is the fixed save, 10 s warm-up and 60 s of scripted movement. Frame times from `RX_VK_FRAME_LOG`; scheduling from the 5 s `vcores:` lines. | | Before: main @ 59f9632b | After: this PR @ 65f2456f | |---|---|---| | title + new-game movie · fps mean | 37.01 | 36.95 | | title + new-game movie · 1% low fps | 27.7 | 27.7 | | title + new-game movie · frame median | 27.13 ms | 27.11 ms | | title + new-game movie · p99 | 31.98 ms | 31.98 ms | | title + new-game movie · process CPU | 211.5 s | 210.3 s | | Hyrule Field · fps mean | 9.83 | 9.97 | | Hyrule Field · 1% low fps | 6.05 | 6.74 | | Hyrule Field · frame median | 99.2 ms | 97.6 ms | | Hyrule Field · p99 | 139.2 ms | 137.5 ms | | Hyrule Field · process CPU | 105.1 s | 107.4 s | The title screen runs at about 35 fps and the new-game movie at about 37 fps; Hyrule Field is GPU-bound at about 10 fps on the 780M. The scheduling counters in the final 5 s were: movie 100 us mean wait and 0 escapes on both; Hyrule Field 676/741 us mean wait on main and 635/769 us here, 0 over the long-wait threshold and 0 escapes on both. No crash in either side. Those two-run medians are at `65f2456f`; on the final head `e1aff25d` a single pair measured movie 29.7 (main) / 30.4 (this PR) fps and Hyrule Field 9.8 / 9.8 fps, so the lock change did not move the game result. The final 5 s lines (run 1 of each): ``` movie main: vcores: 49789 takes, 6470 waits (mean 103 us, longest 4.2 ms, 0 over HOS_VCORE_LOG_MS), 2311 kicks, 2206 yields, 0 starved grants, 0 escapes in 5 s movie PR: vcores: 49598 takes, 5923 waits (mean 96 us, longest 7.0 ms, 0 over HOS_VCORE_LOG_MS), 2153 kicks, 2037 yields, 0 starved grants, 0 escapes in 5 s field main: vcores: 39659 takes, 9890 waits (mean 676 us, longest 21.4 ms, 0 over HOS_VCORE_LOG_MS), 5157 kicks, 5037 yields, 0 starved grants, 0 escapes in 5 s field PR: vcores: 45579 takes, 10156 waits (mean 635 us, longest 22.1 ms, 0 over HOS_VCORE_LOG_MS), 5182 kicks, 5087 yields, 0 starved grants, 0 escapes in 5 s ``` ## Risks A thread that never called `SetThreadCoreMask` is pinned again, as on main; if the game relied on such a thread floating, that behaviour is lost. The explicit mask-0 path from #327 is unchanged. The `svcSetThreadCoreMask(0)` call is ignored as the real kernel does. Turning it off: revert the commit; there is no switch. Saves, options, caches and the vk ABI are unchanged. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] The game-free suite passes (`python -I -B tests/run_all.py --jobs 8`), with the failures named above. - [x] `mise run test` passes (the same failures named above also fail on `main`). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested. - [ ] Approved in review, every comment answered. - [ ] CI passes on the head. Generated by opencode with deepseek-v4.1-flash-1017
fix(vcores): keep a thread that never had a mask on its ideal core
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 14s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
31858e0776
A thread that never called SetThreadCoreMask has core_mask 0, and mask 0 was
also the game's no-affinity value, so every such thread floated. Keep a
mask_set flag: only an explicit SetThreadCoreMask(0) floats, and a thread that
was never masked stays on its ideal core as the kernel and main pinned it.
The svc path refuses an empty mask, as the kernel does.

The fixture adds a never-masked case and a first-SetThreadCoreMask case; it
fails on main and passes here.

Assisted-by: opencode (deepseek-v4.1-flash)
DuckNintendo changed title from fix(vcores): keep a thread that never had a mask on its ideal core to WIP: fix(vcores): keep a thread that never had a mask on its ideal core 2026-11-23 16:14:00 +00:00
DuckNintendo force-pushed fix/vcore-unmasked-ideal from 31858e0776
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 14s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 56f3ab706b
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 18s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-23 16:21:37 +00:00
Compare
DuckNintendo force-pushed fix/vcore-unmasked-ideal from 56f3ab706b
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 18s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 65f2456f56
Some checks failed
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 20s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
2026-11-23 16:28:56 +00:00
Compare
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The new affinity state can race with scheduling, and a rejected service call incorrectly reports success. The scheduler change also needs in-game validation on Windows and Linux.

The change keeps never-masked threads on their initial virtual core while preserving explicit mask-zero floating. The fixture demonstrates that distinction, but the new shared state needs synchronization and the service-call rejection needs a correct result.

Blocking (2): must change before merging.

  1. L1 host/hos_thread.c:130: The new mask_set field is written without the lock used by scheduler readers, so the affinity state has a data race and can be observed inconsistently. (more on the line) Do: Publish the ideal core, mask and mask-set state together under vc_lock, and synchronize other readers and writers of that state; arrange the notification so it does not reacquire the lock recursively.
  2. L2 host/hos_svc.c:427: An empty mask is ignored but the service call still returns success for a valid handle. (more on the line) Do: Return the kernel's invalid-affinity result for an empty mask and add a service-call test covering the result and unchanged affinity.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L3 host/hos_thread.c:1869: The changed scheduling behavior has not been exercised in the game on Linux. (more on the line) Do: Run the game on Linux with masked and never-masked threads active, compare against the base, and report behavior and frame pacing.
  • L4 host/hos_thread.c:1869: The changed scheduling behavior has not been exercised in the game on native Windows. (more on the line) Do: Run the game on native Windows with masked and never-masked threads active, compare against the base, and report behavior and frame pacing.

@fix can do L1 and L2.

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven in the game. The author reports that the new host fixture fails on base 59f9632b and passes on 65f2456f; the reported game-free suite has the same 854 passed, 11 failed and 108 skipped on both revisions.

Other systems: The virtual-core scheduler is on by default and affects guest thread scheduling on both Windows and Linux, independently of GPU vendor. Pinning can change contention and frame pacing; no game runs were reported. HOS_VCORES=0 bypasses this scheduler.

Switches: None added, changed or removed.

Reviewed: 65f2456f56 against 59f9632bef: Read the repository rules, PR template, standards, commit and all three diffs; read the changed test and the scheduler, thread creation, affinity callers and service-call sections. Other portions of the large host files were skimmed, not read in full. The referenced Tooling checkout and docs/review-checklist.md were absent.; nothing run (a code review).

Checked and fine:

  • The new fixture checks that a never-masked thread waits when its ideal core is occupied and that an explicit zero mask permits floating.
  • The commit records AI assistance; no generated files, game-derived files, renderer API changes or switch-table changes appear in the diff.
  • The PR reports the same named game-free suite failures on the base and head.

Testing: Read-only review; no commands from the project, builds or tests were run. CI was still running in the supplied status.

Overlaps and merge order: Not checked; network access is closed. The PR identifies #327 as its predecessor.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The new affinity state can race with scheduling, and a rejected service call incorrectly reports success. The scheduler change also needs in-game validation on Windows and Linux. The change keeps never-masked threads on their initial virtual core while preserving explicit mask-zero floating. The fixture demonstrates that distinction, but the new shared state needs synchronization and the service-call rejection needs a correct result. **Blocking (2)**: must change before merging. 1. **L1** `host/hos_thread.c:130`: The new mask_set field is written without the lock used by scheduler readers, so the affinity state has a data race and can be observed inconsistently. (more on the line) **Do:** Publish the ideal core, mask and mask-set state together under vc_lock, and synchronize other readers and writers of that state; arrange the notification so it does not reacquire the lock recursively. 2. **L2** `host/hos_svc.c:427`: An empty mask is ignored but the service call still returns success for a valid handle. (more on the line) **Do:** Return the kernel's invalid-affinity result for an empty mask and add a service-call test covering the result and unchanged affinity. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3** `host/hos_thread.c:1869`: The changed scheduling behavior has not been exercised in the game on Linux. (more on the line) **Do:** Run the game on Linux with masked and never-masked threads active, compare against the base, and report behavior and frame pacing. - **L4** `host/hos_thread.c:1869`: The changed scheduling behavior has not been exercised in the game on native Windows. (more on the line) **Do:** Run the game on native Windows with masked and never-masked threads active, compare against the base, and report behavior and frame pacing. `@fix` can do L1 and L2. **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven in the game. The author reports that the new host fixture fails on base 59f9632b and passes on 65f2456f; the reported game-free suite has the same 854 passed, 11 failed and 108 skipped on both revisions. **Other systems:** The virtual-core scheduler is on by default and affects guest thread scheduling on both Windows and Linux, independently of GPU vendor. Pinning can change contention and frame pacing; no game runs were reported. HOS_VCORES=0 bypasses this scheduler. **Switches:** None added, changed or removed. **Reviewed:** 65f2456f56ae against 59f9632befed: Read the repository rules, PR template, standards, commit and all three diffs; read the changed test and the scheduler, thread creation, affinity callers and service-call sections. Other portions of the large host files were skimmed, not read in full. The referenced Tooling checkout and docs/review-checklist.md were absent.; nothing run (a code review). **Checked and fine:** - The new fixture checks that a never-masked thread waits when its ideal core is occupied and that an explicit zero mask permits floating. - The commit records AI assistance; no generated files, game-derived files, renderer API changes or switch-table changes appear in the diff. - The PR reports the same named game-free suite failures on the base and head. **Testing:** Read-only review; no commands from the project, builds or tests were run. CI was still running in the supplied status. **Overlaps and merge order:** Not checked; network access is closed. The PR identifies #327 as its predecessor. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
host/hos_svc.c Outdated
@ -425,2 +425,3 @@
HosThread *t = thread_handle((uint32_t)c->x[0]);
if (t) hos_thread_affinity(t, (int)c->x[1], c->x[2]);
/* the real kernel refuses an empty affinity; only nn::os::SetThreadCoreMask's 0 is the game's no-affinity */
if (t && c->x[2]) hos_thread_affinity(t, (int)c->x[1], c->x[2]);
Member

L2 (blocking): An empty mask is ignored but the service call still returns success for a valid handle.

When: A guest calls svcSetThreadCoreMask with a valid thread handle and mask 0. Its affinity remains unchanged, yet x0 is R_OK, so the caller is told that the rejected operation succeeded.

Do: Return the kernel's invalid-affinity result for an empty mask and add a service-call test covering the result and unchanged affinity.

**L2** (blocking): An empty mask is ignored but the service call still returns success for a valid handle. *When:* A guest calls svcSetThreadCoreMask with a valid thread handle and mask 0. Its affinity remains unchanged, yet x0 is R_OK, so the caller is told that the rejected operation succeeded. **Do:** Return the kernel's invalid-affinity result for an empty mask and add a service-call test covering the result and unchanged affinity.
@ -125,3 +127,4 @@
/* (the real kernel refuses an empty affinity; 0 is this game's own no-affinity convention, and its
trampoline caches the entry core for it) */
t->core_mask = mask;
t->mask_set = 1;
Member

L1 (blocking): The new mask_set field is written without the lock used by scheduler readers, so the affinity state has a data race and can be observed inconsistently.

When: One guest thread calls SetThreadCoreMask on a running or queued thread while vc_allowed or vc_free_for examines that target under vc_lock. The writer changes core_mask and mask_set before taking that lock, so the scheduler can observe the intermediate state or race on mask_set and choose the wrong allowed cores.

Do: Publish the ideal core, mask and mask-set state together under vc_lock, and synchronize other readers and writers of that state; arrange the notification so it does not reacquire the lock recursively.

**L1** (blocking): The new mask_set field is written without the lock used by scheduler readers, so the affinity state has a data race and can be observed inconsistently. *When:* One guest thread calls SetThreadCoreMask on a running or queued thread while vc_allowed or vc_free_for examines that target under vc_lock. The writer changes core_mask and mask_set before taking that lock, so the scheduler can observe the intermediate state or race on mask_set and choose the wrong allowed cores. **Do:** Publish the ideal core, mask and mask-set state together under vc_lock, and synchronize other readers and writers of that state; arrange the notification so it does not reacquire the lock recursively.
@ -1858,1 +1867,3 @@
if (t->core_mask == 0) return all; /* (the guest's no-affinity value) */
/* (0 is the guest's no-affinity value only after SetThreadCoreMask; before that it is "never set", and the
thread stays on its ideal core as the kernel and main pinned it) */
if (t->core_mask == 0) return t->mask_set ? all : (1u << vc_pin_core(t));
Member

L3 (should fix): The changed scheduling behavior has not been exercised in the game on Linux.

When: Never-masked threads now contend for their ideal core instead of using another free core; the host fixture does not show whether gameplay remains responsive or frame pacing changes.

Do: Run the game on Linux with masked and never-masked threads active, compare against the base, and report behavior and frame pacing.

**L3** (should fix): The changed scheduling behavior has not been exercised in the game on Linux. *When:* Never-masked threads now contend for their ideal core instead of using another free core; the host fixture does not show whether gameplay remains responsive or frame pacing changes. **Do:** Run the game on Linux with masked and never-masked threads active, compare against the base, and report behavior and frame pacing.
Member

L4 (should fix): The changed scheduling behavior has not been exercised in the game on native Windows.

When: The same core restriction changes contention on Windows, where the host threading implementation differs from Linux; the Linux-only fixture cannot establish game behavior there.

Do: Run the game on native Windows with masked and never-masked threads active, compare against the base, and report behavior and frame pacing.

**L4** (should fix): The changed scheduling behavior has not been exercised in the game on native Windows. *When:* The same core restriction changes contention on Windows, where the host threading implementation differs from Linux; the Linux-only fixture cannot establish game behavior there. **Do:** Run the game on native Windows with masked and never-masked threads active, compare against the base, and report behavior and frame pacing.
DuckNintendo changed title from WIP: fix(vcores): keep a thread that never had a mask on its ideal core to fix(vcores): keep a thread that never had a mask on its ideal core 2026-11-23 18:00:55 +00:00
fix(vcores): publish the affinity under the scheduler lock
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 11s
e1aff25d5e
SetThreadCoreMask now writes the ideal core, the mask and mask_set under
vc_lock, and the remask path runs without reacquiring it. The service call
returns the kernel's InvalidCombination for an empty mask instead of success;
the new fixture cuts the service helper and checks the result and that the
affinity is unchanged.

Assisted-by: opencode (deepseek-v4.1-flash)
Author
Contributor

Addressed in e1aff25d.

  • L1: SetThreadCoreMask now writes ideal_core, core_mask and mask_set together under vc_lock; vc_set_affinity() calls a locked remask helper, so it does not reacquire the lock. The fixture exercises the first-set path through that function.
  • L2: the svc path returns svc::ResultInvalidCombination (0xE801) for an empty mask and does not call the affinity function. The new tests/test_svc_core_mask.py checks the result and that the thread's affinity is unchanged; a valid mask still returns success and passes the ideal core and mask through.
  • L3: Linux game runs are now in the description: title 20 s plus the new-game movie for 130 s, and Hyrule Field for 60 s, two interleaved main/PR runs at 65f2456f; movie 37.0 against 36.95 fps, Hyrule Field 9.83 against 9.97 fps, no crash. A final-head pair at e1aff25d measured 29.7/30.4 fps in the movie and 9.8/9.8 in the field, so the lock change did not move the result.
  • L4: native Windows is still open and remains in Still to test.

The game-free suite at e1aff25d is 855 passed, 11 failed, 108 skipped; untouched 59f9632b is 854 passed with the same 11 failures.

Generated by opencode with deepseek-v4.1-flash-1017

Addressed in `e1aff25d`. - **L1:** `SetThreadCoreMask` now writes `ideal_core`, `core_mask` and `mask_set` together under `vc_lock`; `vc_set_affinity()` calls a locked remask helper, so it does not reacquire the lock. The fixture exercises the first-set path through that function. - **L2:** the svc path returns `svc::ResultInvalidCombination` (`0xE801`) for an empty mask and does not call the affinity function. The new `tests/test_svc_core_mask.py` checks the result and that the thread's affinity is unchanged; a valid mask still returns success and passes the ideal core and mask through. - **L3:** Linux game runs are now in the description: title 20 s plus the new-game movie for 130 s, and Hyrule Field for 60 s, two interleaved main/PR runs at `65f2456f`; movie 37.0 against 36.95 fps, Hyrule Field 9.83 against 9.97 fps, no crash. A final-head pair at `e1aff25d` measured 29.7/30.4 fps in the movie and 9.8/9.8 in the field, so the lock change did not move the result. - **L4:** native Windows is still open and remains in Still to test. The game-free suite at `e1aff25d` is 855 passed, 11 failed, 108 skipped; untouched `59f9632b` is 854 passed with the same 11 failures. Generated by opencode with deepseek-v4.1-flash-1017
Owner
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The affinity and empty-mask fixes address the reported defects, and the Linux game runs show no clear regression. Native Windows game testing remains outstanding. Recommend approval; not approved on the forge.

Threads that never set a mask stay on their ideal virtual core, while an explicitly set zero mask retains the game's floating behavior. Affinity updates are now published under the scheduler lock, and the service rejects an empty mask.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L4 host/hos_thread.c:1869: The changed scheduling behavior has not been exercised in the game on native Windows. When: The same core restriction changes contention on Windows, where the host threading implementation differs from Linux; the Linux-only fixture cannot establish game behavior there. Do: Run the game on native Windows with masked and never-masked threads active, compare against the base, and report behavior and frame pacing.

Since the last review (on 65f2456f56)
Resolved: L1 (The new mask_set field is written without the lock used by scheduler readers, so the affin…); L2 (An empty mask is ignored but the service call still returns success for a valid handle.); L3 (The changed scheduling behavior has not been exercised in the game on Linux.)
Still open: L4 (The changed scheduling behavior has not been exercised in the game on native Windows.)

Checks: Still running: 9 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes: the reported fixture fails on main and passes with the fix. On Linux, two interleaved Radeon 780M runs showed movie averages of 37.01 versus 36.95 fps and field averages of 9.83 versus 9.97 fps; these differences are within run spread.

Other systems: The scheduler affects native Linux and Windows and CPUs with different core counts. Linux game and host-fixture results are reported; native Windows and a low-core CPU or Steam Deck remain untested.

Switches: None added, changed or removed.

Reviewed: e1aff25d5e against 59f9632bef: Read the repository rules, pull request template, diffs, changed scheduler and service paths, and fixture changes. The full host files and test files were skimmed; the combined file output was truncated.; nothing run (a code review).

Checked and fine:

  • The first explicit zero mask sets mask_set and preserves the floating path.
  • The empty-mask service path leaves affinity unchanged and valid masks reach the affinity function.

Testing: No commands from the project were run. The author reports a passing focused fixture and the same 11 game-free suite failures on base and head; CI is still running.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The affinity and empty-mask fixes address the reported defects, and the Linux game runs show no clear regression. Native Windows game testing remains outstanding. Recommend approval; not approved on the forge. Threads that never set a mask stay on their ideal virtual core, while an explicitly set zero mask retains the game's floating behavior. Affinity updates are now published under the scheduler lock, and the service rejects an empty mask. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L4** `host/hos_thread.c:1869`: The changed scheduling behavior has not been exercised in the game on native Windows. *When:* The same core restriction changes contention on Windows, where the host threading implementation differs from Linux; the Linux-only fixture cannot establish game behavior there. **Do:** Run the game on native Windows with masked and never-masked threads active, compare against the base, and report behavior and frame pacing. **Since the last review** (on 65f2456f56ae) Resolved: L1 (The new mask_set field is written without the lock used by scheduler readers, so the affin…); L2 (An empty mask is ignored but the service call still returns success for a valid handle.); L3 (The changed scheduling behavior has not been exercised in the game on Linux.) Still open: L4 (The changed scheduling behavior has not been exercised in the game on native Windows.) **Checks:** Still running: 9 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes: the reported fixture fails on main and passes with the fix. On Linux, two interleaved Radeon 780M runs showed movie averages of 37.01 versus 36.95 fps and field averages of 9.83 versus 9.97 fps; these differences are within run spread. **Other systems:** The scheduler affects native Linux and Windows and CPUs with different core counts. Linux game and host-fixture results are reported; native Windows and a low-core CPU or Steam Deck remain untested. **Switches:** None added, changed or removed. **Reviewed:** e1aff25d5e0d against 59f9632befed: Read the repository rules, pull request template, diffs, changed scheduler and service paths, and fixture changes. The full host files and test files were skimmed; the combined file output was truncated.; nothing run (a code review). **Checked and fine:** - The first explicit zero mask sets mask_set and preserves the floating path. - The empty-mask service path leaves affinity unchanged and valid masks reach the affinity function. **Testing:** No commands from the project were run. The author reports a passing focused fixture and the same 11 game-free suite failures on base and head; CI is still running. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch fix/vcore-unmasked-ideal 2026-11-23 19:58:19 +00:00
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 11s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2368
No description provided.