diff options
| author | OreoFR <29048345+OreoFR@users.noreply.github.com> | 2026-11-27 02:20:24 +0100 |
|---|---|---|
| committer | OreoFR <29048345+OreoFR@users.noreply.github.com> | 2026-11-27 02:20:24 +0100 |
| commit | e5d1a14681fa65de2d8b49b2efeeec62370ec8ee (patch) | |
| tree | 79632e11839f4a0f0e18969d49be5a57fa958f8b /runtime/test/submit_mutex_test.cpp | |
| parent | f7b2497303466eb3bcebe7fe88cde838b1f45334 (diff) | |
compile gate: a held probe needs the create beside it to have just left
A submission that stays 2 s or more in the driver turned its create kind's gate on (or back on). It
now counts only if it came back within 500 ms after a create of that kind, there when it entered,
left the driver: a submission held behind a create comes back when the create does. On the 4070
Laptop (621.40, 8 GB nearly full) a 36 s submission came back 18 s before the compute create beside
it; counted as held, it re-armed the gate, which then kept the next submission 78 s behind compute
creates. One that is slow with its creates still there is logged (the first 8) and judged nothing.
Tests: the held-probe tests release the create 100 ms before the submission comes back; a new one
checks that a slow submission with the create still there gives no held verdict.
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 | 90 |
1 files changed, 71 insertions, 19 deletions
diff --git a/runtime/test/submit_mutex_test.cpp b/runtime/test/submit_mutex_test.cpp index 57ca4558c..69b7c8e1e 100644 --- a/runtime/test/submit_mutex_test.cpp +++ b/runtime/test/submit_mutex_test.cpp | |||
| @@ -338,26 +338,36 @@ int gate_adapts() { | |||
| 338 | EXPECT(passed < 50 && !fresh_ahead); | 338 | EXPECT(passed < 50 && !fresh_ahead); |
| 339 | } | 339 | } |
| 340 | std::printf("compile gate: off after two quick probes a second apart, not after two within the second\n"); | 340 | std::printf("compile gate: off after two quick probes a second apart, not after two within the second\n"); |
| 341 | // A held probe: the gate stays on, and the create is waited for again however long it takes. | 341 | // A held probe: a submission that comes back just after the create beside it leaves. The gate stays on, and a |
| 342 | // later create is waited for however long it takes. | ||
| 342 | { | 343 | { |
| 343 | SubmitMutex m; | 344 | SubmitMutex m; |
| 344 | m.set_gate_adaptive(true); | 345 | m.set_gate_adaptive(true); |
| 345 | m.set_gate_wait_limit_ms(100); | 346 | m.set_gate_wait_limit_ms(100); |
| 346 | m.set_gate_probe_budget_ms(0); // probes at the limit only: gate_probe_budget checks the budget | 347 | m.set_gate_probe_budget_ms(0); // probes at the limit only: gate_probe_budget checks the budget |
| 347 | std::atomic<bool> in{false}, release{false}; | 348 | std::atomic<bool> first_in{false}, first_release{false}; |
| 348 | std::thread create([&] { | 349 | std::thread first([&] { |
| 349 | const SubmitMutex::CompileTurn turn(m); | 350 | const SubmitMutex::CompileTurn turn(m); |
| 350 | in = true; | 351 | first_in = true; |
| 351 | while (!release) std::this_thread::sleep_for(1ms); | 352 | while (!first_release) std::this_thread::sleep_for(1ms); |
| 352 | }); | 353 | }); |
| 353 | const bool entered = eventually([&] { return in.load(); }); | 354 | const bool first_entered = eventually([&] { return first_in.load(); }); |
| 354 | { | 355 | { |
| 355 | const SubmitMutex::SubmitTurn turn(m); // goes ahead, then stays "in the driver" for 2.1 s | 356 | const SubmitMutex::SubmitTurn turn(m); // goes ahead, then stays "in the driver" for 2.1 s |
| 356 | std::this_thread::sleep_for(2100ms); | 357 | std::this_thread::sleep_for(2000ms); |
| 358 | first_release = true; // the create leaves 100 ms before the submission comes back | ||
| 359 | first.join(); | ||
| 360 | std::this_thread::sleep_for(100ms); | ||
| 357 | } | 361 | } |
| 358 | const Verdict held = m.gate_verdict(); | 362 | const Verdict held = m.gate_verdict(); |
| 359 | // The create it stayed beside is waited for again, past the limit (its kind holds submissions), until it | 363 | // A create of the same kind is waited for, past the limit (its kind holds submissions), until it leaves. |
| 360 | // leaves. | 364 | std::atomic<bool> in{false}, release{false}; |
| 365 | std::thread create([&] { | ||
| 366 | const SubmitMutex::CompileTurn turn(m); | ||
| 367 | in = true; | ||
| 368 | while (!release) std::this_thread::sleep_for(1ms); | ||
| 369 | }); | ||
| 370 | const bool entered = first_entered && eventually([&] { return in.load(); }); | ||
| 361 | std::atomic<std::int64_t> released_at{0}; | 371 | std::atomic<std::int64_t> released_at{0}; |
| 362 | std::thread releaser([&] { | 372 | std::thread releaser([&] { |
| 363 | std::this_thread::sleep_for(300ms); | 373 | std::this_thread::sleep_for(300ms); |
| @@ -379,6 +389,30 @@ int gate_adapts() { | |||
| 379 | EXPECT(!ahead && entered_at >= released_at.load()); | 389 | EXPECT(!ahead && entered_at >= released_at.load()); |
| 380 | } | 390 | } |
| 381 | std::printf("compile gate: a probe held 2.1 s keeps it on, and the create is then waited out past the limit\n"); | 391 | std::printf("compile gate: a probe held 2.1 s keeps it on, and the create is then waited out past the limit\n"); |
| 392 | // A slow submission that comes back with the create beside it still there was not held by it: no verdict. | ||
| 393 | { | ||
| 394 | SubmitMutex m; | ||
| 395 | m.set_gate_adaptive(true); | ||
| 396 | m.set_gate_wait_limit_ms(100); | ||
| 397 | m.set_gate_probe_budget_ms(0); | ||
| 398 | std::atomic<bool> in{false}, release{false}; | ||
| 399 | std::thread create([&] { | ||
| 400 | const SubmitMutex::CompileTurn turn(m); | ||
| 401 | in = true; | ||
| 402 | while (!release) std::this_thread::sleep_for(1ms); | ||
| 403 | }); | ||
| 404 | const bool entered = eventually([&] { return in.load(); }); | ||
| 405 | { | ||
| 406 | const SubmitMutex::SubmitTurn turn(m); // goes ahead at the limit, then stays 2.1 s | ||
| 407 | std::this_thread::sleep_for(2100ms); | ||
| 408 | } | ||
| 409 | const Verdict after = m.gate_verdict(); | ||
| 410 | release = true; | ||
| 411 | create.join(); | ||
| 412 | EXPECT(entered); | ||
| 413 | EXPECT(after != Verdict::driver_holds); | ||
| 414 | } | ||
| 415 | std::printf("compile gate: a 2.1 s submission that came back with the create still there is not a held probe\n"); | ||
| 382 | return 0; | 416 | return 0; |
| 383 | } | 417 | } |
| 384 | 418 | ||
| @@ -457,11 +491,12 @@ int gate_probe_budget() { | |||
| 457 | { | 491 | { |
| 458 | const SubmitMutex::SubmitTurn turn(m); // goes ahead at the budget, then is held 2.1 s | 492 | const SubmitMutex::SubmitTurn turn(m); // goes ahead at the budget, then is held 2.1 s |
| 459 | ahead = turn.went_ahead(); | 493 | ahead = turn.went_ahead(); |
| 460 | std::this_thread::sleep_for(2100ms); | 494 | std::this_thread::sleep_for(2000ms); |
| 495 | release = true; // the create it stayed beside leaves 100 ms before it comes back: a held probe | ||
| 496 | create.join(); | ||
| 497 | std::this_thread::sleep_for(100ms); | ||
| 461 | } | 498 | } |
| 462 | const Verdict held = m.gate_verdict(); | 499 | const Verdict held = m.gate_verdict(); |
| 463 | release = true; // the create it stayed beside leaves: it would be waited for again now | ||
| 464 | create.join(); | ||
| 465 | std::atomic<bool> short_in{false}; | 500 | std::atomic<bool> short_in{false}; |
| 466 | std::atomic<std::int64_t> short_left_at{0}; | 501 | std::atomic<std::int64_t> short_left_at{0}; |
| 467 | std::thread short_create([&] { | 502 | std::thread short_create([&] { |
| @@ -533,15 +568,32 @@ int gate_per_kind() { | |||
| 533 | g_release = true; | 568 | g_release = true; |
| 534 | g.join(); | 569 | g.join(); |
| 535 | const Verdict graphics_after = m.gate_verdict(Kind::graphics); // one quick probe: still pending | 570 | const Verdict graphics_after = m.gate_verdict(Kind::graphics); // one quick probe: still pending |
| 536 | // Re-arm: beside the compute create (gate off), a submission stays 2.1 s in the "driver". | 571 | // A second compute create, there through the rest. |
| 537 | { const SubmitMutex::SubmitTurn turn(m); std::this_thread::sleep_for(2100ms); } | 572 | std::atomic<bool> c2_in{false}, c2_release{false}; |
| 573 | std::atomic<std::int64_t> c2_left_at{0}; | ||
| 574 | std::thread c2([&] { | ||
| 575 | const SubmitMutex::CompileTurn turn(m, compute); | ||
| 576 | c2_in = true; | ||
| 577 | while (!c2_release) std::this_thread::sleep_for(1ms); | ||
| 578 | c2_left_at = now_ms(); | ||
| 579 | }); | ||
| 580 | const bool c2_entered = eventually([&] { return c2_in.load(); }); | ||
| 581 | // Re-arm: beside the compute creates (gate off), a submission stays 2.1 s in the "driver" and comes back 100 ms | ||
| 582 | // after the first one leaves. | ||
| 583 | { | ||
| 584 | const SubmitMutex::SubmitTurn turn(m); | ||
| 585 | std::this_thread::sleep_for(2000ms); | ||
| 586 | c_release = true; | ||
| 587 | c.join(); | ||
| 588 | std::this_thread::sleep_for(100ms); | ||
| 589 | } | ||
| 538 | const Verdict compute_rearmed = m.gate_verdict(Kind::compute); | 590 | const Verdict compute_rearmed = m.gate_verdict(Kind::compute); |
| 539 | // The compute create is waited for again, and not gone past at the limit: its kind holds submissions. | 591 | // The second compute create is waited for, and not gone past at the limit: its kind holds submissions. |
| 540 | std::atomic<std::int64_t> released_at{0}; | 592 | std::atomic<std::int64_t> released_at{0}; |
| 541 | std::thread releaser([&] { | 593 | std::thread releaser([&] { |
| 542 | std::this_thread::sleep_for(400ms); | 594 | std::this_thread::sleep_for(400ms); |
| 543 | released_at = now_ms(); | 595 | released_at = now_ms(); |
| 544 | c_release = true; | 596 | c2_release = true; |
| 545 | }); | 597 | }); |
| 546 | std::int64_t entered_at = 0; | 598 | std::int64_t entered_at = 0; |
| 547 | bool after_ahead = true; | 599 | bool after_ahead = true; |
| @@ -551,13 +603,13 @@ int gate_per_kind() { | |||
| 551 | after_ahead = turn.went_ahead(); | 603 | after_ahead = turn.went_ahead(); |
| 552 | } | 604 | } |
| 553 | releaser.join(); | 605 | releaser.join(); |
| 554 | c.join(); | 606 | c2.join(); |
| 555 | EXPECT(c_entered && g_entered); | 607 | EXPECT(c_entered && c2_entered && g_entered); |
| 556 | EXPECT(compute_off == Verdict::driver_does_not_hold && graphics_before == Verdict::pending); | 608 | EXPECT(compute_off == Verdict::driver_does_not_hold && graphics_before == Verdict::pending); |
| 557 | EXPECT(g_ahead && g_waited >= 90 && g_waited < 1000); | 609 | EXPECT(g_ahead && g_waited >= 90 && g_waited < 1000); |
| 558 | EXPECT(graphics_after == Verdict::pending); | 610 | EXPECT(graphics_after == Verdict::pending); |
| 559 | EXPECT(compute_rearmed == Verdict::driver_holds); | 611 | EXPECT(compute_rearmed == Verdict::driver_holds); |
| 560 | EXPECT(!after_ahead && entered_at >= c_left_at.load() && entered_at >= released_at.load()); | 612 | EXPECT(!after_ahead && entered_at >= c2_left_at.load() && entered_at >= released_at.load()); |
| 561 | m.report_creates_on_loss(); // nothing in the driver now: the verdicts only | 613 | m.report_creates_on_loss(); // nothing in the driver now: the verdicts only |
| 562 | std::printf("compile gate: compute off with graphics still gated; a 2.1 s submission re-armed compute, and the next " | 614 | std::printf("compile gate: compute off with graphics still gated; a 2.1 s submission re-armed compute, and the next " |
| 563 | "one waited %lld ms past the 100 ms limit for the compute create\n", | 615 | "one waited %lld ms past the 100 ms limit for the compute create\n", |