diff --git a/core/kvstream/stage.cpp b/core/kvstream/stage.cpp index 56d58734..a36c6e32 100644 --- a/core/kvstream/stage.cpp +++ b/core/kvstream/stage.cpp @@ -223,8 +223,7 @@ bool stage_src(Ctx* ctx, int group, const RadKVGroupBatch* kvb, int layer, Stage * attention then reads a row that is part copy and part stale. The clamp is the * memory-safe answer; this is the promise that it is never a silent one. */ static std::atomic said{false}; - bool expected = false; - if (said.compare_exchange_strong(expected, true)) + if (log_once(said)) RAD_WARN("kvstream: group %d stage runs reach past the host layer's end (%lld of " "%lld bytes): the stage drops what lies past it, and staged attention " "reads stale bytes there (first of possibly many)", diff --git a/core/rad_internal.h b/core/rad_internal.h index 9b7e8d16..c9eae833 100644 --- a/core/rad_internal.h +++ b/core/rad_internal.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,14 @@ uint64_t log_last_line_ns(); * Multi-byte UTF-8 is left alone; only control bytes are replaced. */ std::string log_sanitize(const std::string& s); +/* The once-log idiom: true on the first call for this flag, false forever after -- a warning + * that would otherwise repeat every step logs its first occurrence and stays quiet. Thread-safe + * by compare_exchange, so exactly one thread wins. */ +inline bool log_once(std::atomic& flag) { + bool expected = false; + return flag.compare_exchange_strong(expected, true); +} + /* The whole text of a file, refused BEFORE it is read when it is bigger than `cap`. Files a * container supplies are screened by size as well as by JSON budget: the bounded read counts * values, not bytes, and the slurp used to be the unbounded step -- a multi-gigabyte diff --git a/core/sched/batch.cpp b/core/sched/batch.cpp index a4d5b219..8d9fd773 100644 --- a/core/sched/batch.cpp +++ b/core/sched/batch.cpp @@ -1082,8 +1082,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv, if (a >= b || pm.items[(size_t)run.item].item->kind == mm::Kind::Audio) continue; if (a < prev_b) { static std::atomic said{false}; - bool expected = false; - if (said.compare_exchange_strong(expected, true)) + if (log_once(said)) RAD_WARN("step batch: a rope layout overlaps at token %lld; that run is " "not staged bidirectionally (first of possibly many)", (long long)a); @@ -1094,8 +1093,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv, /* Belt: the disjoint check makes this unreachable; the slice says so * rather than letting an overrun reach the card. */ static std::atomic said2{false}; - bool expected = false; - if (said2.compare_exchange_strong(expected, true)) + if (log_once(said2)) RAD_WARN("step batch: bidi runs overflowed the %lld-token plane " "(first of possibly many)", (long long)T); break;