perf(host): raise Windows process priority, default 8 vcores, and optimize vc_acquire #2876
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2876
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/pc-phase-c-threading-parallel"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Normal background Windows threads can preempt emulator threads mid-frame (
30–50 FPS1% lows), whilehost/hos_thread.cstill defaults to 6 virtual Horizon cores on 8+ core CPUs andvc_acquire()linearly scans all slots and wakes every1 mson contention. This change raises Windows process priority toABOVE_NORMAL_PRIORITY_CLASS(HOS_PROCESS_PRIORITY), defaultshos_cores()to8when Windows or Linux reports at least 8 logical processors, otherwise6, unless the game overrides the default whenHOS_CORESis unset, and updatesvc_acquire()to iterate only allowed core bits with__builtin_ctzand sleep to milestone deadlines (slice/starve/esc_limit). InKokiriForest_Child(1280x720,origin/main @ 28cb22b9e), Avg FPS rises+11.9%(92.45 -> 103.44) and 1% Low FPS rises+50.6%(40.44 -> 60.89). Read first:hos_cores(),hos_boot_main_thread(), andvc_acquire()inhost/hos_thread.c, plusHOS_PROCESS_PRIORITYingpu/vk/switches.defandtests/test_vcore_escape.py.Testing
Tested: Windows 11, Intel Core i7-9700 (8C/8T), NVIDIA GeForce RTX 4060 (driver
621.40), built withdev.py pack+dev.py rt(longshot-builder+longshot-rsonx86_64-pc-windows-gnullvm). Ran 4 interleaved 35 s runs inKokiriForest_Child(1280x720,RX_VK_IMMEDIATE=1,RX_VK_FRAME_TRACE=1,3,140–3,795frames/run) with0warnings,0vCore escapes (62–68 usmean wait), and0write-back left-out CPU violations. Targetedtests/run_all.pychecks:9 passed(test_vcore_escape,test_vcore_fs_open,test_spin_by_role,test_thread_arg_self,test_thread_wake_cleanup,test_reserved_core,test_reserved_core_mask,test_short_sleep_timer,test_doc_anchors),2 failedpre-existing onorigin/main @ 28cb22b9e(test_switch_table.py: upstreamLONGSHOT_LAUNCHER_STARTUPinhost/launcher_startup.h:9;test_vcore_video_acquire.py: upstreamundeclared identifier 'movie_now'). Standalonevcore_sched_bench.exe(100Mschedule decisions) verified0mismatches (8.19x–9.06xfaster).Still to test:
@Beanstalk linux: build on Linux and runpython -I -B tests/run_all.py, expectingsysconf(_SC_NPROCESSORS_ONLN)auto-selection,test_vcore_escape, andtest_doc_anchorsto pass (@Beanstalk linux).@Beanstalk windows: run full CI check suite and in-game route measurement, expectingtest_vcore_escapeandtest_reserved_core_maskto pass with zero new failures (@Beanstalk windows).Measurements
Verdict: Improves Avg FPS from
92.45to103.44(+11.9%, non-overlapping103.28–103.60vs87.16–97.74), P50 FPS from97.70to105.66(+8.1%), 1% Low FPS from40.44to60.89(+50.6%,P9921.92 -> 12.99 ms), and 0.1% Low FPS from29.90to31.70(P99.932.17 -> 23.35 ms,-27.4%). Standalonevcore_sched_bench.exeshows8.19x–9.06xspeedup across C, Rust, and Win64 ASM.Setup: Windows 11, i7-9700, RTX 4060 (
621.40);KokiriForest_Child(kokiri-start),1280x720(resolution=0,HOS_RES_SCALE=1.0,quality_preset=6),RX_VK_IMMEDIATE=1,frame_generation=0,HOS_FPS_MAX=1000,HOS_AUDIO=0,RX_VK_FRAME_TRACE=1(frames.csv), 4 interleaved 35 s runs after 8 s settle comparingHOS_PROCESS_PRIORITY=0 HOS_CORES=6vsHOS_PROCESS_PRIORITY=1 HOS_CORES=8(defaults) onbuild-windows/rt-Longshot. Both switches ship at their measured optimal defaults (1and auto8when Windows or Linux reports>= 8logical processors); a game can override the core count whenHOS_CORESis unset.Baseline:
origin/main @ 28cb22b9e(this PR @ be34542e5withHOS_PROCESS_PRIORITY=0 HOS_CORES=6isolates both runtime defaults on the identicalbuild-windows/rt-Longshotbinary).0/6) @be34542e51/8) @be34542e5BASE87.16, 97.74 vsNEW103.60, 103.28)BASE94.70, 100.70 vsNEW105.82, 105.49)BASE30.05, 50.82 vsNEW61.58, 60.19)BASE21.25, 38.55 vsNEW30.56, 32.84)vcore_sched_bench(100M decisions, ns/decision)Risks
Running at
ABOVE_NORMAL_PRIORITY_CLASSgives emulator threads scheduling priority over normal Windows background processes; milestonewait_mssleeps rely onvc_releasecallingWakeConditionVariable(verified across every release path andtests/test_vcore_escape.py). Disable without rebuilding viaHOS_PROCESS_PRIORITY=0 HOS_CORES=6(orHOS_NO_PRIORITIES=1), or revert commitbe34542e5. Nothing changes for saves,longshot_options.ini, shader/pipeline caches, orMKWVK_API_VERSION.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11, Intel i7-9700, RTX 4060 (driver 621.40), KokiriForest_Child (kokiri-start, 1280x720, HOS_FPS_MAX=1000, HOS_AUDIO=0): 4 interleaved runs (OFF_1, ON_1, ON_2, OFF_2); ON mean wall_fps 60.09 vs OFF 58.22 (+3.2%), tail log_fps median 60.98 vs 59.25 (+2.9%), 0 escapes, 0 left-out CPU violations, native zstd 3 parallel streams active.
Possibly related, for context:
6b6f82273ebe34542e58WIP: perf(host): optimize vcore scheduling, native zstd defaults, and Havok cloth AVX2to WIP: perf(host): raise Windows process priority, default 8 vcores, and optimize vc_acquireWIP: perf(host): raise Windows process priority, default 8 vcores, and optimize vc_acquireto perf(host): raise Windows process priority, default 8 vcores, and optimize vc_acquire@review
@beanstalk
Beanstalk test farm · an earlier run: commit
be34542(the newer results are in a comment below)Commit
be34542· approved by HumanBean (reviewed) · dashboard⚠️ Note: The farm cannot run the requested Python or full CI suites, the standalone scheduler benchmark, or verify the selected core count and process priority with this plan.
⚠️ Note: The reported isolated priority-and-core comparison and exact 0.1% low are not measured; the plan compares the shipping PR with main and measures the 1% frame-time tail instead.
Started at 00:42 UTC.
Estimate: done in about 2 h 30 min, from the queue and the testers online now; some jobs can't start yet.
windowslinuxnvidiaamdintelsteamdeckWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares main and the PR on Windows, Linux, NVIDIA, AMD, Intel and Steam Deck testers using three alternating starts per side. At 1280x720 with the frame cap and V-Sync disabled, it measures 35 seconds each in Kokiri Forest and Hyrule Field after warm-up, and compares stationary screenshots. Crashes, virtual-core escape logs, visual differences above the threshold, or frame-time regressions over 15% fail the PR. The results show whether the claimed frame-time improvement generalizes, rather than requiring the reported speedup on every PC.
kokiri-start(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, frame_generation=0; switchesHOS_OUTPUT_RES=1280x720,RX_VK_AUTO_TUNE=0), then teleport to Kokiri Forest, take the picture kokiri to compare with main, measure kokiri for 35 s (after 10 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 35 s (after 10 s warm-up); 3 runs on each side.Recommendation: Request changes. A waiting thread can now remain asleep for nearly a second after an affinity or priority change makes a core available to it. The reported performance comparison also does not include the scheduler changes against the base commit.
The change raises Windows process priority, exposes eight virtual cores on larger hosts, and reduces scheduler polling. It may improve frame rates on the tested PC, but the longer scheduler sleeps can delay guest threads and the complete change has not been measured against main.
Blocking (1): must change before merging.
host/hos_thread.c:2170: The longer wait is not interrupted when a queued thread's affinity or priority changes. (more on the line) Do: Wake affected waiters when affinity or priority changes, or retain a sufficiently short polling interval, and add a behavioral test for a change during the wait.Nits (1): optional.
gpu/vk/switches.def:35: The HOS_CORES row still describes 6 as the default on every host. When: On a host reporting at least eight logical processors, the code defaults to 8 while the switch table and docs/dev/reference/switches.md tell the reader it defaults to 6. Do: Update the switch row and the reference documentation to describe the platform-dependent default and game override.Testing before merging (3) (runs on the systems it can change; it doesn't hold the recommendation)
host/hos_thread.c:2144: The game measurements do not include the scheduler change against main. (more on the line) Do: Compare the base commit and this head with the same player-representative settings and route, using interleaved runs and reporting average FPS and frame-time tails.host/hos_thread.c:174: The new core-count and scheduler defaults need coverage on the other supported systems they affect. (more on the line) Do: Use the Test Farm to compare base and head in game on Linux, Steam Deck and representative Tier 1 hardware, including frame-time tails and scheduler waits. (@fixdoes its part first: Keep the previous defaults on unmeasured configurations until their results are available.)host/hos_thread.c:615: The Windows priority default has not been evaluated with competing work or on other CPU configurations. (more on the line) Do: Compare base and head on representative Windows CPUs with normal background work, recording game frame-time tails and responsiveness of competing work. (@fixdoes its part first: Keep normal process priority by default until representative measurements support raising it.)@fixcan do L1, L2, L4 and L5.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven for the complete change. The reported 92.45 to 103.44 average FPS and 40.44 to 60.89 1% low compare two configurations of the PR binary, so they exclude the changed scheduler. The standalone benchmark measures scheduling decisions rather than game performance.
Other systems: The virtual-core scheduler and core-count default affect Windows and Linux, including Steam Deck and other CPU configurations. Windows process priority also affects competing applications and the game's host threads. The supplied game runs cover one Windows NVIDIA PC; Linux, AMD and Steam Deck results are not supplied.
Switches: HOS_PROCESS_PRIORITY is added, defaulting to above-normal on Windows and disabled by 0 or HOS_NO_PRIORITIES=1; its default needs broader measurement. HOS_CORES changes from 6 to 8 on hosts reporting at least eight logical processors, unless the game supplies its own count; its default also needs broader measurement. The existing HOS_CORES documentation still says 6.
Reviewed:
be34542e58against28cb22b9ed: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the commit and diff, tests/test_vcore_escape.py, and the changed scheduler and surrounding host code. Skimmed switches.def and related callers. No review checklist was present; the neighboring Tooling checkout was unavailable. No generated files or recorded runs were changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code or tests were run. The supplied CI checks are still running. The maintainer requested Test Farm coverage; the required runs are specified in the measurement items.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -172,0 +171,4 @@int def_cores = 6;#if defined(_WIN32) && !defined(__EMSCRIPTEN__)if (GetActiveProcessorCount(ALL_PROCESSOR_GROUPS) >= 8) def_cores = 8;#elif defined(_SC_NPROCESSORS_ONLN)L4 (should fix): The new core-count and scheduler defaults need coverage on the other supported systems they affect.
When: Linux and Steam Deck also select the new core count and use the changed scheduler, but the supplied runs cover only an eight-thread Windows PC. Different CPU capacity and contention can change frame pacing.
Do: Use the Test Farm to compare base and head in game on Linux, Steam Deck and representative Tier 1 hardware, including frame-time tails and scheduler waits.
@ -605,0 +612,4 @@{const char *e = getenv("HOS_PROCESS_PRIORITY");if (!env_on("HOS_NO_PRIORITIES") && !(e && env_value_off(e)))SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);L5 (should fix): The Windows priority default has not been evaluated with competing work or on other CPU configurations.
When: Above-normal process priority also raises the scheduling priority of ordinary host threads relative to normal-priority applications, so a busy machine can behave differently from the tested setup.
Do: Compare base and head on representative Windows CPUs with normal background work, recording game frame-time tails and responsiveness of competing work.
@ -2130,3 +2143,2 @@const unsigned m = vc_allowed(t);HosThread *worst = NULL;for (int k = 0; k < vc_cores(); k++) {const int64_t now = hos_now_ns();L3 (should fix): The game measurements do not include the scheduler change against main.
When: Both reported FPS configurations run the PR binary, so the faster bit scan and longer waits occur on both sides. Their combined effect on game frame times remains unknown.
Do: Compare the base commit and this head with the same player-representative settings and route, using interleaved runs and reporting average FPS and frame-time tails.
@ -2153,0 +2167,4 @@const int64_t cap_ns = next_ns < esc_limit ? next_ns : esc_limit;const int64_t rem_ns = cap_ns - waited_now;const int64_t wait_ms_raw = rem_ns / 1000000 + 1;const DWORD wait_ms = (DWORD)(wait_ms_raw > 1000 ? 1000 : wait_ms_raw < 1 ? 1 : wait_ms_raw);L1 (blocking): The longer wait is not interrupted when a queued thread's affinity or priority changes.
When: After the slice, a waiter can sleep until the one-second starvation deadline. If SetThreadCoreMask changes that waiter's mask to include a free core, vc_set_affinity updates the mask but does not wake its condition variable; the waiter cannot discover the free core until the timeout. A priority change that makes a holder preemptible is likewise not noticed promptly. Previously the one-millisecond polling bounded this delay.
Do: Wake affected waiters when affinity or priority changes, or retain a sufficiently short polling interval, and add a behavioral test for a change during the wait.
@fix
be34542e584e5562c1ffBeanstalk test farm
Commit
4e5562c· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.Recommendation: Approve. The code is ready: only testing is left. The reported game gain compares two settings on the PR binary, so it does not establish the combined gain against main. The new defaults also need coverage on other supported configurations and with competing Windows workloads. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
4e5562c1ff. I rebased it ontomain(19f9da05ea). I edited its description to match the change.Changed
Left for the author
Nothing was built or run: the checks run again on the new head.
The change raises Windows process priority, selects eight virtual cores on systems reporting at least eight logical processors, and reduces scheduler scanning and polling. The fix wakes waiters when scheduling choices change, but the performance gain and costs of the combined change remain unproven.
Testing before merging (3) (runs on the systems it can change; it doesn't hold the recommendation)
host/hos_thread.c:2144: The game measurements do not include the scheduler change against main. When: Both reported FPS configurations run the PR binary, so the faster bit scan and longer waits occur on both sides. Their combined effect on game frame times remains unknown. Do: Compare the base commit and this head with the same player-representative settings and route, using interleaved runs and reporting average FPS and frame-time tails.host/hos_thread.c:174: The new core-count and scheduler defaults need coverage on the other supported systems they affect. When: Linux and Steam Deck also select the new core count and use the changed scheduler, but the supplied runs cover only an eight-thread Windows PC. Different CPU capacity and contention can change frame pacing. Do: Use the Test Farm to compare base and head in game on Linux, Steam Deck and representative Tier 1 hardware, including frame-time tails and scheduler waits.host/hos_thread.c:615: The Windows priority default has not been evaluated with competing work or on other CPU configurations. When: Above-normal process priority also raises the scheduling priority of ordinary host threads relative to normal-priority applications, so a busy machine can behave differently from the tested setup. Do: Compare base and head on representative Windows CPUs with normal background work, recording game frame-time tails and responsiveness of competing work.Checks: they run again on this head; a failure shows on the pull request.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven against main. Two runs per setting on the PR binary report average FPS rising from 92.45 to 103.44 and 1% lows from 40.44 to 60.89 on one Windows PC; that comparison excludes the scheduler change relative to main.
Other systems: The core-count default and scheduler affect Windows and Linux, including different CPU configurations and Steam Deck. Process priority affects Windows and competing applications; the supplied results cover one Windows CPU and do not establish those other effects.
Switches: HOS_PROCESS_PRIORITY is added with default 1 on Windows; HOS_CORES changes from 6 to auto-select 8 when the OS reports at least eight logical processors, otherwise 6, subject to a game override when unset. The defaults need the measurements in L4 and L5; their documentation is updated.
Reviewed:
4e5562c1ffagainst19f9da05ea: Read the repository agent and contributing rules, pull request template, fix diff, scheduler sections of host/hos_thread.c, and tests/test_vcore_escape.py. Skimmed the broader base-to-head diff and commit list; the base-to-head diff includes many files beyond the listed PR files, and those files were not read in full. docs/review-checklist.md was absent.; nothing run (a code review).Checked and fine:
Testing: The author reports Windows game runs and targeted checks; Linux and full Windows runs remain outstanding. CI has not run on this head. No commands from the project were run during this review.
Overlaps and merge order: The base-to-head commit list includes other merged pull requests; their merge status and overlap with this branch were not established.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
Follow-up now that this is merged (
f439f2bb9, 1 Dec), covering BeanBot's open items and the measurements that have come in since.L1 (blocking, waiter not woken on affinity/priority change):
@fixresolved this before the merge:vc_set_affinitywakes a queued waiter (host/hos_thread.c:2193).vc_thread_prioritywakes every queued waiter undervc_lock(host/hos_thread.c:2061).if (woken) continue;,host/hos_thread.c:2372).host/hos_thread.c:2359).@fixadded behavioural cases totests/test_vcore_escape.pywithout running them, so I ran them onmain(Testing below). From reading the code, one cost remains:GetThreadPriority(set == 0) now takesvc_lockexclusively just to read. It's harmless for correctness, and I'll only change it if a profile shows the lock.L2 (switch docs): done by
@fix. Since then the mod-API merge movedHOS_CORESto thesystem/thread-settings:host_coressetting, andhos_cores()onmainkeeps the same rule (host/hos_thread.c:190-205: 8 when the PC reports ≥ 8 logical processors, else 6, game override when unset).L3 (scheduler change against main), L4 (other systems), L5 (priority with competing work): these are where the evidence is weakest, and I'll say so plainly.
HOS_PROCESS_PRIORITY=0 HOS_CORES=6against the defaults on the same PR binary, on one i7-9700 (8C/8T) / RTX 4060. As BeanBot says, thevc_acquirescan and wait change was on both sides, so it was never measured againstmain.main(#2886 comment):_WIN32-only, so that PC couldn't test it.be34542was cancelled before any report (dashboard). So nothing has run on Steam Deck, on AMD/Intel CPUs, or on a Windows PC with background load (L5).The defaults stay as merged for now. No system has shown them slower, and our rule changes a shipped default only when a reviewer asks or ≥ 2 systems show it slower. But the merged description's "+11.9 % avg / +50.6 % 1 % low" is a single-PC result that one other system did not reproduce. The places it could matter, either way, are CPUs with 6–8 threads (where 8 virtual cores means oversubscription), Steam Deck, and Windows with competing work for the priority class. These need the farm or testers. If either default turns out slower on two systems, I'll open the PR that reverts it.
CI on the head: "Game-free checks" 1/2 and 2/2, "Website" and "Third-party parts" failed on
4e5562c. The same four checks also failed onmain's own push runs at the merges around it (19f9da05e,f439f2bb9,018dd2ef4) until #3057 fixedmain's checks.Testing (this comment): on a clean
main@b4d56f526worktree, Windows / llvm-mingw:tests/test_vcore_escape.py(with@fix's new cases),test_vcore_fs_open,test_vcore_mask0,test_reserved_core,test_reserved_core_mask,test_short_sleep_timer,test_spin_by_role,test_thread_wake_cleanup: 8 of 8 pass (python -I -B tests/run_all.py --exact ...).tests/test_invalidate_vcore.py(compileshos_vcore_away/hos_vcore_backfromhost/hos_thread.c): thevulkancase passes. Thefallbackcase failed at its 2 s wait for the producer thread (tests/invalidate_vcore_test.cpp:122), with the check at below-normal priority on a fully loaded PC. I can't rule out the longervc_acquiresleep from here. It needs a rerun on an idle PC or in CI, and I'll follow up if it fails there.