Day15 - User-space Event Loop and Poll¶
π― Goal¶
Understand how to properly consume events from a driver using:
- blocking I/O
- non-blocking I/O
- poll / select / epoll
- event loop design
1. Blocking vs Non-blocking¶
Blocking I/O¶
- If no data is available β process sleeps
- CPU usage is low
- Simple but not scalable
Non-blocking I/O¶
- If no data β returns
-EAGAIN - Requires polling or retry logic
2. Why poll is needed¶
Problem:
β wastes CPU
Solution:
3. poll concept¶
poll checks whether a file descriptor is ready.
Workflow¶
4. Relationship with driver¶
Driver implements:
Inside:
Key idea¶
- poll does NOT read data
- poll only checks readiness
5. Event-driven model¶
Typical pattern:
6. Level-trigger behavior¶
poll is level-triggered:
- If data exists β poll keeps returning ready
- Must consume data (read)
7. Common mistakes¶
β Busy loop¶
β Forget to read after poll¶
β poll will keep waking
β Mixing blocking read + poll incorrectly¶
8. poll vs select vs epoll¶
| API | νΉμ§ |
|---|---|
| select | old, fd limit |
| poll | simple |
| epoll | scalable |
9. System view¶
Linux is fundamentally:
event-driven system
Examples:
- GPIO IRQ
- socket
- timer
- input device
All can be handled via poll/epoll
π Summary¶
- driver provides readiness
- poll waits for readiness
- read consumes data
- event loop connects everything