diff options
| author | OreoFR <29048345+OreoFR@users.noreply.github.com> | 2026-11-26 22:45:08 +0100 |
|---|---|---|
| committer | OreoFR <29048345+OreoFR@users.noreply.github.com> | 2026-11-26 23:07:38 +0100 |
| commit | 62be3fa1898ffdb80e0ea0ea6a7e6a0be2af3b94 (patch) | |
| tree | d2fe022d725451446e113776e562b951449b2f49 /runtime/test/submit_mutex_test.cpp | |
| parent | e5a7c8942678b323f655939c81f5d8855d20c248 (diff) | |
compile gate: a submission waits at most 15 s for creates in the driver, then goes ahead (LEONIDA_COMPILE_GATE_WAIT_MS)
The gate keeps vkQueueSubmit out of the driver while a pipeline create is
in it (on NVIDIA 630.20 a submission that entered during a long compute
create waited 10 s in the driver and lost the device). The waiter holds the
submit lock, so every queue stops behind it: on an RTX 4070 Laptop (NVIDIA
621.40) one compute create stayed in the driver for over 54 s during the
story load and the title's 30 s hang watchdog ended the process.
A submission now goes ahead after LEONIDA_COMPILE_GATE_WAIT_MS (15 s by
default; 0: no limit). The creates in the driver then hold no later
submission back; creates that enter afterwards are waited for again. On
630.20 that only gives up creates over 25 s (15 s here plus the driver's
10 s), which the watchdog ends anyway. With the watchdog kept kicked
(LEONIDA_TITLE_WATCHDOG=0 and LEONIDA_TITLE_WATCHDOG_KICK) the default stays
no limit. The log names each submission that goes ahead and how long it then
spent in the driver. The README row, which still described the gate as
opt-in, now says it is on by default.
Tested: submit_mutex (new gate_wait_limit case), MSVC, Windows 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/submit_mutex_test.cpp')
| -rw-r--r-- | runtime/test/submit_mutex_test.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/runtime/test/submit_mutex_test.cpp b/runtime/test/submit_mutex_test.cpp index 345f30887..c3b9b2d17 100644 --- a/runtime/test/submit_mutex_test.cpp +++ b/runtime/test/submit_mutex_test.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <atomic> | 9 | #include <atomic> |
| 10 | #include <chrono> | 10 | #include <chrono> |
| 11 | #include <cstdio> | 11 | #include <cstdio> |
| 12 | #include <cstdlib> | ||
| 12 | #include <mutex> | 13 | #include <mutex> |
| 13 | #include <thread> | 14 | #include <thread> |
| 14 | 15 | ||
| @@ -136,6 +137,7 @@ int compile_gate() { | |||
| 136 | return 0; | 137 | return 0; |
| 137 | } | 138 | } |
| 138 | SubmitMutex m; | 139 | SubmitMutex m; |
| 140 | m.set_gate_wait_limit_ms(0); // no limit: gate_wait_limit checks the limit | ||
| 139 | // Nothing in the driver: a submission passes at once. | 141 | // Nothing in the driver: a submission passes at once. |
| 140 | { | 142 | { |
| 141 | const std::int64_t start = now_ms(); | 143 | const std::int64_t start = now_ms(); |
| @@ -197,12 +199,92 @@ int compile_gate() { | |||
| 197 | return 0; | 199 | return 0; |
| 198 | } | 200 | } |
| 199 | 201 | ||
| 202 | int gate_wait_limit() { | ||
| 203 | if (!SubmitMutex::compile_gate_enabled()) { | ||
| 204 | std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): wait limit not checked\n"); | ||
| 205 | return 0; | ||
| 206 | } | ||
| 207 | // The default with neither LEONIDA_COMPILE_GATE_WAIT_MS nor the watchdog kick set. | ||
| 208 | if (!std::getenv("LEONIDA_COMPILE_GATE_WAIT_MS") && !std::getenv("LEONIDA_TITLE_WATCHDOG_KICK")) | ||
| 209 | EXPECT(SubmitMutex::default_gate_wait_limit_ms() == SubmitMutex::kDefaultGateWaitMs); | ||
| 210 | SubmitMutex m; | ||
| 211 | m.set_gate_wait_limit_ms(150); | ||
| 212 | EXPECT(m.gate_wait_limit_ms() == 150); | ||
| 213 | // A create that stays in the driver until it is let go (one that takes longer than the limit). | ||
| 214 | std::atomic<bool> long_in{false}, release_long{false}; | ||
| 215 | std::atomic<std::int64_t> long_left_at{0}; | ||
| 216 | std::thread long_create([&] { | ||
| 217 | const SubmitMutex::CompileTurn turn(m); | ||
| 218 | long_in = true; | ||
| 219 | while (!release_long) std::this_thread::sleep_for(1ms); | ||
| 220 | long_left_at = now_ms(); | ||
| 221 | }); | ||
| 222 | EXPECT(eventually([&] { return long_in.load(); })); | ||
| 223 | // The submission goes ahead at the limit, the create still in the driver. | ||
| 224 | std::int64_t first_waited = 0; | ||
| 225 | bool first_ahead = false; | ||
| 226 | { | ||
| 227 | const std::int64_t start = now_ms(); | ||
| 228 | const SubmitMutex::SubmitTurn turn(m); | ||
| 229 | first_waited = now_ms() - start; | ||
| 230 | first_ahead = turn.went_ahead(); | ||
| 231 | } | ||
| 232 | // The next one passes at once: the create the first went past holds no submission back. | ||
| 233 | std::int64_t second_waited = 0; | ||
| 234 | bool second_ahead = true; | ||
| 235 | { | ||
| 236 | const std::int64_t start = now_ms(); | ||
| 237 | const SubmitMutex::SubmitTurn turn(m); | ||
| 238 | second_waited = now_ms() - start; | ||
| 239 | second_ahead = turn.went_ahead(); | ||
| 240 | } | ||
| 241 | // A create that enters after that is waited for again, until it leaves (well within the limit now), while the | ||
| 242 | // long one is still in the driver. | ||
| 243 | m.set_gate_wait_limit_ms(5000); | ||
| 244 | std::atomic<bool> short_in{false}; | ||
| 245 | std::atomic<std::int64_t> short_left_at{0}; | ||
| 246 | std::thread short_create([&] { | ||
| 247 | const SubmitMutex::CompileTurn turn(m); | ||
| 248 | short_in = true; | ||
| 249 | std::this_thread::sleep_for(200ms); | ||
| 250 | short_left_at = now_ms(); | ||
| 251 | }); | ||
| 252 | const bool short_entered = eventually([&] { return short_in.load(); }); | ||
| 253 | std::int64_t third_entered_at = 0; | ||
| 254 | bool third_ahead = true; | ||
| 255 | { | ||
| 256 | const SubmitMutex::SubmitTurn turn(m); | ||
| 257 | third_entered_at = now_ms(); | ||
| 258 | third_ahead = turn.went_ahead(); | ||
| 259 | } | ||
| 260 | const bool long_still_in = long_left_at.load() == 0; | ||
| 261 | release_long = true; | ||
| 262 | long_create.join(); | ||
| 263 | short_create.join(); | ||
| 264 | EXPECT(short_entered); | ||
| 265 | EXPECT(first_ahead && first_waited >= 140 && first_waited < 1000); | ||
| 266 | EXPECT(!second_ahead && second_waited < 50); | ||
| 267 | EXPECT(!third_ahead && third_entered_at >= short_left_at.load() && long_still_in); | ||
| 268 | const SubmitMutex::GateStats stats = m.gate_stats(); | ||
| 269 | EXPECT(stats.submits == 2 && stats.ahead == 1); | ||
| 270 | // Both gone: a submission passes at once. | ||
| 271 | { | ||
| 272 | const std::int64_t start = now_ms(); | ||
| 273 | const SubmitMutex::SubmitTurn turn(m); | ||
| 274 | EXPECT(now_ms() - start < 50 && !turn.went_ahead()); | ||
| 275 | } | ||
| 276 | std::printf("compile gate: a submission went ahead after %lld ms (limit 150 ms) with the create still in the " | ||
| 277 | "driver, the next passed in %lld ms, and a create that entered later was waited for again\n", | ||
| 278 | static_cast<long long>(first_waited), static_cast<long long>(second_waited)); | ||
| 279 | return 0; | ||
| 280 | } | ||
| 281 | |||
| 200 | } // namespace | 282 | } // namespace |
| 201 | 283 | ||
| 202 | int main() { | 284 | int main() { |
| 203 | std::setvbuf(stdout, nullptr, _IONBF, 0); | 285 | std::setvbuf(stdout, nullptr, _IONBF, 0); |
| 204 | if (owner_tracking() || waits_for_holder() || waits_for_queued_submitter() || handoff_is_capped() || | 286 | if (owner_tracking() || waits_for_holder() || waits_for_queued_submitter() || handoff_is_capped() || |
| 205 | compile_gate()) | 287 | compile_gate() || gate_wait_limit()) |
| 206 | return 1; | 288 | return 1; |
| 207 | std::printf("submit_mutex_test: all passed\n"); | 289 | std::printf("submit_mutex_test: all passed\n"); |
| 208 | return 0; | 290 | return 0; |