JustKernel

Ray Of Hope

Notification chain – linux kernel

Notifier chains send status change messages to code regions that request them. Unlike hard-coded mechanisms, notifiers offer a versatile technique for dynamically loadable code to get notified when events of interest occur. Notifier chains were originally added to pass network events to concerned sections of the kernel, but are now used for many other purposes.

The kernel implements a number of predefined notifiers for significant events. For example:
1.A die notification is sent when a kernel function triggers a trap or a fault, caused by an oops, page fault, or a breakpoint.
2.A network device notification is generated when a network interface goes up or down.
3.A CPU frequency notification is generated when there’s a transition in processor frequency.
4.A Internet address notification is sent when a change is detected in the IP address of a network interface.

To attach your code into a notifier chain, you register an event handler function with the corresponding chain. When the requisite event occurs, the handler is passed two arguments: an event identifier and a chain-specific data argument. To define your own (user-defined) notifier chain, you must also implement the infrastructure to initiate the chain…

A notification chain is simply a list of functions to execute when a given event occurs. Each function lets one other subsystem know about an event that occurred within, or was detected by, the subsystem calling the function.

Thus, for each notification chain there is a passive side (the notified) and an active side (the notifier), as in the so-called publish-and-subscribe model:

  •     The notified are the subsystems that ask to be notified about the event and tat provide a callback function to invoke
  • The notifier is the subsystem that experiences an event and calls the callback function.

The functions executed are chosen by the notified subsystems. It is never up to the owner of the chain (the subsytem that generates the notifications)to decide what functions to execute. The owner simply defines the list; any kernel subsytem can register a callback function with that chain to receive the notification.

The notification chains allow each subsystem to share the occurrence of an event with others, without having to know what the others are and why they are interested.

Defining a chain

The elements of the notification chain’s list are of type notifier_block, whose definition is the following:

struct notifier_bloc {
    int (*notifier_call) (struct notifier_block *self, unsigned long, void *);
    stuct notifier_block *next;
    priority   };

notifier_call is the funciton to execute , next is used to link together the elements of the list, and priority represents the priority of the function.

Registering with chain

When a kernel component is intersted in the evnets of a given notification chain, it can register it with the generatl function notifier_chain_register.

Notification chains for networking subsystem :

– inetaddr_chain: notification about insertion , removal , and change of an ipv4 addresses on local interface.

– ntdev chain : sends notifications about the registration status status of network devices.

Originally Posted On: 2010-05-18 04:36:19

Anshul Makkar, anshul_makkar@justkernel.com

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.