Notbremse in Uhrzeit nur live (KERN_NOTBREMSE_MS=8000 aus decide.py) + Pflicht in BelowNormal

frist::notbremse(): Uhrzeit seit begin() ueber KERN_NOTBREMSE_MS -> left_ms 0, kein Solver startet,
laufende Solver-Schleifen (turn_game, flop/river/river3/multi3, solver_kern) geben ab, die Heuristik
entscheidet. Gesetzt nur von entscheiden/decide.py (Live-Pfad); roentgen.kern_aufruf entfernt sie,
Mess- und Pflichtpfade bleiben rein in Rechenzeit. Pflichtfaelle: Kern in BelowNormal, Frist 30 s je Fall
(vorher Idle, 275 s gesamt, brach unter Volllast ab). Nachweis: Bremse 1 ms -> 0/20 Solver, ohne -> 20/20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 01:26:48 +01:00
co-authored by Claude Opus 5.5
parent 7aa20584ef
commit 55c713d4e0
10 changed files with 60 additions and 15 deletions
+5
View File
@@ -81,6 +81,11 @@ def laeufer_umgebung(schalter, umgebung):
SCHALTER = lies_schalter()
laeufer_umgebung(SCHALTER, os.environ)
KERN_ENV = {**os.environ, **SCHALTER}
# Notbremse in Uhrzeit, NUR im Live-Pfad (Orchestrator 19.11.): Die Fristen des Kerns zählen Rechenzeit
# (deterministisch, auch unter Last). Wartet der Kern auf einem überlasteten Rechner aber länger als 8 s
# Uhrzeit, startet kein Solver mehr und ein laufender gibt ab: die Heuristik entscheidet, kein Tisch-Timeout.
# Mess- und Pflichtwerkzeuge setzen sie nicht und bleiben rein in Rechenzeit.
KERN_ENV.setdefault("KERN_NOTBREMSE_MS", "8000")
if SCHALTER and not os.environ.get("COINPOKER_ARM"):
os.environ["COINPOKER_ARM"] = "schalter:" + ",".join(
f"{k}={v}" for k, v in sorted(SCHALTER.items()) if k not in OHNE_MARKE)
+6 -3
View File
@@ -71,6 +71,7 @@ BEKANNTE_SCHALTER = ("MDF_UNREAD", "RAISE_DRAWS", "RAISE_PRIOR", "TURN_SPIEL", "
"PREFLOP_MIKRO", "PREFLOP_VOLL_TEILE")
OHNE_MARKE = ("GRUNDSTRATEGIE",)
IDLE_PRIORITY_CLASS = 0x00000040
BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
KERN_KOPIE = "pokerbench-roentgen-nachspiel" + (".exe" if sys.platform == "win32" else "")
@@ -469,16 +470,18 @@ def kern_kopie(quelle, ziel_ordner, name=KERN_KOPIE):
return ziel
def kern_aufruf(binary, timeout_je=5.0):
"""kern(anfragen, env) -> antworten: ein Prozess je Bündel, Priorität Idle."""
def kern_aufruf(binary, timeout_je=5.0, prioritaet=None):
"""kern(anfragen, env) -> antworten: ein Prozess je Bündel, Priorität Idle (Windows: `prioritaet` z. B.
BELOW_NORMAL_PRIORITY_CLASS). Die Notbremse des Live-Pfads (KERN_NOTBREMSE_MS) fällt weg: rein Rechenzeit."""
def kern(anfragen, env):
if not anfragen:
return []
umgebung = {k: v for k, v in os.environ.items() if k not in BEKANNTE_SCHALTER and k not in env}
umgebung.update(env)
umgebung.pop("KERN_NOTBREMSE_MS", None)
extra = {}
if sys.platform == "win32":
extra["creationflags"] = IDLE_PRIORITY_CLASS
extra["creationflags"] = prioritaet or IDLE_PRIORITY_CLASS
else:
extra["preexec_fn"] = lambda: os.nice(19)
r = subprocess.run([binary], input="\n".join(json.dumps(a) for a in anfragen) + "\n",
+1 -1
View File
@@ -134,7 +134,7 @@ pub fn solve_flop(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<C
while done < cfg.iterations {
solver.iterate();
done += 1;
if crate::engine::frist::thread_cpu_ms() - cpu0 > cfg.budget_ms {
if crate::engine::frist::thread_cpu_ms() - cpu0 > cfg.budget_ms || crate::engine::frist::notbremse() {
break;
}
}
+35
View File
@@ -11,6 +11,8 @@ use std::time::Instant;
thread_local! {
static START: Cell<Option<f64>> = const { Cell::new(None) };
/// Wall time of the mark, only for the live emergency brake (`notbremse`).
static WAND: 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) };
}
@@ -25,6 +27,24 @@ 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(thread_cpu_ms())));
WAND.with(|s| s.set(Some(Instant::now())));
}
/// Live emergency brake in wall time (`KERN_NOTBREMSE_MS`, set only by the live bridge
/// `entscheiden/decide.py`, 8 s): past it no solver starts and a running one stops with what it has, so a
/// starved machine never times out a table. Measurement and Pflicht paths do not set it and stay purely
/// in CPU time (deterministic); `SOLVER_ZEIT=fest` ignores it.
pub fn notbremse() -> bool {
static MS: std::sync::OnceLock<Option<f64>> = std::sync::OnceLock::new();
let Some(ms) = *MS.get_or_init(|| std::env::var("KERN_NOTBREMSE_MS").ok().and_then(|v| v.trim().parse().ok()).filter(|x: &f64| *x > 0.0)) else {
return false;
};
!fixed() && wand_ueber(ms)
}
/// Wall time since `begin` exceeds `ms`.
fn wand_ueber(ms: f64) -> bool {
WAND.with(|w| w.get().is_some_and(|t| t.elapsed().as_secs_f64() * 1e3 > ms))
}
/// CPU milliseconds this thread used since the mark (0 without one). Not wall time: waiting for a core
@@ -35,6 +55,9 @@ pub fn elapsed_ms() -> f64 {
/// 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 {
if notbremse() {
return 0.0;
}
total_ms - MARGIN_MS - elapsed_ms()
}
@@ -121,6 +144,18 @@ pub fn budget_ms(cap_ms: f64, total_ms: f64) -> f64 {
#[cfg(test)]
mod tests {
#[test]
fn notbremse_zaehlt_uhrzeit() {
super::begin();
std::thread::sleep(std::time::Duration::from_millis(300));
assert!(super::wand_ueber(200.0) && !super::wand_ueber(5000.0));
assert!(super::elapsed_ms() < 100.0);
// Ohne KERN_NOTBREMSE_MS (Mess- und Pflichtpfad) greift sie nie.
if std::env::var("KERN_NOTBREMSE_MS").is_err() {
assert!(!super::notbremse());
}
}
#[test]
fn warten_zaehlt_nicht_zur_frist() {
// Pflichtfälle 19.11.: unter Last wartete der Kern (Idle) Sekunden auf einen Kern, die 3-s-Notuhr
+1 -1
View File
@@ -137,7 +137,7 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
while done < ITERS {
solver.iterate();
done += 1;
if done % 50 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget {
if done % 50 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget || crate::engine::frist::notbremse() {
break;
}
}
+1 -1
View File
@@ -187,7 +187,7 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
while done < ITERS {
solver.iterate();
done += 1;
if done % 200 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget {
if done % 200 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget || crate::engine::frist::notbremse() {
break;
}
}
+1 -1
View File
@@ -175,7 +175,7 @@ pub fn solve_river(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<
while done < ITERS {
solver.iterate();
done += 1;
if done % 10 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget {
if done % 10 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget || crate::engine::frist::notbremse() {
break;
}
}
+4 -4
View File
@@ -758,7 +758,7 @@ pub fn solve(spot: &Spot, c: &Cfg) -> Option<Geloest> {
return None;
}
let ohne_uhr = crate::engine::frist::fixed();
if !ohne_uhr && crate::engine::frist::elapsed_ms() > NOTFALL_MS {
if !ohne_uhr && (crate::engine::frist::elapsed_ms() > NOTFALL_MS || crate::engine::frist::notbremse()) {
return None;
}
let started = std::time::Instant::now();
@@ -868,7 +868,7 @@ pub fn solve(spot: &Spot, c: &Cfg) -> Option<Geloest> {
while done < c.iters {
solver.iterate();
done += 1;
if !ohne_uhr && done % 5 == 0 && (crate::engine::frist::thread_cpu_ms() - cpu0 > BUDGET_MS || crate::engine::frist::elapsed_ms() > NOTFALL_MS) {
if !ohne_uhr && done % 5 == 0 && (crate::engine::frist::thread_cpu_ms() - cpu0 > BUDGET_MS || crate::engine::frist::elapsed_ms() > NOTFALL_MS || crate::engine::frist::notbremse()) {
break;
}
}
@@ -1175,7 +1175,7 @@ pub fn solve_frueh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
return None;
}
let ohne_uhr = crate::engine::frist::fixed();
if !ohne_uhr && crate::engine::frist::elapsed_ms() > NOTFALL_MS {
if !ohne_uhr && (crate::engine::frist::elapsed_ms() > NOTFALL_MS || crate::engine::frist::notbremse()) {
return None;
}
let started = std::time::Instant::now();
@@ -1255,7 +1255,7 @@ pub fn solve_frueh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
while done < iters {
solver.iterate();
done += 1;
if !ohne_uhr && done % 5 == 0 && (crate::engine::frist::thread_cpu_ms() - cpu0 > kappe || crate::engine::frist::elapsed_ms() > NOTFALL_MS) {
if !ohne_uhr && done % 5 == 0 && (crate::engine::frist::thread_cpu_ms() - cpu0 > kappe || crate::engine::frist::elapsed_ms() > NOTFALL_MS || crate::engine::frist::notbremse()) {
break;
}
}
+1 -1
View File
@@ -245,7 +245,7 @@ fn solve_core(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<Card>
while done < cfg.iterations {
solver.iterate();
done += 1;
if crate::engine::frist::thread_cpu_ms() - cpu0 > cfg.budget_ms {
if crate::engine::frist::thread_cpu_ms() - cpu0 > cfg.budget_ms || crate::engine::frist::notbremse() {
break;
}
}
+5 -3
View File
@@ -232,9 +232,11 @@ def main(argv=None):
raise SystemExit(f"keine Fälle in {x.datei}")
ordner = os.path.join(BAUM, "archiv", "roentgen", "kern")
quelle = x.kern or roentgen.kern_pfad(x.wurzel)
k_live = roentgen.kern_aufruf(roentgen.kern_kopie(quelle, ordner, KERN_LIVE))
k_kand = k_live if not x.kern_kandidat else roentgen.kern_aufruf(
roentgen.kern_kopie(x.kern_kandidat, ordner, KERN_KAND))
# BelowNormal statt Idle und lange Frist (19.11.): unter Volllast bekam der Idle-Kern kaum Rechenzeit und
# das Werkzeug brach nach 275 s ab. Die Fristen des Kerns zählen Rechenzeit, das Urteil bleibt gleich.
aufruf = lambda b: roentgen.kern_aufruf(b, timeout_je=30.0, prioritaet=roentgen.BELOW_NORMAL_PRIORITY_CLASS)
k_live = aufruf(roentgen.kern_kopie(quelle, ordner, KERN_LIVE))
k_kand = k_live if not x.kern_kandidat else aufruf(roentgen.kern_kopie(x.kern_kandidat, ordner, KERN_KAND))
live = roentgen.lies_schalter(x.schalter or os.path.join(x.wurzel, "betrieb", "kern_schalter.txt"))
env_k = livefaelle.kandidat_env(live, livefaelle.arm_lesen(x.arm))
r = pruefen(fs, k_live, k_kand, live, env_k, streng=x.streng and not x.nur_rueckschritt)