mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 15:19:58 -04:00
Run every orderly exit through one sequence that puts RivaTuner's profile back before the slow pipeline save.
The window's close, the guest's ExitProcess and the end of a --seconds run each ran their own list. All three waited for the pipeline save (up to 5 s for running builds, then the write) before they put RivaTuner Statistics Server's profile back, stopped HD rumble, wrote the frame-time summary and flushed the save, so a console close, a session end or an "End task" that killed the process in that wait left the game's limit in RTSS's profile (the next run takes it for the player's own), a buzzing controller and no exit summary. ExitProcess also lacked cfg_save and the rumble stop, and it and the window's close had no shared guard, so both could run at once and write the summary twice while the present thread still added to it. gfx_present.c rt_exit_begin is the one guard (the first caller runs; another thread waits for good; the same thread again returns, and svc.c ends the process then rather than resume guest code). rt_exit_steps runs, in order: fs_save_wait (a Commit under way finishes, none is refused), rtss_limit_restore, input_rumble_hd_stop, cfg_save (not for --seconds), the prewarm marker clear, prof_write, vk_mem_exit_log, a non-final log flush (the new logq.c logq_flush, bounded trylocks, queue left on), vk_pipeline_save_exit, and fs_save_flush last. perf.c ft_stop keeps the present thread's frame-time updates out of the exit's summary and waits at most 50 ms, on the exiting thread, for one under way. The restore relies on rtss_limit.c's closed flag to stay restored while frames go on during the pipeline save. The log order changes: "frametime: exit" and the stutter-map exit lines now come before the pipeline save's lines. Not reproduced before the change. tests/exit_order_check.py (new: the step order, the once-guard with a second thread, ft_stop's wait and bound, and statically that the three exits use the helper with the RTSS restore before the pipeline save), tests/logq_check.py (with a logq_flush case), tests/save_share_check.py and the compile checks pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -507,6 +507,25 @@ static struct {
|
||||
} ft;
|
||||
static uint64_t summary_t0; // start of the current period (0: not started)
|
||||
|
||||
// The exit's summary (perf_summary_flush) runs on the exiting thread while the present thread may still add frames to
|
||||
// `ft` and write its own reports (ft_frame, session_report), with no lock between them: the exit lines came out torn,
|
||||
// or twice. ft_stop marks the end, after which the present thread adds nothing, and waits a little for an update
|
||||
// already under way; it is the exiting thread that waits, never the present thread. Both sides are sequentially
|
||||
// consistent, so either the present thread sees ft_ending or ft_stop sees it counted in ft_busy.
|
||||
static volatile int32_t ft_ending, ft_busy;
|
||||
|
||||
static int ft_enter(void) {
|
||||
__atomic_add_fetch(&ft_busy, 1, __ATOMIC_SEQ_CST);
|
||||
return !__atomic_load_n(&ft_ending, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
|
||||
static void ft_leave(void) { __atomic_sub_fetch(&ft_busy, 1, __ATOMIC_SEQ_CST); }
|
||||
|
||||
static void ft_stop(void) {
|
||||
__atomic_store_n(&ft_ending, 1, __ATOMIC_SEQ_CST);
|
||||
for (int i = 0; i < 50 && __atomic_load_n(&ft_busy, __ATOMIC_SEQ_CST); i++) plat_sleep_ms(1);
|
||||
}
|
||||
|
||||
// NX2NAVI_REPLAY_TIME=1: how the replay splits between the kinds of op it walks, reported with the frame-time summary.
|
||||
// The replay is recorded on one thread, so these need no atomics. The kinds are PERF_RP_* in host.h.
|
||||
// NX2NAVI_LOCK_TIME=1 (default 0): the replay threads time every lock they have to wait for (platform.h
|
||||
@@ -745,6 +764,7 @@ static void session_report(uint64_t now) {
|
||||
__attribute__((weak)) void vk_texstat_frame(uint64_t frame, uint64_t d) { (void)frame, (void)d; }
|
||||
|
||||
void perf_summary_flush(void) { // at exit (prof_write)
|
||||
ft_stop();
|
||||
if (rt_trace & RT_TRACE_PERF) seg_close(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), kern_now_ns(), 1);
|
||||
if (summary_t0) {
|
||||
ft_report(kern_now_ns(), "exit");
|
||||
@@ -754,8 +774,9 @@ void perf_summary_flush(void) { // at exit (prof_write)
|
||||
summary_t0 = 0;
|
||||
}
|
||||
|
||||
// Returns the replay time since the previous present.
|
||||
static uint64_t ft_frame(uint64_t frame, uint64_t now, uint64_t d) {
|
||||
// Returns the replay time since the previous present. add 0: the exit's summary is written (ft_stop), so the frame
|
||||
// is not added to it.
|
||||
static uint64_t ft_frame(uint64_t frame, uint64_t now, uint64_t d, int add) {
|
||||
int64_t rep = plat_xchg64(&frame_replay_ns, 0);
|
||||
vk_texstat_frame(frame, d);
|
||||
uint64_t f_cpu = (uint64_t)plat_xchg64(&frame_replay_cpu_ns, 0);
|
||||
@@ -764,6 +785,7 @@ static uint64_t ft_frame(uint64_t frame, uint64_t now, uint64_t d) {
|
||||
uint64_t f_hold = (uint64_t)plat_xchg64(&fr_hold_ns, 0);
|
||||
uint32_t f_op = (uint32_t)fr_max_op;
|
||||
for (int c = 0; c < PERF_RP_N; c++) f_ns[c] = (uint64_t)plat_xchg64(&fr_ns[c], 0), f_n[c] = (uint64_t)plat_xchg64(&fr_n[c], 0);
|
||||
if (!add) return (uint64_t)rep;
|
||||
if (!summary_t0) { // the first present starts the period; there is no interval yet
|
||||
summary_t0 = now;
|
||||
ft.t0 = now;
|
||||
@@ -1080,8 +1102,10 @@ void perf_present(uint64_t frame) {
|
||||
__atomic_fetch_add(&wait_ns[k], (uint64_t)a, __ATOMIC_RELAXED);
|
||||
if (k == PERF_PACE) pace_any += (uint64_t)a;
|
||||
}
|
||||
uint64_t rep = ft_frame(frame, now, d); // d is 0 on the first present: it only starts the period
|
||||
if (__atomic_load_n(&session_due, __ATOMIC_RELAXED) && plat_xchg32(&session_due, 0)) session_report(now);
|
||||
int ft_add = ft_enter(); // 0 once the exit's summary is written
|
||||
uint64_t rep = ft_frame(frame, now, d, ft_add); // d is 0 on the first present: it only starts the period
|
||||
if (ft_add && __atomic_load_n(&session_due, __ATOMIC_RELAXED) && plat_xchg32(&session_due, 0)) session_report(now);
|
||||
ft_leave();
|
||||
ab_b += rt_ab();
|
||||
cpu_placement();
|
||||
reserve_sweep(frame);
|
||||
|
||||
Reference in New Issue
Block a user