fix(profile): the driver's GPU fence wait counts as blocked in perf.py cpu, not as CPU time #1917
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!1917
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:fix/profile-gpu-fence-wait"
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
scripts/perf.py cpuleaves a sample out of CPU time when its leaf is a system call that waits(
BLOCKING_SYSCALLSinscripts/profiling/cpu_categories.py). The renderer's waits on a GPU fence (vkWaitSemaphores,vkWaitForFences) end in the driver'sNtGdiDdDDIWaitForSynchronizationObjectFromCpuinwin32u.dll, which the listdid not name, so a Windows profile counted that wait as the system's CPU time and made a GPU wait look like CPU work.
This PR adds
GdiDdDDIWaitForSynchronizationObjectto the list (it matches the...FromCpuform too).To see it on
main: copy this branch'stests/test_cpu_report.pyontomainand runpython -I -B tests/test_cpu_report.py(its synthetic capture has a thread waiting on a GPU fence).Read first:
BLOCKING_SYSCALLSinscripts/profiling/cpu_categories.py; theGpuWaitersamples and checks intests/test_cpu_report.py.Testing
Tested: Windows 11, i7-9700, Python 3.14.7 (the Builder's), each run in a hidden console of its own in one build job
of the PC's job queue:
python -I -B tests/test_cpu_blocked_waits.pyat the first commit (fff3cd1c, the test withmain's list): fails,the two fence-wait leaves counted as CPU time; with the fix (
04ac0868): passes. That test rebuilt the report's rulefrom the two patterns instead of running the report, so BeanBot's review asked for the check to go through the report:
since
ba2d9e37it is intests/test_cpu_report.pyand the old test is gone.python -I -B tests/test_cpu_report.py(perf.py cpuon a synthetic capture: aGpuWaiterthread with the fencewait under the renderer's
take_captureand aNtGdiDdDDISubmitCommandToHwQueuebeside it), one build job: onmain@
8859673ewith this branch's test file it fails (the wait is not under Blocked, the thread is on the CPU 50 % of acore instead of 25 %,
render/capture50 % instead of 25 %); @ba2d9e37it passes.tests/run_all.py --strict --changed origin/main) @ba2d9e37:test_cpu_reportand the byte-compile pass.No game run: the change is in a profile reader, which the game does not run.
Still to test:
python -I scripts/perf.py cpuon aHOS_PROFILE=1capture of this PC withmain's script andwith this branch's, expecting the render side's fence wait under Blocked instead of in the system's CPU time (by hand)
tests/run_all.py --strict) here and onmain@8859673e, expecting nofailure here that
maindoes not have (by hand, queued)Measurements
Verdict: the GPU fence wait is a blocked sample in
perf.py cpu's report: the report's test that fails onmainpasses here, and a submit beside it stays CPU time.
Setup: Windows 11, i7-9700, Python 3.14.7;
python -I -B tests/test_cpu_report.py(this branch's file on both sides),one run each, through the PC's job queue
8859673e(with this PR's test)ba2d9e37tests/test_cpu_report.pyGpuWaiteron the CPU, % of a coretake_captureRisks
Only
perf.py cpu's report changes: a sample whose leaf is that driver wait moves from the system's CPU time to Blocked.If some driver did CPU work under a function of that name, the report would now count it as waiting. Nothing the game or
its build runs changes; a revert is enough.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (the whole suite is queued: Still to test)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.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.Recommendation: Request changes. The classification change addresses the named fence wait, but its new test duplicates the classifier instead of exercising the report, so it cannot establish that the reported behavior works.
The change moves samples named as Windows GPU fence waits out of reported CPU time and into Blocked, making CPU profiles less misleading. The focused change fits the existing classification scheme, but the regression test needs to cover the actual report path; the planned capture comparison and full suite are also outstanding.
Does it help: Unproven end to end. The author reports that the synthetic test fails for 2 of 9 waits on the base and passes all 9 on the PR, with 5 working calls still classified as CPU time. That test checks the regular expressions directly; the planned comparison using an actual Windows capture has not yet run.
Other systems: The game, renderer, build, saves, audio and input do not run this code. The report applies the new name to matching system-module leaves regardless of GPU vendor or call stack; other Windows driver captures have not been checked. Linux game captures are currently rejected by this report, although the existing Linux syscall patterns are unchanged.
Switches: None.
Reviewed:
04ac086828against8859673e4b: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the PR template, both changed files and both commits in full; read the relevant naming, classification and counting paths in scripts/profiling/cpu.py and tests/test_cpu_report.py. Searched for other consumers and nested AGENTS.md files. docs/review-checklist.md and the adjacent Tooling AGENTS.md were absent. The remainder of the profiling package and developer documentation was not read in full; no generated files or translations changed.; nothing run (a code review).Checked and fine:
Blocking (to change before merge)
Testing: No code or tests were run, as requested. The author reports the changed-file checks passing; the full suite and a real Windows capture comparison are still pending, as are CI and the applicable ready-to-merge checks.
Overlaps and merge order: Not checked: the network is closed and no overlapping pull requests were supplied.
Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.
@ -0,0 +42,4 @@spec.loader.exec_module(cats)block, system = re.compile(cats.BLOCKING_SYSCALLS), re.compile(cats.SYSTEM_MODULES)def blocked(module, symbol): # (as profiling/cpu.py's blocked() decides it)This duplicates the production predicate, so the test still passes if the report stops using it or charges this sample as CPU time. Could the synthetic report fixture include this fence-wait leaf and assert both its Blocked entry and its exclusion from CPU totals, alongside a working-call control?
Pushed
ba2d9e37for BeanBot's review; the description is updated to match.tests/test_cpu_blocked_waits.pyrebuiltblocked()from the two patterns and never ran the report.ba2d9e37moves the check intotests/test_cpu_report.py's synthetic capture: aGpuWaiterthread with the fence wait (NtGdiDdDDIWaitForSynchronizationObjectFromCpu) under the renderer and aNtGdiDdDDISubmitCommandToHwQueuebeside it as the working-call control. It asserts the wait is listed under Blocked and the thread is on the CPU for the submit only (25 % of a core); the old test is removed. Run through this PC's job queue: onmain@8859673ewith this test file it fails (the wait is not under Blocked, the thread shows 50 %); @ba2d9e37it passes, as do the--changedchecks.WIP: fix(profile): the driver's GPU fence wait counts as blocked in perf.py cpu, not as CPU timeto fix(profile): the driver's GPU fence wait counts as blocked in perf.py cpu, not as CPU time