From f7487ceee5ed728f081d742472397c15c2b5ae57 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Fri, 13 Nov 2026 12:25:33 -0500 Subject: [PATCH] Make the memory census walk once and fire on the process's own commit, not on its private bytes. With mem_census = 1 the census trigger compared the private bytes with the last census, and Windows charges the video memory to them, so every gigabyte of textures started another 130-260 ms walk on the presenting thread: 22 of the 33 walks of the 2026-11-13 session came from that trigger, while the process's own commit grew 307 MiB in play. The trigger now reads the private bytes less the write-combined memory of the last walk (and what the driver's device-local figure grew since), compares them with the highest figure seen at a census, and waits 60 s after the last walk; the 3600-frame censuses stay. On Windows one walk of the address space now gives both the commit census and the guest regions' committed bytes, which mem_guest_census walked a second time. The census counts the driver's write-combined views apart instead of as guest memory, counts as guest only the reserved guest regions and the loaded modules, and ranks the process's own allocations wherever they lie. The frame after a walk charges its time to a new "census" cause in the frame-time summary and the stutter map instead of "unattributed". Co-Authored-By: Claude Opus 5.5 --- nx2navi.ini.example | 7 +-- runtime/host.h | 10 +++++ runtime/memory.c | 65 ++++++++++++++++++++++------ runtime/perf.c | 86 +++++++++++++++++++++++++++++++------ runtime/prof.h | 5 ++- runtime/prof_win.c | 54 +++++++++++++++++------ runtime/stutter_map.c | 3 +- runtime/vk_memory.c | 4 ++ tests/stutter_hitch_check.c | 10 +++-- 9 files changed, 195 insertions(+), 49 deletions(-) diff --git a/nx2navi.ini.example b/nx2navi.ini.example index 0ef76279..482c3bed 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -996,9 +996,10 @@ # fps or more with Link on the floor. Each pass slows the game for its few seconds. 0 is off. # floor_watch = 0 # 1: with trace = perf, walks of the process's address space count its private and write-combined memory every 600 -# frames (the "mem: process" line) and where its committed memory lies every 3600 frames (the "commit census" lines). -# Each walk holds the address-space lock for 100-240 ms and delays the next frame by as much, so they are off unless -# asked for. +# frames (the "mem: process" line) and where its committed memory lies every 3600 frames, and when the process's own +# commit (without the video memory Windows charges to it) rose 1 GiB over the highest it was, at most once a minute +# (the "commit census" lines). Each walk holds the address-space lock for 100-260 ms and delays the next frame by as +# much, so they are off unless asked for: leave it off in a run whose smoothness is judged. # mem_census = 0 # The memory the game is taken to need, in MB of commit (RAM plus page file not yet promised to a program). When less # is free at the start, the log gets a warning line: short of memory the game stutters, loses textures or stops with diff --git a/runtime/host.h b/runtime/host.h index 87d2a585..50f810ce 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -116,6 +116,11 @@ typedef struct { uint64_t mirror_ns; // of gpu_ns, the copies into VRAM mirrors (vk_sync.c ts_submitted) } PerfGpu; extern void (*perf_gpu_stats)(PerfGpu *out); +// The write-combined memory of the process (device memory the driver maps into it) as a walk of the address space +// counted it, with the driver's device-local figure at that time (NX2NAVI_MEM_CENSUS: vk_memory.c census_main, perf.c's +// commit census). perf_wc_recent: the last such figure when it is at most max_age_ns old, else 0. +void perf_note_wc(uint64_t wc, uint64_t vram_used); +int perf_wc_recent(uint64_t max_age_ns, uint64_t *wc, uint64_t *vram_used); // The performance overlay (perfmon.c): mode 0 off, 1 fps, 2 full. While it is on, perf_present hands every frame to // perfmon_frame; full also takes the event counts (perf_count) and the GPU timestamps as NX2NAVI_TRACE=perf does. void perf_set_overlay(int mode); @@ -196,6 +201,11 @@ const RtGuestLayout *mem_layout(void); int mem_start_note(int probe); // a game's start: a warning line when the free commit is // below the game's need (mem_need.h); 1 when it is void mem_guest_census(uint64_t frame); // NX2NAVI_TRACE=perf: committed bytes per guest region +// The guest's ranges for a census, each with its name (the loaded modules one range each, all named "modules"), at most +// max; mem_guest_census_log logs the bytes a walk found committed in each (committed[i] for range i). +int mem_guest_ranges(const char **name, RtRange *r, int max); +void mem_guest_census_log(uint64_t frame, const char *const *name, const uint64_t *committed, int n); +void mem_lazy_heap_census(uint64_t frame); // the census's lazy heap line (NX2NAVI_HEAP_LAZY only) void mem_lazy_heap_report(uint64_t frame); // NX2NAVI_TRACE=perf: the lazy heap's faults since the last line // The game's own memory for the memory report (vk_memory.c owner_log): its heap's size, the part of it committed (the // size itself unless the heap is lazy), and the physical memory it mapped. No lock: a log may read a figure late. diff --git a/runtime/memory.c b/runtime/memory.c index 08bbb0c0..471b0d90 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -1775,31 +1775,68 @@ void mem_lazy_heap_report(uint64_t frame) { faults_prv = faults, bytes_prv = bytes; } -// NX2NAVI_TRACE=perf: how many bytes of each guest region are committed, so a process that has grown says which region -// holds the memory. A region is reserved whole at start-up and committed page by page, so the walk reads each run of -// pages of the same state; the alias window is the largest and costs the most steps when it is full. -void mem_guest_census(uint64_t frame) { +// The guest's ranges: the regions reserved at start-up and the loaded modules. The span from the low block to +// RT_ADDRESS_LIMIT (layout aslr) is not one of them: the graphics driver maps device memory into its free parts, and +// counted as guest it made the guest regions grow by gigabytes with the textures (13.5 to 32.0 GiB in a session of +// 2026-11-13). +int mem_guest_ranges(const char **name, RtRange *r, int max) { const RtGuestLayout *g = mem_layout(); const struct { const char *name; RtRange r; } reg[] = { - {"aslr", g->aslr}, {"stack", g->stack}, {"heap", g->heap}, - {"alias", g->alias}, {"kernel", g->kernel}, {"hostfn", g->hostfn}, + {"stack", g->stack}, {"heap", g->heap}, {"alias", g->alias}, {"kernel", g->kernel}, {"hostfn", g->hostfn}, }; + int n = 0; + for (unsigned i = 0; i < sizeof reg / sizeof *reg && n < max; i++) + if (reg[i].r.size) name[n] = reg[i].name, r[n++] = reg[i].r; + for (int i = 0; i < ldr_count() && n < max; i++) { + const RtLoaded *m = ldr_module(i); + if (m && m->size) name[n] = "modules", r[n++] = (RtRange){m->base, m->size}; + } + return n; +} + +// The census line: ranges of one name (the modules) are summed. +void mem_guest_census_log(uint64_t frame, const char *const *name, const uint64_t *committed, int n) { char line[400]; - int o = snprintf(line, sizeof line, "mem: guest regions at frame %llu (MiB committed):", - (unsigned long long)frame); + int o = snprintf(line, sizeof line, "mem: guest regions at frame %llu (MiB committed):", (unsigned long long)frame); uint64_t all = 0; - for (unsigned i = 0; i < sizeof reg / sizeof *reg && o < (int)sizeof line - 40; i++) { - uint64_t x = reg[i].r.base, end = reg[i].r.base + reg[i].r.size, committed = 0, b = 0; + for (int i = 0; i < n && o < (int)sizeof line - 40; i++) { + int first = 1; + for (int k = 0; k < i && first; k++) first = strcmp(name[k], name[i]) != 0; + if (!first) continue; + uint64_t sum = 0; + for (int k = i; k < n; k++) + if (!strcmp(name[k], name[i])) sum += committed[k]; + all += sum; + o += snprintf(line + o, sizeof line - o, " %s %.0f", name[i], sum / 1048576.0); + } + rt_log("%s; all %.0f", line, all / 1048576.0); +} + +// NX2NAVI_MEM_CENSUS: how many bytes of each guest range are committed, so a process that has grown says which region +// holds the memory. A region is reserved whole at start-up and committed page by page, so the walk reads each run of +// pages of the same state; the alias window is the largest and costs the most steps when it is full. Where the OS has +// a walk of the whole address space (prof_win.c prof_commit_census) that walk counts these too and this one is not +// made (perf.c census_check). +void mem_guest_census(uint64_t frame) { + const char *name[16]; + RtRange r[16]; + uint64_t committed[16]; + int n = mem_guest_ranges(name, r, 16); + for (int i = 0; i < n; i++) { + uint64_t x = r[i].base, end = r[i].base + r[i].size, b = 0; + committed[i] = 0; while (x < end) { int st = plat_mem_state(x, end, &b); if (b <= x) break; - if (st >= 0) committed += b - x; // a PLAT_PROT_* state: these pages are committed + if (st >= 0) committed[i] += b - x; // a PLAT_PROT_* state: these pages are committed x = b; } - all += committed; - o += snprintf(line + o, sizeof line - o, " %s %.0f", reg[i].name, committed / 1048576.0); } - rt_log("%s; all %.0f", line, all / 1048576.0); + mem_guest_census_log(frame, name, committed, n); + mem_lazy_heap_census(frame); +} + +void mem_lazy_heap_census(uint64_t frame) { if (heap_lazy) rt_log("mem: lazy heap at frame %llu: %.0f of %.0f MiB committed, by %llu faults and the rest by kernel " "accesses and pointer checks", (unsigned long long)frame, heap_lazy_bytes / 1048576.0, diff --git a/runtime/perf.c b/runtime/perf.c index abc3aaab..67b35ddc 100644 --- a/runtime/perf.c +++ b/runtime/perf.c @@ -24,7 +24,7 @@ __attribute__((weak)) int prof_sampler_start(void) { } __attribute__((weak)) void prof_sampler_write(void) {} __attribute__((weak)) void prof_sampler_frame(uint64_t frame, uint64_t now, uint64_t d) { (void)frame, (void)now, (void)d; } -__attribute__((weak)) void prof_commit_census(uint64_t frame) { (void)frame; } +__attribute__((weak)) int prof_commit_census(uint64_t frame, uint64_t *wc) { (void)frame, *wc = 0; return 0; } __attribute__((weak)) void mem_guest_census(uint64_t frame) { (void)frame; } __attribute__((weak)) void mem_lazy_heap_report(uint64_t frame) { (void)frame; } @@ -371,9 +371,12 @@ typedef struct { // The replay's part is its time without the pipeline, translation and texture waits, which all happen inside it: with // them in, every frame that waited 900 ms for a pipeline was charged to "replay", the larger number, and a log // could not tell a pipeline stall from a slow replay. -enum { FT_C_PIPE, FT_C_XLATE, FT_C_TEX, FT_C_FENCE, FT_C_PACE, FT_C_REPLAY, FT_C_OTHER, FT_C_N }; +// "census" is the address-space walk of NX2NAVI_MEM_CENSUS (census_check), which runs on the presenting thread after a +// present: its time is charged to the next frame, which it delays. +enum { FT_C_PIPE, FT_C_XLATE, FT_C_TEX, FT_C_FENCE, FT_C_PACE, FT_C_REPLAY, FT_C_CENSUS, FT_C_OTHER, FT_C_N }; static const char *const ft_cause_name[FT_C_N] = { "pipeline", "translation", "texture", "fence", "pacing", "replay", - "unattributed" }; + "census", "unattributed" }; +static uint64_t census_part_ns; // present thread: the census walks since the last present (census_check) static struct { uint64_t t0, frames, sum, over25, over50, over100; uint32_t hist[FT_BINS]; @@ -617,7 +620,10 @@ static uint64_t ft_frame(uint64_t frame, uint64_t now, uint64_t d) { // (stutter_map.c) uint64_t part[FT_C_N] = {0}; int best = FT_C_OTHER; + uint64_t census_ns = census_part_ns; + census_part_ns = 0; if (d > 25000000ull || (stutter_map_on && d >= 12000000ull)) { + part[FT_C_CENSUS] = census_ns < d ? census_ns : d; part[FT_C_PIPE] = frame_ns[PERF_PIPE]; part[FT_C_XLATE] = frame_ns[PERF_XLATE]; part[FT_C_TEX] = frame_ns[PERF_TEX]; @@ -660,6 +666,70 @@ static uint64_t ft_frame(uint64_t frame, uint64_t now, uint64_t d) { return (uint64_t)rep; } +// The write-combined memory of the process (device-local memory the driver maps into it, which Windows charges to the +// process's private bytes) as the latest walk of the address space counted it: vk_memory.c census_main every 600 frames +// and the commit census below, both only with NX2NAVI_MEM_CENSUS=1. vram_used: the driver's device-local figure at that +// walk, so that a later estimate can add what the device memory grew since. +static PlatMutex wc_lock = PLAT_MUTEX_INIT; +static uint64_t wc_bytes, wc_vram, wc_at; // wc_lock; wc_at 0: no walk yet + +void perf_note_wc(uint64_t wc, uint64_t vram_used) { + plat_mutex_lock(&wc_lock); + wc_bytes = wc, wc_vram = vram_used, wc_at = kern_now_ns(); + plat_mutex_unlock(&wc_lock); +} + +int perf_wc_recent(uint64_t max_age_ns, uint64_t *wc, uint64_t *vram_used) { + plat_mutex_lock(&wc_lock); + int ok = wc_at && kern_now_ns() - wc_at <= max_age_ns; + if (ok) *wc = wc_bytes, *vram_used = wc_vram; + plat_mutex_unlock(&wc_lock); + return ok; +} + +// The process's commit without the device memory charged to it: the private bytes less the write-combined memory of +// the last walk and less what the driver's device-local figure grew since (before any walk, less that figure alone). +// The device-local figure (heapUsage) lies 0.2-1.1 GiB under the write-combined total, so it serves for the change only. +// Where the commit does not count device memory (plat_commit_counts_vram) it is the private bytes. +static uint64_t host_commit(uint64_t prv, const PerfGpu *g) { + if (!plat_commit_counts_vram()) return prv; + uint64_t wc, at_vram; + int64_t dev; + if (perf_wc_recent(~0ull, &wc, &at_vram)) + dev = (int64_t)wc + (g->have_vram && at_vram ? (int64_t)g->vram_used - (int64_t)at_vram : 0); + else + dev = g->have_vram ? (int64_t)g->vram_used : 0; + if (dev <= 0) return prv; + return (uint64_t)dev >= prv ? 0 : prv - (uint64_t)dev; +} + +// Where the committed memory lies (NX2NAVI_MEM_CENSUS=1 only), every 3600 frames and when the process's own commit +// (host_commit) rose 1 GiB over the highest it was at a census: the process has run out of commit in long sessions +// while the game's own pools stayed flat. The walk holds the address-space lock the game's threads take at every page +// fault and runs here on the presenting thread, so each one delays the next frame by 130-260 ms (ft_frame charges it +// to "census"). In a session of 2026-11-13 the trigger read the private bytes, which take in the device memory Windows +// charges to the process, so every gigabyte of textures re-armed it: 22 of the 33 walks came from it, 120 frames +// apart in bursts, while the process's own commit grew 307 MiB in 7 minutes of play. So the trigger reads the commit +// without the device memory against the highest it was at a census (a figure that falls and rises again does not +// re-arm it), and a growth census waits CENSUS_GAP_NS after the last walk. The scheduled ones stay. +#define CENSUS_GAP_NS 60000000000ull +static void census_check(uint64_t frame, uint64_t prv, const PerfGpu *g) { + static int census_on = -1; + static uint64_t census_high, census_ns; + if (census_on < 0) census_on = cfg_bool("NX2NAVI_MEM_CENSUS"); + if (!census_on) return; + uint64_t host = host_commit(prv, g), t0 = kern_now_ns(); + int grown = host >= census_high + (1ull << 30) && (!census_ns || t0 - census_ns >= CENSUS_GAP_NS); + if (frame % 3600 && !grown) return; + uint64_t wc = 0; + if (prof_commit_census(frame, &wc)) perf_note_wc(wc, g->have_vram ? g->vram_used : 0); // one walk for both lines + else mem_guest_census(frame); + uint64_t t1 = kern_now_ns(); + census_part_ns += t1 - t0, census_ns = t1; + host = host_commit(prv, g); // with the walk's own write-combined figure + if (host > census_high) census_high = host; +} + // The second line of the 60-frame window: GPU busy time (timestamps), the time threads waited for GPU fences, VRAM and // process memory, and which side holds the frame back. pace: the frame waited for pacing (vsync, the frame limiter) at // least 15% of the window; gpu: the GPU was busy for 80% of the frame interval or more (without timestamps: threads @@ -689,15 +759,7 @@ static void perf_gpu_line(uint64_t frame, double interval_ms, double pace_share, rt_log("perf: frame %llu: %s; fence wait per frame: render thread %.2f ms, other threads %.2f ms; %s; ram working set " "%.0f MiB, private %.0f MiB; bound: %s", (unsigned long long)frame, gs, rw, ow, vs, ws, priv, bound); - // Where the committed memory lies, every 3600 frames and whenever it grew by 1 GiB since the last census: the process - // has run out of commit in long sessions while the game's own pools stayed flat. Only with NX2NAVI_MEM_CENSUS=1, as - // vk_memory.c's census: the walk holds the address-space lock the game's threads take at every page fault, and here - // it ran on the presenting thread, so each one delayed a frame by 65-240 ms. - static int census_on = -1; - static uint64_t census_prv; - if (census_on < 0) census_on = cfg_bool("NX2NAVI_MEM_CENSUS"); - if (census_on && (frame % 3600 == 0 || prv >= census_prv + (1ull << 30))) - prof_commit_census(frame), mem_guest_census(frame), census_prv = prv; + census_check(frame, prv, &g); mem_lazy_heap_report(frame); if (g.have_gpu && g.have_idle) rt_log("perf: frame %llu: gpu idle per frame %.2f ms between timed parts: %.2f ms waiting for the next submission, " diff --git a/runtime/prof.h b/runtime/prof.h index 1619b4e3..ef8b0dc0 100644 --- a/runtime/prof.h +++ b/runtime/prof.h @@ -10,4 +10,7 @@ extern volatile uint32_t prof_replay_tid; // the asynchronous replay (perf_rep int prof_sampler_start(void); // NX2NAVI_PROFILE: starts sampling; 1 when it runs void prof_sampler_write(void); // writes the profile once (prof_write) void prof_sampler_frame(uint64_t frame, uint64_t now, uint64_t d); // every present; d: the interval, 0 on the first -void prof_commit_census(uint64_t frame); // NX2NAVI_TRACE=perf: logs where the process's committed memory lies +// NX2NAVI_MEM_CENSUS (perf.c census_check): logs where the process's committed memory lies and the guest regions' +// committed bytes from one walk of the address space; *wc the write-combined total. 0 where there is no such walk +// (perf.c's weak version): mem_guest_census walks the guest regions then. +int prof_commit_census(uint64_t frame, uint64_t *wc); diff --git a/runtime/prof_win.c b/runtime/prof_win.c index a8df4008..c0d95067 100644 --- a/runtime/prof_win.c +++ b/runtime/prof_win.c @@ -30,6 +30,7 @@ #include "perfmon.h" #include "prof.h" #include "prof_syms.h" +#include "platform/platform.h" #define render_tid prof_render_tid #define main_tid prof_main_tid @@ -407,10 +408,17 @@ int prof_sampler_start(void) { return 1; } -// NX2NAVI_TRACE=perf (perf.c): the process's committed memory by kind, and outside the guest's address range the -// allocations holding the most private memory, so a log shows what grows: guest memory, a heap, the graphics driver's -// mappings or loaded images. A walk of the address space with VirtualQuery: tens of milliseconds, so only now and then. +// NX2NAVI_MEM_CENSUS (perf.c census_check): the process's committed memory by kind, and the allocations of the process's +// own memory holding the most, so a log shows what grows: the guest's memory, a heap, the graphics driver's mappings or +// loaded images. One walk of the address space with VirtualQuery, tens of milliseconds, so only now and then; it also +// counts the guest ranges' committed bytes (mem_guest_ranges), which mem_guest_census would walk a second time. +// Kinds of committed memory: images and mapped views by type; of the private memory, the write-combined views (device +// memory the driver maps into the process; Windows charges it to the process's commit), the guest's ranges, and the +// rest, the process's own ("other private"). The driver places its views anywhere in the free address space, below +// RT_ADDRESS_LIMIT too: with every private region under it counted as guest, "other private" was 0 MiB in all 33 +// censuses of a session (2026-11-13) and the guest's figure grew with the textures. #define CENSUS_TOP 12 +#define CENSUS_RANGES 16 typedef struct { uint64_t base, bytes; DWORD protect; } CensusRun; static void census_keep(CensusRun *top, int *nt, const CensusRun *r) { // top[] stays sorted, largest first @@ -420,24 +428,37 @@ static void census_keep(CensusRun *top, int *nt, const CensusRun *r) { // top[ top[k] = *r; } -void prof_commit_census(uint64_t frame) { +int prof_commit_census(uint64_t frame, uint64_t *wc_out) { // Allocations by committed size: under 256 KiB, under 4 MiB, under 64 MiB, larger. A few large ones growing is a // pool or cache; many small ones is a stream of allocations that are not freed. static const uint64_t edge[3] = {256ull << 10, 4ull << 20, 64ull << 20}; uint64_t bcount[4] = {0}, bbytes[4] = {0}; - uint64_t t0 = GetTickCount64(), guest = 0, priv = 0, mapped = 0, image = 0, regions = 0; + uint64_t t0 = plat_now_ns(), guest = 0, priv = 0, wc = 0, mapped = 0, image = 0, regions = 0; + const char *gname[CENSUS_RANGES]; + RtRange gr[CENSUS_RANGES]; + uint64_t gcom[CENSUS_RANGES] = {0}; + int ng = mem_guest_ranges(gname, gr, CENSUS_RANGES); CensusRun top[CENSUS_TOP], cur = {0}; int nt = 0; MEMORY_BASIC_INFORMATION mi; for (uint8_t *a = NULL; VirtualQuery(a, &mi, sizeof mi) == sizeof mi; a = (uint8_t *)mi.BaseAddress + mi.RegionSize) { regions++; uint64_t base = (uint64_t)(uintptr_t)mi.AllocationBase, at = (uint64_t)(uintptr_t)mi.BaseAddress; - int committed = mi.State == MEM_COMMIT, outside = committed && mi.Type == MEM_PRIVATE && at >= RT_ADDRESS_LIMIT; + uint64_t end = at + mi.RegionSize, in_guest = 0; + int committed = mi.State == MEM_COMMIT, host = 0; + if (committed) // the guest ranges' committed bytes, whatever the kind (the census mem_guest_census made) + for (int i = 0; i < ng; i++) { + uint64_t lo = at > gr[i].base ? at : gr[i].base, hi = end < gr[i].base + gr[i].size ? end : gr[i].base + gr[i].size; + if (hi > lo) gcom[i] += hi - lo, in_guest += hi - lo; + } if (committed) { if (mi.Type == MEM_IMAGE) image += mi.RegionSize; else if (mi.Type == MEM_MAPPED) mapped += mi.RegionSize; - else if (at < RT_ADDRESS_LIMIT) guest += mi.RegionSize; - else priv += mi.RegionSize; + else if (mi.Protect & PAGE_WRITECOMBINE) wc += mi.RegionSize; + else { + guest += in_guest < mi.RegionSize ? in_guest : mi.RegionSize; + if (in_guest < mi.RegionSize) priv += mi.RegionSize - in_guest, host = 1; + } } // An allocation's regions are contiguous: its run ends where the next allocation begins, reserved gaps inside // it (a heap segment's uncommitted tail) included. @@ -446,20 +467,21 @@ void prof_commit_census(uint64_t frame) { bcount[k]++, bbytes[k] += cur.bytes; census_keep(top, &nt, &cur), cur.bytes = 0; } - if (outside) { + if (host) { if (!cur.bytes) cur.base = base, cur.protect = mi.AllocationProtect; - cur.bytes += mi.RegionSize; + cur.bytes += mi.RegionSize - in_guest; } - if (at + mi.RegionSize < at) break; // the top of the address space + if (end < at) break; // the top of the address space } if (cur.bytes) { int k = cur.bytes < edge[0] ? 0 : cur.bytes < edge[1] ? 1 : cur.bytes < edge[2] ? 2 : 3; bcount[k]++, bbytes[k] += cur.bytes; census_keep(top, &nt, &cur); } - rt_log("mem: commit census at frame %llu: guest %.0f MiB, other private %.0f MiB, mapped %.0f MiB, images %.0f MiB " - "(%llu regions walked in %llu ms)", (unsigned long long)frame, guest / 1048576.0, priv / 1048576.0, - mapped / 1048576.0, image / 1048576.0, (unsigned long long)regions, (unsigned long long)(GetTickCount64() - t0)); + rt_log("mem: commit census at frame %llu: guest %.0f MiB, device memory views (write-combined) %.0f MiB, other " + "private %.0f MiB, mapped %.0f MiB, images %.0f MiB (%llu regions walked in %.1f ms)", (unsigned long long)frame, + guest / 1048576.0, wc / 1048576.0, priv / 1048576.0, mapped / 1048576.0, image / 1048576.0, + (unsigned long long)regions, (plat_now_ns() - t0) / 1e6); rt_log("mem: other private by allocation size: under 256 KiB %llu allocations %.0f MiB, under 4 MiB %llu %.0f MiB, " "under 64 MiB %llu %.0f MiB, larger %llu %.0f MiB; the largest:", (unsigned long long)bcount[0], bbytes[0] / 1048576.0, (unsigned long long)bcount[1], bbytes[1] / 1048576.0, @@ -467,6 +489,10 @@ void prof_commit_census(uint64_t frame) { for (int i = 0; i < nt; i++) rt_log("mem: %#llx %.1f MiB committed (protect %#lx)", (unsigned long long)top[i].base, top[i].bytes / 1048576.0, (unsigned long)top[i].protect); + mem_guest_census_log(frame, gname, gcom, ng); + mem_lazy_heap_census(frame); + *wc_out = wc; + return 1; } // perf_present, every present: the frame the sampler's NX2NAVI_PROFILE_FRAMES window counts, and a NX2NAVI_PROFILE_SLOW diff --git a/runtime/stutter_map.c b/runtime/stutter_map.c index 0a8a2d86..0bbf3565 100644 --- a/runtime/stutter_map.c +++ b/runtime/stutter_map.c @@ -300,8 +300,9 @@ void stutter_frame(uint64_t frame, uint64_t now, uint64_t d, const uint64_t *par } } +// In the order of perf.c's causes (FT_C_*); "census" is NX2NAVI_MEM_CENSUS's walk of the address space. static const char *const cause_short[SM_CAUSES] = {"pipeline", "translation", "texture", "fence", "pacing", "replay", - "unattributed", "?"}; + "census", "unattributed"}; static int area_cmp(const void *x, const void *y) { const Area *a = &areas[*(const int *)x], *b = &areas[*(const int *)y]; diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index 723b5a3e..3e423897 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -4508,6 +4508,10 @@ static void census_main(void *arg) { 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); + uint64_t used = 0, budget = 0; + int exact = 0; + if (!vk_mem_vram(&used, &budget, &exact)) used = 0; + perf_note_wc(wc, used); // perf.c host_commit and the memory report (system_log) take the device memory out now = wc; } else { VmaBudget vb[VK_MAX_MEMORY_HEAPS]; diff --git a/tests/stutter_hitch_check.c b/tests/stutter_hitch_check.c index 469a7011..1d537ec8 100644 --- a/tests/stutter_hitch_check.c +++ b/tests/stutter_hitch_check.c @@ -17,16 +17,18 @@ void rt_log(const char *fmt, ...) { logged++; } -static const char *const names[7] = {"pipeline", "translation", "texture", "fence", "pacing", "replay", "unattributed"}; +// perf.c's causes, in its order (FT_C_*) +static const char *const names[8] = {"pipeline", "translation", "texture", "fence", "pacing", "replay", "census", + "unattributed"}; static uint64_t frame_no; static void frames(int n, double ms) { - uint64_t part[7] = {0}; + uint64_t part[8] = {0}; for (int i = 0; i < n; i++) { uint64_t d = (uint64_t)(ms * 1e6); clock_ns += d; - part[6] = d; - stutter_frame(++frame_no, clock_ns, d, part, names, 7, 6); + part[7] = d; + stutter_frame(++frame_no, clock_ns, d, part, names, 8, 7); } }