mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 18:09:58 -04:00
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>
78 lines
4.8 KiB
C
78 lines
4.8 KiB
C
// runtime/perf_census.h: the part of a frame an address-space walk overlapped moves to the frame's census part, from
|
|
// its replay part first and then from its unattributed part, never more than the overlap and never past the frame.
|
|
// Built and run by tests/census_charge_check.py; prints each failed check and exits 1 on any failure.
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "perf_census.h"
|
|
|
|
static int fails;
|
|
#define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL line %d: ", __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0)
|
|
|
|
#define MS 1000000ull
|
|
|
|
typedef struct { uint64_t replay, other, census, moved; } Parts;
|
|
|
|
// A frame of d ms ending at now ms, with replay / unattributed / census parts as given, and a walk w0..w1 ms (0: none
|
|
// seen; w1 0: still running).
|
|
static Parts charge(uint64_t now, uint64_t d, uint64_t w0, uint64_t w1, uint64_t replay, uint64_t other,
|
|
uint64_t census) {
|
|
Parts p = {replay * MS, other * MS, census * MS, 0};
|
|
p.moved = census_charge(now * MS, d * MS, w0 * MS, w1 * MS, &p.replay, &p.other, &p.census);
|
|
return p;
|
|
}
|
|
|
|
int main(void) {
|
|
// no walk seen, and a walk that ended before the frame or started after it
|
|
Parts p = charge(1000, 40, 0, 0, 30, 10, 0);
|
|
CHECK(p.moved == 0 && p.replay == 30 * MS && p.other == 10 * MS, "no walk: moved %llu", (unsigned long long)p.moved);
|
|
p = charge(1000, 40, 800, 950, 30, 10, 0);
|
|
CHECK(p.moved == 0 && p.census == 0, "a walk before the frame: moved %llu", (unsigned long long)p.moved);
|
|
p = charge(1000, 40, 1000, 0, 30, 10, 0);
|
|
CHECK(p.moved == 0, "a walk that starts as the frame ends: moved %llu", (unsigned long long)p.moved);
|
|
// a walk that ended 10 ms into the frame: 10 ms from the replay
|
|
p = charge(1000, 40, 900, 970, 30, 10, 0);
|
|
CHECK(p.moved == 10 * MS && p.replay == 20 * MS && p.other == 10 * MS && p.census == 10 * MS,
|
|
"partial overlap: replay %llu other %llu census %llu", (unsigned long long)p.replay, (unsigned long long)p.other,
|
|
(unsigned long long)p.census);
|
|
// a walk inside the frame, longer than the replay part: the replay's 15 ms, then 10 ms of the 20 unattributed
|
|
p = charge(1000, 60, 950, 975, 15, 20, 0);
|
|
CHECK(p.moved == 25 * MS && p.replay == 0 && p.other == 10 * MS && p.census == 25 * MS,
|
|
"a walk inside the frame: replay %llu other %llu census %llu", (unsigned long long)p.replay,
|
|
(unsigned long long)p.other, (unsigned long long)p.census);
|
|
// a walk still running (w1 0, or the end of the walk before it): it reaches now
|
|
p = charge(1000, 40, 985, 0, 30, 10, 0);
|
|
CHECK(p.moved == 15 * MS && p.replay == 15 * MS, "a running walk: moved %llu", (unsigned long long)p.moved);
|
|
p = charge(1000, 40, 985, 700, 30, 10, 0);
|
|
CHECK(p.moved == 15 * MS && p.replay == 15 * MS, "a running walk with the last one's end: moved %llu",
|
|
(unsigned long long)p.moved);
|
|
// the overlap caps the charge; the parts cap it too (nothing taken from the other parts of the frame)
|
|
p = charge(1000, 100, 900, 0, 5, 3, 0);
|
|
CHECK(p.moved == 8 * MS && p.replay == 0 && p.other == 0 && p.census == 8 * MS, "parts smaller than the overlap: "
|
|
"moved %llu", (unsigned long long)p.moved);
|
|
// never past the frame: census_check's own walk already took 35 of its 40 ms
|
|
p = charge(1000, 40, 900, 0, 30, 10, 35);
|
|
CHECK(p.moved == 5 * MS && p.census == 40 * MS && p.replay == 25 * MS, "census at the frame's length: moved %llu, "
|
|
"census %llu", (unsigned long long)p.moved, (unsigned long long)p.census);
|
|
// random frames: the census part never passes the frame, the moved time never passes the overlap, and the sum of
|
|
// the three parts is kept
|
|
srand(7);
|
|
for (int i = 0; i < 100000; i++) {
|
|
uint64_t now = 1000 + (uint64_t)(rand() % 1000), d = 1 + (uint64_t)(rand() % 300);
|
|
uint64_t w0 = (uint64_t)(rand() % 2000), w1 = rand() % 3 ? w0 + (uint64_t)(rand() % 400) : 0;
|
|
uint64_t census = (uint64_t)(rand() % (int)d), replay = (uint64_t)(rand() % 300), other = (uint64_t)(rand() % 300);
|
|
p = charge(now, d, w0, w1, replay, other, census);
|
|
uint64_t lo = now - d > w0 ? now - d : w0, hi = w1 && w1 < now ? w1 : now;
|
|
uint64_t ov = w0 && hi > lo ? (hi - lo) * MS : 0;
|
|
int ok = p.census <= d * MS && p.moved <= ov && p.replay + p.other + p.census == (replay + other + census) * MS &&
|
|
p.census == census * MS + p.moved && (p.other == other * MS || p.replay == 0);
|
|
CHECK(ok, "case %d: now %llu d %llu walk %llu-%llu: moved %llu of overlap %llu, census %llu", i,
|
|
(unsigned long long)now, (unsigned long long)d, (unsigned long long)w0, (unsigned long long)w1,
|
|
(unsigned long long)p.moved, (unsigned long long)ov, (unsigned long long)p.census);
|
|
if (!ok) break;
|
|
}
|
|
if (fails) return 1;
|
|
printf("census_charge_check: all checks passed\n");
|
|
return 0;
|
|
}
|