place+runtime: make the telemetry the HTTP thread reads atomic

/stats and LiveView read the mover's and heat engine's counters, the live tier of every
unit, and OpInfo::issued while the rank and step threads write them between passes. Plain
fields under a concurrent reader are a data race: no torn number matters on a dashboard,
but the compiler may tear, and the sanitizer is right to stop the process for it.

MoverCounters and HeatCounters mirror each struct's fields as relaxed atomics, written
exactly as the plain counters were and read whole through snapshot(); tier_ gains a
per-unit atomic byte mirror (TierMirror, copyable because HeatEngine is), and the step
path and the graph dump meet on OpInfo::issued through std::atomic_ref, which keeps the
struct layout and its copies intact. Engine-internal decisions keep reading the plain
counters -- they never race -- and only the HTTP-thread readers go through the mirrors.
This commit is contained in:
fl0l0u authored and StillDeadcode committed 2026-10-29 16:22:35 +01:00
1 parent b9c685a9c3
commit 9093bf618e
9 files changed
+222 -15

No files matched your search

+3 -3
View File
@@ -2320,8 +2320,8 @@ int Engine::run_server() {
s.experts.n_experts = n_expert;
s.experts.tier.assign((size_t)n_layer * (size_t)n_expert, (uint8_t)Tier::VRAM);
/* The live tier when the heat engine runs, else the plan's (where a unit started).
* HeatEngine::tier is a plain vector written by the dispatch thread at step
* boundaries, so a racing read sees either side of a single store. */
* tier_published is the HTTP-readable mirror HeatEngine::set_tier keeps; reading
* the dispatch thread's own tier_ here would be a data race. */
const HeatEngine& heat = ranks_[0]->heat;
const bool live_tier = heat.enabled();
s.experts.heat_enabled = live_tier;
@@ -2330,7 +2330,7 @@ int Engine::run_server() {
for (size_t u = 0; u < p.units.size(); ++u) {
const MoveUnit& mu = p.units[u];
if (mu.expert < 0 || mu.layer < 0) continue;
const Tier t = live_tier ? heat.tier((int32_t)u) : mu.tier;
const Tier t = live_tier ? heat.tier_published((int32_t)u) : mu.tier;
s.experts.tier[(size_t)mu.layer * (size_t)n_expert + (size_t)mu.expert]
= (uint8_t)t;
/* Count residency over units, not plane cells: the plane is a rectangle a