Repository navigation
ev/epoll: use epoll_pwait2 for nanosecond timeout precision - #500
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds ChangesNanosecond-precision epoll timeout via epoll_pwait2
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
de3b5a2 to
7a6f799
Compare
epoll_wait only accepts a millisecond timeout, so a sub-millisecond timer deadline rounds to the nearest millisecond. Use epoll_pwait2 (Linux 5.11+), which takes a nanosecond timespec, so the loop sleeps exactly until the next deadline instead of waking early. Prefer epoll_pwait2 and, the first time it returns ENOSYS (kernel < 5.11), latch a flag and fall back to epoll_wait for the rest of the loop's lifetime. Refs #493 Co-Authored-By: Claude Opus 4.8 <[email protected]>
7a6f799 to
cbf14a7
Compare
Stacked on #499 (
fix/timer-timeout-rounding) — review/merge that first; this PR's diff against its base is only the epoll change.Problem
epoll_waitaccepts a millisecond timeout, so even with the ceiling fix in #499 a sub-millisecond timer deadline is rounded up to a full millisecond, adding up to ~1ms of latency/jitter to every short timer.Fix
Use
epoll_pwait2(Linux 5.11+), which takes a nanosecondtimespec, so the loop sleeps exactly until the next deadline. Prefer it, and the first time it returnsENOSYS(kernel < 5.11), latch a per-loop flag and fall back toepoll_waitfor the rest of that loop's lifetime.epoll_pwait2wrapper insrc/os/linux.zig(usesstd.os.linux.kernel_timespec; the msepoll_waitstays via std).waitEventsin the epoll backend does the prefer/fallback.Verification
epoll_pwait2, 0epoll_pwait(fallback only on ENOSYS).Refs #493