mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-27 02:32:02 -04:00
fdbd2b515f
Two distinct bugs were causing OPTIONS-black hard freezes after 12K-65K frames: 1. interrupts.c + traps.c: exception_jmpbuf is a single global. setjmp captures the running fiber, but longjmp may be requested from a different fiber via psx_exception_longjmp / psx_restore_state_escape during chain-handler dispatch. Cross-fiber longjmp restores RSP to the wrong stack while Win32 still tracks the calling fiber, corrupting fiber state until SwitchToFiber eventually hangs. Fix: track g_exception_owner_fiber at setjmp time. New deferred_exception_longjmp checks the current fiber; if it's not the owner, sets a pending flag and SwitchToFiber's back to the owner. psx_change_thread_fiber's post-SwitchToFiber path observes the flag and executes the longjmp on the correct stack. 2. gpu.c: gpu_read_gpustat fired gpu_vblank_tick() after 1000 polls, which invoked sdl_vblank_present (SDL_Delay -> Sleep) from inside an MMIO read code path. That meant recompiled MIPS spent wall time in Sleep deep inside the fiber call tree -- confusing to reason about and a contributor to fiber/longjmp interactions. Fix: synthetic VBLANK from a poll-storm only updates emulation state (LCF + I_STAT). The host-side render+sleep happens only at the proper cycle-paced VBLANK trigger in psx_check_interrupts. Also adds: dirty_block ring slice to the freeze auto-dump, Win32 main- thread stack capture for wedge_kind=1 hard freezes (SuspendThread + StackWalk64 + SymFromAddr), and dbghelp link. Validated: TombaRecomp psx-runtime ran 30+ minutes / 105K+ frames at OPTIONS with no hard freeze. Previous freezes consistently hit at 11900, 20493, and 64596 frames. Diagnostic tooling under tools/_options_session/ that produced this diagnosis is included. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
"""Quick analysis of a freeze auto-dump file."""
|
|
import json, sys
|
|
from collections import Counter
|
|
|
|
path = sys.argv[1] if len(sys.argv) > 1 else \
|
|
'F:/Projects/TombaRecomp/psx_freeze_dump_psx-runtime_1778800465.json'
|
|
|
|
with open(path) as f:
|
|
d = json.load(f)
|
|
|
|
print(f'== Dump: {path}')
|
|
print(f' wall_clock_epoch={d["wall_clock_epoch"]}')
|
|
print(f' wedge={d["wedge_kind_name"]} frame={d["frame_count"]} '
|
|
f'exc_re={d["exception_reentry_blocks"]} '
|
|
f'dispatch_count={d["dispatch_count"]}')
|
|
print(f' in_exc={d["in_exception"]} cur_fn={d["current_func"]} '
|
|
f'last_store_pc={d["last_store_pc"]}')
|
|
print(f' i_stat={d["i_stat"]} i_mask={d["i_mask"]} '
|
|
f'sio_card_active={d["sio_card_active"]} mc_max={d["mc_max_state"]}')
|
|
|
|
print()
|
|
print(f'== wtrace_all: {len(d["wtrace_all"])} entries')
|
|
addr_c = Counter(e['addr'] for e in d['wtrace_all'])
|
|
pc_c = Counter(e['pc'] for e in d['wtrace_all'])
|
|
print('Top 15 ADDRS:')
|
|
for a, c in addr_c.most_common(15):
|
|
print(f' {a}: {c}')
|
|
print('Top 15 PCs:')
|
|
for p, c in pc_c.most_common(15):
|
|
print(f' {p}: {c}')
|
|
|
|
print()
|
|
print(f'== fn_entry: {len(d["fn_entry"])} entries')
|
|
fn_c = Counter(e['func'] for e in d['fn_entry'])
|
|
print('Top 10 funcs entered:')
|
|
for f_, c in fn_c.most_common(10):
|
|
print(f' {f_}: {c}')
|
|
|
|
print()
|
|
print(f'== restore_trace: {len(d["restore_trace"])} entries')
|
|
if d['restore_trace']:
|
|
kind_c = Counter(e['name'] for e in d['restore_trace'])
|
|
print('Kinds:', dict(kind_c))
|
|
pc_c2 = Counter(e['cpu_pc'] for e in d['restore_trace'])
|
|
print('Top 10 cpu_pcs:')
|
|
for p, c in pc_c2.most_common(10):
|
|
print(f' {p}: {c}')
|
|
|
|
print()
|
|
print(f'== thread_trace: {len(d["thread_trace"])} entries')
|
|
if d['thread_trace']:
|
|
kind_c = Counter(e['name'] for e in d['thread_trace'])
|
|
print('Kinds:', dict(kind_c))
|
|
|
|
print()
|
|
print(f'== sio_pc_trace: {len(d["sio_pc_trace"])} entries')
|
|
if d['sio_pc_trace']:
|
|
addr_c = Counter(e['addr'] for e in d['sio_pc_trace'])
|
|
print('Top 5 SIO addrs:')
|
|
for a, c in addr_c.most_common(5):
|
|
print(f' {a}: {c}')
|
|
|
|
print()
|
|
print(f'== frame_history: {len(d["frame_history"])} frames')
|
|
if d['frame_history']:
|
|
first = d['frame_history'][0]
|
|
last = d['frame_history'][-1]
|
|
print(f' first frame {first["frame"]}: sr={first["sr"]} i_stat={first["i_stat"]} pad={first["pad"]} disp={first["disp"]}')
|
|
print(f' last frame {last["frame"]}: sr={last["sr"]} i_stat={last["i_stat"]} pad={last["pad"]} disp={last["disp"]}')
|
|
# see if display went off
|
|
off_count = sum(1 for f in d['frame_history'] if f['disp']['off'])
|
|
print(f' display_off frames: {off_count}/{len(d["frame_history"])}')
|