Day51 - Timer-based Pollable Event Driver¶
Overview¶
Day51 extends the Day50 pollable character driver into a timer-driven asynchronous event framework.
New features introduced:
- delayed_work periodic event source
- timer start/stop control
- manual trigger events
- event source abstraction
- runtime statistics
- queue overflow handling
- sysfs runtime observability
- epoll integration
The driver architecture evolved from:
into:
1. Review of Day50 Architecture¶
Day50 implemented a pollable character driver with:
- blocking read
- non-blocking read
- wait queue
.poll()support- epoll integration
- FIFO event queue
Original event flow:
write(/dev/mypoll)
↓
push event into queue
↓
wake_up_interruptible()
↓
poll()/epoll() reports EPOLLIN
↓
read()
↓
pop event from queue
Only userspace write operations could generate events.
2. Internal Timer Event Source¶
Day51 introduced a driver-internal event source using delayed work.
New event flow:
delayed_work handler
↓
mypoll_generate_event()
↓
queue push
↓
wake_up_interruptible()
↓
epoll()/read()
Userspace write is no longer the only event source.
3. Event Generation Refactor¶
Event generation logic was refactored into a shared helper:
This centralizes:
- sequence generation
- queue push
- overflow handling
- statistics update
- wait queue wakeup
Benefits:
- reusable event generation path
- cleaner architecture
- easy future extension
- consistent queue policy
4. delayed_work as Periodic Event Source¶
The driver uses:
Periodic event generation flow:
Important APIs:
5. Event Source Abstraction¶
Multiple event sources were introduced:
Each event now contains source information:
Userspace output example:
6. Runtime Statistics¶
Runtime statistics were grouped into:
struct mypoll_stats {
u32 events_generated;
u32 events_dropped;
u32 events_manual;
u32 events_timer;
};
Driver state also tracks:
Statistics are updated during event generation.
7. Queue Overflow Handling¶
Timer-generated events may exceed userspace consumption speed.
Overflow policy:
Important design decision:
This prevents gaps caused by dropped events.
Example:
8. Runtime Observability with sysfs¶
A read-only sysfs node was added:
Implementation:
Example output:
event_sequence=83
generated=83
dropped=174
manual_triggered=1
timer_triggered=82
queue_depth=0
timer_running=0
This separates:
| Purpose | Interface |
|---|---|
| Event stream | /dev/mypoll |
| Control commands | write() |
| Runtime state | sysfs |
| Debug logging | dev_info() |
9. epoll Integration¶
The timer-generated events fully integrate with epoll.
Event flow:
timer delayed_work
↓
queue push
↓
wake_up_interruptible()
↓
epoll receives EPOLLIN
↓
userspace read()
Userspace asynchronous event handling works without modification.
10. Python Integration Test¶
A full Python integration test was added.
Covered features:
- device existence
- manual trigger event
- timer event generation
- timer stop behavior
- epoll integration
- queue overflow statistics
- reset statistics
The test also validates:
- event source correctness
- runtime stats behavior
- queue overflow handling
Key Learning Points¶
Day51 introduced several important Linux driver concepts:
- asynchronous event generation
- periodic delayed work scheduling
- event source abstraction
- runtime observability
- queue overflow/backpressure
- sysfs runtime status
- epoll with internal event source