WIP: fix(fs): a create, delete or rename gives the virtual core up on every mount #2529

Draft
unixman wants to merge 2 commits from unixman/fix/save-vcore-path-calls into main AGit
First-time contributor

Summary

The game's threads run only while they hold one of six virtual cores. A thread that waits in a host file call should give its core up first, so the threads waiting for that core can run in the meantime. OpenFile, the file-handle calls (SetFileSize, WriteFile, FlushFile, CloseFile) and a staged save's Commit already do this. Five calls did not do it fully: CreateFile, DeleteFile, CreateDirectory and DeleteDirectoryRecursively (all four through save_path_call), and RenameFile.

  • On a staged save they gave the core up only after host_path, and its link checks (save_guard) are host file calls, so those calls ran with the core held.
  • On a mount with no working copy they kept the core through every host file call. That covers a save mounted in place (no working copy, or its folder already mounted directly), cache storage and temporary storage.

A thread in a host call reaches no checkpoint, so it cannot be asked to give its core up. Neither the request of a better-priority waiter nor the starve rule (HOS_VCORE_STARVE_US, 1 s) helps while the call blocks. Unless another core the waiter may use comes free, only the 2 s escape (HOS_VCORE_ESCAPE_US, HOS_VCORE_ESCAPE_EQ_US) ends the wait, and the escape then runs the waiter without a core, beside the holder.

This change makes save_path_call and RenameFile give the core up before host_path on every mount, as OpenFile does. They take it back on every way out, with no lock held. A failed call still reads its error before the core is taken back, because that wait sets the last error. A call refused for its mount (read-only or unknown) also gives the core up and takes it back, as OpenFile's refusals do. A thread that held no core takes none.

The result: none of these five calls makes a host file call with the core held, and the game gets the same answers as before.

How to see it on main: not in the game. It comes from reading the code, and the new check shows it: on main, tests/test_vcore_fs_save.py fails with 29 checks, each a host file call made with the core held (Measurements). The windowless runs in Testing make two of the five calls through the changed code in the game, but the 5 s vcores: lines are too coarse to show one call's wait (Risks).

Read first: save_path_call and HLE(_ZN2nn2fs10RenameFileEPKcS2_) in host/nn_fs.c, then tests/test_vcore_fs_save.py.

Related, each checked from its own commits or diff:

  • #607 (merged as a1c09a3c) added save_path_call. It gives the core up only for a staged save, and only after host_path. That is the gap this change closes.
  • Commit 26c12b0d on main, "no core held while OpenFile builds the button prompts", moved OpenFile's give-up to before host_path. This change does the same for the five path calls.
  • #594 (merged as d6878186) lets a starved waiter have its core after 1 s instead of escaping at 2 s. It came from #262 (closed): workers that waited the full 2 s for a core while a save loaded. That rule needs the holder to give its core up, and a holder in a host call cannot. Whether this change affects #262's report was not tested.
  • See #1503 (open): the gate's waits, and the 1 s starve limit that bounds this change's worst case (Risks).
  • No open, merged or closed pull request makes this change. I searched for: virtual core, vcore, nn_fs.c, save_path_call, host_path, RenameFile, CreateFile and DeleteDirectoryRecursively, and read the host/nn_fs.c part of each hit. Several open pull requests change host/nn_fs.c, but none changes how these calls hold the core. The host/nn_fs.c changes of #2154, #2173, #2180, #2411 and #2434 apply to this branch as they are. Those of #461, #61, #1577, #68 and #1428 already fail to apply on main.
  • #68 (open, feat(coop)) is the closest of these. It puts the five calls behind a shared save lock of its own, taken after host_path, and gives the core up only while it waits for that lock, not during the host file calls. Its host/nn_fs.c hunks are written against the code from before save_path_call. #1428 (WIP) changes Commit, to back the saves up.

Testing

Tested: Gentoo Linux, Ryzen 9 9950X3D, Radeon RDNA4 (1002:7550), Mesa RADV 26.2.6, sched_ext scx_lavd. The checks ran on this branch's head alone. The game ran windowless (HOS_HEADLESS=1), on this desktop while it was in use, so its numbers are rough.

The branch is on main be663a08. The game ran before that rebase, in two rounds. The latest round ran this fix at 0918f3c5 against main 9046a8d7. An earlier round ran this fix at 4bdfb221 against main 90fae88c, before the fix commit's message was reworded and before the branch was rebased twice. host/nn_fs.c and the new check are byte for byte the same at 4bdfb221 and at this head. The earlier round is kept because only it ran a series on a full save folder. Since 9046a8d7, main has replaced its builder and moved the game's code (#2286, #2411). Their changes to host/nn_fs.c read the RomFS through romfs.h and choose the saves folder (hos_saves_root); they don't touch the five calls this PR changes, and the rebase onto be663a08 changed nothing in this PR's diff of host/nn_fs.c. This PC's lab builds the game with the builder main replaced, so the game was not run again at be663a08.

  • In the game, this PR against main, windowless, latest round (at 0918f3c5, on main 9046a8d7).
    • The two sides: this fix at 0918f3c5 and main 9046a8d7, each built as a pack over the same main 90fae88c base, logging longshot v3.2.0-17-g0918f3c5 (source 5542d96f) and longshot v3.2.0-15-g9046a8d7 (source 643c1bab). The two packs' sources differ only by this PR's diff.
    • How: one game at a time, the sides alternated, each started by my own driver script at nice 19 and idle I/O priority, not through dev.py queue run. That driver is what this PC's lab runs use: it checks every 2 s that no other game build on this PC is running and stops only the game it started. No pair has run through dev.py queue run --mode shared yet; one a side can be repeated that way if a reviewer asks. The same switches on both sides: HOS_HEADLESS=1, HOS_FS_TRACE=1, HOS_OOT_TRACE_SAVES=1, HOS_OOT_CHEATS=1 (for the teleport) and HOS_CONTROL (the control bridge, used for status, the save listing and the quit). Uncapped, Autosave on, the rest as Auto picks it.
    • One run: the Skip title row loads the newest save, and !cheat 112 and !cheat 1003 set 12:00 and go to the Market. Link walks out of its gate into Hyrule Field and back in, and the game writes a transition autosave each way. Then the bridge's quit, after which every game logged stop: close work done.
    • The runs: a warm-up a side that only loads, then three walk runs a side, alternating, on a save folder with slots 03 to 05 removed on both sides, then a run a side that only loads. Each walk run's first save went into a new slot and logged create directory slot_0N, create file slot_0N/progress.sav and create file slot_0N/caption.sav. Those are CreateDirectory and two CreateFile on a staged save, through save_path_call: 9 calls a side.
    • Seen on both sides: all 12 saves of the 6 walk runs were published (fs: save: published 3 files). Each run's save loaded in the next run of its side (slot_03, slot_04, then slot_05), with the game in play in the map the previous run had ended in. All 10 runs logged 0 escapes and no ran without a core line. No wait of 50 ms or more named the thread that saves (gmd::SaveDataMgr) or fell between a save's first file call and its published line. The vcores: numbers are in Risks.
  • In the game, earlier round: this fix at 4bdfb221 against main 90fae88c, windowless. The same method. This branch ran as a pack over a main 90fae88c base, logging longshot v3.2.0-14-g4bdfb221 (source f14d9e21), against that base itself, logging longshot v3.2.0-11-g90fae88c (source 90deadee).
    • Series 1, as planned, on a save folder with all six slots used: a warm-up and three runs a side, then a run a side that only loads. The autosave rewrote the next slot in place (GetEntryType, OpenFile, resize, write, close, Commit) and made no create, delete or rename call, so the changed code did not run on either side.
    • Series 2, on the same saves with slots 03 to 05 removed on both sides: three runs a side, then a load run each. Each run's first save went into a new slot and logged create directory slot_0N, create file slot_0N/progress.sav, create file slot_0N/caption.sav and Commit: 3 files, 4 ops. Those are CreateDirectory and two CreateFile on a staged save, through save_path_call: 9 calls a side.
    • Seen on both sides in that round: all 28 saves of the 14 walk runs were published (fs: save: published 3 files). Each run's save loaded in the next run of its side, with the published folder byte for byte as the run before had left it, the game in play and Link where he had stood. All 18 runs logged 0 escapes and no ran without a core line. No wait of 50 ms or more named the thread that saves (gmd::SaveDataMgr) or fell between a save's first file call and its published line. The vcores: numbers are in Risks.
  • Not exercised in the game, in either round: DeleteFile, DeleteDirectoryRecursively and RenameFile (the autosave makes none of them, and I did not look for a game path that does), a save mounted in place, cache and temporary storage, and calls refused for their mount. The check covers each of them.
  • The new check, tests/test_vcore_fs_save.py, ran alone through tests/run_all.py --strict --container --exact in CI's image (Ubuntu 24.04), once with clang++ 18.1.3 and once with g++ 13.3.0. At the test commit 6bd9ca57 (main 8aa5ab87 plus the test only), both fail the same 29 checks. Every one is a host file call made with the core held, by one of the five calls, on a staged save, a save mounted in place or cache storage. None is on SetFileSize, CloseFile, Commit or the refusals. At the head (4bdfb221, the same files as this head), it passes with both. After the rebase onto main 9046a8d7 it ran again with both compilers: the same 29 checks fail at the test commit, then 69e6ef0c, and it passes at the fix, 0918f3c5. On main be663a08 the check's stand-in for a file handle needed the RomFS field #2286 added (Handle.rom, closed through hos_romfs_file_close), and the check now has it. CI's image could not be rebuilt on this PC without a network after #2286 changed its Dockerfile, so at be663a08 the check ran on this PC's own compilers, clang++ 22.1.8 and g++ 16.2.1: the same 29 checks fail at the test commit, ea92a2be, and it passes at this head, 537fbfb4. As a test of the test, it also ran against 12 deliberately broken versions of the fix, and it fails on all 12 with both compilers. Among them: a refusal that takes a core back although the thread held none, the give-up after host_path as on main, and the take-back with the save lock still held.
  • The whole suite, mise run test's command (python -I -B tests/run_all.py, unsharded), on this branch alone and on main:
    • At be663a08, on this PC's own tools (not CI's image, see above; not --strict): main 686 passed, 56 failed, 101 skipped; this PR at 537fbfb4 687 passed, 56 failed, 101 skipped. The same 56 checks fail on both sides; they need tools CI's image has and this PC lacks. The extra pass is the new check.
    • Before the rebase, in CI's container (--strict --container): main 9046a8d7 962 passed, 0 failed, 18 skipped; this PR at 0918f3c5 963 passed, 0 failed, 18 skipped.
    • In a first run of both at 9046a8d7, two timing-dependent checks failed once, one on each side, and passed when run again alone on both sides: nx2/test_depth_sample_types on this PR and tests/test_crash_dialog on main. tests/byte_compile_tracked also failed on this PR, because this PC's checkout had a stale worktree path, and passed once that was fixed. The counts above are from a second run of both.
    • No check changed status against main. The 11 other checks that read host/nn_fs.c pass, except test_fs_path_utf8, which is Windows-only and skips. The 18 skips are 13 Windows-only checks, 2 that need a Vulkan device and 3 that need the game's files.

Still to test:

  • Windows, an NVIDIA RTX and an AMD RX card (Tier 1): from a save with a free slot after it, walk out of the Market's gate into Hyrule Field and back in, which makes two autosaves, the first into a new slot. Expecting two fs: save: published lines, and 0 escapes and no ran without a core line in the vcores: lines near them (@Beanstalk on Windows with NVIDIA and AMD: walk out of the Market gate into Hyrule Field and back, then read the log's save and core lines).
  • Steam Deck (Tier 1): the same walk, then quit and load the save. Expecting the two saves, the save loading, and no new core waits of 50 ms or more near the saves (by hand).

Measurements

Verdict: the bug is gone: the game-free check fails with 29 checks on main and passes with this PR, with clang++ and with g++. For a fix that is the measurement; the in-game cost is in Risks.

Setup: Gentoo Linux, Ryzen 9 9950X3D. python -I -B tests/run_all.py --exact tests/test_vcore_fs_save.py on this PC's own compilers (clang++ 22.1.8, and g++ 16.2.1 through CXX=g++), once for each commit and compiler; CI's image could not be rebuilt here without a network (Testing). The before side ran at the test commit ea92a2be, which is main be663a08 with only the test added, so its host/nn_fs.c is main's. The after side ran at this head, 537fbfb4. Before the rebase, the same rows gave the same result in CI's image (clang++ 18.1.3, g++ 13.3.0) at 69e6ef0c and 0918f3c5 (on main 9046a8d7), and earlier at 6bd9ca57 (on main 8aa5ab87) and 4bdfb221.

Before: main @ be663a08 After: this PR @ 537fbfb4
test_vcore_fs_save, clang++ 22.1.8 FAIL, 29 checks pass
test_vcore_fs_save, g++ 16.2.1 FAIL, 29 checks pass
The 29 failing checks on main (clang++; g++ prints the same lines)
FAIL: save, CreateFile: 11 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, CreateFile of a file that exists: 8 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, DeleteFile: 7 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, DeleteFile of a file that is not there: 7 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, CreateDirectory: 4 host file calls (some expected), 2 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, CreateDirectory of a folder that exists: 4 host file calls (some expected), 2 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, DeleteDirectoryRecursively: 5 host file calls (some expected), 2 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, RenameFile: 13 host file calls (some expected), 6 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: save, RenameFile that fails: 13 host file calls (some expected), 6 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0)
FAIL: inplace, CreateFile: 5 host file calls (5 expected), 5 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, CreateFile of a file that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, DeleteFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, DeleteFile of a file that is not there: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, CreateDirectory: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, CreateDirectory of a folder that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, DeleteDirectoryRecursively: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, DeleteDirectoryRecursively of a link (DeleteFileA, then RemoveDirectoryA): 3 host file calls (3 expected), 3 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, RenameFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: inplace, RenameFile that fails: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, CreateFile: 5 host file calls (5 expected), 5 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, CreateFile of a file that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, DeleteFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, DeleteFile of a file that is not there: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, CreateDirectory: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, CreateDirectory of a folder that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, DeleteDirectoryRecursively: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, DeleteDirectoryRecursively of a link (DeleteFileA, then RemoveDirectoryA): 3 host file calls (3 expected), 3 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, RenameFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
FAIL: cache, RenameFile that fails: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0)
a create, delete or rename holds the virtual core through a host file call (host/nn_fs.c)
result       time  check
FAIL         0.2s  tests/test_vcore_fs_save.py
0 passed, 1 failed, 0 skipped in 0 s (linux, 32 at once)

After (clang++; g++ prints the same, in 0.1 s):

pass         0.2s  tests/test_vcore_fs_save.py
1 passed, 0 failed, 0 skipped in 0 s (linux, 32 at once)

Risks

The first points come from reading host/nn_fs.c and vc_acquire in host/hos_thread.c. The in-game points come from the windowless runs in Testing.

  • On a staged save: still one give-up and one take per call, as on main. Only host_path's link checks have moved inside that window.

  • On a save mounted in place, cache storage, temporary storage, and a call refused for its mount: one give-up and one take per call that main did not have. None of these ran in the game.

  • The cost of a take: when a core the thread may use is free, it takes one at once. This counts in the vcores: line's takes, not its waits. When another thread has taken the core meanwhile and no other allowed core is free, the caller waits as OpenFile, the handle calls, a staged Commit and MountSaveData already do:

    • A worse-priority holder gives the core up at its next checkpoint.
    • A holder of equal priority does so after the 2 ms slice (HOS_VCORE_SLICE_US), at its next checkpoint.
    • A better-priority holder is asked only once the caller counts as starved (1 s).
    • The 2 s escape still bounds the wait.
  • At worst, while better-priority threads keep every allowed core busy without blocking, a create, delete or rename returns up to about 1 s later, and never more than 2 s later. A few milliseconds is the case of an equal-priority holder.

  • In the game, no cost beyond the spread. Windowless, on a desktop in use, three runs a side, so rough. The walk covers two map loads and two saves. Latest round, this fix at 0918f3c5 against main 9046a8d7, each walk run creating a new slot; medians (range):

    The walk, 3 runs a side main 9046a8d7 this PR 0918f3c5
    create calls a run 3 (old code) 3 (changed code)
    waits per 5 s block 125 026 (87 784 to 136 718) 127 164 (87 747 to 130 978)
    mean wait 72.1 us (69.2 to 72.4) 67.1 us (65.3 to 73.0)
    waits of 50 ms or more 7 (7 to 10) 5 (2 to 12)
    longest wait 589.5 ms (119.0 to 601.2) 163.8 ms (81.1 to 742.0)
    escapes, starved grants, ran without a core 0, 0, 0 0, 0, 0
    a save's publish (code not changed) 44.3 ms (37.2 to 125.7) 39.4 ms (38.5 to 40.6)
    • Every row's ranges overlap, so there is no difference beyond the spread either way.
    • The longest waits, several hundred ms, are on both sides and far above the earlier round's. None falls in a save. The ones I read fall in map loads, with threads such as PreActorModelCompose and BaseProcExecutor0 waiting for a core that sead::MainThread or GeneralFormatAsync_ held. The PC was busier than in the earlier round: a 1-minute load average of 4 to 6 at the run starts, and KDE's file indexer on about one core throughout.
    • main's 125.7 ms publish is one run (both of its saves took about 125 ms), in code this PR does not change.

    The earlier round, this fix at 4bdfb221 against main 90fae88c; series 1 made no create call on either side:

    The walk, 3 runs a side Series 1, main Series 1, this PR Series 2, main Series 2, this PR
    create calls a run 0 0 3 (old code) 3 (changed code)
    waits per 5 s block 115 984 (101 888 to 130 137) 129 035 (110 638 to 138 584) 113 136 (91 836 to 127 026) 95 872 (95 046 to 119 192)
    mean wait 66.7 us 67.6 us 68.0 us 68.1 us
    waits of 50 ms or more 3 (1 to 5) 6 (3 to 7) 6 (6 to 9) 5 (0 to 8)
    longest wait 77.5 ms (60.1 to 91.1) 110.5 ms (61.7 to 138.0) 116.6 ms (82.7 to 139.0) 91.7 ms (49.4 to 175.6)
    escapes, starved grants, ran without a core 0, 0, 0 0, 0, 0 0, 0, 0 0, 0, 0
    a save's Commit (code not changed) 40.9 ms (37.8 to 48.0) 42.2 ms (38.3 to 50.4) 41.2 ms (38.1 to 60.1) 41.1 ms (37.2 to 47.7)
    • In the earlier round, over both series together, this PR's medians lie inside main's ranges on every row: waits of 50 ms or more 5.5 against 5.5, longest wait 101.1 ms against 86.9 ms.
    • In series 1 alone, this PR's count of waits of 50 ms or more and its longest wait lie above main's range, although neither side made a changed call there. Series 2, where the calls ran, goes the other way. Those waits fall in a map load or right around one, none in a save. I read it as run-to-run noise of three runs, not as a cost.
    • What these numbers cannot show: the cost of one give-up and take. Three changed calls a run are lost among about 100 000 waits a 5 s block, and the log has no times, so a create's own duration was not measured.
  • The frame trace and the FPS counter's Breakdown count the time in these calls as the thread's blocked time, not its running time.

  • What a player notices after updating: nothing is expected. Saves, longshot_options.ini and the caches are unchanged, and the calls write the same files. In the runs, every save published and loaded again on both sides.

  • How to turn it off: there is no switch, so a revert is the way back. HOS_VCORES=0 is no fallback: it turns the virtual cores off altogether, and the game's job queues need them.

  • Left as on main: GetEntryType, OpenDirectory, IsSaveDataExisting, the cache-storage calls and user_mount still make host file calls with the core held.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit. The branch is on be663a08, the head of main when this PR was opened.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. Windowless, on main 9046a8d7, before the rebase onto be663a08; the runs made CreateDirectory and CreateFile through the changed code.
  • mise run test passes (any failure that also fails on main is named). Not yet in CI's container at this head: its image could not be rebuilt here without a network. On this PC's own tools the same 56 checks fail on main be663a08 and here, for tools this PC lacks; in CI's container at 9046a8d7, 0 failed (Testing). CI's run on this PR settles it.
  • Measured against main, or Measurements says why there is nothing to measure. For this fix, the check fails on main and passes here (Measurements); the in-game cost is in Risks.
  • 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. None needed a change: the 11 checks that read host/nn_fs.c pass as they are (test_fs_path_utf8 is Windows-only and skips here).
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not yet for Windows. On Linux the game builds with this change, as a pack over a main 90fae88c base. This PC has no llvm-mingw, so host/nn_fs.c was compiled on its own for Windows with zig cc, with the same diagnostics as main's, but it has not been built with llvm-mingw. The change adds no path handling.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested. Not yet: the Windows and Steam Deck items have not run.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). Not yet: only an RDNA4 card with RADV on Linux; Windows with NVIDIA and AMD, and the Steam Deck, are in Still to test.
  • Approved in review, every comment answered. Not yet: no review so far.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold. Not yet: CI has not run on this head.

🤖 Generated with Claude Code

## Summary The game's threads run only while they hold one of six virtual cores. A thread that waits in a host file call should give its core up first, so the threads waiting for that core can run in the meantime. OpenFile, the file-handle calls (SetFileSize, WriteFile, FlushFile, CloseFile) and a staged save's Commit already do this. Five calls did not do it fully: CreateFile, DeleteFile, CreateDirectory and DeleteDirectoryRecursively (all four through `save_path_call`), and RenameFile. - On a staged save they gave the core up only after `host_path`, and its link checks (`save_guard`) are host file calls, so those calls ran with the core held. - On a mount with no working copy they kept the core through every host file call. That covers a save mounted in place (no working copy, or its folder already mounted directly), cache storage and temporary storage. A thread in a host call reaches no checkpoint, so it cannot be asked to give its core up. Neither the request of a better-priority waiter nor the starve rule (`HOS_VCORE_STARVE_US`, 1 s) helps while the call blocks. Unless another core the waiter may use comes free, only the 2 s escape (`HOS_VCORE_ESCAPE_US`, `HOS_VCORE_ESCAPE_EQ_US`) ends the wait, and the escape then runs the waiter without a core, beside the holder. This change makes `save_path_call` and RenameFile give the core up before `host_path` on every mount, as OpenFile does. They take it back on every way out, with no lock held. A failed call still reads its error before the core is taken back, because that wait sets the last error. A call refused for its mount (read-only or unknown) also gives the core up and takes it back, as OpenFile's refusals do. A thread that held no core takes none. The result: none of these five calls makes a host file call with the core held, and the game gets the same answers as before. How to see it on `main`: not in the game. It comes from reading the code, and the new check shows it: on `main`, `tests/test_vcore_fs_save.py` fails with 29 checks, each a host file call made with the core held (Measurements). The windowless runs in Testing make two of the five calls through the changed code in the game, but the 5 s `vcores:` lines are too coarse to show one call's wait (Risks). Read first: `save_path_call` and `HLE(_ZN2nn2fs10RenameFileEPKcS2_)` in `host/nn_fs.c`, then `tests/test_vcore_fs_save.py`. Related, each checked from its own commits or diff: - #607 (merged as a1c09a3c) added `save_path_call`. It gives the core up only for a staged save, and only after `host_path`. That is the gap this change closes. - Commit 26c12b0d on `main`, "no core held while OpenFile builds the button prompts", moved OpenFile's give-up to before `host_path`. This change does the same for the five path calls. - #594 (merged as d6878186) lets a starved waiter have its core after 1 s instead of escaping at 2 s. It came from #262 (closed): workers that waited the full 2 s for a core while a save loaded. That rule needs the holder to give its core up, and a holder in a host call cannot. Whether this change affects #262's report was not tested. - See #1503 (open): the gate's waits, and the 1 s starve limit that bounds this change's worst case (Risks). - No open, merged or closed pull request makes this change. I searched for: virtual core, vcore, nn_fs.c, save_path_call, host_path, RenameFile, CreateFile and DeleteDirectoryRecursively, and read the `host/nn_fs.c` part of each hit. Several open pull requests change `host/nn_fs.c`, but none changes how these calls hold the core. The `host/nn_fs.c` changes of #2154, #2173, #2180, #2411 and #2434 apply to this branch as they are. Those of #461, #61, #1577, #68 and #1428 already fail to apply on `main`. - #68 (open, feat(coop)) is the closest of these. It puts the five calls behind a shared save lock of its own, taken after `host_path`, and gives the core up only while it waits for that lock, not during the host file calls. Its `host/nn_fs.c` hunks are written against the code from before `save_path_call`. #1428 (WIP) changes Commit, to back the saves up. ## Testing **Tested:** Gentoo Linux, Ryzen 9 9950X3D, Radeon RDNA4 (1002:7550), Mesa RADV 26.2.6, sched_ext scx_lavd. The checks ran on this branch's head alone. The game ran windowless (`HOS_HEADLESS=1`), on this desktop while it was in use, so its numbers are rough. The branch is on `main` be663a08. The game ran before that rebase, in two rounds. The latest round ran this fix at 0918f3c5 against `main` 9046a8d7. An earlier round ran this fix at 4bdfb221 against `main` 90fae88c, before the fix commit's message was reworded and before the branch was rebased twice. `host/nn_fs.c` and the new check are byte for byte the same at 4bdfb221 and at this head. The earlier round is kept because only it ran a series on a full save folder. Since 9046a8d7, `main` has replaced its builder and moved the game's code (#2286, #2411). Their changes to `host/nn_fs.c` read the RomFS through `romfs.h` and choose the saves folder (`hos_saves_root`); they don't touch the five calls this PR changes, and the rebase onto be663a08 changed nothing in this PR's diff of `host/nn_fs.c`. This PC's lab builds the game with the builder `main` replaced, so the game was not run again at be663a08. - **In the game, this PR against `main`, windowless, latest round (at 0918f3c5, on `main` 9046a8d7).** - The two sides: this fix at 0918f3c5 and `main` 9046a8d7, each built as a pack over the same `main` 90fae88c base, logging `longshot v3.2.0-17-g0918f3c5 (source 5542d96f)` and `longshot v3.2.0-15-g9046a8d7 (source 643c1bab)`. The two packs' sources differ only by this PR's diff. - How: one game at a time, the sides alternated, each started by my own driver script at nice 19 and idle I/O priority, not through `dev.py queue run`. That driver is what this PC's lab runs use: it checks every 2 s that no other game build on this PC is running and stops only the game it started. No pair has run through `dev.py queue run --mode shared` yet; one a side can be repeated that way if a reviewer asks. The same switches on both sides: `HOS_HEADLESS=1`, `HOS_FS_TRACE=1`, `HOS_OOT_TRACE_SAVES=1`, `HOS_OOT_CHEATS=1` (for the teleport) and `HOS_CONTROL` (the control bridge, used for status, the save listing and the quit). Uncapped, Autosave on, the rest as Auto picks it. - One run: the Skip title row loads the newest save, and `!cheat 112` and `!cheat 1003` set 12:00 and go to the Market. Link walks out of its gate into Hyrule Field and back in, and the game writes a transition autosave each way. Then the bridge's `quit`, after which every game logged `stop: close work done`. - The runs: a warm-up a side that only loads, then three walk runs a side, alternating, on a save folder with slots 03 to 05 removed on both sides, then a run a side that only loads. Each walk run's first save went into a new slot and logged `create directory slot_0N`, `create file slot_0N/progress.sav` and `create file slot_0N/caption.sav`. Those are CreateDirectory and two CreateFile on a staged save, through `save_path_call`: 9 calls a side. - Seen on both sides: all 12 saves of the 6 walk runs were published (`fs: save: published 3 files`). Each run's save loaded in the next run of its side (slot_03, slot_04, then slot_05), with the game in play in the map the previous run had ended in. All 10 runs logged 0 escapes and no `ran without a core` line. No wait of 50 ms or more named the thread that saves (gmd::SaveDataMgr) or fell between a save's first file call and its `published` line. The `vcores:` numbers are in Risks. - **In the game, earlier round: this fix at 4bdfb221 against `main` 90fae88c, windowless.** The same method. This branch ran as a pack over a `main` 90fae88c base, logging `longshot v3.2.0-14-g4bdfb221 (source f14d9e21)`, against that base itself, logging `longshot v3.2.0-11-g90fae88c (source 90deadee)`. - Series 1, as planned, on a save folder with all six slots used: a warm-up and three runs a side, then a run a side that only loads. The autosave rewrote the next slot in place (GetEntryType, OpenFile, resize, write, close, Commit) and made no create, delete or rename call, so the changed code did not run on either side. - Series 2, on the same saves with slots 03 to 05 removed on both sides: three runs a side, then a load run each. Each run's first save went into a new slot and logged `create directory slot_0N`, `create file slot_0N/progress.sav`, `create file slot_0N/caption.sav` and `Commit: 3 files, 4 ops`. Those are CreateDirectory and two CreateFile on a staged save, through `save_path_call`: 9 calls a side. - Seen on both sides in that round: all 28 saves of the 14 walk runs were published (`fs: save: published 3 files`). Each run's save loaded in the next run of its side, with the published folder byte for byte as the run before had left it, the game in play and Link where he had stood. All 18 runs logged 0 escapes and no `ran without a core` line. No wait of 50 ms or more named the thread that saves (gmd::SaveDataMgr) or fell between a save's first file call and its `published` line. The `vcores:` numbers are in Risks. - Not exercised in the game, in either round: DeleteFile, DeleteDirectoryRecursively and RenameFile (the autosave makes none of them, and I did not look for a game path that does), a save mounted in place, cache and temporary storage, and calls refused for their mount. The check covers each of them. - **The new check**, `tests/test_vcore_fs_save.py`, ran alone through `tests/run_all.py --strict --container --exact` in CI's image (Ubuntu 24.04), once with clang++ 18.1.3 and once with g++ 13.3.0. At the test commit 6bd9ca57 (main 8aa5ab87 plus the test only), both fail the same 29 checks. Every one is a host file call made with the core held, by one of the five calls, on a staged save, a save mounted in place or cache storage. None is on SetFileSize, CloseFile, Commit or the refusals. At the head (4bdfb221, the same files as this head), it passes with both. After the rebase onto `main` 9046a8d7 it ran again with both compilers: the same 29 checks fail at the test commit, then 69e6ef0c, and it passes at the fix, 0918f3c5. On `main` be663a08 the check's stand-in for a file handle needed the RomFS field #2286 added (`Handle.rom`, closed through `hos_romfs_file_close`), and the check now has it. CI's image could not be rebuilt on this PC without a network after #2286 changed its Dockerfile, so at be663a08 the check ran on this PC's own compilers, clang++ 22.1.8 and g++ 16.2.1: the same 29 checks fail at the test commit, ea92a2be, and it passes at this head, 537fbfb4. As a test of the test, it also ran against 12 deliberately broken versions of the fix, and it fails on all 12 with both compilers. Among them: a refusal that takes a core back although the thread held none, the give-up after `host_path` as on `main`, and the take-back with the save lock still held. - **The whole suite**, `mise run test`'s command (`python -I -B tests/run_all.py`, unsharded), on this branch alone and on `main`: - At be663a08, on this PC's own tools (not CI's image, see above; not `--strict`): `main` 686 passed, 56 failed, 101 skipped; this PR at 537fbfb4 687 passed, 56 failed, 101 skipped. The same 56 checks fail on both sides; they need tools CI's image has and this PC lacks. The extra pass is the new check. - Before the rebase, in CI's container (`--strict --container`): `main` 9046a8d7 962 passed, 0 failed, 18 skipped; this PR at 0918f3c5 963 passed, 0 failed, 18 skipped. - In a first run of both at 9046a8d7, two timing-dependent checks failed once, one on each side, and passed when run again alone on both sides: nx2/test_depth_sample_types on this PR and tests/test_crash_dialog on `main`. tests/byte_compile_tracked also failed on this PR, because this PC's checkout had a stale worktree path, and passed once that was fixed. The counts above are from a second run of both. - No check changed status against `main`. The 11 other checks that read `host/nn_fs.c` pass, except test_fs_path_utf8, which is Windows-only and skips. The 18 skips are 13 Windows-only checks, 2 that need a Vulkan device and 3 that need the game's files. **Still to test:** - Windows, an NVIDIA RTX and an AMD RX card (Tier 1): from a save with a free slot after it, walk out of the Market's gate into Hyrule Field and back in, which makes two autosaves, the first into a new slot. Expecting two `fs: save: published` lines, and 0 escapes and no `ran without a core` line in the `vcores:` lines near them (@Beanstalk on Windows with NVIDIA and AMD: walk out of the Market gate into Hyrule Field and back, then read the log's save and core lines). - Steam Deck (Tier 1): the same walk, then quit and load the save. Expecting the two saves, the save loading, and no new core waits of 50 ms or more near the saves (by hand). ## Measurements **Verdict:** the bug is gone: the game-free check fails with 29 checks on `main` and passes with this PR, with clang++ and with g++. For a fix that is the measurement; the in-game cost is in Risks. Setup: Gentoo Linux, Ryzen 9 9950X3D. `python -I -B tests/run_all.py --exact tests/test_vcore_fs_save.py` on this PC's own compilers (clang++ 22.1.8, and g++ 16.2.1 through `CXX=g++`), once for each commit and compiler; CI's image could not be rebuilt here without a network (Testing). The before side ran at the test commit ea92a2be, which is `main` be663a08 with only the test added, so its `host/nn_fs.c` is main's. The after side ran at this head, 537fbfb4. Before the rebase, the same rows gave the same result in CI's image (clang++ 18.1.3, g++ 13.3.0) at 69e6ef0c and 0918f3c5 (on `main` 9046a8d7), and earlier at 6bd9ca57 (on `main` 8aa5ab87) and 4bdfb221. | | Before: main @ be663a08 | After: this PR @ 537fbfb4 | |---|---|---| | test_vcore_fs_save, clang++ 22.1.8 | FAIL, 29 checks | pass | | test_vcore_fs_save, g++ 16.2.1 | FAIL, 29 checks | pass | <details><summary>The 29 failing checks on main (clang++; g++ prints the same lines)</summary> ``` FAIL: save, CreateFile: 11 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, CreateFile of a file that exists: 8 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, DeleteFile: 7 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, DeleteFile of a file that is not there: 7 host file calls (some expected), 3 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, CreateDirectory: 4 host file calls (some expected), 2 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, CreateDirectory of a folder that exists: 4 host file calls (some expected), 2 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, DeleteDirectoryRecursively: 5 host file calls (some expected), 2 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, RenameFile: 13 host file calls (some expected), 6 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: save, RenameFile that fails: 13 host file calls (some expected), 6 of them with the core held (0 expected); the core held 1, taken 1 times (1, 1), with 0 locks held (0) FAIL: inplace, CreateFile: 5 host file calls (5 expected), 5 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, CreateFile of a file that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, DeleteFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, DeleteFile of a file that is not there: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, CreateDirectory: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, CreateDirectory of a folder that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, DeleteDirectoryRecursively: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, DeleteDirectoryRecursively of a link (DeleteFileA, then RemoveDirectoryA): 3 host file calls (3 expected), 3 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, RenameFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: inplace, RenameFile that fails: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, CreateFile: 5 host file calls (5 expected), 5 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, CreateFile of a file that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, DeleteFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, DeleteFile of a file that is not there: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, CreateDirectory: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, CreateDirectory of a folder that exists: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, DeleteDirectoryRecursively: 2 host file calls (2 expected), 2 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, DeleteDirectoryRecursively of a link (DeleteFileA, then RemoveDirectoryA): 3 host file calls (3 expected), 3 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, RenameFile: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) FAIL: cache, RenameFile that fails: 1 host file calls (1 expected), 1 of them with the core held (0 expected); the core held 1, taken 0 times (1, 1), with -1 locks held (0) a create, delete or rename holds the virtual core through a host file call (host/nn_fs.c) result time check FAIL 0.2s tests/test_vcore_fs_save.py 0 passed, 1 failed, 0 skipped in 0 s (linux, 32 at once) ``` </details> After (clang++; g++ prints the same, in 0.1 s): ``` pass 0.2s tests/test_vcore_fs_save.py 1 passed, 0 failed, 0 skipped in 0 s (linux, 32 at once) ``` ## Risks The first points come from reading `host/nn_fs.c` and `vc_acquire` in `host/hos_thread.c`. The in-game points come from the windowless runs in Testing. - **On a staged save:** still one give-up and one take per call, as on `main`. Only `host_path`'s link checks have moved inside that window. - **On a save mounted in place, cache storage, temporary storage, and a call refused for its mount:** one give-up and one take per call that `main` did not have. None of these ran in the game. - **The cost of a take:** when a core the thread may use is free, it takes one at once. This counts in the `vcores:` line's takes, not its waits. When another thread has taken the core meanwhile and no other allowed core is free, the caller waits as OpenFile, the handle calls, a staged Commit and MountSaveData already do: - A worse-priority holder gives the core up at its next checkpoint. - A holder of equal priority does so after the 2 ms slice (`HOS_VCORE_SLICE_US`), at its next checkpoint. - A better-priority holder is asked only once the caller counts as starved (1 s). - The 2 s escape still bounds the wait. - **At worst,** while better-priority threads keep every allowed core busy without blocking, a create, delete or rename returns up to about 1 s later, and never more than 2 s later. A few milliseconds is the case of an equal-priority holder. - **In the game, no cost beyond the spread.** Windowless, on a desktop in use, three runs a side, so rough. The walk covers two map loads and two saves. Latest round, this fix at 0918f3c5 against `main` 9046a8d7, each walk run creating a new slot; medians (range): | The walk, 3 runs a side | `main` 9046a8d7 | this PR 0918f3c5 | |---|---|---| | create calls a run | 3 (old code) | 3 (changed code) | | waits per 5 s block | 125 026 (87 784 to 136 718) | 127 164 (87 747 to 130 978) | | mean wait | 72.1 us (69.2 to 72.4) | 67.1 us (65.3 to 73.0) | | waits of 50 ms or more | 7 (7 to 10) | 5 (2 to 12) | | longest wait | 589.5 ms (119.0 to 601.2) | 163.8 ms (81.1 to 742.0) | | escapes, starved grants, `ran without a core` | 0, 0, 0 | 0, 0, 0 | | a save's publish (code not changed) | 44.3 ms (37.2 to 125.7) | 39.4 ms (38.5 to 40.6) | - Every row's ranges overlap, so there is no difference beyond the spread either way. - The longest waits, several hundred ms, are on both sides and far above the earlier round's. None falls in a save. The ones I read fall in map loads, with threads such as PreActorModelCompose and BaseProcExecutor0 waiting for a core that sead::MainThread or GeneralFormatAsync_ held. The PC was busier than in the earlier round: a 1-minute load average of 4 to 6 at the run starts, and KDE's file indexer on about one core throughout. - `main`'s 125.7 ms publish is one run (both of its saves took about 125 ms), in code this PR does not change. The earlier round, this fix at 4bdfb221 against `main` 90fae88c; series 1 made no create call on either side: | The walk, 3 runs a side | Series 1, `main` | Series 1, this PR | Series 2, `main` | Series 2, this PR | |---|---|---|---|---| | create calls a run | 0 | 0 | 3 (old code) | 3 (changed code) | | waits per 5 s block | 115 984 (101 888 to 130 137) | 129 035 (110 638 to 138 584) | 113 136 (91 836 to 127 026) | 95 872 (95 046 to 119 192) | | mean wait | 66.7 us | 67.6 us | 68.0 us | 68.1 us | | waits of 50 ms or more | 3 (1 to 5) | 6 (3 to 7) | 6 (6 to 9) | 5 (0 to 8) | | longest wait | 77.5 ms (60.1 to 91.1) | 110.5 ms (61.7 to 138.0) | 116.6 ms (82.7 to 139.0) | 91.7 ms (49.4 to 175.6) | | escapes, starved grants, `ran without a core` | 0, 0, 0 | 0, 0, 0 | 0, 0, 0 | 0, 0, 0 | | a save's Commit (code not changed) | 40.9 ms (37.8 to 48.0) | 42.2 ms (38.3 to 50.4) | 41.2 ms (38.1 to 60.1) | 41.1 ms (37.2 to 47.7) | - In the earlier round, over both series together, this PR's medians lie inside `main`'s ranges on every row: waits of 50 ms or more 5.5 against 5.5, longest wait 101.1 ms against 86.9 ms. - In series 1 alone, this PR's count of waits of 50 ms or more and its longest wait lie above `main`'s range, although neither side made a changed call there. Series 2, where the calls ran, goes the other way. Those waits fall in a map load or right around one, none in a save. I read it as run-to-run noise of three runs, not as a cost. - What these numbers cannot show: the cost of one give-up and take. Three changed calls a run are lost among about 100 000 waits a 5 s block, and the log has no times, so a create's own duration was not measured. - **The frame trace and the FPS counter's Breakdown** count the time in these calls as the thread's blocked time, not its running time. - **What a player notices after updating:** nothing is expected. Saves, `longshot_options.ini` and the caches are unchanged, and the calls write the same files. In the runs, every save published and loaded again on both sides. - **How to turn it off:** there is no switch, so a revert is the way back. `HOS_VCORES=0` is no fallback: it turns the virtual cores off altogether, and the game's job queues need them. - **Left as on `main`:** GetEntryType, OpenDirectory, IsSaveDataExisting, the cache-storage calls and `user_mount` still make host file calls with the core held. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. The branch is on be663a08, the head of `main` when this PR was opened. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. Windowless, on `main` 9046a8d7, before the rebase onto be663a08; the runs made CreateDirectory and CreateFile through the changed code. - [ ] `mise run test` passes (any failure that also fails on `main` is named). Not yet in CI's container at this head: its image could not be rebuilt here without a network. On this PC's own tools the same 56 checks fail on `main` be663a08 and here, for tools this PC lacks; in CI's container at 9046a8d7, 0 failed (Testing). CI's run on this PR settles it. - [x] Measured against `main`, or Measurements says why there is nothing to measure. For this fix, the check fails on `main` and passes here (Measurements); the in-game cost is in Risks. - [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. None needed a change: the 11 checks that read `host/nn_fs.c` pass as they are (test_fs_path_utf8 is Windows-only and skips here). - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not yet for Windows. On Linux the game builds with this change, as a pack over a `main` 90fae88c base. This PC has no llvm-mingw, so `host/nn_fs.c` was compiled on its own for Windows with zig cc, with the same diagnostics as main's, but it has not been built with llvm-mingw. The change adds no path handling. - [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. Not yet: the Windows and Steam Deck items have not run. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). Not yet: only an RDNA4 card with RADV on Linux; Windows with NVIDIA and AMD, and the Steam Deck, are in Still to test. - [ ] Approved in review, every comment answered. Not yet: no review so far. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. Not yet: CI has not run on this head. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CreateFile, DeleteFile, CreateDirectory and DeleteDirectoryRecursively
(save_path_call) and RenameFile give the thread's virtual core up only for
a staged save, and only after host_path. For a staged save host_path
checks the path for links (save_guard), and those checks are host file
calls made with the core held. On a mount without a working copy (a save
mounted in place, cache or temporary storage) every host file call of the
five is made with the core held.

A thread in a host call reaches no checkpoint, so while the call blocks,
the better threads that ask for its core wait, and unless another core
they may use comes free, only vc_acquire's escape (HOS_VCORE_ESCAPE_US,
2 s) ends that wait.

The check compiles the actual functions, host_path and its link checks
included, with stand-ins that count the host file calls and how many ran
with the core held. It covers a staged save, a save mounted in place and
cache storage, for calls that work and calls that fail, and the answers
those give. A call refused for its mount answers PathNotFound, and a
thread that held no core takes none, refused or not. SetFileSize and
CloseFile, and Commit of a staged save, already give the core up and are
checked to stay that way; Commit of any other mount makes no host file
call and is checked to keep the core.

On main it fails with 29 checks, all of them on the five calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(fs): a create, delete or rename gives the virtual core up on every mount
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test) (pull_request) Blocked by required conditions
CI / longshot-builder end to end (synthetic game) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (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 4s
537fbfb411
CreateFile, DeleteFile, CreateDirectory, DeleteDirectoryRecursively and
RenameFile gave the core up only for a staged save, and only after
host_path. A staged save's link checks in host_path (save_guard) ran with
the core held, and so did every host file call on a mount without a
working copy: a save mounted in place (no working copy, or its folder
already mounted directly), cache storage and temporary storage. A thread
in a host call reaches no checkpoint, so neither the better waiters'
request nor a starved waiter's (HOS_VCORE_STARVE_US, 1 s) can make it
give the core up while the call blocks. Unless another core a waiter may
use comes free, only the escape (HOS_VCORE_ESCAPE_US and
HOS_VCORE_ESCAPE_EQ_US, 2 s) ends such a wait, and it runs the waiter
beside the holder.

save_path_call and RenameFile now give the core up before host_path, as
OpenFile does, on every mount, and take it again on every way out, with
no lock held. A failed call's error is still read before the core is
taken again (vc_acquire's timed wait sets the last error). A call refused
for its mount now gives the core up and takes it back too, as OpenFile's
refusals do; a thread that held no core takes none.

The bug was found by reading the code. In windowless game runs
(HOS_HEADLESS=1) against main, three runs a side wrote their first
autosave into a new slot of a staged save: CreateDirectory and two
CreateFile through the changed save_path_call, 9 calls a side. Every save
was published and loaded again, no wait escaped, and the 5 s vcores lines
showed no cost beyond the run-to-run spread; they are too coarse to time
one call. DeleteFile, DeleteDirectoryRecursively, RenameFile, the other
mounts and the refusals did not run in the game; the test covers them.

SetFileSize, CloseFile and Commit are unchanged: save_handle_call gives
the core up for every handle, Commit does for a staged save's publish,
and Commit of any other mount makes no host file call.

tests/test_vcore_fs_save.py passes (on main it fails with 29 checks).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
First-time contributor

Tested in game: Gentoo Linux, Ryzen 9 9950X3D, Radeon RDNA4 (1002:7550), Mesa RADV 26.2.6, sched_ext scx_lavd; windowless (HOS_HEADLESS=1), on a desktop in use.

  • Builds: this fix at 0918f3c5, longshot v3.2.0-17-g0918f3c5 (source 5542d96f), against main 9046a8d7, longshot v3.2.0-15-g9046a8d7 (source 643c1bab), each a pack over the same main 90fae88c base, so the two differ only by this PR's diff. The branch has since been rebased onto main be663a08 (the new builder, #2286, and #2411); this PR's diff of host/nn_fs.c is unchanged, and the game was not run again there.
  • What ran: 10 runs, the sides alternated, with HOS_FS_TRACE=1: a warm-up a side that only loads, three walk runs a side and a run a side that only loads. The walk, from a save: 12:00, teleport to the Market, walk out of its gate into Hyrule Field and back in (two transition autosaves), quit through the control bridge. Each walk run's first save went into a new slot, so CreateDirectory and two CreateFile ran through save_path_call, 9 calls a side (on this PR's side, the changed one).
  • What I saw, on both sides: all 12 saves published (fs: save: published 3 files), and each run's save loaded in the next run of its side, with the game in play. 0 escapes and no ran without a core line in any run, and no wait of 50 ms or more inside a save. The vcores: numbers overlap on every row (Risks).
  • An earlier round, this fix at 4bdfb221 (the same host/nn_fs.c) against main 90fae88c, 18 runs, saw the same; it is in Testing.
  • Not run in the game: DeleteFile, DeleteDirectoryRecursively, RenameFile, a save mounted in place, cache and temporary storage (the autosave makes none of them); tests/test_vcore_fs_save.py covers them.

Opened by AGit (refs/for/main) from my clone, without a fork, so forge.py pr create did not post this comment: I post it by hand.

Tested in game: Gentoo Linux, Ryzen 9 9950X3D, Radeon RDNA4 (1002:7550), Mesa RADV 26.2.6, sched_ext scx_lavd; windowless (`HOS_HEADLESS=1`), on a desktop in use. - Builds: this fix at 0918f3c5, `longshot v3.2.0-17-g0918f3c5 (source 5542d96f)`, against `main` 9046a8d7, `longshot v3.2.0-15-g9046a8d7 (source 643c1bab)`, each a pack over the same `main` 90fae88c base, so the two differ only by this PR's diff. The branch has since been rebased onto `main` be663a08 (the new builder, #2286, and #2411); this PR's diff of `host/nn_fs.c` is unchanged, and the game was not run again there. - What ran: 10 runs, the sides alternated, with `HOS_FS_TRACE=1`: a warm-up a side that only loads, three walk runs a side and a run a side that only loads. The walk, from a save: 12:00, teleport to the Market, walk out of its gate into Hyrule Field and back in (two transition autosaves), quit through the control bridge. Each walk run's first save went into a new slot, so CreateDirectory and two CreateFile ran through `save_path_call`, 9 calls a side (on this PR's side, the changed one). - What I saw, on both sides: all 12 saves published (`fs: save: published 3 files`), and each run's save loaded in the next run of its side, with the game in play. 0 escapes and no `ran without a core` line in any run, and no wait of 50 ms or more inside a save. The `vcores:` numbers overlap on every row (Risks). - An earlier round, this fix at 4bdfb221 (the same `host/nn_fs.c`) against `main` 90fae88c, 18 runs, saw the same; it is in Testing. - Not run in the game: DeleteFile, DeleteDirectoryRecursively, RenameFile, a save mounted in place, cache and temporary storage (the autosave makes none of them); `tests/test_vcore_fs_save.py` covers them. Opened by AGit (`refs/for/main`) from my clone, without a fork, so `forge.py pr create` did not post this comment: I post it by hand.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test) (pull_request) Blocked by required conditions
CI / longshot-builder end to end (synthetic game) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (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 4s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2529/head:unixman/fix/save-vcore-path-calls'
git switch 'unixman/fix/save-vcore-path-calls'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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!2529
No description provided.