mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 19:04:50 +07:00
[GH-ISSUE #615] ds4: Pool can leave a batch to nobody - start() can miss a worker going to sleep (store -> load without a fence), and a worker that starts late takes the first batch as already seen; a pool nobody help()s then hangs #258
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#258
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @SeriousRising on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/615
Symptom
Found by reading, then reproduced by a new test (below); we have not seen it in the engine. A CPU-lane worker can sleep through a batch in two ways. On one pool the batch still finishes, one thread short, because the caller's
help()and the other workers drain it. With two pools (NH = 2, a 2-socket host)run_nodeshelps onlypools[0]and then waits forpools[1]: if every worker of pool 1 misses the batch, nobody runs it and the engine waits for ever.Cause
src/ds4/ds4_pool.hpp(v1.1.35):start()can miss a worker going to sleep.:67gen_.store(g, std::memory_order_release);then:68if (sleeping_.load(std::memory_order_acquire) > 0) { ... cv_.notify_all(); }. The worker,:105-106:sleeping_.fetch_add(1);thencv_.wait(lk, [&] { return gen_.load() != seen || quit_.load(); });.:67->:68is a store followed by a load of another location. Release / acquire do not order that pair, and x86 lets the load complete while the store is still in the store buffer (the store-buffering / Dekker shape). So the starter can readsleeping_ == 0and skip the notify while the worker, which has just done itsfetch_add, reads the oldgen_in the wait predicate and sleeps.loop()reads itsseenwhen its thread first runs (:95uint64_t seen = gen_.load();). If the constructor returns and the callerstart()s before that thread has run, the worker takes the new generation as seen and sleeps through that batch. We did not trace whether the engine starts a second NUMA pool right after building it.src/ds4/ds4_model.cu:8567-8587(run_nodes):for X: pools[X]->start(...), thenpools[0]->help()only, thenfor X: pools[X]->wait(). So pool 1's batch is run by pool 1's workers alone.Proposed fix
fetch_addand the predicate'sload()use the default order). With a seq_cst fence F between them, C++20 [atomics.order]/4 rules the bad outcome out: the starter reads 0 => F precedes the worker's RMW; the worker reads the oldgen_=> its load precedes F; the RMW precedes the load; contradiction. On x86 this is onemfenceperstart()(two per CPU-lane call).loop()starts fromseen = 0, the value ofgen_at construction, before anystart()can run.A PR with both (and a test) follows.
Reproduction
New test in
tests/ds4_pool_test.cpp(built by hand as its header says):pool_start_wakes_sleeperruns 200000 one-job batches on a one-worker pool withspin_us = 0,start()+wait()and nohelp(), and fails (a watchdog: 5 s without progress) if one never runs. 10 runs each:ds4_pool.hppseen = 0onlyNot platform-specific. The NH = 2 hang itself is from reading: we have no 2-socket box. #56 reports decode varying between restarts on a dual-socket PC; we have no evidence it is this.
Not in the fix, seen while reading:
glmfast::Workers(src/core/glm_fast_state.hpp, the design this pool copies) has the same shape:gen_.store(release)thensleeping_.load(acquire)at:164-165, andseen = gen_.load()when its thread starts at:202. Not tested.