Ursache der 3 roten Tests unter Volllast (Idle, CPU voll), belegt: 1. Wanduhr-Budget: river_spieler loest in Ruhe 600 Iterationen in ~0,6 s von 1,5 s, Stufe B (Turn) in ~0,6 s von 1,1 s. Ab etwa 2- bis 3-facher Verlangsamung schneidet das Budget Iterationen ab (andere Zahlen: a_read_without_confidence_is_bit_identical vergleicht zwei Loesungen bitgenau) oder unter MIN_ITERS ab (None, die Heuristik entscheidet: stage_b_... expect scheitert). 2. Wettlauf globaler Schalter: jedes Testmodul hatte sein eigenes MODE_LOCK. off_means_none_... vergleicht ganze decide()-Antworten auf Flop-/River-Spots, waehrend river_spieler- bzw. flop_spieler-Tests SOLVER_RIVER/FLOP prozessweit einschalten. river3/multi3 ohne gemeinsamen Lock. frist::begin() ist thread-lokal und nicht die Ursache. Fix (nur Tests, Live-Pfad unveraendert): - frist::fest_hier(): Guard, unter dem DIESER Thread wie SOLVER_ZEIT=fest die volle Iterationszahl rechnet. Solver-Ergebnis-Tests laufen darunter. - engine::SCHALTER_LOCK (cfg(test)): ein Lock fuer alle Tests, die Solver-Schalter umlegen. - river3/multi3: "legal" (fest) und "in time" (Wanduhr, None erlaubt) getrennt. - Spec a_spent_deadline_hands_back_and_fest_hier_ignores_it: Frist verbraucht -> None; fest_hier -> dieselben Zeilen bitgenau. Lib-Tests mit Idle-Prioritaet bei ~76 % Maschinenlast 2x: 267 gruen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.8 KiB
Rust
70 lines
2.8 KiB
Rust
//! The decision deadline of the postflop solvers ("Solver ueberall"): `decide_with` marks the start of
|
|
//! each decision on its thread, and a solver gets what is left of its street's total before it starts.
|
|
//! Totals per decision (live table): river and flop 2 s, turn 1.25 s, each minus `MARGIN_MS` for the
|
|
//! work after the solve. Without a mark (tests, tools calling a solver directly) the full total is left.
|
|
|
|
use std::cell::Cell;
|
|
use std::time::Instant;
|
|
|
|
thread_local! {
|
|
static START: Cell<Option<Instant>> = const { Cell::new(None) };
|
|
/// `fest_hier`: this thread ignores wall time like `SOLVER_ZEIT=fest` (tests, tools).
|
|
static FEST_HIER: Cell<bool> = const { Cell::new(false) };
|
|
}
|
|
|
|
/// Total wall time of one decision per street, in ms.
|
|
pub const RIVER_MS: f64 = 2000.0;
|
|
pub const TURN_MS: f64 = 1250.0;
|
|
pub const FLOP_MS: f64 = 2000.0;
|
|
/// Kept free after the solve (strategy readout, sampling, the answer).
|
|
pub const MARGIN_MS: f64 = 150.0;
|
|
|
|
/// Mark the start of a decision on this thread.
|
|
pub fn begin() {
|
|
START.with(|s| s.set(Some(Instant::now())));
|
|
}
|
|
|
|
/// Milliseconds since the mark (0 without one).
|
|
pub fn elapsed_ms() -> f64 {
|
|
START.with(|s| s.get().map_or(0.0, |t| t.elapsed().as_secs_f64() * 1e3))
|
|
}
|
|
|
|
/// What a solver may still spend of `total_ms` (may be ≤ 0: then it must not start).
|
|
pub fn left_ms(total_ms: f64) -> f64 {
|
|
total_ms - MARGIN_MS - elapsed_ms()
|
|
}
|
|
|
|
/// Measurement switch `SOLVER_ZEIT=fest`: solvers ignore wall time and always run their full iteration
|
|
/// count, so ladder and LBR results do not depend on machine load (read once).
|
|
pub fn fixed() -> bool {
|
|
static FIXED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
|
FEST_HIER.with(Cell::get) || *FIXED.get_or_init(|| std::env::var("SOLVER_ZEIT").as_deref() == Ok("fest"))
|
|
}
|
|
|
|
/// While the guard lives, solvers on THIS thread run their full iteration count whatever the load (as
|
|
/// `SOLVER_ZEIT=fest`, but per thread). For tests that check a solver's result rather than its deadline:
|
|
/// under a busy machine the wall-time budget otherwise cuts iterations (different numbers) or drops the
|
|
/// solve below its minimum (the heuristic decides). Never called on the live path.
|
|
pub fn fest_hier() -> FestHier {
|
|
FestHier(FEST_HIER.with(|f| f.replace(true)))
|
|
}
|
|
|
|
/// Guard of `fest_hier`; restores the previous state on drop.
|
|
pub struct FestHier(bool);
|
|
|
|
impl Drop for FestHier {
|
|
fn drop(&mut self) {
|
|
FEST_HIER.with(|f| f.set(self.0));
|
|
}
|
|
}
|
|
|
|
/// The budget a solve gets: `cap_ms` (its own limit), cut to what is left of the street's total;
|
|
/// infinite under `SOLVER_ZEIT=fest`.
|
|
pub fn budget_ms(cap_ms: f64, total_ms: f64) -> f64 {
|
|
if fixed() {
|
|
f64::INFINITY
|
|
} else {
|
|
cap_ms.min(left_ms(total_ms))
|
|
}
|
|
}
|