Skip to content

Long frames: one line naming what a frame over 100 ms waited for, and paging on the memory line (release builds) - #3703

Open
Lyrnc wants to merge 2 commits into
trustno1-coder:mainfrom
Lyrnc:diag/long-frame-line
Open

Lyrnc wants to merge 2 commits into
trustno1-coder:mainfrom
Lyrnc:diag/long-frame-line

Conversation

@Lyrnc

@Lyrnc Lyrnc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

G1. Release builds do not say what a long frame waited for. The frame times line only counts frames over 50 and 100 ms. Every other per-second line (the submitting thread's split, settles by why, resident waits, the texture pass) spreads a 500 ms frame over its second. The per-part timers (copystat, timeline) are in diagnostics builds only. So the perf30 cause table (CAUSES.md) had to be built by coincidence per second (tools/classify.py):

  • the once-a-second sweep: one frame over 100 ms in 79-100 % of sweep seconds;
  • pipelines made at first use: single frames of 380-620 ms.

Tonight's A/B needs the per-frame cause.

G4. Nothing logs paging, although the bench PC runs with 0.1-1.3 GB of physical memory free and the process has about 5.5 GB paged out (26310 MB private ... (20844 MB in memory)). A hard fault stalls whichever thread takes it, and no line can show that.

Fix

Two commits on main:

  1. 87f9814a, author Wtry (wtry-gta, Submit-thread speedups, in-session A/B, teleport test tool, texture cap, ambient floor #1925): Submit-thread speedups, in-session A/B, teleport test tool, texture cap, ambient floor #1925's longframe.rs module as it is at 1a4eefb, with its call in the frame-rate meter. Submit-thread speedups, in-session A/B, teleport test tool, texture cap, ambient floor #1925 is on f9dfb76 and conflicts on main, so only the module and that one call come over. The places that feed its stages are in Submit-thread speedups, in-session A/B, teleport test tool, texture cap, ambient floor #1925's other changes and are not ported.
  2. ccc22ecc: the module gets the parts G1 lists, a default and a rate limit. memory_now gets paging (G4).

G1: crate::longframe, on by default.

  • At every present the meter swaps a set of AtomicU64 counters back to 0 (µs and span counts per part).

  • When the present came more than VICTORY_LONG_FRAME_MS after the one before (default 100; 0 turns it off), one line at info, target victory_gpu::longframe. At most 4 lines a second; the next line says how many long frames had none. Example (from the unit test):

    long frame 512 ms (frame 18200), ms on all threads: pipeline waits 480 (graphics 480; 3 threads), sweep 0, settles 6 (sync 6), lock 0, resident 12 (mapped 1), texture pass 3, translated 0, pipelines made 2 (1260 ms)

  • What feeds each part. Every feed is a relaxed fetch_add, placed where the code already reads a clock:

    Part Where
    pipeline waits, graphics / compute / screen passes pipeline/make.rs: wait() (by waits_as_screen and graphics.is_none()), and the inline compute make in ready() (where compute_spent is fed). Threads: each thread counts once per present (a thread-local present number)
    sweep host.rs::sweep(), from past its once-a-second gate to its end. This part adds its own clock read, once a second
    settles by why relay_wait() and Host::settle(), next to LATE_WAITED[why]. The line shows the total, then each why of at least 0.5 ms (always the largest), named after host's WHY_ places. A const assert in host.rs keeps those places in line with the names
    lock Host::submit, the same nanoseconds as SPLIT[11] ("waiting for the submission lock")
    resident host::resident() (MakeResident) plus host::mapped() (until mapped), the counters behind the "new memory waited for" lines; the mapped part is shown when it is 0.5 ms or more
    texture pass draw.rs heap_textures(): the loop's took plus what came before the loop (HEAP_TEXTURE_REST[7]), from the clocks it already reads
    translated pipeline.rs Shader::translated(): ms and shaders
    pipelines made make.rs Pending::make(): every HostPipeline::new (driver compile or library load), with its ms
  • A span counts whole in the frame it ended in. Parts on other threads overlap the submitting thread and each other, so the parts need not add up to the frame (the line says "on all threads").

  • The steady-state cost is relaxed atomics on paths that already wait or take a clock, an OnceLock read per feed, and 43 atomic swaps per present. The gate's mutex is taken only for frames over the threshold.

G4: memory_now() (once a second, from the sweep). The memory now: line keeps its text and gets a ; ... tail:

  • the PC's memory free (residency::physical_free);
  • our page faults a second: the delta of PageFaultCount, which counts soft and hard faults, from the K32GetProcessMemoryInfo call the line already makes;
  • the pages all processes read from disk a second, and the reads that brought them (hard faults). These are SYSTEM_PERFORMANCE_INFORMATION's PageReadCount (0x50, behind \Memory\Pages Input/sec) and PageReadIoCount (0x54, \Memory\Page Reads/sec), from NtQuerySystemInformation(SystemPerformanceInformation) (ntdll raw-dylib, as host.rs does for NtWriteVirtualMemory).

All are wrapping u32 counters. Rates are per second of the actual time between lines (the sweep can come later than a second). The first line says the rates come from the next line on. If Windows does not answer, the line says the page reads are not known.

memory now: committed 26310 MB, ...; the PC's memory free 640 MB, page faults of ours 4000 a second, pages read from disk by all processes 1000 a second in 50 reads (hard faults)

Verification

Windows 11, rustc 1.98.1 (the pinned toolchain), Ryzen 7 9800X3D. On ccc22ec's tree, before it was committed:

  • cargo check -p victory-gpu --locked: passes. None of the crate's 18 warnings is in the lines this touches; they are existing dead code elsewhere (pipeline.rs 841-898, make.rs 1328 Queue::pop, host.rs 3160/12825/12966, shadow.rs, watch.rs and others).
  • cargo test -p victory-gpu --lib --locked -- longframe paging_tests: 10 passed, 0 failed.
    • longframe::tests:
      • threshold_defaults_to_100_ms_and_0_turns_it_off: unset, empty or not a number gives 100; 0, a negative or inf turns it off.
      • only_frames_over_the_threshold_are_long.
      • each_present_takes_the_parts_and_starts_again: the reset.
      • a_thread_counts_once_a_present_among_pipeline_waiters.
      • at_most_four_lines_a_second_and_the_next_says_how_many_had_none: the rate limit and its window.
      • the_line_names_each_part: the exact text, rounding, the settle why shown, the skipped tail.
    • host::paging_tests:
      • page_counters_are_taken_a_second_and_across_a_wrap.
      • the_paging_text_has_rates_from_the_second_line_on.
      • performance_words_are_read_little_end_first.
      • system_performance_information_is_read_where_windows_puts_it: this calls NtQuerySystemInformation for real. AvailablePages at 0x2c times 4 KiB matched GlobalMemoryStatusEx's free memory, which checks the offsets. Page reads came back no lower than the IOs that brought them.
  • cargo clippy -p victory-gpu --all-targets --locked -j 6 on ccc22ec (2026-11-30, target directory C:\it, built from C:\i-long): finishes with warnings only (victory-gpu lib 25, lib test 24, victory-shader 3). None is on a line this branch adds (checked against git diff -U0 716a0c99 ccc22ecc: all of longframe.rs, paging_tests and memory_now's helpers, the feeds in host.rs, draw.rs, pipeline.rs and pipeline/make.rs).
  • cargo clippy ... --all-features on ccc22ec itself does not compile, for a reason that is main's: its base 716a0c9 has the diagnostics build errors that main's 41adb55 fixed (mb missing in copystat.rs's windows-cut line, timing() shadowed in Host::submit; 9 errors, none in this branch's lines). The branch merges cleanly with main 41adb55, so it was run on that merge (dd105afc, a scratch commit, not pushed; the PR's CI checks the same merge): finishes with warnings only (lib 27, lib test 30, victory-shader 3). None is on a line this branch adds, and its 37 warnings are the same, file by file and kind by kind, as an --all-features clippy of main 41adb55 (with only pipeline/library.rs changed, which adds none).

NOT tested

  • No game run: no long frame line or paging tail has been seen in a real log. Whether the line's causes match classify.py on R1/R2 is for the benchmark agent.
  • Not measured: the steady-state cost (expected to be in the noise; no A/B was run).
  • Not checked: whether NtQuerySystemInformation answers under Wine/Proton. If it does not, the line says the page reads are not known.
  • cargo clippy --all-features on the branch as it is (base 716a0c9): it stops at main's old diagnostics errors; it was run on the branch merged with main (see Verification). Not rebased: it merges cleanly.
  • Settles that take the relay's other paths (settle_now, settle_unlocked) are counted only where they reach relay_wait or Host::settle. The submission lock taken outside Host::submit (settle_now, the present's order lock) is not in "lock".

Overlap

AI use

Claude Code (Claude Opus 5.5) ported #1925's module (with its author kept), wrote the second commit and its unit tests, ran the checks listed above, and wrote this note. Nothing was run in game.

🤖 Generated with Claude Code

wtry-gta and others added 2 commits November 30, 2026 01:12
crates/victory-gpu/src/longframe.rs as trustno1-coder#1925 (wtry-gta) has it at
1a4eefb, with its hook in the frame-rate meter. trustno1-coder#1925 is on f9dfb76 and
does not apply to main (run.rs, ab.rs, descriptor and others conflict), so
only the module and the meter's call come here; the places that feed its
stages are in trustno1-coder#1925's other changes and are not ported. The next commit
gives it the stages of a long frame on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aging on the memory line

In every build, when a present comes more than VICTORY_LONG_FRAME_MS
(100 by default; 0: never) after the one before, one line names the
frame's parts on all threads: pipeline waits (graphics, compute, passes
over the screen, and how many threads waited), the sweep, settles by why,
the submission lock, resident and mapping waits, the texture pass, shaders
translated at first use and pipelines made. At most 4 lines a second; the
next says how many long frames had none.

The per-second lines spread a spike over its second, so the causes of the
long frames on the RTX 5080 bench (one frame over 100 ms nearly every
second, single frames of 380-620 ms) were only known by coincidence per
second. The parts are AtomicU64 counters the present swaps back to 0,
fed with relaxed adds where a clock is read already (the sweep's once a
second is the only new one).

The once-a-second "memory now:" line also says the PC's free memory, our
page faults a second (PageFaultCount, soft and hard) and the pages all
processes read from disk a second with the reads that brought them (hard
faults: SystemPerformanceInformation's PageReadCount and PageReadIoCount).
That PC runs with 0.1-1.3 GB free and ~5.5 GB of ours paged out, and no
line could show a stall from a hard fault.

Built on the module of trustno1-coder#1925 (previous commit, its author's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants