Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 1: Introduction and Overview


Table 1-1: Standard Methods for Processingkobjects

Function Meaning

kobject_get,kobject_put Increments or decrements the reference counter of akobject

kobject_(un)register Registers or removesobjfrom a hierarchy (the object is added to the
existing set (if any) of the parent element; a corresponding entry is cre-
ated in thesysfsfilesystem).

kobject_init Initializes akobject; that is, it sets the reference counter to its initial
value and initializes the list elements of the object.

kobect_add Initializes a kernel object and makes it visible in sysfs

kobject_cleanup Releases the allocated resources when akobject(and therefore the
embedding object) is no longer needed

Encapsulation of the single value in a structure was chosen to prevent direct manipulation of the value.
kref_initmust always be used for initialization. If an object is in use,kref_getmust be invoked
beforehand to increment the reference counter.kref_putdecrements the counter when the object is no
longer used.

Sets of Objects


In many cases, it is necessary to group different kernel objects into a set — for instance, the set of all
character devices or the set of all PCI-based devices. The data structure provided for this purpose is
defined as follows:

<kobject.h>
struct kset {
struct kobj_type * ktype;
struct list_head list;
...
struct kobject kobj;
struct kset_uevent_ops * uevent_ops;
};

Interestingly, theksetserves as the first example for the use of kernel objects. Since the management
structure for sets is nothing other than a kernel object, it can be managed via the previously discussed
struct kobj. Indeed, an instance is embedded viakobj. It has nothing to do with thekobjects collected
in the set, but only serves to manage the properties of theksetobject itself.

The other members have the following meaning:

❑ ktypepoints to a further object that generalizes the behavior of thekset.
❑ listis used to build a list of all kernel objects that are a member of the set.
❑ uevent_opsprovides several function pointers to methods that relay information about the state
of the set to userland. This mechanism is used bythe core of the driver model, for instance, to
format messages that inform about the addition of new devices.
Free download pdf