9/21/2023 0 Comments Linux kernel kref![]() Refcount is an atomic data type to specify the number of positions in the kernel at which an object is currently being used. The layout of the kref structure used to manage references is as follows: Table 1-1 lists the standard operations provided by the kernel to manipulate kobject instances, and therefore effectively act on the embedding structure. The similarity between the name kobject and the object concept of, well, object-oriented languages like C++ or Java is by no means coincidental: The kobject abstraction indeed allows for using object-oriented techniques in the kernel, but without requiring all the extra mechanics (and bloat, and overhead) of C++. Of greatest importance is the destructor function that returns the resources of the embedding data structure. □ ktype provides more detailed information on the data structure in which a kobject is embedded. □ parent is a pointer to the parent element and enables a hierarchical structure to be established between kobjects. □ kset is required when an object is grouped with other objects in a set. □ entry is a standard list element used to group several kobjects in a list (known as a set in this case). □ kref holds the general type struct kref designed to simplify reference management. Likewise sd supports this connection, and I will come back to this in Chapter 10. Sysfs is a virtual filesystem that allows for exporting various properties of the system into userspace. □ k_name is a text name exported to userspace using sysfs. The meanings of the individual elements of struct kobject are as follows: Adding a single new element to this data structure results in a size increase of many other data structures. Since struct kobject is embedded into many data structures of the kernel, the developers take care to keep it small. Managing the kernel object itself amounts to managing the whole containing object this way. It is essential that kobjects are not linked with other data structures by means of pointers but are directly embedded. I deal with this in more detail in the appendix on C programming. The following data structure that is embedded in other data structures is used as a basis.Ĭonst char struct kref struct list_head struct kobject struct kset struct kobj_type struct sysfs_direntĤEven if there is only one list element in the structure, this entry is used to find the correct start address of the instance by means of pointer arithmetic the address is translated into the required data type by means of type conversion. □ Exporting object properties into userspace (via the sysfs filesystem) The generic kernel object mechanism can be used to perform the following operations on objects: It also allows for providing a coherent view on objects managed by different parts of the kernel, and this information can be brought to good use in many parts of the kernel, for instance, for power management. The framework is, however, not just required to prevent code duplication. Since this is a bad thing, the kernel has adopted generic methods to manage kernel objects during the development of 2.5. ![]() Despite the fact that these objects will be used in the most varying forms, some operations are very similar across subsystems - just consider reference counting. * Returns NULL if the posix_clock instance attached to 'fp' is old and stale.All over the kernel, the need to keep track of instances of C structures arises. */ # include # include # include # include # include # include # include static void delete_clock ( struct kref * kref ) /* * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * along with this program if not, write to the Free Software * You should have received a copy of the GNU General Public License * GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * but WITHOUT ANY WARRANTY without even the implied warranty of * This program is distributed in the hope that it will be useful, * the Free Software Foundation either version 2 of the License, or * it under the terms of the GNU General Public License as published by * This program is free software you can redistribute it and/or modify * Copyright (C) 2010 OMICRON electronics GmbH * posix-clock.c - support for dynamic clock devices
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |