Completion¶
Overview¶
Completion is a Linux kernel synchronization primitive designed for one-shot event notification.
It allows one execution context to wait until another execution context signals that an operation has finished.
Common use cases include:
- Hardware initialization
- Firmware loading
- DMA completion
- Worker startup synchronization
- Driver probe synchronization
Why Completion Exists¶
Many synchronization problems can be expressed as:
Traditionally this could be implemented using a wait queue and a completion flag:
Completion encapsulates this pattern into a dedicated synchronization primitive.
Completion Lifecycle¶
Typical workflow:
The waiter blocks until another execution context signals completion.
One-Shot Synchronization¶
Completion is designed for one-shot events.
Examples:
Unlike wait queues, completion is not intended for repeated event processing.
Completion State Persistence¶
After:
or:
the completion object remains in the completed state.
Future waiters return immediately.
Example:
returns immediately.
Reusing a Completion Object¶
To reuse a completion object:
must be called.
This resets the completion state and allows future waiters to block again.
Completion vs Wait Queue¶
| Feature | Completion | Wait Queue |
|---|---|---|
| Waiting Model | Operation-based | Condition-based |
| One-shot Event | Excellent | Possible |
| Repeated Events | Poor | Excellent |
| State Machine | Poor | Excellent |
| Initialization Synchronization | Excellent | Acceptable |
Typical Driver Usage¶
Completion is commonly used in:
- Driver initialization
- Firmware loading
- DMA engines
- Hardware reset sequences
- Worker startup synchronization
Example:
Relationship to Wait Queues¶
Internally, completion is built on top of wait queues.
Kernel definition:
Completion can be viewed as:
Choosing Completion¶
Use completion when:
Use wait queues when:
Summary¶
Completion provides a lightweight mechanism for operation completion notification.
It is ideal for:
- Initialization synchronization
- Startup sequencing
- Hardware-ready notification
- DMA completion
Completion simplifies many synchronization patterns that would otherwise require a wait queue and a separate completion flag.