Skip to content

Commit cfda109

Browse files
Re-submit wakeup read immediately on completion (simulated multi-shot).
Instead of waiting until the next select() call to re-register the wakeup eventfd read, re-submit it immediately in select_process_completions while still on the owner thread. This keeps a read always pending and removes one SQE submission from the hot blocking-wait path. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 800cda7 commit cfda109

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

ext/io/event/selector/uring.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,12 +1175,19 @@ unsigned select_process_completions(struct IO_Event_Selector_URing *selector) {
11751175
continue;
11761176
}
11771177

1178-
// Wakeup eventfd read completion — the read already consumed the counter,
1179-
// no separate drain needed. Clear the flag so the next blocking wait
1180-
// re-submits the read.
1178+
// Wakeup eventfd read completion — the read already consumed the counter.
1179+
// Immediately re-submit a new read so one is always pending (simulating
1180+
// multi-shot), avoiding an extra submission on the next blocking wait.
11811181
if (cqe->user_data == (uint64_t)(uintptr_t)&selector->wakeup_fd) {
1182-
selector->wakeup_registered = 0;
11831182
io_uring_cq_advance(ring, 1);
1183+
struct io_uring_sqe *wakeup_sqe = io_uring_get_sqe(ring);
1184+
if (wakeup_sqe) {
1185+
io_uring_prep_read(wakeup_sqe, selector->wakeup_fd, &selector->wakeup_value, sizeof(selector->wakeup_value), 0);
1186+
io_uring_sqe_set_data(wakeup_sqe, &selector->wakeup_fd);
1187+
selector->pending += 1;
1188+
} else {
1189+
selector->wakeup_registered = 0;
1190+
}
11841191
continue;
11851192
}
11861193

0 commit comments

Comments
 (0)