Day70 - Notifier Chain¶
Overview¶
Today I learned the Linux kernel notifier chain framework, which provides a generic event notification mechanism for communication between kernel subsystems.
Unlike completion or wait queues, notifier chains are designed for one-to-many event propagation. A subsystem can publish an event without knowing which modules are interested in receiving it.
Topics covered:
- notifier_block
- blocking notifier chain
- atomic notifier chain
- callback registration
- callback unregistration
- notifier priority ordering
- NOTIFY_STOP propagation control
- event payload delivery
- dynamic subscriber management
Lab Summary¶
Lab1 - Basic Blocking Notifier¶
Implemented a basic blocking notifier chain.
Learned:
- BLOCKING_NOTIFIER_HEAD()
- blocking_notifier_chain_register()
- blocking_notifier_chain_unregister()
- blocking_notifier_call_chain()
Verified:
- callback registration
- callback execution
- callback unregistration
Lab2 - Priority Ordering¶
Added notifier priorities.
Verified:
- higher priority callbacks execute first
- execution order is determined by priority
- execution order is not determined by registration order
Example:
Execution order:
Lab3 - NOTIFY_STOP¶
Tested event propagation control.
Verified:
stops execution of the remaining callbacks.
Example:
CLIENT-A is not executed.
Lab4 - Event Payload¶
Implemented event payload delivery using:
Created:
Verified:
- publisher passes event context
- callbacks receive identical event data
- notifier chain supports event-specific payloads
Lab5 - Blocking and Atomic Notifier¶
Implemented:
Verified:
- blocking notifier registration
- atomic notifier registration
- event delivery through both chains
Observed:
when called from module_init().
Key understanding:
Atomic notifier does not imply execution inside interrupt context.
Instead:
Lab6 - Dynamic Unregister¶
Verified runtime removal of subscribers.
Initial chain:
After removing C:
After removing B:
Confirmed:
- notifier chains behave like callback linked lists
- unregister immediately removes callbacks from future event delivery
Key Concepts Learned¶
Notifier Chain¶
A generic kernel event notification framework.
Provides:
without tight coupling.
notifier_block¶
Represents a callback registration entry.
Contains:
- callback function
- priority
- next pointer
Notifier chains internally maintain linked lists of notifier blocks.
Event Propagation¶
Publisher:
Subscribers:
Event information is delivered through:
Priority Ordering¶
Callbacks are executed according to:
rather than registration order.
NOTIFY_STOP¶
Allows a callback to stop further event propagation.
Useful when:
- event is fully handled
- remaining subscribers should not execute
Blocking vs Atomic Notifier¶
Blocking notifier:
Atomic notifier:
Atomic notifier does not guarantee execution in interrupt context.
Comparison with Previous Topics¶
Completion¶
Used to wait for an operation to finish.
Wait Queue¶
Used for sleep and wakeup synchronization.
Workqueue¶
Used to move work into process context.
Notifier Chain¶
Used for event propagation between subsystems.
Takeaways¶
Notifier chains provide a flexible event broadcast mechanism inside the Linux kernel.
The framework decouples publishers and subscribers while supporting:
- callback priorities
- event payloads
- propagation control
- dynamic registration and removal
This mechanism is widely used by:
- CPUFreq
- Power Management
- Reboot Notifier
- Network Subsystems
- USB Subsystems
and serves as a foundation for many kernel event propagation paths.
Next Steps¶
Day71:
- Linux Driver Model Fundamentals
- Device
- Driver
- Bus
- Matching Process
- Driver Registration Flow