WIP: perf(os): HOS_WORKERS_SPREAD=1 puts the six job workers on one logical processor of each whole core (off by default) #2360
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2360
Loading…
Reference in a new issue
No description provided.
Delete branch "klimovich008/Longshot:perf/job-workers-one-per-core"
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
In busy scenes the game's six job workers (
BaseProcExecutor0-5) hold the frame, and Windows often puts two of them onthe two halves of one SMT core, where both run slower. This PR adds a switch,
HOS_WORKERS_SPREAD=1, off unless set,that gives the six workers one logical processor of each whole core the game may use, so no two of them share a core.
In Lost Woods (child) on one 8-core PC it gave +4.6 % fps and 2.3 ms less CPU a frame (3 pairs, "diagnostic" by the
standard test's own rule). Whether it ever becomes a default is the maintainers' call after other CPUs have run it.
What it does, in player words. At start, with the switch on, the host works out one logical processor of each whole
core the game is allowed to use: inside the process's affinity mask (#1776), inside the cache cores where those narrow
the game, and without the core reserved for the render thread. On a Ryzen 7 5700X3D that is
0x1555(the first logicalprocessor of cores 0-6; core 7 is the reserved one). Only threads named
BaseProcExecutor*get that set; every otherthread keeps today's mask. One log line says what was chosen, or why it declined:
threads: HOS_WORKERS_SPREAD=1: the job workers (BaseProcExecutor*) on logical processors 0x1555, one of each of the 7 whole cores the game may use .../threads: HOS_WORKERS_SPREAD=1 does nothing here: <why> ....It declines (logged; the workers keep today's mask) when:
0x5555);Limits, plainly:
/sys/devices/cpu_core). AMD's Zen 5 + Zen 5c (e.g.Ryzen AI 9 HX 370) is not declined there: its workers go one per core over both kinds, where today they float over
both. Windows declines it (tested).
mask is refused and the worker keeps the mask it inherited; Windows narrows existing threads itself).
RX_VK_RECORDER_PIN=next(another experiment) pins the recorder to the core below the reserved one, which is oneof the workers' cores. The two were never run together.
RX_VK_RT_HOME): they compose. #2240's home is the reserved core, and this set is built withoutit, so the two never share a processor (asserted in the test for every accepted set). The two branches merge without a
conflict and the tests both touch pass on the merged tree; they were not built or measured together.
HOS_PINstill overrides the set (applied after it, as today), andHOS_PIN_BY_CORE=1overrides everything.Read first:
host/hos_thread.cpick_worker_cpus(the pure choice, besidepick_reserved_core),worker_cores(itsinput:
GetLogicalProcessorInformationExon Windows, the shim's topology on Linux),workers_spread_cpusand theBaseProcExecutorbranch inhos_thread_pin. Also:gpu/vk/switches.def(the row),docs/dev/reference/switches.md,docs/dev/reference/threads.md, andtests/test_workers_spread.py(new).Testing
Tested: Windows 11, Ryzen 7 5700X3D (8 cores, 16 threads), RX 9070 XT, AMD 26.11.2; this PR's build over main
0e32bc10's (exe
acc663cc...6b33b3).switch beat every control.
running threads: all six
BaseProcExecutor0-5at0x1555in every reading of every switch-on run (7 game starts),0x3fffin every control. By thread kind (58-60 a run) the switch-on runs differ from main only in the six workers.same masks) and no log line; game-free, unset,
0andoffmake exactly main's affinity calls.start to end, 3 rounds a side in Lost Woods: frames over 40 ms 0/0/0 with the switch, 0/0/0 without (bar: off + 1). With
the switch on the worst frame was 2-3 ms higher in 2 of 3 rounds (the worker on the held processor waits out a burst);
fps held (89.1-91.0 on, 80.6-83.9 off).
p99 -0.4 ms, worst -5 ms. One pair can't tell -1.8 % from noise (a pair below where both arms make the same calls
differs by 1.6 %): no sign of harm where the render thread holds the frame, but not proof of none.
--affinity 0x00ff(4 cores, one reserved: 3 whole) and0x5555(no core with both halves)log why and leave every thread where main has it.
tests/test_workers_spread.py(clang and gcc): the real choice over topologies (this PC, masks0x5555,0x00ff, a half core, 6/7/8/16 cores, two L3 groups with the cache cores, no SMT, Intel hybrid with and without itsclasses, Zen 5 + Zen 5c, more than 32 processors); the wiring through the real
hos_thread_pin(unset/0/off = main'sten calls;
=1sets the six workers only;HOS_PINstill wins); where the compiler haswindows.h, the realworker_coresover a fakeGetLogicalProcessorInformationExwriting Windows' 48-byte records (masks above bit 31,classes, two processor groups). 17 broken variants, each failing. The test fails on main (no
pick_worker_cpus).run_all.py --jobs 4): the branch 887 passed / 15 failed / 56 skipped, main0e32bc10885 / 16 / 56; everybranch failure fails on main too.
host/hos_thread.ccompiles whole with MSVC-target clang, llvm-mingw (the same 33warnings as main's file, none in the new code), and on Linux (
linux_syntax.sh, clang and gcc).mise run lint: onlymain's shellcheck SC2016 on
.forgejo/workflows/build-windows.yml:82.Still to test:
build,
HOS_WORKERS_SPREAD=1against unset, Lost Woods and Hyrule Field, uncapped, 3 starts a cell, expecting fps upor level and p99 no worse (@Beanstalk).
(@Beanstalk).
RX_VK_RECORDER_PIN=nexttogether withthis, #838's real case (a service's thread holding a worker's core), sessions past ~75 s, area changes, full screen
(by hand).
Measurements
Verdict: +4.6 % fps and -2.3 ms CPU a frame in Lost Woods on this PC, 3 pairs (std_test: "diagnostic", under 5 % with
3 pairs); every switch-on run above every control; stutter unchanged. Off by default.
Setup: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2. Lost Woods as child (the profile save, then the teleport),
fast rotation, 16:9 1280x720 window,
RX_VK_ASYNC=1, frame rate unlocked (HOS_FPS_MAX=240), the fixed test profile anda fixed light GPU load beside the game, 20 s window, 3 alternating pairs, no warm-ups, none rejected, medians. Main's
longshot.exeb658e14b...; this PR'sacc663cc...6b33b3(fromcee7013f; the later commits change the test only),with
HOS_WORKERS_SPREAD=1.0e32bc1004fd9a57,HOS_WORKERS_SPREAD=10x3fff0x1555Pairs: +4.8 %, +6.4 %, +3.1 %. GPU ms a frame is the same in both arms (4.20 / 4.25).
Risks
set keeps one spare core. Measured with one held processor (above); two held processors and #838's real service were
not run.
RX_VK_RECORDER_PIN=nextshares a core with the set.0make main's affinity calls exactly (tested),with no topology read and no log line. No saves, options or shader caches change (
switches.defis not a stampedfile).
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.🤖 Generated with Claude Code
Tested in game: Windows 11, Ryzen 7 5700X3D (8C/16T), RX 9070 XT, AMD 26.11.2. Lost Woods (child), the standard test: 3 alternating pairs, frame rate unlocked (HOS_FPS_MAX=240), RX_VK_ASYNC=1, main
0e32bc10against this PR's build (exe acc663cc...6b33b3) with HOS_WORKERS_SPREAD=1: 86.04 -> 89.99 fps (median, +4.6 %, diagnostic under 5 %), CPU 55.64 -> 53.37 ms a frame, p99 14.50 -> 14.08 ms, every switch-on run above every control, 0 frames over 50 ms, clock 1.000. The six BaseProcExecutor threads read 0x1555 in every live reading of every switch-on run; every other thread kept main's mask; unset = main's masks and no log line. Stall test (one worker processor held 35 ms in every 250 ms at priority 15): 0 frames over 40 ms on both sides. Hyrule Field one pair: -1.8 % (no sign of harm, not proof). Declines logged under --affinity 0x00ff and 0x5555. No error lines. Not run: other CPUs, Linux, hybrid Intel, RX_VK_RECORDER_PIN=next together with it.@Beanstalk the PR's own build only, its switch against itself: baseline ref = pr, [matrix.pr_only] HOS_WORKERS_SPREAD = ["1"] against unset (unset is main's placement), judged 1 against unset on the pr side. It is a runtime switch (read at start), so one build serves both sides. 3 game starts a cell.
What it does: with it on, the game's six job workers (BaseProcExecutor*) get one logical processor of each whole core the game may use, so no two share an SMT core. It acts only on SMT CPUs with more than 6 whole cores beside the render thread's reserved one, and declines (logged) elsewhere.
Targets, 1-2 reports each, by model; don't let the plan wait on any one:
No Steam Deck (4 cores: it declines there by design).
Settings: frame_rate_cap = 6 (Uncapped), vsync = 2 (Off), frame_generation = 0; headless is fine (nothing in the present path changes).
Scenes, in one start: Lost Woods as child Link (from the save kokiri-start, teleport destination 5) measured 30 s, our standard scene, where the workers hold the frame; then Hyrule Field (HyruleField_Child) measured 30 s. Compare rules, pr side, =1 vs unset, per scene: fps_mean min_delta_pct = 3 (fail on a loss of more than 3 %), frametime_p99_ms max_delta_pct = 10; crash = false. Hitch counts (run_hitch_count, run_frametime_max_ms) report-only.
Log on the =1 cells: "threads: HOS_WORKERS_SPREAD=1: the job workers (BaseProcExecutor*) on logical processors" expected on the 8-core, 12-core and Linux targets; on the 6-core target expect "threads: HOS_WORKERS_SPREAD=1 does nothing here" instead (that cell compares the same placement twice: please show the line). Unset cells: neither line.
Beanstalk test farm · an earlier run: commit
04fd9a5(the newer results are in a comment below)Commit
04fd9a5· approved by klimovich008 (reviewed) · dashboardStarted at 12:27 UTC.
Estimate: done in about 50 min, from the queue and the testers online now.
anyWhat was tested
What will be tested · default plan (AI failed: the plan was refused: pass.compare[0].against must be one of HOS_WORKERS_SPREAD's values (1))
The AI plan failed: the plan was refused: pass.compare[0].against must be one of HOS_WORKERS_SPREAD's values (1); using the default plan.
kokiri-start, then teleport to Hyrule Field, measure field for 60 s (after 10 s warm-up); 2 runs on each side.@Beanstalk plan (the first plan was refused: 'against' must be one of the switch's values, so 0 is the off side; 0 is exactly unset, main's placement): the PR's own build only, its switch against itself: baseline ref = pr, [matrix.pr_only] HOS_WORKERS_SPREAD = ["0", "1"], and pass.compare HOS_WORKERS_SPREAD = "1" against "0" on the pr side. It is a runtime switch (read at start), so one build serves both sides. 3 game starts a cell.
What it does: with it on, the game's six job workers (BaseProcExecutor*) get one logical processor of each whole core the game may use, so no two share an SMT core. It acts only on SMT CPUs with more than 6 whole cores beside the render thread's reserved one, and declines (logged) elsewhere.
Targets, 1-2 reports each, by model; don't let the plan wait on any one:
No Steam Deck (4 cores: it declines there by design).
Settings: frame_rate_cap = 6 (Uncapped), vsync = 2 (Off), frame_generation = 0; headless is fine (nothing in the present path changes).
Scenes, in one start: Lost Woods as child Link (from the save kokiri-start, teleport destination 5) measured 30 s, our standard scene, where the workers hold the frame; then Hyrule Field (HyruleField_Child) measured 30 s. Compare rules, pr side, =1 vs =0, per scene: fps_mean min_delta_pct = 3 (fail on a loss of more than 3 %), frametime_p99_ms max_delta_pct = 10; crash = false. Hitch counts (run_hitch_count, run_frametime_max_ms) report-only.
Log on the =1 cells: "threads: HOS_WORKERS_SPREAD=1: the job workers (BaseProcExecutor*) on logical processors" expected on the 8-core, 12-core and Linux targets; on the 6-core target expect "threads: HOS_WORKERS_SPREAD=1 does nothing here" instead (that cell compares the same placement twice: please show the line). =0 cells: neither line.
Beanstalk test farm · 🔄 testing (6 of 5 reports so far)
Commit
04fd9a5· approved by klimovich008 (reviewed) · dashboard⚠️ Note: Two runs per cell are used rather than the requested three to stay within the farm's 60-minute limit; this reduces confidence in small performance differences.
⚠️ Note: The schema cannot restrict expected log lines by target and switch cell, so the placement and decline messages are not judged; on the six-core target both cells should use the same placement.
⚠️ Note: The Linux target cannot enforce SMT or an eight-core minimum, and the farm cannot verify live worker affinity masks or reproduce the background-thread stall test.
Started at 2026-11-23 12:27 UTC. Run 2: re-planned by klimovich008.
⚠ No tester has a PC for
windows+cpu-i7-10700_i7-10700k_i7-11700k_i9-9900_i9-9900k(none seen in 14 days): it waits until one signs in.windows+cpu-5700x_5800x_7700_7700x(CPU "5700x" or "5800x" or "7700" or "7700x")windows+cpu-i7-10700_i7-10700k_i7-11700k_i9-9900_i9-9900k(CPU "i7 10700" or "i7 10700k" or "i7 11700k" or "i9 9900" or "i9 9900k")windows+cpu-3900x_5900x_7900_7900x(CPU "3900x" or "5900x" or "7900" or "7900x")windows+cpu-3600_5600_5600x_7600_7600x_i5-10400_i5-11400_i7-8700k(CPU "3600" or "5600" or "5600x" or "7600" or "7600x" or "i5 10400" or "i5 11400" or "i7 8700k")linuxwoods-and-field· frame time p99 (ms)HOS_WORKERS_SPREAD=0(reference)HOS_WORKERS_SPREAD=1windows+cpu-5700x_5800x_7700_7700x(CPU "5700x" or "5800x" or "7700" or "7700x")windows+cpu-i7-10700_i7-10700k_i7-11700k_i9-9900_i9-9900k(CPU "i7 10700" or "i7 10700k" or "i7 11700k" or "i9 9900" or "i9 9900k")windows+cpu-3900x_5900x_7900_7900x(CPU "3900x" or "5900x" or "7900" or "7900x")windows+cpu-3600_5600_5600x_7600_7600x_i5-10400_i5-11400_i7-8700k(CPU "3600" or "5600" or "5600x" or "7600" or "7600x" or "i5 10400" or "i5 11400" or "i7 8700k")linuxCouldn't be judged: the tester's PC could not finish the test. The farm tries another PC, or the same one after a fix; it says nothing about the PR on its own.
windows+cpu-5700x_5800x_7700_7700x, report 2:the baseline runtime failed (exit 1): return a.func(a) or 0linux, report 1:the pull request's pack failed (exit 1): build.py stopped (exit status 1): <data>/jobs/jb_81b331689b9a63f6/pack/game-work/sa/build/obj/code_001.split.c:17426:5: error: expected ')'linux, report 2:no scenario could be judged: a step ran out of time at step 2 (wait map LostWood_Child): timeout: not met in time (then the game was in play on KokiriForest_Child)What was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares worker spreading on and off in the PR build on the requested Windows CPU groups and Linux, with uncapped frame rates and frame generation off. Each start measures child Lost Woods and Hyrule Field for 30 seconds apiece; FPS, frame times and run-wide hitches are reported. A crash, an FPS loss over 3%, or a p99 frame-time increase over 10% in either scene fails the comparison. Some requested CPU groups may wait for a matching online tester. No tester online now matches windows+cpu-i7-10700_i7-10700k_i7-11700k_i9-9900_i9-9900k, windows+cpu-3600_5600_5600x_7600_7600x_i5-10400_i5-11400_i7-8700k: those targets wait for one.
HOS_WORKERS_SPREAD) and off; main is not built or run.0or1(PR only).kokiri-start(settings vsync=2, frame_rate_cap=6, frame_generation=0), then teleport to Lost Woods, measure woods for 30 s (after 10 s warm-up), teleport to Hyrule Field, measure field for 30 s (after 10 s warm-up); 2 runs on each side for each of 2 cells (2 game starts a run).Measurements on `windows+cpu-5700x_5800x_7700_7700x`, for the PR description
Verdict: pass on windows+cpu-5700x_5800x_7700_7700x (2 reports): no rule failed and no PR run crashed.
Hardware: 1: windows+amd+amd-proprietary+dgpu
AMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 7 7700 8-Core Processor, 32 GB RAM; 2: windows+amd+amd-proprietary+dgpuAMD Radeon RX 7900 XT, 2.0.416AMD Ryzen 7 5700X 8-Core Processor, 16 GB RAMScene: woods-and-field, from the repository's save kokiri-start (vsync=2, frame_rate_cap=6, frame_generation=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: this PR built once and run with its PR-only switches on and off on the same PC in one session, game starts alternating (ABBA); woods-and-field: 2 game starts a side, woods 30 s after 10 s warm-up, field 30 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)04fd9a5, switch off04fd9a5, switch onHOS_WORKERS_SPREAD=0 (PR only)· field · frame time (p99) (ms)HOS_WORKERS_SPREAD=0 (PR only)· woods · frame time (p99) (ms)HOS_WORKERS_SPREAD=1 (PR only)· field · frame time (p99) (ms)HOS_WORKERS_SPREAD=1 (PR only)· woods · frame time (p99) (ms)Flags and settings
HOS_WORKERS_SPREAD0,1As Markdown for the PR description:
Measurements on `windows+cpu-3900x_5900x_7900_7900x`, for the PR description
Verdict: pass on windows+cpu-3900x_5900x_7900_7900x (2 reports): no rule failed and no PR run crashed.
Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 4070, 621.24.0AMD Ryzen 9 7900X 12-Core Processor, 64 GB RAM; 2: windows+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce RTX 3080 Ti, 621.24.0AMD Ryzen 9 5900X 12-Core Processor, 64 GB RAMScene: woods-and-field, from the repository's save kokiri-start (vsync=2, frame_rate_cap=6, frame_generation=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: this PR built once and run with its PR-only switches on and off on the same PC in one session, game starts alternating (ABBA); woods-and-field: 2 game starts a side, woods 30 s after 10 s warm-up, field 30 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)04fd9a5, switch off04fd9a5, switch onHOS_WORKERS_SPREAD=0 (PR only)· field · frame time (p99) (ms)HOS_WORKERS_SPREAD=0 (PR only)· woods · frame time (p99) (ms)HOS_WORKERS_SPREAD=1 (PR only)· field · frame time (p99) (ms)HOS_WORKERS_SPREAD=1 (PR only)· woods · frame time (p99) (ms)Flags and settings
HOS_WORKERS_SPREAD0,1As Markdown for the PR description:
Measurements on `linux`, for the PR description
Verdict: could not be judged on linux (2 reports).
Hardware: 1: linux+amd+radv+dgpu
AMD Radeon RX 9070 XT (RADV GFX1201), 26.1.99AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAM; 2: linux+amd+radv+igpuAMD Radeon 890M Graphics (RADV STRIX1), 26.1.99AMD Ryzen Z2 Extreme, 32 GB RAMScene: woods-and-field, from the repository's save kokiri-start (vsync=2, frame_rate_cap=6, frame_generation=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: this PR built once and run with its PR-only switches on and off on the same PC in one session, game starts alternating (ABBA); woods-and-field: 2 game starts a side, woods 30 s after 10 s warm-up, field 30 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)Nothing was measured: no metric came back.
Flags and settings
HOS_WORKERS_SPREAD0,1As Markdown for the PR description:
The testers' hardware
windows+cpu-5700x_5800x_7700_7700xAMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 7 7700 8-Core Processor, 32 GB RAMwindows+cpu-5700x_5800x_7700_7700xAMD Radeon RX 7900 XT, 2.0.416AMD Ryzen 7 5700X 8-Core Processor, 16 GB RAMwindows+cpu-3900x_5900x_7900_7900xNVIDIA GeForce RTX 4070, 621.24.0AMD Ryzen 9 7900X 12-Core Processor, 64 GB RAMwindows+cpu-3900x_5900x_7900_7900xNVIDIA GeForce RTX 3080 Ti, 621.24.0AMD Ryzen 9 5900X 12-Core Processor, 64 GB RAMlinuxAMD Radeon RX 9070 XT (RADV GFX1201), 26.1.99AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAMlinuxAMD Radeon 890M Graphics (RADV STRIX1), 26.1.99AMD Ryzen Z2 Extreme, 32 GB RAMTwo of this round's Linux reports couldn't be judged, and neither is this PR's code:
=0and=1), one start each. The PR's pack built and started fine there (warm, lift 105 s, compile 1,626 s). The teleport from the savekokiri-startto Lost Woods was asked for but the game stayed in Kokiri Forest, on the switch-off side as much as the switch-on side. The same step timed out today on #2355's i5-12400 report rp_0629753247797734 on main's side as well as the PR's, and once on #2240's rp_3a2353eac6aa882a (wait map HyruleField_Child, one start of six). So it looks like the farm's teleport step not taking right after the save loads, not something a build does. Could the farm's owners retry the teleport (or wait for play before sending it) when the wait times out?code_001.split.c:17426:5: error: expected ')'(the giant-function splitter's output,nx2/split_giants.py). This PR changeshost/hos_thread.c, docs,switches.defand a test only, nothing innx2/or the lift's inputs, and the same commit's pack compiled every lifted file and ran on the other Linux tester above. That tester's main base was reused (no main build in this job), so the report can't show main's side; a main-only pack build there would settle whether it's that PC's build or main's.No re-plan from me yet.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.