Skip to content

Day86 - epoll Internals

Goal

Understand how Linux epoll improves scalability over poll, how Interest List and Ready List work internally, and why device drivers only implement the standard .poll() callback.

Lab Overview

This lab builds a simplified Linux-style epoll implementation.

Implemented components:

  • eventpoll
  • epitem
  • Interest List
  • Ready List
  • Driver .poll() callback registration
  • Blocking epoll_wait_sim()
  • Level Trigger (LT)
  • Edge Trigger (ET)

Lab1 - Basic epoll Control Operations

Objective

Implement the basic control APIs.

Topics:

  • epoll_ctl_add()
  • epoll_ctl_mod()
  • epoll_ctl_del()
  • Interest List

Expected outcome:

  • Register file descriptors.
  • Modify interested events.
  • Remove monitored file descriptors.

Lab2 - Ready List Management

Objective

Implement Ready List management.

Topics:

  • epoll_mark_ready()
  • Ready List
  • Duplicate ready prevention

Expected outcome:

  • Ready file descriptors are inserted only once.
  • Interest List remains unchanged.

Lab3 - Event Consumption

Objective

Implement epoll_wait_sim().

Topics:

  • Ready List consumption
  • maxevents

Expected outcome:

  • Return ready events.
  • Remove consumed entries from the Ready List.

Lab4 - Blocking epoll_wait()

Objective

Implement blocking event notification.

Topics:

  • Producer / Consumer
  • wake_up()
  • Blocking wait

Expected outcome:

  • Consumer blocks until producer generates an event.

Lab5 - Driver poll Callback

Objective

Move readiness detection into the driver .poll() callback.

Topics:

  • Driver .poll()
  • Device state
  • Readiness recheck

Expected outcome:

  • epoll_wait_sim() rechecks driver readiness instead of relying on manually inserted events.

Lab6 - Level Trigger

Objective

Understand Level Trigger behavior.

Topics:

  • Driver state
  • Readiness persistence

Expected outcome:

  • As long as data remains available, every epoll_wait_sim() reports the file descriptor again.

Lab7 - Edge Trigger

Objective

Understand Edge Trigger behavior.

Topics:

  • Readiness transition
  • EPOLL_ET

Expected outcome:

  • Notification occurs only when readiness changes from not-ready to ready.
  • No repeated notification while the device remains ready.

Key Concepts

Interest List

Stores all monitored file descriptors.

Ready List

Stores file descriptors that should be returned by the current epoll_wait().

The Ready List is temporary and rebuilt from the driver readiness state.

Driver .poll()

Device drivers only implement the standard .poll() callback.

The driver never knows whether userspace uses:

  • poll()
  • select()
  • epoll()

Level Trigger (LT)

As long as the device remains ready, every epoll_wait() reports the event.

Edge Trigger (ET)

Only readiness transitions from not-ready to ready generate notifications.

Result

After completing this lab, you should understand:

  • Why epoll scales better than poll
  • How Interest List and Ready List cooperate
  • Why drivers only implement .poll()
  • The difference between Level Trigger and Edge Trigger
  • How epoll_wait() rebuilds readiness from the driver state