Notifier Chain API Reference¶
Overview¶
Notifier Chain provides a generic event notification mechanism inside the Linux kernel.
It allows one subsystem to publish events while multiple subscribers register callback handlers independently.
Notifier chains are commonly used for:
- CPU frequency transitions
- Reboot notifications
- Power management events
- Network device state changes
- USB device events
Core Structure¶
struct notifier_block¶
Definition¶
Purpose¶
Represents a subscriber entry within a notifier chain.
Members¶
| Member | Description |
|---|---|
| notifier_call | Callback function |
| next | Next notifier block |
| priority | Callback priority |
Callback Prototype¶
notifier_call¶
Prototype¶
Parameters¶
| Parameter | Description |
|---|---|
| nb | Current notifier block |
| action | Event identifier |
| data | Event payload |
Return Values¶
Continue propagation.
Event ignored.
Stop further callback execution.
Event handling failed.
Blocking Notifier¶
BLOCKING_NOTIFIER_HEAD()¶
Prototype¶
Purpose¶
Declare and initialize a blocking notifier chain.
Characteristics¶
Example¶
blocking_notifier_chain_register()¶
Prototype¶
int blocking_notifier_chain_register(
struct blocking_notifier_head *nh,
struct notifier_block *nb);
Purpose¶
Register a notifier callback.
Parameters¶
| Parameter | Description |
|---|---|
| nh | Notifier chain |
| nb | Subscriber |
Return Value¶
Success.
Negative error code on failure.
blocking_notifier_chain_unregister()¶
Prototype¶
int blocking_notifier_chain_unregister(
struct blocking_notifier_head *nh,
struct notifier_block *nb);
Purpose¶
Remove a notifier callback from a chain.
Parameters¶
| Parameter | Description |
|---|---|
| nh | Notifier chain |
| nb | Subscriber |
blocking_notifier_call_chain()¶
Prototype¶
int blocking_notifier_call_chain(
struct blocking_notifier_head *nh,
unsigned long action,
void *data);
Purpose¶
Broadcast an event to all registered subscribers.
Parameters¶
| Parameter | Description |
|---|---|
| nh | Notifier chain |
| action | Event identifier |
| data | Event payload |
Example¶
Atomic Notifier¶
ATOMIC_NOTIFIER_HEAD()¶
Prototype¶
Purpose¶
Declare and initialize an atomic notifier chain.
Characteristics¶
Example¶
atomic_notifier_chain_register()¶
Prototype¶
Purpose¶
Register an atomic notifier callback.
atomic_notifier_chain_unregister()¶
Prototype¶
Purpose¶
Remove an atomic notifier callback.
atomic_notifier_call_chain()¶
Prototype¶
Purpose¶
Broadcast an event through an atomic notifier chain.
Notes¶
Callbacks must not sleep.
Avoid:
Raw Notifier¶
RAW_NOTIFIER_HEAD()¶
Prototype¶
Purpose¶
Declare a notifier chain without internal synchronization.
Characteristics¶
Typical Synchronization¶
Priority Ordering¶
Notifier callbacks are executed in descending priority order.
Example:
Execution order:
Priority is independent of registration order.
Event Payload¶
Event-specific information is passed through:
Example:
Publisher:
Subscriber:
Common Pitfalls¶
Using Registration Order as Execution Order¶
Incorrect assumption:
Actual behavior:
Sleeping in Atomic Notifier Callbacks¶
Incorrect:
Atomic notifier callbacks must remain atomic-safe.
Reusing One notifier_block Across Multiple Chains¶
Avoid:
Recommended:
Related Notes¶
Related Topics¶
Related Labs¶
- Day70 - Notifier Chain