mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 07:09:57 -04:00
A fetch of lazily written pages runs inside the fault handler under frz_lock (memory.c lazy_gone_locked and lazy_piece_fetch_locked call vk_memory.c lazy_fetch, a GPU copy after everything handed over and a wait for it), so every other fault, thaw, freeze and arm waits for the whole copy. The line gave only the fetches' sum: the 0.10.0 session's 848 fetches took 415.8 ms in all, and how long one took, or how long another thread waited behind it, was not known. Both fetch sites now keep the longest fetch, and lazy_fault keeps the longest time a fault waited to take frz_lock; the report line prints them as "the longest X ms, faults waited up to Y ms for the freeze lock" and starts both over. No tool parses the line. tests\lazy_fetch_check.py's new report scenario fetches for 30 and 120 ms and has a third fault wait 60 ms for frz_lock: the line reads 120.29 ms and 60.03 ms, and the next one 0.00 for both. arm_race, arm_race_slow, wb_lazy_check and heap_lazy_copy_check passed; memory.c compiles without a warning under -Wall -Wextra. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.5 KiB
Python
92 lines
3.5 KiB
Python
"""Build and run tests/lazy_fetch_check.c: runtime/memory.c's lazy write-back (memory.c "Lazy write-back") with the
|
|
Windows platform layer and its real fault handler, the rest of the runtime stubbed and the back end's fetch a stand-in
|
|
that only waits. Each scenario runs as its own process, so an access violation passed to the crash handler shows as
|
|
its exit code; any exit code other than 0, or a scenario that does not end within 120 s, fails.
|
|
|
|
Windows only (the fault handler is): no game files, no GPU. The module layout the runtime includes is a stand-in
|
|
written to the test's build folder.
|
|
|
|
Usage: lazy_fetch_check.py [scenario ...]
|
|
"""
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
MSYS_BIN = Path(r'C:\msys64\ucrt64\bin')
|
|
# name: (scenario argument, extra environment)
|
|
SCENARIOS = {
|
|
'arm_race': ('arm_race', {}),
|
|
'arm_race_slow': ('arm_race_slow', {}),
|
|
'report': ('report', {}),
|
|
}
|
|
|
|
|
|
def compiler():
|
|
if os.environ.get('CC'):
|
|
return os.environ['CC']
|
|
if os.name == 'nt' and (MSYS_BIN / 'clang.exe').exists():
|
|
return str(MSYS_BIN / 'clang.exe')
|
|
return shutil.which('clang') or 'clang'
|
|
|
|
|
|
LAYOUT = '''// A stand-in for the generated layout.h (tests/lazy_fetch_check.py).
|
|
#pragma once
|
|
#define MOD_MAIN_BASE 0x7000000000ull
|
|
#define MOD_MAIN_SIZE 0x4ea0000ull
|
|
#define MOD_COUNT 3
|
|
'''
|
|
|
|
|
|
def main():
|
|
if os.name != 'nt':
|
|
print('lazy_fetch_check: the fault handler it runs is Windows only; skipped')
|
|
return 0
|
|
names = sys.argv[1:] or list(SCENARIOS)
|
|
unknown = [n for n in names if n not in SCENARIOS]
|
|
if unknown:
|
|
print('lazy_fetch_check: unknown scenario %s; known: %s' % (', '.join(unknown), ', '.join(SCENARIOS)))
|
|
return 2
|
|
work = ROOT / 'build' / 'test' / 'lazy_fetch'
|
|
work.mkdir(parents=True, exist_ok=True)
|
|
(work / 'layout.h').write_text(LAYOUT)
|
|
exe = work / 'lazy_fetch_check.exe'
|
|
env = dict(os.environ)
|
|
if MSYS_BIN.exists():
|
|
env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '')
|
|
rt = ROOT / 'runtime'
|
|
plat = [rt / 'platform' / 'win32.c', rt / 'platform' / 'common.c']
|
|
libs = ['-lbcrypt', '-lws2_32', '-lpsapi', '-lwinmm', '-ldbghelp', '-lshell32', '-lole32', '-luser32', '-ladvapi32']
|
|
subprocess.check_call([compiler(), '-O1', '-g', '-Wall', '-Wno-unused-function', '-fno-strict-aliasing',
|
|
'-march=x86-64-v3', '-I', str(rt), '-I', str(work),
|
|
str(ROOT / 'tests' / 'lazy_fetch_check.c'), *map(str, plat), '-o', str(exe), '-lm',
|
|
*libs], env=env)
|
|
bad = 0
|
|
for name in names:
|
|
arg, extra = SCENARIOS[name]
|
|
try:
|
|
p = subprocess.run([str(exe), arg], env={**env, **extra}, capture_output=True, text=True, timeout=120)
|
|
except subprocess.TimeoutExpired:
|
|
bad += 1
|
|
print('lazy_fetch_check: %s: FAIL: did not end within 120 s' % name)
|
|
continue
|
|
code = p.returncode & 0xFFFFFFFF
|
|
if code:
|
|
bad += 1
|
|
print('lazy_fetch_check: %s: FAIL: exit code %#x%s' % (
|
|
name, code, ' (an access violation)' if code == 0xC0000005 else ''))
|
|
sys.stdout.write(p.stdout)
|
|
else:
|
|
print('lazy_fetch_check: %s: passed' % name)
|
|
if bad:
|
|
print('lazy_fetch_check: %d of %d scenarios failed' % (bad, len(names)))
|
|
return 1
|
|
print('lazy_fetch_check: all %d scenarios passed' % len(names))
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|