WIP: perf(nvn): ReportCounter reads its first-report flag before the locked exchange #1955
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1955
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/nvn-report-counter-flag"
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
nvnCommandBufferReportCounter(host/nvn_native.c) logs the first report of each counter type the game asks for,with its caller. It found the first one with a locked exchange on
seen[type]at every report, a write to one cacheline that every thread recording command buffers shares, long after each type had been seen. The flag is now read
first and the exchange made only while it is clear: the same log lines, and no locked write once a type has been seen.
From a7d746ac on
exp/x86-asm-sync(its other half, the handle binds' records, is its own PR).Read first: the
seenblock innvnCommandBufferReportCounter,host/nvn_native.c.Testing
Tested: Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), llvm-mingw clang 23.1.5; game-free checks and a
micro-benchmark only. This change has not run in the game on this PC yet (the run is queued: Still to test). It has no
test of its own: the log lines are the same and no check cuts
nvnCommandBufferReportCounter; what was checked insteadis the run of every check that reads
host/nvn_native.c, and the micro-benchmark in Measurements. In a hidden consoleof its own, in one job of the PC's job queue (fb-1954-2), on this branch rebased onto
main@6e1521a7(with #1949),head
38094d72:python -I -B tests/run_all.py --strict --changed origin/mainat38094d72(the checks that read a changed file,8 at once): 18 passed, 2 failed, 1 skipped (
test_tracy_funcs.py: Linux only). The 2 failing checks(
test_dev_packs.py,test_host_guest_writes.py) fail onmain@6e1521a7too, run by name in the same queuejob, with the same messages; none fails on this branch alone.
Still to test:
maininterleaved,no switches set, expecting the same
nvn: the game reports counter typelines and fps and frame times within theruns' spread or better (by hand, queued)
main,expecting the same frame times as
mainor better and no crash (@Beanstalk play Castle Town's market for two minuteson Linux and the Steam Deck, this PR against main, comparing frame times)
Measurements
Verdict: micro-benchmark only, not measured in play yet: a report of a type already seen took 4.96 ns on one thread
on
mainand 0.80 ns here, and 67.86 ns against 0.85 ns a thread with four threads reporting at once.Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5,
-O2 -march=nativeas the host is built; the first-report test astwo lines copied into the benchmark,
main's (a locked exchange at every report) and this PR's (a read first), on 1and 4 threads reporting a type already seen side by side; 21 interleaved rounds, the median and the rounds' range of
each thread's ns a report, in one job of the PC's job queue (
microbench.py reportflag). Measured withmain@8859673eand this change as it was there (791d6da5); the rebase ontofc4a6769changed none of its lines.8859673e8859673e)Risks
Two threads that report a new type at once can both read the flag clear; the exchange still lets only one of them log,
as before. No switch: a revert is enough. Players notice nothing (no saves,
longshot_options.inior caches change).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
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: Wait. The relaxed load removes the recurring locked write and preserves one log entry per counter type. The isolated flag is faster, but the player benefit and in-game behavior still need verification on a buildable base.
Repeat counter reports avoid taking exclusive ownership of a shared cache line. The code adds one load and branch to the first-report path and keeps the same counter records and diagnostics.
Does it help: Unproven in play. In 21 interleaved Windows 11 microbenchmark rounds on an i7-9700, the median for the copied flag check fell from 4.96 to 0.80 ns on one thread and from 67.86 to 0.85 ns per thread with four threads. The reported ranges were separate. The comparison used main
8859673eand PR 791d6da5. It measures the flag check in isolation, so the cost of the full call and the effect on frame times remain unknown.Other systems: The flag is private to host-side logging on Windows and Linux. The recorded type, address and conditional-write marker feed the same Vulkan replay paths for timestamps, dynamic resolution and occlusion queries. The timing change can affect CPU contention across GPU vendors and on Steam Deck. The diff adds no resource lifetime, memory budget, cache, save, audio or input changes.
Switches: None.
Reviewed:
8fdb2327c2against2e1f6c32d3: Read the full diff and commit, the full changed ReportCounter function, the call and record paths it relies on, the Linux atomic shim, and the Vulkan counter consumers. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, the developer standards and measurement guidance. The checkout has no docs/review-checklist.md or adjacent Tooling checkout. Skimmed the rest of host/nvn_native.c, related checks, local run records and relevant history. The benchmark source and raw output were unavailable beyond the PR excerpt. No translations or generated files changed.; nothing run (a code review).Checked and fine:
Waiting on the author (a run, a measurement or a decision; no edit does it)
Testing: Read-only review. The author reports 18 passed, two failed and one skipped on d6867876. The two failures, test_dev_packs.py and test_host_guest_writes.py, also failed on
fc4a6769. No game run or CI result was supplied for8fdb2327. The source-check checklist item is inapplicable because the reviewed checks cut other functions.Overlaps and merge order: Use main containing #1949 before testing or merging. The handle-bind companion is mentioned in the PR description, but local history shows no dependency or required merge order for it.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -1924,2 +1924,2 @@static volatile LONG seen[64];if (U32(1) < 64 && !InterlockedExchange(&seen[U32(1)], 1))static volatile LONG seen[64]; /* (looked at before the exchange: a locked exchange on every report, on a line allrecording threads share, was a third of the call) */The benchmark times the flag check in isolation. Drop the one-third figure here or cite a measurement of the full call.
8fdb2327c238094d7226Thank you for the review. Pushed: the branch is now rebased onto current
main@6e1521a7, which has #1949 (thevk_replay.cppbrace), head38094d72(was8fdb2327).git range-diffshows the PR's own commit unchanged by the rebase.host/nvn_native.c:1925(the one-third figure): agreed, the micro-benchmark timed only the flag check, not the whole call.38094d72takes the share out of the comment: it now says only that, once a type has been seen, its reports make no locked write to the shared line. Measurements already calls its numbers a micro-benchmark of the flag check alone; the description is unchanged there.Checked at
38094d72through the PC's job queue:tests/run_all.py --strict --changed origin/main(job fb-1954-2): 18 passed, 2 failed, 1 skipped. The 2 failures (test_dev_packs.py,test_host_guest_writes.py) fail onmain@6e1521a7with the same messages. The description's Tested now names this base and head; nothing has run in the game.@Beanstalk This makes NVN's ReportCounter read its first-report flag before the locked exchange (host/nvn_native.c), so the exchange runs only for the first report of each counter type. It has not run in the game here with this head yet. Please play Castle Town Market for 2 minutes on Linux with NVIDIA, on Linux with AMD (RADV), on Windows with an Intel GPU and on the Steam Deck, the PR against main. No crash; the log's "nvn: the game reports counter type" lines must be the same on both sides, once per type; frame time p99 equal to main's or better, within the spread.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Recommendation: Wait for gameplay and performance evidence. The new base contains the renderer build fix, and the updated comment drops the unsupported estimate of the flag's share of the full call. The flag change itself carries over unchanged. Renderer build fix
The type bound guards both accesses to the 64-entry array. If two recorders see zero, the exchange still selects one logger. The flag carries no data from the logging thread, so the relaxed load is sufficient. The type, address and conditional-write marker continue to feed the same Vulkan counter replay, including timestamps and occlusion. The change adds no switches.
Gameplay benefit remains unproven. In the author's 21 interleaved Windows microbenchmark rounds, the steady-state flag check went from 4.96 to 0.80 ns on one thread and from 67.86 to 0.85 ns per thread on four contending threads. Use the exact rebased pair for warmed, interleaved Market and heavy-scene runs. Record average FPS, 1% lows, median and p99 frame times, and verify one diagnostic per observed type below 64 on each fresh start. A separate
HOS_HLE_STATS=1pass can countnvnCommandBufferReportCountercalls in each scene. Keep it off for the frame-time comparison because the diagnostic adds atomics to the host-call path.Testing. The author reports 18 changed-file checks passed, two failures with matching base failures, and one Linux-only check skipped on the rebased head. The description check passed and the other CI checks remain pending. The existing Market Test Farm request can cover Linux NVIDIA, RADV and Steam Deck, plus Windows Intel if an opted-in volunteer matches. Windows AMD coverage, the author's own Windows gameplay run, the full suite and exact-head build evidence are still open. Check the farm plan before treating any result as Market gameplay evidence. Existing Test Farm request
Reviewed the entire diff for
38094d7226b0against6e1521a70a32with revision-matched Graphify maps and source inspection of the NVN dispatch and record path, platform atomics, and Vulkan consumers. Source review only.Beanstalk test farm · 🔄 testing (4 of 4 reports so far)
Commit
38094d7· approved by futondestroyer (👍 on siantm's request) (reviewed) · dashboard⚠️ Note: The farm cannot compare arbitrary counter-type log sets or enforce one line per observed type; the log probe only checks for the diagnostic's presence and marks its absence unjudged.
⚠️ Note: The 5% p99 allowance is a fixed proxy for run-to-run spread, not a statistical test of that spread. The two-minute measurement is stationary after a short movement through the Market.
Started at 03:04 UTC.
linux+nvidialinux+radvwindows+intelsteamdeckCouldn'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.
linux+nvidia, report 1:Insufficient frame-time evidence for 1 required comparison(s). See rule results. a step ran out of time at step 2 (wait map Market_Child): timeout: not met in time (then the game was in play on KokiriForest_Child)linux+nvidia, report 2:Insufficient frame-time evidence for 1 required comparison(s). See rule results. a step ran out of time at step 2 (wait map Market_Child): timeout: not met in time (then the game was in play on KokiriForest_Child)linux+radv, report 1:the main base failed (exit 1): build.py stopped (exit status 1): <data>/bases/main/work/sa/build/obj/code_hot_5.split.c:47749:31: error: called object type 'int' is not a function or function pointerlinux+radv, report 2:Insufficient frame-time evidence for 1 required comparison(s). See rule results. a step ran out of time at step 2 (wait map Market_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)Compare the PR with main in Castle Town Market on Linux NVIDIA, Linux RADV, Windows Intel and Steam Deck. Each side gets two interleaved runs with a two-minute frame-time measurement; the plan fails on a crash or a p99 regression over 5%. The Windows Intel target will wait for a matching tester. Each tester's game runs take roughly 30 minutes. No tester online now matches windows+intel: that target waits for one.
kokiri-start, then teleport to Market, move the stick, take the picture market to compare with main, measure market for 2 min (after 10 s warm-up); 2 runs on each side.Measurements on `linux+nvidia`, for the PR description
Verdict: could not be judged on linux+nvidia (2 reports): required frame-time comparison inconclusive (fewer than two usable starts per side).
Hardware: 1: linux+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 5070, 620.70.6AMD Ryzen 5 9600X 6-Core Processor, 32 GB RAM; 2: linux+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce GTX 1060, 580.178.4Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz, 24 GB RAMScene: castle-town-market, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); castle-town-market: 2 game starts a side, market 120 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)6e1521a38094d7Flags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
Measurements on `linux+radv`, for the PR description
Verdict: could not be judged on linux+radv (2 reports): required frame-time comparison inconclusive (fewer than two usable starts per side).
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+dgpuAMD Radeon RX 580 Series (RADV POLARIS10), 26.2.7AMD Ryzen 5 5500F 6-Core Processor, 32 GB RAMScene: castle-town-market, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); castle-town-market: 2 game starts a side, market 120 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)6e1521a38094d7Flags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
The testers' hardware
linux+nvidiaNVIDIA GeForce RTX 5070, 620.70.6AMD Ryzen 5 9600X 6-Core Processor, 32 GB RAMlinux+nvidiaNVIDIA GeForce GTX 1060, 580.178.4Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz, 24 GB RAMlinux+radvAMD Radeon RX 9070 XT (RADV GFX1201), 26.1.99AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAMlinux+radvAMD Radeon RX 580 Series (RADV POLARIS10), 26.2.7AMD Ryzen 5 5500F 6-Core Processor, 32 GB RAM@futondestroyer, on your review: there is no code change this round, so the head stays
38094d72, the commit the farm run you approved is testing. None of the following has run yet:main@6e1521a7in the Market and in a heavy scene (average fps, 1 % lows, median and p99 frame times). The pack ofmain@6e1521a7they need is waiting in this PC's job queue.nvn: the game reports counter typeline per observed type below 64 on each fresh start, and a separateHOS_HLE_STATS=1pass that countsnvnCommandBufferReportCountercalls in each scene, kept out of the frame-time runs. Both are asked of whoever does the game runs on this PC, with the pair above.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.