Commit 1f4e6b6
authored
fix(pipe): correct waitqueue wakeup semantics (#2148)
* fix(pipe): correct waitqueue wakeup semantics
Track blocked writer intents while holding the pipe state lock and choose single or broadcast wakeups according to whether heterogeneous write predicates may be waiting. Reuse the lock guard returned by the wait path so predicate publication, sleep, and revalidation remain ordered.
Move waitqueue, epoll, async I/O, and SIGPIPE notifications outside pipe spinlocks. Preserve partial-write results and observer notifications when readers close, and align zero-length, nonblocking EPIPE, resize, splice, and tee behavior with Linux semantics.
Prevent splice-held data from being consumed twice and keep tee source data intact while preserving partial progress. Add deterministic dunitest coverage for endpoint side effects, writer eligibility, partial-write notifications, splice and tee wakeups, reader baton passing, and resize threshold changes.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(pipe): select eligible writer waiters
Replace unconditional multi-writer broadcasts with predicate-tagged waits. Track the free-space requirement of each blocked writer, choose one eligible class in round-robin order, and wake only that class to avoid thundering-herd retries.
Preserve progress with bounded fallback across the register-before-enqueue window. Pass the writer baton only after the selected write or splice operation completes or aborts, and pass the reader baton when an interrupted reader leaves consumable data behind.
Keep tagged waitqueue lookup and cleanup bounded, reserve the ordinary waiter tag, and move wake-all destruction outside the IRQ-disabled critical section. Add homogeneous and heterogeneous writer, splice, tee, signal, and resize regression coverage.
Tests: make fmt
Tests: make kernel
Tests: pipe_waitqueue_wakeup_test (11/11)
Tests: pipe_release_test (8/8)
Tests: splice_concurrent_io_test (7/7)
Tests: epoll_timeout_budget_test (1/1)
Tests: TCPResetDuringClose (12/12, twice)
Signed-off-by: longjin <longjin@dragonos.org>
* fix(pipe): serialize splice writer transactions
Add a per-pipe writer transaction that coordinates writes, output-side splice operations, endpoint close, and pipe resizing. Blocking writers publish their tagged wait predicate before releasing the transaction and pass an eligible writer baton only when another published waiter remains.
Keep file-to-pipe splice ownership across the input read and commit so competing writers cannot steal previously observed capacity. Validate readers before consuming stream input, including nonblocking EPIPE handling, and retain destination-only transaction locking for pipe-to-pipe splice and tee to avoid ABBA.
Add Dunitest regressions for no-reader stream preservation and competing writer serialization. Bound regression reads with poll deadlines so incorrect behavior fails deterministically instead of timing out.
Signed-off-by: longjin <longjin@dragonos.org>
---------
Signed-off-by: longjin <longjin@dragonos.org>1 parent 0f4e53c commit 1f4e6b6
4 files changed
Lines changed: 1942 additions & 324 deletions
File tree
- kernel/src
- filesystem/vfs/syscall
- ipc
- libs
- user/apps/tests/dunitest/suites/normal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
| 260 | + | |
259 | 261 | | |
260 | 262 | | |
261 | 263 | | |
262 | 264 | | |
263 | 265 | | |
264 | 266 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
| 267 | + | |
277 | 268 | | |
278 | | - | |
| 269 | + | |
279 | 270 | | |
280 | | - | |
| 271 | + | |
281 | 272 | | |
282 | 273 | | |
283 | 274 | | |
| |||
290 | 281 | | |
291 | 282 | | |
292 | 283 | | |
293 | | - | |
294 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
295 | 287 | | |
296 | | - | |
| 288 | + | |
| 289 | + | |
297 | 290 | | |
| 291 | + | |
298 | 292 | | |
299 | 293 | | |
300 | 294 | | |
| |||
303 | 297 | | |
304 | 298 | | |
305 | 299 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 300 | + | |
311 | 301 | | |
312 | 302 | | |
313 | 303 | | |
| |||
0 commit comments