Event Loop¶
The event loop topic connects the userspace and kernel-side event-driven patterns used throughout this learning series.
In Linux, many event sources can be represented as file descriptors. Once an event source becomes an fd, it can be integrated into a single poll() or epoll() loop.
What This Topic Covers¶
| Area | Main Idea | Related APIs |
|---|---|---|
| Readiness notification | Wait until an fd can be read or written | poll(), epoll_wait() |
| Scalable event loop | Manage many fds in one loop | epoll_create1(), epoll_ctl() |
| Timer events | Convert timers into fd events | timerfd_create(), timerfd_settime() |
| Signal events | Convert signals into fd events | sigprocmask(), signalfd() |
| Kernel driver readiness | Allow drivers to wake userspace event loops | .poll, poll_wait(), wake_up_interruptible() |
| Async notification | Notify userspace using SIGIO | .fasync, kill_fasync() |
Recommended Learning Path¶
- Start with poll and select to understand readiness-based I/O.
- Move to epoll for scalable fd multiplexing.
- Add timerfd to integrate periodic or timeout events.
- Add signalfd to handle signals inside the event loop.
- Study eventfd for userspace/kernel or thread-to-thread event notification.
- Review fasync and SIGIO as an alternative async notification model.
Event-Driven Architecture¶
Common Linux event sources:
- TCP sockets
- UNIX domain sockets
- character devices
timerfdsignalfdeventfd- message queues
- input devices
- IIO buffers
Related Notes¶
- Day15 - User-space Event Loop and Poll
- Day48 - Epoll + Timerfd + Idle Timeout
- Day49 - signalfd + epoll
- Linux fasync / SIGIO / eventfd Notes
- Driver I/O Model
- Pollable Character Driver