perf(host): default short sleep timer on Windows integrated GPUs to prevent APU TDP starvation #1114
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
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1114
Loading…
Reference in a new issue
No description provided.
Delete branch "Jer9/Longshot:perf/apu-sleep-timer"
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?
Type: perf · Risk: low · Tested on: Windows 11, AMD Ryzen AI 7 350 / Radeon 860M (2x2 interleaved A/B in ZoraDomain_Child + game-free C/Python checks) · Needs: Windows discrete GPU (> 6 threads); Linux, any GPU
Why
On multi-threaded Windows APUs (such as an 8-core / 16-thread AMD Ryzen AI 7 350 with Radeon 860M graphics),
process_threads() > 6causedhost/hos_thread.cto leavehow = 0and setpoll_cap = threads / 4 = 4(from https://git.notrexed.dev/Hookshot/Hookshot/pulls/2709) whenHOS_SHORT_SLEEP_TIMERis unset. OoT's idle guest job workers call 20 us sleeps thousands of times a second and spin inSwitchToThread()/YieldProcessor()loops across up to 4 CPU cores.Because a mobile APU shares one package TDP between CPU cores and the integrated GPU, those 4 spinning pollers burn package power and throttle iGPU clocks. On Linux, https://git.notrexed.dev/Hookshot/Hookshot/pulls/2637 already defaulted
how = 1across all processor counts because OoT's idle job workers are not on the frame's critical path. Scoping the Windowshow = 1default strictly to integrated GPUs (VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) lets guest short sleeps block onCreateWaitableTimerExWhigh-resolution timers and returns socket power headroom to the iGPU while keeping Windows discrete-GPU desktops completely unchanged on https://git.notrexed.dev/Hookshot/Hookshot/pulls/2709's processor threshold andHOS_SHORT_SLEEP_POLLERScap. See #1040.What changed
Adds an integrated-GPU query option (
HOS_OPT_INTEGRATED_GPU = 62) on the existing renderer option callback sosleep_ns()inhost/hos_thread.cdefaultshow = 1on Windows only when the chosen Vulkan physical device isVK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, leaving discrete GPUs untouched.gpu/vk/vk_api.hdefinesHOS_OPT_INTEGRATED_GPU = 62(answered by the existingoptioncallback, soMkwVkHost,MkwVkRenderer, andMKWVK_API_VERSIONare unchanged).gpu/vk/vk_replay.cppanswersid == HOS_OPT_INTEGRATED_GPUinfill_replay_table()'st.optionlambda withdev.props.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU(populated duringrx_initbeforennMainor guest short sleeps start).host/hos_thread.cdeclaresint rx_option(int id, int otherwise);, updates#else(Windows) insleep_ns()to sethow = 1when!getenv("HOS_SHORT_SLEEP_TIMER") && rx_option(62, 0), and updates the comments abovehos_short_sleep_timer()and insidesleep_ns()to document the unset defaults across platforms, explicit=0/=1(cap = 0), andsead::MainThread's 3.3–3.6 ms/frame readback yields. Discrete GPUs (rx_option(62, 0) == 0) continue usinghos_short_sleep_timer()andHOS_SHORT_SLEEP_POLLERS.docs/development.mdaddsHOS_SHORT_SLEEP_TIMER=0|1,HOS_SHORT_SLEEP_POLLERS=<n>to### Running a test;docs/tested/2026-11-16-short-sleep-igpu-jer9-old.mdanddocs/tested/2026-11-16-short-sleep-igpu-jer9-new.mdrecord the 2x2 interleaved A/B runs on Windows 11 / Radeon 860M.tests/test_short_sleep_timer.pydrops the duplicate pure-Python file (tests/test_short_sleep_default.pyis removed), folds theHOS_OPT_INTEGRATED_GPU = 62wiring checks againstgpu/vk/vk_api.handgpu/vk/vk_replay.cpp(t.option) directly intotest_short_sleep_timer.py, stubsrx_option(62, 0)in its C fixture, addsigpu = 1cases while preserving allmaindiscrete-GPU cases, and addsigpu-ignored/dgpu-forcedmutant checks.Measurements
Verdict: Helps significantly on Windows multi-threaded APUs with
HOS_SHORT_SLEEP_TIMERunset: across 2 interleaved compiled-binary A/B pairs inZoraDomain_Child, Locked-View wall FPS improved +15.3% (24.32 -> 28.05 fps), settled log FPS improved +13.8% (25.0 -> 28.45 fps), GPU frame time dropped -22.3% (28.3 -> 22.0 ms), and > 40 ms present intervals fell from32–76to3–4per 5 s window with0texture budget evictions and0device losses. Auto-detection (how = 1after Vulkan init) confirmed inlongshot_log.txt.Hardware: Windows 11 (build 26200), AMD Radeon(TM) 860M Graphics (integrated, 1002:1114, 8 CUs, RDNA 3.5, 12855 MB video memory), AMD proprietary driver 26.10.1 (LLPC), AMD Ryzen AI 7 350 (8c/16t, znver5), 32 GB RAM (26277 MB usable, 6 GB Variable Graphics Memory)
Scene:
ZoraDomain_Child,1920x1080offscreen (scene1728x1080, picture2304x1440), Quality preset Minimum, Handheld profile (handheld_profile=1), game's own upscaler (upscaling=0),threaded_rendering=0,RX_VK_COMMIT_RESERVE_MB=512,RX_VK_ASTC_CPU=1,RX_VK_VRAM_MB=8192,HOS_SHORT_SLEEP_TIMERunset; stationary Locked View atpos=[4.61, 103.88, -36.14],cam=7.6(1,840-1,855draws/frame)Method: Built both arms locally with
nx2/build.py --standalone --kept-lift(llvm-mingw clang 23,RX_RELEASE=1;0_main&2_mainbuilt frommainsource013b1d3a;1_pr&3_prbuilt from the Option B patcha9f9d4bd, committed cleanly as3dde802). Ran 2 interleaved pairs (0_main,1_pr,2_main,3_pr) viascripts/longshot_ctl.py --profile test --repo-save kokiri-start:teleport 13 --arrive 60,wait in_play, 180-present warm-up, then 360-present measured Locked View; per-run medians taken from the final three0.0 uploads120-present windows alongside wall clock360 / elapsed_s.How to reproduce:
python -I scripts/longshot_ctl.py --run <dir> launch <GAME_DIR> --profile test --repo-save kokiri-start --repo . --env RX_VK_COMMIT_RESERVE_MB=512 --env RX_VK_ASTC_CPU=1 --env RX_VK_VRAM_MB=8192,teleport 13 --arrive 60,wait in_play,wait present --frames 180,wait present --frames 360bbe421f3dde80223.55,25.09fps (24.32 fps)27.76,28.34fps (28.05 fps)24.8,25.2fps (25.0 fps)28.0,28.9fps (28.45 fps)28.7,27.9ms (28.3 ms)22.5,21.5ms (22.0 ms)56, 76/51, 324, 4/3, 3HOS_SHORT_SLEEP_TIMERunset)how = 0, cap = 4(max 4 pollers)how = 1, cap = 0(guest timer, host yield)0/ none0/ none(Earlier single-run
v3.0.0-rc.5switch exploration on top ofRX_VK_PASS_BARRIER=gamewithHOS_SHORT_SLEEP_TIMER=1(how = 2) showed consistent behavior in the same scene:24.10 -> 30.42 fpswall FPS,28.5 -> 19.3 msGPU time.)0_main(main@bbe421f, source013b1d3a,HOS_SHORT_SLEEP_TIMERunset;rx: rendererline 55,sleep:line 80):1_pr(this PR, sourcea9f9d4bd,HOS_SHORT_SLEEP_TIMERunset;rx: rendererline 55,sleep:line 80):2_main(main@bbe421f, source013b1d3a,HOS_SHORT_SLEEP_TIMERunset):3_pr(this PR, sourcea9f9d4bd,HOS_SHORT_SLEEP_TIMERunset):Flags and settings
No new switch added; narrows the existing unset
HOS_SHORT_SLEEP_TIMERdefault on Windows to integrated GPUs while keeping discrete GPUs onmain's behavior, and addsHOS_SHORT_SLEEP_TIMER/HOS_SHORT_SLEEP_POLLERStodocs/development.md.HOS_SHORT_SLEEP_TIMER0(yield all),1(guest on timer, host yields),2(all on timer)0on Windows with > 6 threads (cap = threads / 4),1on Linux1on Windows integrated GPUs (rx_option(62, 0)),0on Windows discrete GPUs (> 6 threads),1on Linuxhow = 1); host sleeps keep precision yield+15.3%FPS,-22.3%GPU ms on Radeon 860M); Windows dGPU kept unchanged (untested on hardware here)how = 1) by default for Windows iGPUsTesting
Tested:
842dedbfails as expected onmain(bbe421f); on3dde802python -I -B tests/test_short_sleep_timer.py --cc gcc(PASS),python -I -B tests/test_short_sleep_timer.py --cc clang(PASS),python -I -B tests/test_option_ids.py(PASS),python -I -B tests/test_doc_anchors.py(PASS),python -I -B tests/test_utf8_paths.py(PASS),python -I -B tests/test_spin_by_role.py(PASS),python -I -B tests/test_tested_configurations.py Repository(PASS), andpython -I -B tests/run_all.py --exact tests/byte_compile_tracked.py tests/test_check_pr_description.py(2 passed, 0 failed).nx2/build.py --standalone --kept-lift, llvm-mingw clang 23) + 2x2 interleaved A/B benchmark inZoraDomain_Child(longshot_ctl.py --profile test,HOS_SHORT_SLEEP_TIMERunset).python -I -B tests/run_all.py --changedon3dde802(131 passed, 8 failed, 4 skippedwithLONGSHOT_MINGW&RX_CPM, all 8 failures pre-existing Windows /mainfixture drift:tests/test_crash_dialog.py,tests/test_fsr_uniform_ownership.py,tests/test_longshot_ctl.py,tests/test_pads_after_menu.py,tests/test_parallel_init_order.py,tests/test_replay_write_order.py,tests/test_vk_occlusion_queries.py,tests/test_walk_key.py), plus fullpython -I -B tests/run_all.pyon the identical C/C++ implementation prior to droppingtest_short_sleep_default.pyand updating comments/docs/development.md(592 passed, 21 failed, 51 skippedwithoutzstandard/dotnet/glslang/spirv-val, all 21 failures pre-existing Windows /mainfixture drift unrelated to this PR:tests/test_auto_handheld.py,tests/test_bug_report_defaults.py,tests/test_crash_dialog.py,tests/test_crt_options.py,tests/test_fsr_uniform_ownership.py,tests/test_guest_imported.py,tests/test_import_reach.py,tests/test_linux_preflight.py,tests/test_longshot_ctl.py,tests/test_make_game_cache.py,tests/test_missing_nup.py,tests/test_pads_after_menu.py,tests/test_parallel_init_order.py,tests/test_pending_guest_import.py,tests/test_release.py,tests/test_replay_write_order.py,tests/test_run_all_changed.py,tests/test_srccut.py,tests/test_tested_configurations.py(CRLF pipe check only;Repositorypasses),tests/test_vk_occlusion_queries.py,tests/test_walk_key.py).Not tested:
dev.props.deviceType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU).tests/run_all.py(spirv-val,glslang, POSIX tests).Must be tested:
HOS_SHORT_SLEEP_TIMERunset and inspectlongshot_log.txt, expectingsleep: at most N of the game's threads yield through a short sleep at a time(unchanged frommain, e.g.4on 16 threads) and identical FPS (Test Farm:@Beanstalk windows, or by hand on any dGPU desktop)python -I -B tests/test_short_sleep_timer.pyandpython -I -B tests/run_all.pywithgccandclang, expecting all short-sleep and host checks to pass cleanly (Test Farm:@Beanstalk linux)Risks
What could break: On older Windows builds lacking
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION(prior to Windows 10 1803),sleep_ns()falls back toSwitchToThread()yielding as before. On systems where an integrated GPU reportsVK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, unsetHOS_SHORT_SLEEP_TIMERswitches guest short sleeps to the high-resolution timer (how = 1). Discrete GPUs (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) do not enter this path.Turning it off: Set
HOS_SHORT_SLEEP_TIMER=0inlongshot_env.txtor revert commit3dde802.Compatibility: Nothing changes for saves,
longshot_options.ini, shader/pipeline caches, orMKWVK_API_VERSION(addingHOS_OPT_INTEGRATED_GPU = 62to the existing option callback does not changeMkwVkHostorMkwVkRenderer).Issues
See #1040
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).mainand passing here.tests/that reads changed source updated in this PR, not weakened.Tested in game: Windows 11, AMD Radeon 860M, Adrenalin 26.10.1: ZoraDomain_Child locked view on v3.0.0-rc.5 (+22% FPS, -31.3% GPU frame time); game-free tests pass on branch
Small, easy-to-revert change, and the APU TDP story is believable. A few things before it becomes the default for every Windows desktop:
how = 1, so this only changes PCs with 7+ logical processors, which is nearly every desktop. The evidence is one APU, measuringHOS_SHORT_SLEEP_TIMER=1(how = 2, not thehow = 1shipped). Those are single runs on rc.5, withRX_VK_PASS_BARRIER=gameonly on the "after" side.how = 1their short sleeps go to the Windows timer, about 0.5 ms late (line 1104), on the frame's critical path. The Linux evidence doesn't carry over, because the shim waits withclock_nanosleep(win32_posix.c:530). YourPOLLERS=1column was the fastest, so a lower cap, or the timer with the serial threads still yielding, may keep the win with less risk.=0now gets the cap).HOS_SHORT_SLEEP_TIMERalso has no docs/development.md row, and this is a good time to add one.test_short_sleep_default.pycopieshos_short_sleep_pollersinto Python (453-464) instead of reading it.test_short_sleep_timer.pyalready compiles the real code, so I'd drop it.This is from reading the code only: nothing was built or run.
🤖 Generated with Claude Code
@ -1191,1 +1184,4 @@the host's still yield (how = 1). On multi-threaded Windows APUs, spinning idle worker pollers starvethe integrated GPU of package TDP; on Linux (#2602), OoT's idle job workers yielded ~9 ms of CPU a framewithout being on the critical path. HOS_SHORT_SLEEP_TIMER=0: all yield, as before; =1: all on the timer */if (!getenv("HOS_SHORT_SLEEP_TIMER")) how = 1;With
how = 1,short_timer < (guest ? 1 : 2)is false for every guest sleep, so sead::MainThread and the Presentation Thread go to the timer as well. On main above 6 threads they always yield (!hos_thread_serial(hos_self())at 1205). The removed Linux comment notes that MainThread itself makes these short sleeps. On Windows that is about 0.5 ms late per wake (line 1104). On Linux it isclock_nanosleep(host/posix/win32_posix.c:530), so the Linux result doesn't tell us much here. Could the serial threads keep yielding underhow = 1?@ -1198,7 +1193,7 @@ static void sleep_ns(int64_t ns, int guest) {"(%d logical processors, 0: not counted; HOS_SHORT_SLEEP_TIMER=0: all yield)",how == 2 ? "all" : "the game's", threads);/* (HOS_SHORT_SLEEP_TIMER set says how all short sleeps wait: no limit then) */This comment is stale now: an explicit
HOS_SHORT_SLEEP_TIMER=0gets the poller cap. The same goes for the log line's "HOS_SHORT_SLEEP_TIMER=0: all yield" just above, and forhos_short_sleep_timer's comment (1103-1114), which still describes the unset default by processor count.@ -0,0 +450,4 @@"SHORT_SLEEP_TIMER_THREADS": short_sleep_timer_threads,}))# Fallback for hos_short_sleep_pollersif "strtol" in body:This fallback is a Python copy of
hos_short_sleep_pollers, not the source. If the C changes, this keeps passing.tests/test_short_sleep_timer.pyalready compiles the realsleep_ns/ choice / pollers and covers these cases, so I'd drop this file rather than maintain a 560-line C evaluator.2b34e076c2e2011b2761Switched to Option B (scoping the Windows how = 1 default to integrated GPUs via HOS_OPT_INTEGRATED_GPU = 62 so discrete-GPU desktops keep #2709's processor rule and HOS_SHORT_SLEEP_POLLERS), added 2x2 interleaved compiled-binary A/B measurements on Ryzen AI 7 350 / Radeon 860M (+15.3% wall FPS, -22.3% GPU frame time), and added docs/tested/ fragments.
WIP: perf(host): default short sleep timer on Windows to prevent APU TDP starvationto perf(host): default short sleep timer on Windows to prevent APU TDP starvationperf(host): default short sleep timer on Windows to prevent APU TDP starvationto perf(host): default short sleep timer on Windows integrated GPUs to prevent APU TDP starvatione2011b27613dde802f47Rebuilt
perf/apu-sleep-timercleanly ontobbe421f(842dedbtest failing onmain->3dde802fix passing) and addressed all four points from @dyst's review:HOS_OPT_INTEGRATED_GPU = 62ingpu/vk/vk_api.handgpu/vk/vk_replay.cpp), scoping the unsetHOS_SHORT_SLEEP_TIMERhow = 1default on Windows strictly toVK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU. Windows discrete GPUs (> 6logical processors) remain unchanged onmain's processor threshold andHOS_SHORT_SLEEP_POLLERScap. The PR description replaces the earlier single-run rc.5 numbers with a 2x2 interleaved compiled-binary A/B inZoraDomain_Child(HOS_SHORT_SLEEP_TIMERunset, testing the shippedhow = 1path directly with identical settings on both arms):+15.3%Locked-View wall FPS (24.32 -> 28.05 fps),+13.8%settled log FPS (25.0 -> 28.45 fps),-22.3%GPU frame time (28.3 -> 22.0 ms), and> 40 mspresent intervals down from32–76to3–4.how = 1: In ourv3.0.0-rc.5single-run sweep (both stacked onRX_VK_PASS_BARRIER=game+RX_VK_READBACK_LATE=newest),HOS_SHORT_SLEEP_POLLERS=1(how = 0, cap = 1, where serial threads stay exempt and yield) gave33.39Locked-View FPS vs32.93withHOS_SHORT_SLEEP_TIMER=1(how = 2), but had higher GPU frame time (24.58 msvs21.35 ms) and lower tail average FPS (26.43vs28.73 fps). As noted inhost/hos_thread.c:1194(and1204-1206),sead::MainThreaditself yields 3.3–3.6 ms/frame while waiting on GPU readbacks; letting serial threads keep yielding on an integrated GPU leavesMainThreadburning a core out of the shared APU package TDP during readbacks. Underhow = 1, host short sleeps (hos_sleep_nswithguest = 0: frame limiter, audio renderer) still satisfyshort_timer < 2(host/hos_thread.c:1225) and continue to yield.main'sconst int cap = how || getenv("HOS_SHORT_SLEEP_TIMER") ? 0 : ...(host/hos_thread.c:1217), so explicitHOS_SHORT_SLEEP_TIMER=0keepscap = 0(all yield) matching the log line. Updated the comments abovehos_short_sleep_timer()(1104-1120), insidesleep_ns()(1181-1185), and in the Windows#elsebranch (1202-1206), and added theHOS_SHORT_SLEEP_TIMER=0|1,HOS_SHORT_SLEEP_POLLERS=<n>row todocs/development.md(### Running a test).test_short_sleep_default.py: Removedtests/test_short_sleep_default.pyand folded theHOS_OPT_INTEGRATED_GPU = 62wiring checks (gpu/vk/vk_api.handgpu/vk/vk_replay.cppt.option) directly intotests/test_short_sleep_timer.pyalongside the C fixture'srx_option(62, 0)stub andigpu-ignored/dgpu-forcedmutant checks (--cc gccand--cc clangboth pass).@Beanstalk
Beanstalk test farm
Commit
3dde802· tier reviewed · approved by HumanBean · dashboardWhat will be tested · AI plan (
gpt-6.1-terra)Windows integrated and discrete GPUs and a Linux PC will compare main and the PR in Zora’s Domain, using the reported Minimum preset. Two alternating runs per side take about 22 minutes per tester and measure frame times, FPS, GPU time and CPU use, with a scene screenshot. Crashes, device loss, major performance regressions or a significant visual difference fail the plan; a Windows integrated-GPU report may wait for a matching volunteer. No tester online now matches windows+igpu: that target waits for one.
kokiri-start(settings quality_preset=1, handheld_profile=1), then teleport to Zora's Domain, measure domain for 30 s (after 10 s warm-up), take the picture domain-view to compare with main; 2 runs on each side.Started.
Code-and-evidence re-review of exact head
3dde802f4770648d1af92db52c757b0c4e4ead89. No tests, builds or gameplay run for this review.No blocking code finding. The current branch addresses the scope and evidence concerns in dyst's earlier review: the extra unset-default override is Windows-only and conditional on the selected Vulkan device being integrated. Explicit HOS_SHORT_SLEEP_TIMER values retain precedence, discrete GPUs retain the processor/poller rule, and the Linux branch keeps its existing behavior. The existing option callback carries the new query without changing the callback structures. Host short sleeps continue through the
short_timer < (guest ? 1 : 2)distinction; this is not the former blanket timer-for-all-sleeps proposal.The changed test compiles the real sleep path with timer/yield/option stand-ins, retains discrete-GPU and explicit-setting cases, and adds integrated-GPU cases and mutations that reject ignoring detection or forcing the discrete path onto the timer. That is materially stronger evidence than the superseded copied Python decision. It does not measure real timer latency, package power, driver classification or startup on another machine. The reported APU evidence now uses two interleaved pairs of the shipped unset-default path; it supports the claim on that measured setup, not every Windows iGPU.
Remaining readiness: the description's required Windows discrete-GPU and Linux runs have not reported results yet, and current CI checks are pending. HumanBean already authorized this exact head on the farm, which currently has Windows discrete-GPU and Linux jobs running and a Windows iGPU job queued. No duplicate request or restart is needed. Keep HOS_SHORT_SLEEP_TIMER unset in those comparisons and verify the actual selected GPU and sleep-policy log, especially on hybrid systems.
Verdict: code looks ready; merge approval deferred until the required non-regression results and CI are available. This comment does not claim a personal hardware pass.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.