From 55eb8ab64ea19bd1b01570837e29652dd232f18b Mon Sep 17 00:00:00 2001 From: aznohonza Date: Tue, 1 Dec 2026 11:34:01 +0100 Subject: [PATCH] runtime: say why a held list value gate stays shut A gate held past a minute now prints one line a minute naming what kept it: the releaser signalling, a title ExecuteCommandLists, a running write group or action, the present settle, the title still calling, or the quiet window. Counts and seconds only. list_value_progress.h gains hold_reason()/hold_text()/report_due() beside the policy; decide() and can_progress() are untouched. The pure test covers every outcome and the 59/60/61 s rate limit. --- runtime/shims/d3d12_xs_list_values.h | 25 +++++++++++- runtime/src/list_value_progress.h | 49 +++++++++++++++++++++++ runtime/test/list_value_progress_test.cpp | 46 +++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/runtime/shims/d3d12_xs_list_values.h b/runtime/shims/d3d12_xs_list_values.h index 0872958ec9..96703690b7 100644 --- a/runtime/shims/d3d12_xs_list_values.h +++ b/runtime/shims/d3d12_xs_list_values.h @@ -1156,6 +1156,21 @@ class Pump { } } + // A gate that stays shut says why, at most once a minute (report_due): counts and seconds only, no address. + void note_held(leonida::list_value_progress::Hold why, std::uint64_t now_ms) { + namespace lvp = leonida::list_value_progress; + if (gates_.empty()) { + held_report_ms_ = 0; // nothing held: the next hold starts its own minute + return; + } + const std::uint64_t oldest = gates_.front().held_ms; + if (!lvp::report_due(oldest, now_ms, held_report_ms_)) return; + held_report_ms_ = now_ms; + std::fprintf(stderr, "[rt] d3d12_xs: a list value gate has been held %llu s (%zu held): %s\n", + static_cast((now_ms - oldest) / 1000), gates_.size(), + lvp::hold_text(why)); + } + // The progress rules over what is in flight (src/list_value_progress.h): the index of the gate that goes, noted // and logged, or gates_.size(). Called with mutex_ held, after a pass that opened nothing. std::size_t choose_release(bool landed_any) { @@ -1169,6 +1184,7 @@ class Pump { if (activity.releasing || activity.title_submitting) { last_progress_ms_ = now_ms; last_progress_at_ = now; + note_held(activity.releasing ? lvp::Hold::releasing : lvp::Hold::submitting, now_ms); return gates_.size(); // the cheap answer first } activity.presents = presents_.load(std::memory_order_relaxed); @@ -1193,6 +1209,7 @@ class Pump { last_progress_ms_ = now_ms; last_progress_at_ = now; if (done >= wg.value && wake_) SetEvent(wake_); + note_held(lvp::Hold::write_running, now_ms); return gates_.size(); } groups.push_back({wg.queue.get(), wg.after_gate, false, @@ -1221,6 +1238,7 @@ class Pump { last_progress_ms_ = now_ms; last_progress_at_ = now; if (done >= g.after && wake_) SetEvent(wake_); + note_held(lvp::Hold::action_running, now_ms); return gates_.size(); } } @@ -1229,7 +1247,10 @@ class Pump { g.presents_at_hold, g.held_ms}); } const lvp::Decision decision = lvp::decide(groups, view, activity, console_value_met); - if (decision.reason == lvp::Reason::hold || decision.gate >= gates_.size()) return gates_.size(); + if (decision.reason == lvp::Reason::hold || decision.gate >= gates_.size()) { + note_held(lvp::hold_reason(groups, view, activity), now_ms); + return gates_.size(); + } // Gate ONLY Reason::present on a short high-resolution quiet window after the last observed progress (leaving // list_value_progress::decide() pure for unit tests) so sub-ms races from deferred CPU Fence::Signal // callbacks or post-PresentX CPU writes settle before releasing a gate unmet. Using Clock::now() (QPC) instead @@ -1237,6 +1258,7 @@ class Pump { constexpr auto kPresentQuiet = std::chrono::milliseconds(2); if (decision.reason == lvp::Reason::present && last_progress_at_ != Clock::time_point{} && now - last_progress_at_ < kPresentQuiet) { + note_held(lvp::Hold::settling, now_ms); return gates_.size(); } const Reason reason = gates_[decision.gate].queue->written->GetCompletedValue() == UINT64_MAX @@ -1526,6 +1548,7 @@ class Pump { unsigned logged_met_ = 0; std::uint64_t logged_released_ = 0; std::uint64_t last_progress_ms_ = 0; // guarded by mutex_: latest tick progress was observed + std::uint64_t held_report_ms_ = 0; // guarded by mutex_: when the held-gate line last printed Clock::time_point last_progress_at_{}; // guarded by mutex_: high-res QPC progress timestamp Clock::time_point last_lost_check_{}; // pump thread only (mutex_): throttled device-loss poll timestamp std::atomic presents_{0}; // the title's PresentX calls so far diff --git a/runtime/src/list_value_progress.h b/runtime/src/list_value_progress.h index 4afe64e5bd..d8f7ec4c92 100644 --- a/runtime/src/list_value_progress.h +++ b/runtime/src/list_value_progress.h @@ -148,6 +148,55 @@ inline bool can_progress(std::span writes, std::span writes, std::span gates, + const Activity& activity) { + if (activity.releasing) return Hold::releasing; + if (activity.title_submitting) return Hold::submitting; + for (const PendingWriteGroup& w : writes) + if (w.running) return Hold::write_running; + for (const PendingGate& g : gates) + if (g.is_action && g.action_running) return Hold::action_running; + if (activity.now_ms < activity.title_call_ms || activity.now_ms - activity.title_call_ms < kStalledMs) + return Hold::title_calling; + return Hold::young; +} + +// One line once the oldest gate has stood kHeldReportMs, then at most one per kHeldReportMs (a `last_report_ms` of +// 0 is "nothing said yet"). +inline bool report_due(std::uint64_t oldest_ms, std::uint64_t now_ms, std::uint64_t last_report_ms) { + if (!oldest_ms || now_ms < oldest_ms || now_ms - oldest_ms < kHeldReportMs) return false; + return !last_report_ms || (now_ms >= last_report_ms && now_ms - last_report_ms >= kHeldReportMs); +} + // Which held gate goes now without its value, if any. `gates` are the pending gates in the order they were held // (each queue's in rising value); `met(comparison, value, reference, wide)` is console_value_met. template diff --git a/runtime/test/list_value_progress_test.cpp b/runtime/test/list_value_progress_test.cpp index 94c4cfa119..4310068e42 100644 --- a/runtime/test/list_value_progress_test.cpp +++ b/runtime/test/list_value_progress_test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -554,6 +555,51 @@ int main() { holds.detach(&holder); } + // 15. The held-gate line names the condition can_progress() found, then the quiet window. Diagnostics only: + // decide() answers the same as before. + { + const PendingGate gates[] = {gate(qa, 1, wait_x, 0, 0)}; + Activity a; + a.now_ms = 100'000; + a.title_call_ms = a.now_ms; // the title called just now + CHECK(hold_reason({}, gates, a) == Hold::title_calling); + CHECK(run({}, gates, a).reason == Reason::hold); + a.releasing = true; + CHECK(hold_reason({}, gates, a) == Hold::releasing); + a.releasing = false; + a.title_submitting = true; + CHECK(hold_reason({}, gates, a) == Hold::submitting); + a.title_submitting = false; + const PendingWriteGroup running[] = {group(qb, 0, write_y, true)}; + CHECK(hold_reason(running, gates, a) == Hold::write_running); + PendingGate action = gate(qc, 1, {}); + action.is_action = true; + action.action_running = true; + const PendingGate with_action[] = {gates[0], action}; + CHECK(hold_reason({}, with_action, a) == Hold::action_running); + // The title quiet past kStalledMs and the gate younger than it: the quiet window keeps it, not a call. + a.title_call_ms = a.now_ms - kStalledMs; + const PendingGate young[] = {gate(qa, 1, wait_x, 0, a.now_ms - 1'000)}; + CHECK(hold_reason({}, young, a) == Hold::young); + CHECK(run({}, young, a).reason == Reason::hold); + // Every wording is present and distinct. + for (Hold h : {Hold::releasing, Hold::submitting, Hold::write_running, Hold::action_running, Hold::settling, + Hold::title_calling, Hold::young}) + CHECK(hold_text(h) && hold_text(h)[0]); + CHECK(std::string(hold_text(Hold::young)) != hold_text(Hold::settling)); + } + + // 16. One line once the oldest gate is a minute old, then at most one a minute. + { + CHECK(!report_due(0, 100'000, 0)); // nothing held + CHECK(!report_due(99'000, 100'000, 0)); // a second old + CHECK(!report_due(100'000 - (kHeldReportMs - 1), 100'000, 0)); // one ms short of a minute + CHECK(report_due(100'000 - kHeldReportMs, 100'000, 0)); // exactly a minute + CHECK(!report_due(1, 100'000, 99'999)); // said a moment ago + CHECK(report_due(1, 100'000, 100'000 - kHeldReportMs)); // a minute after the last line + CHECK(!report_due(200'000, 150'000, 0)); // a clock that went back + } + std::printf("list_value_progress_test: all checks passed\n"); return 0; }