Skip to content

Day52 - fasync / SIGIO and eventfd Integration

Summary

Today I learned Linux asynchronous notification mechanisms for character device drivers.

The existing pollable driver from Day51 was extended with:

  • .fasync
  • SIGIO notification
  • eventfd integration
  • epoll-based userspace event dispatch

Topics Covered

  • Linux async notification model
  • struct fasync_struct
  • fasync_helper()
  • kill_fasync()
  • SIGIO userspace handling
  • signal-safe design
  • eventfd
  • event aggregation
  • epoll event loop integration

Driver Updates

Added:

struct fasync_struct *async_queue;

Implemented:

.fasync = mypoll_fasync

Added SIGIO notification:

kill_fasync()

Userspace Experiments

Implemented:

  • minimal SIGIO test
  • nonblocking event drain
  • eventfd aggregation demo
  • SIGIO → eventfd → epoll bridge

eventfd Understanding

Learned that eventfd is:

  • an fd-based kernel counter object
  • epoll compatible
  • aggregation-based
  • NOT a message queue

Observed:

write(1)
write(1)
write(1)
→ read() returns 3

Final Architecture

kernel event
SIGIO
signal handler
eventfd
epoll
driver event drain

Key Learnings

  • SIGIO should only be used for lightweight notification
  • signal handlers should remain minimal
  • eventfd is ideal for signal-safe epoll wakeup
  • Linux event-driven systems heavily rely on fd abstraction
  • epoll can unify heterogeneous event sources

Result

Successfully implemented:

  • poll
  • epoll
  • SIGIO
  • eventfd
  • unified userspace event loop

for the custom pollable Linux char driver.