Day80 - IRQ Bottom Half and Deferred Work¶
Date: 2026-06-18
Objective¶
Learn how Linux defers interrupt processing from IRQ context to process context.
Topics covered:
- Top Half
- Bottom Half
- Workqueue
- Delayed Work
- Threaded IRQ
- IRQ_WAKE_THREAD
- request_threaded_irq()
- Workqueue vs Threaded IRQ
Key Concepts¶
Top Half¶
The Top Half runs in interrupt context.
Responsibilities:
- Acknowledge interrupt source
- Perform minimal processing
- Wake deferred execution mechanism
Restrictions:
- Must execute quickly
- Cannot sleep
- Should avoid lengthy operations
Typical flow:
Bottom Half¶
The Bottom Half runs in process context.
Responsibilities:
- Deferred processing
- Device state updates
- Data transfer and parsing
- Operations that may sleep
Typical flow:
Workqueue¶
Workqueue defers processing to a worker thread.
Flow:
Characteristics:
- Shared worker thread
- Runs in process context
- Sleep allowed
- Common deferred work mechanism
Delayed Work¶
Delayed Work combines a timer with Workqueue.
Flow:
Common use cases:
- GPIO debounce
- Retry operations
- Delayed state transitions
Threaded IRQ¶
Threaded IRQ executes interrupt handling in a dedicated IRQ thread.
Flow:
Characteristics:
- Dedicated IRQ thread
- Runs in process context
- Sleep allowed
- Lower latency than shared workqueue
Workqueue vs Threaded IRQ¶
| Item | Workqueue | Threaded IRQ |
|---|---|---|
| Worker | Shared | Dedicated |
| Trigger | queue_work() | IRQ_WAKE_THREAD |
| Context | Process Context | Process Context |
| Sleep Allowed | Yes | Yes |
| Typical Use | Deferred Work | Interrupt Processing |
| Ownership | Workqueue Subsystem | IRQ Subsystem |
| Latency | Usually Higher | Usually Lower |
Lab Summary¶
Lab1 - Workqueue Bottom Half¶
Implemented:
- work_struct
- workqueue
- queue_work()
- Worker thread
Verified:
Lab2 - Delayed Work¶
Implemented:
- delayed_work
- schedule_delayed_work()
- cancel_delayed_work()
- mod_delayed_work()
Verified:
GPIO debounce pattern:
Lab3 - Threaded IRQ¶
Implemented:
- request_threaded_irq()
- IRQ_WAKE_THREAD
- IRQ thread
- thread_fn()
Verified:
Files¶
New:
utils/gpio-sim/workqueue.h
utils/gpio-sim/workqueue.c
utils/gpio-sim/delayed_work.h
utils/gpio-sim/delayed_work.c
utils/kernel_macro.h
Updated:
Result¶
Successfully implemented and verified three common Linux Bottom Half mechanisms:
- Workqueue
- Delayed Work
- Threaded IRQ
Built a complete simulation path from interrupt handling to deferred processing.
Next Step¶
Day81 - Workqueue Internals
Topics:
- System Workqueue
- alloc_workqueue()
- Worker Pool
- Concurrency Control
- flush_work()
- cancel_work_sync()
- Workqueue Lifecycle
- Workqueue vs kthread