WIP: feat(host): switches that change during a run: set and apply them through the control bridge, and HOS_AB any of them #2185

Draft
dyst wants to merge 3 commits from dyst/Longshot:feat/switch-store into main
Member

Summary

Every switch was read once, as the game starts, so trying another value meant quitting, setting it and starting again. That costs a boot, a save load and the scene's warm-up for each value, and runs on either side of a restart differ by more than many changes are worth. This makes 16 of the host's switches change during a run. Each is decided again at every use, so a change between two uses leaves nothing the old value built:

  • the spin and short-sleep timings: HOS_SPIN_US, HOS_SPIN_OTHER_US, HOS_SHORT_SLEEP_TIMER, HOS_SHORT_SLEEP_POLLERS, HOS_POLL_SLEEP_NS;
  • the virtual cores' four timings: HOS_VCORE_SLICE_US, _STARVE_US, _ESCAPE_US, _ESCAPE_EQ_US;
  • the present and pacing switches: HOS_PRESENT_NOWAIT, HOS_PRESENT_POLL, HOS_NVN_SYNC_BLOCK, HOS_NO_PACING, HOS_VI_DOUBLE, HOS_GAME_INTERVAL, HOS_VSYNC_YIELD.

How it works:

  • The store: host/switch_store.c holds their text, taken from the environment (and longshot_env.txt) before the game's threads start, until an apply gives one another.
  • The readers: each keeps its value with its own rule, default and clamps, as before. It works the value out again when the store's generation has moved (hos_sw_due, hos_sw_seen): a use costs one more load, and no read takes a lock.
  • The bridge commands:
    • switch_set gives a switch a value for the next apply; switch_apply applies; switch_set with "apply": true does both.
    • switch_list and switch_get say what each switch reads now and has pending.
    • Refused: a switch read once at the start (at_start: it takes a restart), a name that is no switch, and a value its type does not take.
  • HOS_AB alternates a store switch by setting and applying its value at each change of side, with no reader asking hos_ab_value. So any of the 16 can be A/B'd in one run.

This is the first step toward testing many flags in one run: a sweep sets and applies values through the bridge, with no restart between them. The list is gpu/vk/switches_live.def. Seven more host switches the audit found safe to change during a run wait for their checks to be rewritten: those checks hold them to one read on purpose (HOS_SPIN_ALWAYS, HOS_CV_SIGNAL_ALWAYS, HOS_MW_WAKE, HOS_NO_HANDOFF, HOS_NO_OBJ_CACHE, HOS_COLLECT_VECTOR, HOS_TEXELS_KEEP_CORE). HOS_SYNC_TABLE_LOCK stays read-once: it is read under mw_lock in WaitAny's scan (tests/test_multiwait_wake.py).

On main: switch_set is an unknown command, and HOS_AB=HOS_SPIN_US=0 alternates nothing; its end line says "HOS_SPIN_US was never read during the A/B".

Read first: host/switch_store.h (the pattern a reader follows), host/switch_store.c, the four commands in host/control.c, hos_ab_tick in host/hos_ab.c; then one converted reader, hos_spin_ns in host/hos_thread.c.

Testing

Tested: Windows 11, RTX 3080 (NVIDIA 621.14), from the kokiri-start save with Skip title screen, through the PC's job queue. The runtime was this branch's pack over main 971f77f52's base (main since then changed five lines of nx2/build.py, none of this).

  • The bridge, in the game:
    • switch_list with live gave the 16;
    • switch_get HOS_SPIN_US gave value: null (unset);
    • switch_set HOS_AUDIO 0 was refused, at_start: "HOS_AUDIO is read once, as the game starts: set it in the environment or longshot_env.txt and start again";
    • switch_set HOS_SPIN_US abc was refused, bad_request: "… is no number";
    • switch_set HOS_SPIN_US 0 left it pending (switch_get: value: null, pending: "0"), and switch_apply applied it (changed: 1, generation 2; the log: switches: applied (2): HOS_SPIN_US=0);
    • then HOS_VI_DOUBLE with apply: true, both unset again with unset: true, and an apply with nothing pending (changed: 0).
    • The game ran on through each.
  • HOS_AB=HOS_SPIN_US=0,3,20 in the game: 12 applies, one at each change of side after the warm-up. The end line: side 0 (normal) 1648 frames, 10.299 ms a frame (97.1 fps); side 1 (the A/B's value) 1481 frames, 10.984 ms a frame (91.0 fps); side 1 +6.66 % frame time. In Link's house, uncapped: no spin before a wait sleeps costs frame time here.
  • Checks:
    • tests/test_switch_store.py: every read of a listed switch goes through the store. It compiles the store with a fixture: set, apply, the same text again, unset, a number in another base, the three refusals, a path not said in the log, every row listed, and four threads reading through 2,000 applies. Three broken copies of the store fail it.
    • test_control: the four commands over the real transport.
    • test_hos_ab: the A/B sets and applies a store switch at each change of side, and nothing for another.
    • The checks that cut a converted reader from the source take the store's header and a stand-in that reads the environment (tests/switch_store_stub.h): test_short_sleep_timer, test_spin_by_role, test_pacing_policy, test_frame_rate_cap_30, test_frame_rate_cap_step, test_threaded_rendering, test_vcore_escape, test_vcore_mask0.
    • The checks that read the changed files (tests/run_all.py --changed, 131): every one that failed also failed on main 1101b6127. Main's #2171 has since repaired many of its checks, test_vcore_escape and test_vcore_mask0 among them; both cut the converted virtual-core block, and now take the store's stand-in too (ed6ce62df). Rebased onto main a2dc53859; nothing has run on this head, and the whole suite not at all.

Still to test:

  • Linux, any GPU: build this PR, start the game with HOS_CONTROL set, send switch_set with name HOS_SPIN_US, value 0 and apply true over the bridge, expecting the build to pass, the reply "changed":1,"applied":"HOS_SPIN_US=0" and the log line switches: applied (2): HOS_SPIN_US=0 (@Beanstalk)

Measurements

Verdict: no cost with nothing set. The PR's undisturbed runs are at or above main's in both series: 71.8 and 71.6 fps against 71.1, and 67.9 against 65.3.

Setup: Windows 11, RTX 3080 (NVIDIA 621.14). dev.py ab --runs 2, this branch's pack against its base, main 1101b6127, in two series of four interleaved timing jobs (A1, B1, A2, B2). Hyrule Field, child, the far view; 60 s measured after the warm-up, uncapped. Three of the eight runs are left out, each spoiled by another session's runtime build running beside it and preparing shaders on the GPU: rt-pr1937, 16:41-16:49, during series 1's B1 (27.9 fps) and A2 (29.1 fps); rt-1937b, 17:00-17:02, during series 2's A1 (41.1 fps). Such a build is a light job, which the queue lets start beside a timing one.

Before: main @ 1101b6127 After: this PR @ d9e16a38c
Series 2: fps (each undisturbed run) 71.1 71.8, 71.6
Series 2: median frame time 14.00 ms 13.85 ms, 13.88 ms
Series 2: p99 frame time 18.37 ms 18.10 ms, 17.99 ms
Series 1: fps (each undisturbed run) 65.3 67.9
Series 1: median, p99 15.00 ms, 21.18 ms 14.40 ms, 21.17 ms

The 16 switches ship unset, as on main: their defaults are unchanged.

Risks

  • A changed value reaches each reader at its next use: a wait or sleep in flight finishes with the old timing. A switch is listed only when a change between two uses leaves nothing behind, and tests/test_switch_store.py holds its reads to the store.
  • Nothing set, nothing changes: the readers' rules, defaults and clamps are as before, and the text is the environment's.
  • The log: an apply's line names what changed, a value that names a folder said as <a path>.
  • Turning it off: don't send switch_set; reverting is enough.

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.
  • mise run test passes (any failure that also fails on main is named). The 131 checks that read the changed files ran (Testing); the whole suite has not.
  • 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 check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows: built and run here. Linux: waits on the Test Farm run in Still to test.
  • Docs updated.
  • 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 (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary Every switch was read once, as the game starts, so trying another value meant quitting, setting it and starting again. That costs a boot, a save load and the scene's warm-up for each value, and runs on either side of a restart differ by more than many changes are worth. This makes 16 of the host's switches change during a run. Each is decided again at every use, so a change between two uses leaves nothing the old value built: - the spin and short-sleep timings: `HOS_SPIN_US`, `HOS_SPIN_OTHER_US`, `HOS_SHORT_SLEEP_TIMER`, `HOS_SHORT_SLEEP_POLLERS`, `HOS_POLL_SLEEP_NS`; - the virtual cores' four timings: `HOS_VCORE_SLICE_US`, `_STARVE_US`, `_ESCAPE_US`, `_ESCAPE_EQ_US`; - the present and pacing switches: `HOS_PRESENT_NOWAIT`, `HOS_PRESENT_POLL`, `HOS_NVN_SYNC_BLOCK`, `HOS_NO_PACING`, `HOS_VI_DOUBLE`, `HOS_GAME_INTERVAL`, `HOS_VSYNC_YIELD`. How it works: - **The store:** `host/switch_store.c` holds their text, taken from the environment (and `longshot_env.txt`) before the game's threads start, until an apply gives one another. - **The readers:** each keeps its value with its own rule, default and clamps, as before. It works the value out again when the store's generation has moved (`hos_sw_due`, `hos_sw_seen`): a use costs one more load, and no read takes a lock. - **The bridge commands:** - `switch_set` gives a switch a value for the next apply; `switch_apply` applies; `switch_set` with `"apply": true` does both. - `switch_list` and `switch_get` say what each switch reads now and has pending. - Refused: a switch read once at the start (`at_start`: it takes a restart), a name that is no switch, and a value its type does not take. - **`HOS_AB`** alternates a store switch by setting and applying its value at each change of side, with no reader asking `hos_ab_value`. So any of the 16 can be A/B'd in one run. This is the first step toward testing many flags in one run: a sweep sets and applies values through the bridge, with no restart between them. The list is `gpu/vk/switches_live.def`. Seven more host switches the audit found safe to change during a run wait for their checks to be rewritten: those checks hold them to one read on purpose (`HOS_SPIN_ALWAYS`, `HOS_CV_SIGNAL_ALWAYS`, `HOS_MW_WAKE`, `HOS_NO_HANDOFF`, `HOS_NO_OBJ_CACHE`, `HOS_COLLECT_VECTOR`, `HOS_TEXELS_KEEP_CORE`). `HOS_SYNC_TABLE_LOCK` stays read-once: it is read under `mw_lock` in `WaitAny`'s scan (`tests/test_multiwait_wake.py`). On main: `switch_set` is an unknown command, and `HOS_AB=HOS_SPIN_US=0` alternates nothing; its end line says "HOS_SPIN_US was never read during the A/B". Read first: `host/switch_store.h` (the pattern a reader follows), `host/switch_store.c`, the four commands in `host/control.c`, `hos_ab_tick` in `host/hos_ab.c`; then one converted reader, `hos_spin_ns` in `host/hos_thread.c`. ## Testing **Tested:** Windows 11, RTX 3080 (NVIDIA 621.14), from the `kokiri-start` save with Skip title screen, through the PC's job queue. The runtime was this branch's pack over main `971f77f52`'s base (main since then changed five lines of `nx2/build.py`, none of this). - **The bridge, in the game:** - `switch_list` with `live` gave the 16; - `switch_get HOS_SPIN_US` gave `value: null` (unset); - `switch_set HOS_AUDIO 0` was refused, `at_start`: "HOS_AUDIO is read once, as the game starts: set it in the environment or longshot_env.txt and start again"; - `switch_set HOS_SPIN_US abc` was refused, `bad_request`: "… is no number"; - `switch_set HOS_SPIN_US 0` left it pending (`switch_get`: `value: null, pending: "0"`), and `switch_apply` applied it (`changed: 1`, generation 2; the log: `switches: applied (2): HOS_SPIN_US=0`); - then `HOS_VI_DOUBLE` with `apply: true`, both unset again with `unset: true`, and an apply with nothing pending (`changed: 0`). - The game ran on through each. - **`HOS_AB=HOS_SPIN_US=0,3,20` in the game:** 12 applies, one at each change of side after the warm-up. The end line: `side 0 (normal) 1648 frames, 10.299 ms a frame (97.1 fps); side 1 (the A/B's value) 1481 frames, 10.984 ms a frame (91.0 fps); side 1 +6.66 % frame time`. In Link's house, uncapped: no spin before a wait sleeps costs frame time here. - **Checks:** - `tests/test_switch_store.py`: every read of a listed switch goes through the store. It compiles the store with a fixture: set, apply, the same text again, unset, a number in another base, the three refusals, a path not said in the log, every row listed, and four threads reading through 2,000 applies. Three broken copies of the store fail it. - `test_control`: the four commands over the real transport. - `test_hos_ab`: the A/B sets and applies a store switch at each change of side, and nothing for another. - The checks that cut a converted reader from the source take the store's header and a stand-in that reads the environment (`tests/switch_store_stub.h`): `test_short_sleep_timer`, `test_spin_by_role`, `test_pacing_policy`, `test_frame_rate_cap_30`, `test_frame_rate_cap_step`, `test_threaded_rendering`, `test_vcore_escape`, `test_vcore_mask0`. - The checks that read the changed files (`tests/run_all.py --changed`, 131): every one that failed also failed on main `1101b6127`. Main's #2171 has since repaired many of its checks, `test_vcore_escape` and `test_vcore_mask0` among them; both cut the converted virtual-core block, and now take the store's stand-in too (`ed6ce62df`). Rebased onto main `a2dc53859`; nothing has run on this head, and the whole suite not at all. **Still to test:** - Linux, any GPU: build this PR, start the game with `HOS_CONTROL` set, send `switch_set` with `name` `HOS_SPIN_US`, `value` 0 and `apply` true over the bridge, expecting the build to pass, the reply `"changed":1,"applied":"HOS_SPIN_US=0"` and the log line `switches: applied (2): HOS_SPIN_US=0` (@Beanstalk) ## Measurements **Verdict:** no cost with nothing set. The PR's undisturbed runs are at or above main's in both series: 71.8 and 71.6 fps against 71.1, and 67.9 against 65.3. Setup: Windows 11, RTX 3080 (NVIDIA 621.14). `dev.py ab --runs 2`, this branch's pack against its base, main `1101b6127`, in two series of four interleaved timing jobs (A1, B1, A2, B2). Hyrule Field, child, the far view; 60 s measured after the warm-up, uncapped. Three of the eight runs are left out, each spoiled by another session's runtime build running beside it and preparing shaders on the GPU: `rt-pr1937`, 16:41-16:49, during series 1's B1 (27.9 fps) and A2 (29.1 fps); `rt-1937b`, 17:00-17:02, during series 2's A1 (41.1 fps). Such a build is a light job, which the queue lets start beside a timing one. | | Before: main @ 1101b6127 | After: this PR @ d9e16a38c | |---|---|---| | Series 2: fps (each undisturbed run) | 71.1 | 71.8, 71.6 | | Series 2: median frame time | 14.00 ms | 13.85 ms, 13.88 ms | | Series 2: p99 frame time | 18.37 ms | 18.10 ms, 17.99 ms | | Series 1: fps (each undisturbed run) | 65.3 | 67.9 | | Series 1: median, p99 | 15.00 ms, 21.18 ms | 14.40 ms, 21.17 ms | The 16 switches ship unset, as on main: their defaults are unchanged. ## Risks - **A changed value reaches each reader at its next use:** a wait or sleep in flight finishes with the old timing. A switch is listed only when a change between two uses leaves nothing behind, and `tests/test_switch_store.py` holds its reads to the store. - **Nothing set, nothing changes:** the readers' rules, defaults and clamps are as before, and the text is the environment's. - **The log:** an apply's line names what changed, a value that names a folder said as `<a path>`. - **Turning it off:** don't send `switch_set`; reverting is enough. ## 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. - [ ] `mise run test` passes (any failure that also fails on `main` is named). The 131 checks that read the changed files ran (Testing); the whole suite has not. - [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 check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows: built and run here. Linux: waits on the Test Farm run in Still to test. - [x] Docs updated. - [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 (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A switch was read once, as the game starts, so trying another value meant a restart. Sixteen of the host's switches now
change during a run (gpu/vk/switches_live.def): the spin and short-sleep timings (HOS_SPIN_US, HOS_SPIN_OTHER_US,
HOS_SHORT_SLEEP_TIMER, HOS_SHORT_SLEEP_POLLERS, HOS_POLL_SLEEP_NS), the virtual cores' four timings (HOS_VCORE_SLICE_US,
_STARVE_US, _ESCAPE_US, _ESCAPE_EQ_US), and the present and pacing ones (HOS_PRESENT_NOWAIT, HOS_PRESENT_POLL,
HOS_NVN_SYNC_BLOCK, HOS_NO_PACING, HOS_VI_DOUBLE, HOS_GAME_INTERVAL, HOS_VSYNC_YIELD). Each is decided again at every use,
so a change between two uses leaves nothing the old value built.

host/switch_store.c holds their text: the environment's (and longshot_env.txt's), taken before the game's threads start,
until an apply gives one another. Each reader keeps its value, with its own rule, default and clamps, as before, and works
it out again when the store's generation has moved (hos_sw_due, hos_sw_seen): a use costs two loads, and no read takes a
lock. The control bridge's switch_set gives one a value for the next apply, switch_apply applies (switch_set with "apply"
does both), switch_list and switch_get say what each switch reads now and has pending. A switch read once at the start is
refused (at_start), as is a name that is no switch or a value its type does not take. HOS_AB alternates a store switch by
setting and applying its value at each change of side, so any of them can be A/B'd in one run.

tests/test_switch_store.py holds every read of a listed switch to the store and compiles the store with a fixture (set,
apply, refusals, four threads reading through 2000 applies, broken variants caught); test_control and test_hos_ab cover
the bridge's commands and the A/B's sets. The checks that cut a converted reader from the source take the store's header
and a stand-in that reads the environment (tests/switch_store_stub.h).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(host): switch_set takes "unset": true, for a client that leaves a null out
Some checks failed
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 21s
CI / Website build and checks (pull_request) Failing after 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 31s
CI / Workflow lint (actionlint) (pull_request) Successful in 33s
Third-party parts / As their notes say (pull_request) Successful in 39s
d9e16a38c8
scripts/longshot_bridge.py sends no argument whose value is None, so a script could not unset a switch with
"value": null: the bridge took it as no value and refused. "unset": true does the same as a null value, and is refused
with a value beside it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in game: Windows 11, RTX 3080, NVIDIA 621.14, from the kokiri-start save. Through the control bridge in the game: switch_list (the 16), switch_set refused for HOS_AUDIO (at_start) and for a value that is no number, HOS_SPIN_US=0 pending then applied (switches: applied (2)), HOS_VI_DOUBLE applied, both unset again; the game ran on. HOS_AB=HOS_SPIN_US=0,3,20: 12 applies, side 1 +6.66 % frame time in Link's house uncapped. dev.py ab against main, Hyrule Field: the undisturbed runs 71.8 and 71.6 fps against 71.1.

Tested in game: Windows 11, RTX 3080, NVIDIA 621.14, from the kokiri-start save. Through the control bridge in the game: switch_list (the 16), switch_set refused for HOS_AUDIO (at_start) and for a value that is no number, HOS_SPIN_US=0 pending then applied (switches: applied (2)), HOS_VI_DOUBLE applied, both unset again; the game ran on. HOS_AB=HOS_SPIN_US=0,3,20: 12 applies, side 1 +6.66 % frame time in Link's house uncapped. dev.py ab against main, Hyrule Field: the undisturbed runs 71.8 and 71.6 fps against 71.1.
dyst force-pushed feat/switch-store from d9e16a38c8
Some checks failed
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 21s
CI / Website build and checks (pull_request) Failing after 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 31s
CI / Workflow lint (actionlint) (pull_request) Successful in 33s
Third-party parts / As their notes say (pull_request) Successful in 39s
to ed6ce62dfe
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 16s
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Website build and checks (pull_request) Failing after 19s
2026-11-22 03:20:06 +00:00
Compare
dazemc left a comment

Read of ed6ce62d on main a2dc5385 (three commits: the store and the commands, "unset": true, the two vcore checks' stand-in). The store's write/read protocol and the live boundary hold up. One concrete mismatch between what the bridge accepts and what the readers actually parse is the finding.

1. The store's int rule is not the readers' rule. hos_sw_int and value_fits parse with strtol(v, &end, 0) (host/switch_store.h:57-64, host/switch_store.c:106-118), so switch_set HOS_SPIN_US 0x10 is accepted, applied and reported back as HOS_SPIN_US=0x10. Every converted numeric reader parses in decimal, though: hos_spin_ns uses atoll (host/hos_thread.c:727), vc_sw_ns atoll (:2044-2051), hos_sleep_logged's poll cap atoll (:1453-1456), and hos_short_sleep_pollers strtol(asked, &end, 10) with the whole string (:1231). So 0x10 reaches the game as 0 for spin/vcore/poll (and the pollers fall back to the processor rule, a third meaning), while switch_get says 0x10 and tests/test_switch_store.py:114 asserts the other meaning — its fixture reads through hos_sw_int, which no live reader calls. That is the silent-misread class this feature exists to remove, now on the bridge's side, and a tester's hex value becomes a measurement of 0. The same applies to "010" (octal 8 vs decimal 10). Fix: validate in value_fits with the readers' rule (base 10 and the whole string, as hos_short_sleep_pollers does), or convert the readers to hos_sw_int and say in the row that the env text now takes any base (a behaviour change), or refuse a base prefix; then the test's 0x10 case matches. (hos_sw_int also returns the default for an empty text where atoll("") gives 0 — only the helper, not a live reader.)

2. The store writes and the live boundary. One SRW lock serialises hos_sw_set/hos_sw_apply/hos_sw_pending/hos_sw_each; now_v is an atomically loaded pointer whose text is never freed, and the generation is bumped with release after the texts, so a reader that sees the new generation sees the new text (switch_store.c:148-173, switch_store.h:26-38). hos_sw_init runs after longshot_env.txt (hos_main.c:2139 before :2446) and before hos_ab_start, and the lazy take_env seeds a switch under the lock for a read before init. A reader's hos_sw_due/seen can at worst work a value out twice around an apply, never keep a value for a generation it was not worked out at. I checked each of the 16: all recompute inside the due block and none keeps a derived value outside it (hos_thread.c:727, 1292, 1453, 1501, 2044; nn_vi.c:51, 225, 248-250; nvn_native.c:1187, 1241), and I agree with the listed ones that a change between two uses leaves nothing the old value built (the HOS_VI_DOUBLE/HOS_NO_PACING pair only decides the wait and the pacing of the present in flight; the short-sleep mode is decided per sleep). HOS_AB's live path sets and applies under the store's lock with side 0 from the store's text at setup (hos_ab.c:141-144, 161), and the source scan forbids hos_ab_value on a live name.

3. The ini keys. None: these are environment/longshot_env.txt keys, not longshot_options.ini rows, so tests/test_menu_ini_keys.py and the saved options are untouched. All 16 are switches.def rows and the list is sorted (switches_live.def; the store test checks both). The bridge's JSON keys (name, value, apply, unset, live) match docs/dev/reference/control-bridge.md and tests/control_test.c; HOS_AB's NAME=value[,value...] syntax is unchanged. The switch_set/switch_get replies redact a value that names a folder as <a path> in applied as well as the log, which is the host's rule.

4. The test. It fails on main (the store files do not exist), and it covers the store's set→pending→apply→unset, the same text changing nothing, the three refusals, the path redaction, hos_sw_each over every row, four threads reading through the pattern while 2000 applies run, and three broken copies. The source scan holds every literal read of a live name to the store and forbids hos_ab_value on one. Two gaps: it does not enforce the hos_sw_due/hos_sw_seen pattern at each reader (a reader that read the store once, without a due check, would pass the scan and never change), and its numeric rule is the helper's, not the readers' (finding 1). The converted readers' own checks include switch_store_stub.h, whose hos_sw_env is getenv and whose generation never moves, so they exercise main's behaviour, not the live apply — which is fine while the store has its own test, but it is why 1 slipped through.

5. The default. The 16 ship unset and the readers' rules/defaults are unchanged as far as I read them: HOS_SPIN_US 20, HOS_SPIN_OTHER_US unset → the 5 us rule, HOS_VI_DOUBLE/HOS_NO_PACING off, HOS_GAME_INTERVAL off, HOS_PRESENT_NOWAIT unset → the renderer's option, HOS_SHORT_SLEEP_TIMER unset → the processor rule (Linux: the timer), HOS_SHORT_SLEEP_POLLERS unset → the thread count. switch_get reporting null while the reader uses its own default is correct but worth one line in the docs.

6. Process. WIP, 0 reviews. The Measurements are against main 1101b6127 and the head d9e16a38c; the PR is now on a2dc5385 (the status warning stands), and Testing says nothing has run on this head. The Linux bridge run in Still to test is the one that matters for the new files.

No approval, and no claim on it.

**Read of `ed6ce62d` on main `a2dc5385` (three commits: the store and the commands, `"unset": true`, the two vcore checks' stand-in).** The store's write/read protocol and the live boundary hold up. One concrete mismatch between what the bridge accepts and what the readers actually parse is the finding. **1. The store's int rule is not the readers' rule.** `hos_sw_int` and `value_fits` parse with `strtol(v, &end, 0)` (`host/switch_store.h:57-64`, `host/switch_store.c:106-118`), so `switch_set HOS_SPIN_US 0x10` is accepted, applied and reported back as `HOS_SPIN_US=0x10`. Every converted numeric reader parses in decimal, though: `hos_spin_ns` uses `atoll` (`host/hos_thread.c:727`), `vc_sw_ns` `atoll` (`:2044-2051`), `hos_sleep_logged`'s poll cap `atoll` (`:1453-1456`), and `hos_short_sleep_pollers` `strtol(asked, &end, 10)` with the whole string (`:1231`). So `0x10` reaches the game as **0** for spin/vcore/poll (and the pollers fall back to the processor rule, a third meaning), while `switch_get` says `0x10` and `tests/test_switch_store.py:114` asserts the other meaning — its fixture reads through `hos_sw_int`, which no live reader calls. That is the silent-misread class this feature exists to remove, now on the bridge's side, and a tester's hex value becomes a measurement of 0. The same applies to `"010"` (octal 8 vs decimal 10). Fix: validate in `value_fits` with the readers' rule (base 10 and the whole string, as `hos_short_sleep_pollers` does), or convert the readers to `hos_sw_int` and say in the row that the env text now takes any base (a behaviour change), or refuse a base prefix; then the test's `0x10` case matches. (`hos_sw_int` also returns the default for an empty text where `atoll("")` gives 0 — only the helper, not a live reader.) **2. The store writes and the live boundary.** One SRW lock serialises `hos_sw_set`/`hos_sw_apply`/`hos_sw_pending`/`hos_sw_each`; `now_v` is an atomically loaded pointer whose text is never freed, and the generation is bumped with release after the texts, so a reader that sees the new generation sees the new text (`switch_store.c:148-173`, `switch_store.h:26-38`). `hos_sw_init` runs after `longshot_env.txt` (`hos_main.c:2139` before `:2446`) and before `hos_ab_start`, and the lazy `take_env` seeds a switch under the lock for a read before init. A reader's `hos_sw_due`/`seen` can at worst work a value out twice around an apply, never keep a value for a generation it was not worked out at. I checked each of the 16: all recompute inside the due block and none keeps a derived value outside it (`hos_thread.c:727, 1292, 1453, 1501, 2044`; `nn_vi.c:51, 225, 248-250`; `nvn_native.c:1187, 1241`), and I agree with the listed ones that a change between two uses leaves nothing the old value built (the `HOS_VI_DOUBLE`/`HOS_NO_PACING` pair only decides the wait and the pacing of the present in flight; the short-sleep mode is decided per sleep). `HOS_AB`'s live path sets and applies under the store's lock with side 0 from the store's text at setup (`hos_ab.c:141-144, 161`), and the source scan forbids `hos_ab_value` on a live name. **3. The ini keys.** None: these are environment/`longshot_env.txt` keys, not `longshot_options.ini` rows, so `tests/test_menu_ini_keys.py` and the saved options are untouched. All 16 are `switches.def` rows and the list is sorted (`switches_live.def`; the store test checks both). The bridge's JSON keys (`name`, `value`, `apply`, `unset`, `live`) match `docs/dev/reference/control-bridge.md` and `tests/control_test.c`; `HOS_AB`'s `NAME=value[,value...]` syntax is unchanged. The `switch_set`/`switch_get` replies redact a value that names a folder as `<a path>` in `applied` as well as the log, which is the host's rule. **4. The test.** It fails on main (the store files do not exist), and it covers the store's set→pending→apply→unset, the same text changing nothing, the three refusals, the path redaction, `hos_sw_each` over every row, four threads reading through the pattern while 2000 applies run, and three broken copies. The source scan holds every literal read of a live name to the store and forbids `hos_ab_value` on one. Two gaps: it does not enforce the `hos_sw_due`/`hos_sw_seen` pattern at each reader (a reader that read the store once, without a due check, would pass the scan and never change), and its numeric rule is the helper's, not the readers' (finding 1). The converted readers' own checks include `switch_store_stub.h`, whose `hos_sw_env` is `getenv` and whose generation never moves, so they exercise main's behaviour, not the live apply — which is fine while the store has its own test, but it is why 1 slipped through. **5. The default.** The 16 ship unset and the readers' rules/defaults are unchanged as far as I read them: `HOS_SPIN_US` 20, `HOS_SPIN_OTHER_US` unset → the 5 us rule, `HOS_VI_DOUBLE`/`HOS_NO_PACING` off, `HOS_GAME_INTERVAL` off, `HOS_PRESENT_NOWAIT` unset → the renderer's option, `HOS_SHORT_SLEEP_TIMER` unset → the processor rule (Linux: the timer), `HOS_SHORT_SLEEP_POLLERS` unset → the thread count. `switch_get` reporting `null` while the reader uses its own default is correct but worth one line in the docs. **6. Process.** WIP, 0 reviews. The Measurements are against main `1101b6127` and the head `d9e16a38c`; the PR is now on `a2dc5385` (the status warning stands), and Testing says nothing has run on this head. The Linux bridge run in Still to test is the one that matters for the new files. No approval, and no claim on it.
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 16s
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Website build and checks (pull_request) Failing after 19s
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'feat/switch-store:dyst-feat/switch-store'
git switch 'dyst-feat/switch-store'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 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!2185
No description provided.