refactor: migrate notification mechanism from signal to eventfd and signalfd#78
refactor: migrate notification mechanism from signal to eventfd and signalfd#78
signal to eventfd and signalfd#78Conversation
6bd7ae5 to
d2c4449
Compare
c9f9a61 to
a3adfaa
Compare
There was a problem hiding this comment.
Pull request overview
Refactors the virtio daemon ↔ kernel notification path away from legacy signal delivery (sigwait/send_sig_info) to a file-descriptor-driven approach using eventfd (VirtIO kicks) and signalfd + epoll (termination + kicks), aligning with a more scalable event loop design.
Changes:
- Add a new ioctl (
HVISOR_SET_EVENTFD) to pass aneventfdfrom userspace to the kernel driver. - Kernel IRQ handler now notifies userspace via
eventfd_signal()instead ofsend_sig_info(). - Userspace virtio daemon creates an
eventfdand waits oneventfd+signalfdwithepoll.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| tools/virtio/virtio.c | Creates/installs eventfd, switches request loop from sigwait to epoll over eventfd + signalfd. |
| include/hvisor.h | Adds HVISOR_SET_EVENTFD ioctl definition. |
| driver/hvisor.c | Stores an eventfd_ctx from userspace and signals it from the virtio IRQ handler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Does the |
This PR does not resolve the deadlock issue. The fix for the deadlock is located in the While this PR improves the ceiling of our notification performance, the |
|
Thank you very much for this PR! These changes provide a significant performance boost and the interface improvements make the codebase much cleaner. I have a few suggestions regarding the implementation of the event loop:
Overall, great work on the optimization. Looking forward to your thoughts on consolidating the polling logic! |
|
As far as I know, the current trigger frequency of sigwait is not high because the code polls after waking it up, hence the busy-polling you mentioned. Therefore, the performance improvement of switching from sigwait to epoll could theoretically limited, especially under high load (even the previous signal method doesn't sleep). However, embracing new technologies, like epoll, is commendable! 👍 |
This commit introduces eventfd-based interrupt handling mechanism to replace the previous signal-based approach, providing more efficient and reliable kernel-to-user communication. Key changes: - Added eventfd creation and configuration in virtio initialization - Implemented epoll-based event monitoring for both signalfd and eventfd - Replaced signal-based interrupt handling with eventfd notifications - Enhanced termination signal handling using signalfd for graceful shutdown The new implementation eliminates race conditions in signal handling and provides better performance through efficient event-driven architecture. This establishes a solid foundation for future VirtIO backend optimizations.
a3adfaa to
2681f1b
Compare
This PR refactors the virtio daemon's notification mechanism from the legacy
sigwaitto a modern architecture usingeventfdandsignalfd. This migration provides significant performance gains and eliminates complex kernel-version-dependent code.Architectural Evolution & Code Maintainability
struct siginfowas replaced bystruct kernel_siginfoinsend_sig_info(around Kernel 4.20/5.0).eventfdhas provided a stable and consistent API since Linux 2.6.22, removing the need for version-specific hacks and reducing maintenance overhead.Performance Benchmarks
The following tables compare the Legacy Architecture (
sigwait) and the New Architecture (epoll) usingfio. The file tested (/dev/vdb/) is the virtio-blk device implemented by ramdisk. The test commands are listed below.Table 1: Without Busy-Polling (Pure Event-Driven)
sigwait)epoll)Table 2: With Busy-Polling
sigwait+ Poll)epoll+ Poll)Conclusion
The
eventfd&signalfdarchitecture is more efficient than signals in pure event-driven scenarios and offers a much cleaner and more portable codebase across different Linux kernel versions.References
Depends On: #77
Closes: #64