mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 20:09:57 -04:00
Charge the frames a memory-census walk overlapped to census, the memory report's time to a report part, and walk once at frame 3600N.
With mem_census = 1 and trace = perf, vk_memory.c census_main walks the address space for 100-240 ms on its own
thread, holding the process's address-space lock. The replaying thread's write-watch queries wait for that lock
("mem: slow write-watch query: 20-34 ms ... 0 pages written"), and ft_frame charged the frame to "replay": in the
0.10.0 fresh session (nx2navi.1.log, 7,974,927 bytes) 63 of the stutter map's 66 replay hitches sat beside such a
walk, 49 of them at frames 600N+1..3. The presenting thread's own 600-frame memory report (10-17 ms, timed in
vk_mem_census since b81a9561) went to "unattributed". And at frame 3600N, census_check walked on the presenting thread
and the same frame's heap_log started census_main's second walk.
- perf.c perf_census_walk brackets census_main's walk (atomics); ft_frame moves the part of a frame over 25 ms (or a
stutter-map candidate) that overlapped the walk out of the replay part first, then out of the unattributed part,
into "census". The rule is runtime/perf_census.h census_charge, capped by the overlap and the frame.
- A new cause "report": vk_mem_census feeds the report's time (perf_report_part), and so do perf.c's memory
snapshots and its 600-frame sizes lines; the next frame takes it, so the overlap rule no longer has to infer it.
The cause list changes together: perf.c FT_C_* and ft_cause_name, stutter_map.c SM_CAUSES and cause_short,
tests/stutter_hitch_check.c names[].
- census_check records the frame it walked (perf_census_walked_frame); heap_log does not start census_main for that
frame, so frame 3600N walks once. A frame stamp, not a time window, since prof_commit_census can fail and leave
perf_note_wc uncalled.
- The "mem: process" line gives the walk's start and end on the run's clock and its length, so a play-test with
mem_census = 0 can tell the walk from the presenting thread's report as the cause of the 600N+1 hitches.
New tests/census_charge_check.py builds runtime/perf_census.h alone: no overlap, partial, contained and still-running
walks, the charge from replay first, capped by the overlap and the parts, and 100,000 random frames in which the census
part never passes the frame; docs/building.md describes it. Diagnostics only: NX2NAVI_MEM_CENSUS defaults to 0, and
nothing in gameplay, pacing or the save changes. Not reproduced before the change (it needs a game run). The pass's
known-issues table, which should say that hitch counts are taken with mem_census = 0 and trace off, is not in the
repository. census_charge_check, stutter_hitch_check and stutter_map_check pass; every runtime file compiles with the
dev flags, and perf.c, stutter_map.c and vk_memory.c add no -Wall -Wextra warnings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1003,6 +1003,7 @@ void vk_mem_census(uint64_t frame) {
|
||||
rt_log("mem: the report of frame %llu took %.2f ms on the presenting thread: vram lines %.2f ms, holes %.2f ms, "
|
||||
"owners and the rest %.2f ms", (unsigned long long)frame, qpc_ms(h2 - r0), qpc_ms(rv), qpc_ms(h1 - h0),
|
||||
qpc_ms(h2 - h1));
|
||||
perf_report_part(h2 - r0); // the next frame's "report" part (perf.c ft_frame), not unattributed
|
||||
}
|
||||
if (vk_texture_compact_due()) compact_look(); // NX2NAVI_TEX_COMPACT: 0 at once with the setting off
|
||||
if ((rt_trace & RT_TRACE_PERF) && frame % 60 == 0)
|
||||
@@ -4558,10 +4559,17 @@ static void census_main(void *arg) {
|
||||
free(arg);
|
||||
const double M = 1048576.0;
|
||||
uint64_t priv = 0, wc = 0, wcn = 0, now;
|
||||
// perf.c ft_frame charges the frames the walk overlapped to "census"; the line gives the walk's span on the run's
|
||||
// clock (kern_now_ns) so that it can be set beside the frames it held up
|
||||
perf_census_walk(1);
|
||||
uint64_t w0 = kern_now_ns();
|
||||
int have = plat_mem_census(&priv, &wc, &wcn);
|
||||
uint64_t w1 = kern_now_ns();
|
||||
perf_census_walk(0);
|
||||
if (have) {
|
||||
rt_log("mem: process frame %llu: private %.0f MiB, write-combined %.0f MiB in %llu allocations",
|
||||
(unsigned long long)j.frame, priv / M, wc / M, (unsigned long long)wcn);
|
||||
rt_log("mem: process frame %llu: private %.0f MiB, write-combined %.0f MiB in %llu allocations; the walk %.3f s "
|
||||
"to %.3f s, %.1f ms", (unsigned long long)j.frame, priv / M, wc / M, (unsigned long long)wcn, w0 / 1e9,
|
||||
w1 / 1e9, (w1 - w0) / 1e6);
|
||||
uint64_t used = 0, budget = 0;
|
||||
int exact = 0;
|
||||
if (!vk_mem_vram(&used, &budget, &exact)) used = 0;
|
||||
@@ -4625,9 +4633,10 @@ static void heap_log(VkCtx *c, uint64_t frame, const VmaBudget *vb) {
|
||||
// The address-space walk of the census (plat_mem_census, 100-240 ms of VirtualQuery) runs on its own thread, but
|
||||
// it holds the process's address-space lock, which the game's threads take at every page fault and every
|
||||
// VirtualAlloc: the present after each walk arrived 65-120 ms late. NX2NAVI_MEM_CENSUS=1 asks for it.
|
||||
// Not when this frame's present walked already (perf.c census_check, every 3600 frames and on commit growth).
|
||||
static int census_on = -1;
|
||||
if (census_on < 0) census_on = cfg_bool("NX2NAVI_MEM_CENSUS");
|
||||
if (!census_on || plat_xchg32(&census_busy, 1)) return;
|
||||
if (!census_on || perf_census_walked_frame() == frame || plat_xchg32(&census_busy, 1)) return;
|
||||
CensusJob *j = malloc(sizeof *j);
|
||||
if (j) *j = (CensusJob){c, frame};
|
||||
if (!j || !plat_thread_spawn(census_main, j, "mem census", 0)) free(j), plat_xchg32(&census_busy, 0);
|
||||
|
||||
Reference in New Issue
Block a user