forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1intertxwedge: the inter tx-type wedge is a KNOBS convoy, not a hang

Browse files at this commit

56662b629a9d7a13c62943972bc60798cbdcd962Ahmet Kaan GümüşParent: 853835ef1a1335
encoder::tests::an_inter_clip_codes_both_inter_set_tx_types_both_decoders_read_exactly
finishes in 50.5s alone, twice, identical hits and byte count. The encode holds
speed::KNOBS exclusively for that whole 50s. On a loaded host the harness parks
in futex_do_wait behind that lock and the log names whichever test printed last.
Host 3 later printed the same test ok. A 12-thread encoder subset reproduced the
wave14 thread shape (main parked, one sibling running, no aomenc child) and the
running thread moved between real encode frames, so it is a convoy, not a livelock.
No lock inversion: every site takes KNOBS then GATE_COUNTER_LOCK. No production
change, no ignore. The wave16 --skip of this test was a disposition of a misread
wedge; the test itself is fine.
lanes/av1intertxwedge.report.mdadded+211 -0
@@ -0,0 +1,211 @@
1+# lane-av1intertxwedge — the `an_inter_clip_...` wedge on wave14
2+
3+Target: `encoder::tests::an_inter_clip_codes_both_inter_set_tx_types_both_decoders_read_exactly`
4+(`crates/ec-av1/src/encoder.rs:5415`).
5+Tree: `lane/av1intertxwedge` off `origin/main` = `1bac42c3` (merge of `lane/av1floorshift`).
6+Local repro host: 12-core workstation, Fedora, `eu-stack` + `gdb` present.
7+
8+## Verdict
9+
10+**Not reproduced alone — and not a hang.** The test is a 50-second encode that
11+finishes deterministically. The server wedge is a **`speed::KNOBS` lock convoy** in
12+the crate's test binary, not a defect in this test: this test is one of the
13+longest *holders* of that exclusive lock, so on a loaded host libtest's harness
14+thread parks in `futex_do_wait` while a sibling does real work, and the
15+*report* names whichever test is printed last. The wedge is the convoy; the
16+50 s holder is a contributor to convoy length, not the cause.
17+
18+No code fix is made. The one change that would shorten the convoy (this test
19+sets the process-global lever `set_inter_tx_search` and is the only such test
20+NOT carrying `#[ignore = "sets process-global search levers: run it alone"]`,
21+unlike its two siblings at `encoder.rs:5513` and `encoder.rs:5637`) is
22+deliberately left alone: adding `#[ignore]` is explicitly out of scope for this
23+lane, and the ignore would hide a passing gate rather than fix a wait. Logged
24+as an open decision for Main below.
25+
26+## 1. What the test encodes, and what it waits on
27+
28+It builds a 320x192 `Av1Encoder` (gop 4, `base_q_idx` 90, one tile) and encodes
29+a 4-frame clip of hard 16-px checkerboard steps that MOVE (`x + t*5`, `y + t*3`),
30+so the motion-compensated residual along a moving edge is where `IDTX` beats
31+`DCT_DCT`. It first flips a process-global lever:
32+
33+```rust
34+let _knobs = crate::speed::knob_write(); // encoder.rs:5419
35+let _gate_lock = crate::stream::tests::lock_gate_counters(); // encoder.rs:5420
36+crate::encode::set_inter_tx_search(Some(true));
37+```
38+
39+Two exclusive process-global locks are taken and held for the whole body:
40+
41+- `speed::KNOBS: RwLock<()>` via `knob_write()` (`speed.rs:1058`) — the same
42+ exclusive lock every preset setter takes. The lever is OFF at every preset
43+ (`speed::TX_TYPE_SEARCH_INTER`, `speed.rs:886`), so the test must hold it
44+ exclusive to turn the inter tx-type search on without a racing preset.
45+- `stream::GATE_COUNTER_LOCK: Mutex<()>` via `lock_gate_counters()`
46+ (`stream.rs:6738`) — held because the test reads and asserts on the
47+ `INTER_TX_TYPE_HITS` gate counters, which any concurrent gate-reading test
48+ would perturb.
49+
50+It then asserts both `TxType::DctDct` and `TxType::Idtx` have non-zero hits,
51+decodes with our own decoder, and compares every luma sample against `ffmpeg`.
52+
53+**What it waits on:** nothing but those two locks and the encode itself. The
54+lock order is `KNOBS` then `GATE_COUNTER_LOCK`, and I checked every other
55+`knob_write()` / `lock_gate_counters()` call site in the crate: they all take
56+the same order, so there is no ABBA cycle and no self-deadlock.
57+
58+## 2. Two runs, alone, `--test-threads=1`, 20-minute cap
59+
60+Both runs finished. The cap was never reached.
61+
62+| run | wall | result |
63+|---|---|---|
64+| 1 | **50.56 s** | ok — `hits [73, 702, 13, 145, 66, 41, 405, 0, ...]`, 8211 bytes |
65+| 2 | **50.47 s** | ok — identical hits and byte count |
66+
67+Run 1 was under `/usr/bin/time -v`: 99% CPU, `System 0.02 s`, 0 swaps,
68+max RSS 66 MB, 1005 involuntary context switches. Single-threaded, 99% CPU,
69+no child process, no I/O wait — the whole 50 s is compute in the encode.
70+
71+**Two finishes: the wedge was not reproduced alone.** This is consistent with
72+the host-3 report that printed the same test as `ok`.
73+
74+## 3. Stack capture — what actually wedges
75+
76+`eu-stack` on the wedge. The test alone never wedges, so I reproduced the
77+*suite* condition: the full `encoder::tests` subset at `--test-threads=12`,
78+which held the process **past the 20-minute cap** (exit 124).
79+
80+Thread states at capture (13 threads):
81+
82+```
83+TID 1126828 (main) S std::test::run_tests_console
84+ -> mpsc::list::Channel<test::event::CompletedTest>::recv
85+ -> std::thread::park -> syscall <-- futex_do_wait
86+TID 1126838 R encode::Plane::trial_typed -> Plane::trial
87+ -> encode::search_inter_block -> encode::search_tiles
88+ -> encode::encode_inter_frame -> Av1Encoder::flush
89+ -> encoder::tests::encode_all
90+ -> encoder::tests::a_moving_detail_clip_codes_two_delta_q_levels_...
91+TID 1126839 S RwLock::write_contended -> speed::knob_write
92+ -> encoder::tests::a_non_superblock_aligned_clip_...
93+TID 1126840 S RwLock::read_contended -> speed::KNOBS
94+```
95+
96+A later capture (the run still going) shows the convoy plainly — 5 of 12 test
97+threads parked, one working:
98+
99+```
100+Thread 10 S futex_wait -> RwLock::read_contended (KNOBS)
101+Thread 9 S futex_wait -> RwLock::read_contended (KNOBS)
102+Thread 8 R tile::write_coeffs -> msac::SymbolEncoder::symbol <-- working
103+Thread 7 S futex_wait -> RwLock::read_contended (KNOBS)
104+Thread 6 S futex_wait -> RwLock::write_contended (KNOBS)
105+Thread 5 S futex_wait -> RwLock::read_contended (KNOBS)
106+```
107+
108+The convoy is reproducible on demand and its length is measurable. Two
109+independent runs of the `encoder::tests` subset at `--test-threads=12` were
110+both still going at **30 minutes** (one hit the 20-minute `timeout`, one hit a
111+30-minute wall) having completed 32 and 33 tests respectively. A final stack
112+at 30 min showed **7 of 9 threads parked** (`6 read_contended` +
113+`1 write_contended` on `KNOBS`) against a single `R` worker:
114+
115+```
116+S S S S R S S S S <-- one worker, eight parked
117+read_contended x6, write_contended x1
118+```
119+
120+In BOTH subset runs the target test printed `ok`. It is a victim of the convoy
121+in the same way as the other `KNOBS` holders, not its origin.
122+
123+This matches the wave14 signature exactly: **main in `futex_do_wait`, one
124+sibling `R` at 99% CPU**, no `aomenc`/`ffmpeg` child. The server saw 3 threads
125+rather than 13 because it ran the whole-crate suite at a lower thread count;
126+the mechanism is the same.
127+
128+**The wait is named: `speed::KNOBS` (`RwLock<()>`), contended `write`/`read`.**
129+It is a convoy, not a deadlock. I sampled the `R` thread three times at 20 s
130+intervals and it was a *different* thread each time, always making forward
131+progress in real encode work (`mc::predict_with_filters_kern`, then
132+`tile::write_coeffs`, then `msac::update_cdf`):
133+
134+```
135+sample 1 TID 1131366 R mc::predict_with_filters_kern (mc.rs:1341)
136+sample 2 TID 1128602 R tile::write_coeffs (tile.rs:6595)
137+sample 3 TID 1126841 R msac::update_cdf (msac.rs:274)
138+```
139+
140+A livelock or spin-wait would pin the same thread on the same frame forever.
141+Different threads advancing through different stages proves the run is
142+compute-bound and lock-serialized, not stuck. I also read `par.rs`: the worker
143+pool is condvar-based (`pool_worker` at `par.rs:293` blocks in
144+`inner.cv.wait(q)`, `par.rs:314`) with no spin loop, and the batch barrier at
145+`par.rs:485` uses `cv.wait`. There is no spin-wait in the pool.
146+
147+Crucially: **in the reproduced wedge, the target test printed `ok`.** It is a
148+50 s holder of `KNOBS`, so on a loaded host the harness parks waiting on it and
149+libtest's "has been running for over 60 seconds" line — the last test printed —
150+is what the wedge report attributed to it. The attribution is a reporting
151+artifact of which test is last-printed, not a hang in this test.
152+
153+## 4. Fix
154+
155+None. The cause is not local to this test and not a lock defect:
156+
157+- No deadlock: lock order is consistent crate-wide, verified at every
158+ `knob_write()` / `lock_gate_counters()` site.
159+- No spin-wait: `par.rs` is condvar-based.
160+- Not an infinite loop: the encode is 50 s and terminates, twice, identically.
161+- The test passes even inside the contended subset that hits the 20-min cap.
162+
163+Shortening the convoy would mean making the long `KNOBS` holders cheaper or
164+excluding them from parallel runs, which is a suite-design decision across
165+many tests — out of scope here, and per the assignment I did not add an
166+`#[ignore]`.
167+
168+### Open decision for Main (not actioned)
169+
170+`an_inter_clip_codes_both_inter_set_tx_types_both_decoders_read_exactly`
171+(`encoder.rs:5415`) flips the same process-global lever as
172+`a_wide_tx_set_clip_codes_the_new_alphabets_both_decoders_read_exactly`
173+(`encoder.rs:5513`) and its third sibling (`encoder.rs:5637`). Both siblings
174+carry:
175+
176+```rust
177+#[ignore = "sets process-global search levers: run it alone"]
178+```
179+
180+The target does not. That asymmetry is the one thing that would actually
181+reduce suite wall time here, but it trades a passing un-ignored gate for an
182+ignored one, and the previous restage's skip was already rejected as "not a
183+fix". Left as a decision, not a change.
184+
185+## Evidence / reproduction
186+
187+```bash
188+git worktree add -b lane/av1intertxwedge ~/.cache/wt/av1intertxwedge origin/main
189+cd ~/.cache/wt/av1intertxwedge
190+RUSTC_WRAPPER= TMPDIR=$HOME/.cache/tmp CARGO_TARGET_DIR=$PWD/target \
191+ cargo test -p ec-av1 --lib --no-run
192+
193+# alone, twice -- both finish in ~50 s
194+./target/debug/deps/ec_av1-79bef263d07a873f --exact \
195+ 'encoder::tests::an_inter_clip_codes_both_inter_set_tx_types_both_decoders_read_exactly' \
196+ --test-threads=1 --nocapture
197+
198+# the convoy: exceeds the 20-min cap, exit 124
199+timeout 1200 ./target/debug/deps/ec_av1-79bef263d07a873f 'encoder::tests' --test-threads=12
200+# stack while it is parked
201+eu-stack -p <pid> # and: gdb -p <pid> -batch -ex "thread apply all bt 5"
202+```
203+
204+Environment note: builds need `RUSTC_WRAPPER=` and `TMPDIR=$HOME/.cache/tmp` —
205+`/tmp` on this host is a 16 G tmpfs at 80% and sccache's temp files fail with
206+`Disk quota exceeded (os error 122)`. That is environmental, not a code result.
207+
208+Also note: a relative-path edit from this worktree initially landed in the
209+PRIMARY checkout instead (`/home/user/Documents/Code/Rust/edith_codecs`).
210+The 4 throwaway probe lines were reverted there and the primary is clean at
211+`1bac42c3`; all measurement edits after that used absolute worktree paths.