mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 02:09:57 -04:00
Add a hang watch that logs a report when no frame is shown with the window in front, or the GPU does not finish, for 20 s.
A present, a submission or a completion that never came back (a deadlock, a driver wait that does not return, a
GPU hang without a reset) left a log that just stopped: kernel.c wait_watch covers guest lock and thread-end waits
only and is off by default, and nothing watched the present, submit or completion threads.
hang_watch.c runs a thread of its own in a game run (main.c starts it before the boot; never in the tool modes).
Once a second it reads, without a lock, gfx_counters.frames and the submissions issued and done (the new
vk_sync.c vk_sync_progress, no device call). It reports a stall of the frames while the guest runs, the window is
in front and not minimized (gfx_window_in_front) and no orderly end has begun (rt_exit_started): the game stops
presenting without the focus, so a focus change starts the count again, and the boot screen is not judged. It
reports submissions issued and not done, "done" unchanged for N s, whatever the focus. One report per stall, a
new stall needs progress, at most 3 a run. A report names the stall with the counts, the focus and the world
clock; who holds the present, queue and window-start locks (gfx_present.c gfx_lock_holders, read from
PlatRMutex.owner and depth); the guest threads' lock and thread-end waits (kernel.c kern_wait_report, wait_watch's
walk factored out as wait_pass, run with limit 0 under ten 10 ms trylocks of the kernel lock); and then writes the
log out with logq_flush, never rt_log_sync, which would put every later line on the thread that logs it in a run
that may recover. It never ends the process and adds no wait to a drawing thread. The per-thread wait sites and
lock owner wrappers are left for a later change.
NX2NAVI_HANG_WATCH_S sets the seconds (default 20, 0..600, read at start, 0 off): a metas row, a known[] name, a
diagnostics sections[] entry and an nx2navi.ini.example entry.
Not reproduced before the change (a diagnostic). The new tests/hang_watch_check.py drives hang_watch.c's decisions
on made-up readings: no report while things move, unfocused, minimized or ending; one per stall of the frames with
the window in front and one again after progress; one for submissions not done whatever the focus; none for an
idle GPU; at most 3; logq_flush called and logq_sync never. tests/cfg_rows_check.py (0 problems), the scratchpad
rows check ("missing []") and the compile checks of every runtime file pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -968,6 +968,35 @@ static void wait_watch_holder(char *out, size_t cap, const RtThread *h) {
|
||||
(kern_now_ns() - h->blk_since) / 1e9, kinds[k], (unsigned long long)h->wobj);
|
||||
}
|
||||
|
||||
// One walk over the guest threads, G held: each one that has waited `limit` ns or longer for a lock or for another
|
||||
// thread's end gets a line, at most max of them. mark: a wait gets its line once (wait_watch); the hang watch's report
|
||||
// (kern_wait_report) lists every such wait as it stands. Returns the lines written.
|
||||
static int wait_pass(uint64_t limit, int max, int mark) {
|
||||
int lines = 0;
|
||||
uint64_t now = kern_now_ns();
|
||||
for (RtThread *t = g_all; t && lines < max; t = t->all) {
|
||||
if (!t->blk_since || (mark && t->blk_told) || now - t->blk_since < limit) continue;
|
||||
char who[160];
|
||||
if (t->wkind == W_LOCK) { // the lock word's owner field is the holder's handle
|
||||
wait_watch_holder(who, sizeof who, h_peek((uint32_t)t->wobj, O_THREAD));
|
||||
rt_log("kernel: thread %#x (priority %d) has waited %.0f s for the lock at %#llx held by %s",
|
||||
t->handle, t->prio, (now - t->blk_since) / 1e9, (unsigned long long)t->waddr, who);
|
||||
} else if (t->wkind == W_SYNC && t->whs) {
|
||||
const RtThread *end = NULL;
|
||||
for (int i = 0; i < t->wn && !end; i++) end = h_peek(t->whs[i], O_THREAD);
|
||||
if (!end) continue;
|
||||
wait_watch_holder(who, sizeof who, end);
|
||||
rt_log("kernel: thread %#x (priority %d) has waited %.0f s for the end of %s", t->handle, t->prio,
|
||||
(now - t->blk_since) / 1e9, who);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (mark) t->blk_told = 1;
|
||||
lines++;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
static void wait_watch(void *arg) {
|
||||
(void)arg;
|
||||
uint64_t limit = (uint64_t)atoi(cfg_value("NX2NAVI_WAIT_WATCH_S")) * 1000000000ull;
|
||||
@@ -976,31 +1005,26 @@ static void wait_watch(void *arg) {
|
||||
while (lines < WAIT_WATCH_LINES) {
|
||||
plat_wait_ns(2000000000ull);
|
||||
lock();
|
||||
uint64_t now = kern_now_ns();
|
||||
for (RtThread *t = g_all; t && lines < WAIT_WATCH_LINES; t = t->all) {
|
||||
if (!t->blk_since || t->blk_told || now - t->blk_since < limit) continue;
|
||||
char who[160];
|
||||
if (t->wkind == W_LOCK) { // the lock word's owner field is the holder's handle
|
||||
wait_watch_holder(who, sizeof who, h_peek((uint32_t)t->wobj, O_THREAD));
|
||||
rt_log("kernel: thread %#x (priority %d) has waited %.0f s for the lock at %#llx held by %s",
|
||||
t->handle, t->prio, (now - t->blk_since) / 1e9, (unsigned long long)t->waddr, who);
|
||||
} else if (t->wkind == W_SYNC && t->whs) {
|
||||
const RtThread *end = NULL;
|
||||
for (int i = 0; i < t->wn && !end; i++) end = h_peek(t->whs[i], O_THREAD);
|
||||
if (!end) continue;
|
||||
wait_watch_holder(who, sizeof who, end);
|
||||
rt_log("kernel: thread %#x (priority %d) has waited %.0f s for the end of %s", t->handle, t->prio,
|
||||
(now - t->blk_since) / 1e9, who);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
t->blk_told = 1, lines++;
|
||||
}
|
||||
lines += wait_pass(limit, WAIT_WATCH_LINES - lines, 1);
|
||||
unlock();
|
||||
}
|
||||
rt_log("kernel: %d long waits logged: no more", lines);
|
||||
}
|
||||
|
||||
// The hang watch's report (hang_watch.c): the guest threads' lock and thread-end waits as they stand. G is only tried,
|
||||
// ten times 10 ms apart: its holder may be the thread that hangs, and the watch adds no wait of its own.
|
||||
void kern_wait_report(void) {
|
||||
int got = 0;
|
||||
for (int i = 0; i < 10 && !(got = plat_mutex_trylock(&G)); i++) plat_sleep_ms(10);
|
||||
if (!got) {
|
||||
rt_log("kernel: the thread lock stayed taken for 100 ms; the guest threads' waits are not listed");
|
||||
return;
|
||||
}
|
||||
int lines = wait_pass(0, 16, 0);
|
||||
unlock();
|
||||
if (!lines) rt_log("kernel: no guest thread waits for a lock or for another thread's end");
|
||||
}
|
||||
|
||||
int kern_core_away(void) {
|
||||
RtThread *t = tcur;
|
||||
if (!t || t->cur_core < 0) return 0;
|
||||
|
||||
Reference in New Issue
Block a user