| 1287 | } |
| 1288 | |
| 1289 | void ExpertPool::wait_parked(const char* what) { |
| 1290 | hstate_.store(kWaitParked, std::memory_order_relaxed); |
| 1291 | hstate_ms_.store(now_ms(), std::memory_order_relaxed); |
| 1292 | if (pf_inflight_) // a prefetch still reading stops at its next check; the batch below must not wait for it |
| 1293 | pf_abort_.store(true, std::memory_order_release); |
| 1294 | struct PfEnd { |
| 1295 | ExpertPool* p; |
| 1296 | ~PfEnd() { |
| 1297 | if (p->pf_inflight_) { p->pf_inflight_ = false; p->pf_abort_.store(false, std::memory_order_relaxed); } |
| 1298 | } |
| 1299 | } pf_end{this}; |
| 1300 | uint32_t spins = 0; |
| 1301 | std::chrono::steady_clock::time_point t0{}; |
| 1302 | // 'every worker parked' is not enough while a prefetch is in flight (issue #35): nobody waits for that batch, a worker that slept through its publish still counts as parked, wakes |
| 1303 | // late, and would then run the prefetch's all-workers barrier with the abort flag already cleared below (pool_tasks_test stalled 6 of 6 on a 13900K, always in prefetch_task). |
| 1304 | // So the host also waits until every worker has finished that batch; the abort flag keeps a late worker from doing the work of it. |
| 1305 | while (parked_count() != (uint32_t) n_ || (pf_inflight_ && !pf_acked())) { |
| 1306 | strata_cpu_pause(); |
| 1307 | if ((++spins & 1023u) != 0) continue; |
| 1308 | const auto now = std::chrono::steady_clock::now(); |
| 1309 | if (spins == 1024u) t0 = now; |
| 1310 | else if (now - t0 > kStall) { |
| 1311 | std::fprintf(stderr, "strata: the CPU expert pool stalled %s (%u of %d workers parked)%s - stopping the engine " |
| 1312 | "so the server can start it again (issue #29)\n", |
| 1313 | what, parked_count(), n_, numa_counters().c_str()); |
| 1314 | dump_thread_stacks(threads_); // where each pool thread is (Linux, glibc): the host thread is the one that prints this, its own place is the wait above |
| 1315 | diag(stderr); // every worker's state (parked, sleeping, draining, or the job it runs), the host's, the batch counters and the mode: what a stall report needs (issue #29, #35) |
| 1316 | strata::core::release_gpu_waits(stderr); // #267: the GPU may be spinning on this layer's flag |
| 1317 | std::fflush(stderr); |
| 1318 | std::abort(); |
| 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | void ExpertPool::wait_done(int n) { |
| 1324 | hstate_.store(kWaitDone, std::memory_order_relaxed); |
nothing calls this directly
no test coverage detected