fix(profile): the driver's GPU fence wait counts as blocked in perf.py cpu, not as CPU time #1917

Merged
HumanBean merged 3 commits from siantm/Longshot:fix/profile-gpu-fence-wait into main 2026-11-20 21:13:39 +00:00
Contributor

Summary

scripts/perf.py cpu leaves a sample out of CPU time when its leaf is a system call that waits
(BLOCKING_SYSCALLS in scripts/profiling/cpu_categories.py). The renderer's waits on a GPU fence (vkWaitSemaphores,
vkWaitForFences) end in the driver's NtGdiDdDDIWaitForSynchronizationObjectFromCpu in win32u.dll, which the list
did 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 GdiDdDDIWaitForSynchronizationObject to the list (it matches the ...FromCpu form too).

To see it on main: copy this branch's tests/test_cpu_report.py onto main and run python -I -B tests/test_cpu_report.py (its synthetic capture has a thread waiting on a GPU fence).

Read first: BLOCKING_SYSCALLS in scripts/profiling/cpu_categories.py; the GpuWaiter samples and checks in
tests/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.py at the first commit (fff3cd1c, the test with main's list): fails,
    the two fence-wait leaves counted as CPU time; with the fix (04ac0868): passes. That test rebuilt the report's rule
    from the two patterns instead of running the report, so BeanBot's review asked for the check to go through the report:
    since ba2d9e37 it is in tests/test_cpu_report.py and the old test is gone.
  • python -I -B tests/test_cpu_report.py (perf.py cpu on a synthetic capture: a GpuWaiter thread with the fence
    wait under the renderer's take_capture and a NtGdiDdDDISubmitCommandToHwQueue beside it), one build job: on main
    @ 8859673e with this branch's test file it fails (the wait is not under Blocked, the thread is on the CPU 50 % of a
    core instead of 25 %, render/capture 50 % instead of 25 %); @ ba2d9e37 it passes.
  • The checks that read the changed files (tests/run_all.py --strict --changed origin/main) @ ba2d9e37:
    test_cpu_report and the byte-compile pass.

No game run: the change is in a profile reader, which the game does not run.

Still to test:

  • Windows 11, this PC: python -I scripts/perf.py cpu on a HOS_PROFILE=1 capture of this PC with main's script and
    with this branch's, expecting the render side's fence wait under Blocked instead of in the system's CPU time (by hand)
  • Windows 11, this PC: the whole suite (tests/run_all.py --strict) here and on main @ 8859673e, expecting no
    failure here that main does 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 on main
passes 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

Before: main @ 8859673e (with this PR's test) After: this PR @ ba2d9e37
tests/test_cpu_report.py FAIL: the fence wait counted as CPU time PASS
GpuWaiter on the CPU, % of a core 50.0 (the wait and the submit) 25.0 (the submit only)
the fence wait under Blocked absent under take_capture
main:  the GPU fence wait should be listed under Blocked, under the function that waits: []
main:  thread table: GpuWaiter should be on the CPU for its submit only (25% of a core), its GPU fence wait not CPU time: | GpuWaiter | 50.0 | 10.00 | 0.0 | 0.0 | 0.0 | 25.0 | 25.0 |
PR:    PASS perf.py cpu: owner and self views, guest subsystems, threads, descriptions, unclassified; control caught

Risks

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

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (the whole suite is queued: Still to test)
  • Measured against main, or Measurements says why there is nothing to measure.
  • 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.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary `scripts/perf.py cpu` leaves a sample out of CPU time when its leaf is a system call that waits (`BLOCKING_SYSCALLS` in `scripts/profiling/cpu_categories.py`). The renderer's waits on a GPU fence (`vkWaitSemaphores`, `vkWaitForFences`) end in the driver's `NtGdiDdDDIWaitForSynchronizationObjectFromCpu` in `win32u.dll`, which the list did 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 `GdiDdDDIWaitForSynchronizationObject` to the list (it matches the `...FromCpu` form too). To see it on `main`: copy this branch's `tests/test_cpu_report.py` onto `main` and run `python -I -B tests/test_cpu_report.py` (its synthetic capture has a thread waiting on a GPU fence). Read first: `BLOCKING_SYSCALLS` in `scripts/profiling/cpu_categories.py`; the `GpuWaiter` samples and checks in `tests/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.py` at the first commit (`fff3cd1c`, the test with `main`'s list): fails, the two fence-wait leaves counted as CPU time; with the fix (`04ac0868`): passes. That test rebuilt the report's rule from the two patterns instead of running the report, so BeanBot's review asked for the check to go through the report: since `ba2d9e37` it is in `tests/test_cpu_report.py` and the old test is gone. - `python -I -B tests/test_cpu_report.py` (`perf.py cpu` on a synthetic capture: a `GpuWaiter` thread with the fence wait under the renderer's `take_capture` and a `NtGdiDdDDISubmitCommandToHwQueue` beside it), one build job: on `main` @ 8859673e with this branch's test file it fails (the wait is not under Blocked, the thread is on the CPU 50 % of a core instead of 25 %, `render/capture` 50 % instead of 25 %); @ ba2d9e37 it passes. - The checks that read the changed files (`tests/run_all.py --strict --changed origin/main`) @ ba2d9e37: `test_cpu_report` and the byte-compile pass. No game run: the change is in a profile reader, which the game does not run. **Still to test:** - Windows 11, this PC: `python -I scripts/perf.py cpu` on a `HOS_PROFILE=1` capture of this PC with `main`'s script and with this branch's, expecting the render side's fence wait under Blocked instead of in the system's CPU time (by hand) - Windows 11, this PC: the whole suite (`tests/run_all.py --strict`) here and on `main` @ 8859673e, expecting no failure here that `main` does 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 on `main` passes 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 | | Before: main @ 8859673e (with this PR's test) | After: this PR @ ba2d9e37 | |---|---|---| | `tests/test_cpu_report.py` | FAIL: the fence wait counted as CPU time | PASS | | `GpuWaiter` on the CPU, % of a core | 50.0 (the wait and the submit) | 25.0 (the submit only) | | the fence wait under Blocked | absent | under `take_capture` | ``` main: the GPU fence wait should be listed under Blocked, under the function that waits: [] main: thread table: GpuWaiter should be on the CPU for its submit only (25% of a core), its GPU fence wait not CPU time: | GpuWaiter | 50.0 | 10.00 | 0.0 | 0.0 | 0.0 | 25.0 | 25.0 | PR: PASS perf.py cpu: owner and self views, guest subsystems, threads, descriptions, unclassified; control caught ``` ## Risks 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 - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (the whole suite is queued: Still to test) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [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. - [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. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
tests/test_cpu_blocked_waits.py checks which leaves perf.py cpu leaves out of CPU time, as profiling/cpu.py's blocked()
decides it: the waits a Windows and a Linux capture end in, among them the driver's wait on a GPU fence from the CPU
(NtGdiDdDDIWaitForSynchronizationObjectFromCpu in win32u.dll, under vkWaitSemaphores and vkWaitForFences), and calls
that do work. It fails on main: the fence wait is counted as CPU time.

Assisted-by: Claude Code
fix(profile): the driver's GPU fence wait counts as blocked in perf.py cpu, not as CPU time
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 7s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
04ac086828
The renderer's waits on a GPU fence (vkWaitSemaphores, vkWaitForFences) end in win32u.dll's
NtGdiDdDDIWaitForSynchronizationObjectFromCpu, which BLOCKING_SYSCALLS did not name, so perf.py cpu charged that wait to
the system's CPU time. On the branch this came from, 99 % of the render-side wait's samples sat there, reported as
11.3 % (Kokiri Forest) and 7.6 % (Hyrule Field) of a core of system CPU that was GPU wait.

tests/test_cpu_blocked_waits.py passes.

Assisted-by: Claude Code
BeanBot left a comment

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: 04ac086828 against 8859673e4b: 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:

  • The change is one topic, follows the existing pattern style, introduces no dependency or switch, and does not touch third_party or game data.
  • The existing report path checks both the leaf symbol and system module before excluding a sample from CPU counts.
  • The commits record AI assistance; the author reports the new check failing on the base and passing on the PR.

Blocking (to change before merge)

  1. tests/test_cpu_blocked_waits.py:45: The test reimplements blocked() using the two regexes rather than invoking the production classifier or report. If the report stops applying the classifier, resolves the symbol incorrectly, or continues charging a blocked sample to CPU time, this test can still pass. Add the fence-wait sample to the existing synthetic report fixture and assert both its Blocked entry and exclusion from CPU totals, with a working-call control.

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.

**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:** 04ac08682802 against 8859673e4bf5: 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:** - The change is one topic, follows the existing pattern style, introduces no dependency or switch, and does not touch third_party or game data. - The existing report path checks both the leaf symbol and system module before excluding a sample from CPU counts. - The commits record AI assistance; the author reports the new check failing on the base and passing on the PR. **Blocking** (to change before merge) 1. tests/test_cpu_blocked_waits.py:45: The test reimplements blocked() using the two regexes rather than invoking the production classifier or report. If the report stops applying the classifier, resolves the symbol incorrectly, or continues charging a blocked sample to CPU time, this test can still pass. Add the fence-wait sample to the existing synthetic report fixture and assert both its Blocked entry and exclusion from CPU totals, with a working-call control. **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. --- <sub>Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -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)
Member

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?

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?
test(profile): the GPU fence wait is checked through perf.py cpu's report, not a copy of its rule
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (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) Failing after 10s
ba2d9e37f2
tests/test_cpu_report.py's synthetic capture gains a thread whose leaf is the driver's wait on a GPU fence from the CPU
(NtGdiDdDDIWaitForSynchronizationObjectFromCpu in win32u.dll) under the renderer, and a submit in win32u.dll beside it.
The report must list the wait under Blocked, under the function that waits, and count only the submit as that thread's
CPU time. tests/test_cpu_blocked_waits.py, which rebuilt blocked() from the two patterns instead of running the report,
is gone: it would still pass if the report stopped applying them.

Assisted-by: Claude Code
Author
Contributor

Pushed ba2d9e37 for BeanBot's review; the description is updated to match.

  • Blocking 1 (the test duplicates the predicate): confirmed, tests/test_cpu_blocked_waits.py rebuilt blocked() from the two patterns and never ran the report. ba2d9e37 moves the check into tests/test_cpu_report.py's synthetic capture: a GpuWaiter thread with the fence wait (NtGdiDdDDIWaitForSynchronizationObjectFromCpu) under the renderer and a NtGdiDdDDISubmitCommandToHwQueue beside 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: on main @ 8859673e with this test file it fails (the wait is not under Blocked, the thread shows 50 %); @ ba2d9e37 it passes, as do the --changed checks.
Pushed ba2d9e37 for BeanBot's review; the description is updated to match. - [Blocking 1](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1917#issuecomment-60346) (the test duplicates the predicate): confirmed, `tests/test_cpu_blocked_waits.py` rebuilt `blocked()` from the two patterns and never ran the report. ba2d9e37 moves the check into `tests/test_cpu_report.py`'s synthetic capture: a `GpuWaiter` thread with the fence wait (`NtGdiDdDDIWaitForSynchronizationObjectFromCpu`) under the renderer and a `NtGdiDdDDISubmitCommandToHwQueue` beside 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: on `main` @ 8859673e with this test file it fails (the wait is not under Blocked, the thread shows 50 %); @ ba2d9e37 it passes, as do the `--changed` checks.
HumanBean changed title from WIP: fix(profile): the driver's GPU fence wait counts as blocked in perf.py cpu, not as CPU time to fix(profile): the driver's GPU fence wait counts as blocked in perf.py cpu, not as CPU time 2026-11-20 21:13:30 +00:00
HumanBean deleted branch fix/profile-gpu-fence-wait 2026-11-20 21:13:42 +00:00
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (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) Failing after 10s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!1917
No description provided.