191 likes | 343 Views
This chapter delves into kobjects, ktypes, ksets, and subsystems in the Linux kernel, emphasizing the device model and sysfs. Learn about managing kobjects, reference counts, sysfs conventions, and the kernel events layer. Gain insights into representing devices, minimizing code duplication, and structuring device topology efficiently.
E N D
Linux Kernel Development Chpt17: kobjects and sysfs Tao Yang 2007-06-01
Overview • Device model • Kobject • Ktypes • Ksets • Subsystems • Reference Counts • Sysfs • The Kernel Events Layer
device model • Representing devices & describing topology • Benefits: • Minimization of code duplication • providing common facilities • enumerate all the devices • generate a complete tree of the entire device structure • link devices to their drivers • categorize devices by their class • The ability to walk the tree of devices from the leaves up to the root, poweringdown devices in the correct order
kobjects • Kobject: the heart of the device model
ktype • which the kobjects are associated with • describing default behavior for a family of kobjects • define default properties: deconstruction behavior, sysfs behavior, and default attributes
ksets • Collections of kobjects • Distinction of ksets and ktypes: • ksets collect kobjects into a set • ktypes describe properties shared by kobjects of a related type • allow kobjects of identical ktypes to be grouped into different ksets
Subsystem • high-level concepts in the kernel • a collection of one or more ksets • Ksets contain kobjects • subsystems contain ksets
Same ktype Relationship of these Structure • Kobject: the basic unit • Ktype: describe default properties • Ksets: Collections of kobjects
Managing and Manipulating kobjects • declaring and initializing • Before calling this function, the kobject must be zeroed • set the kobject's name
Reference Counts • To keep the kobject in memory or destroy it • Incrementing the reference count: • Decrementing the reference count: • Kref: provide the kobject reference counting
sysfs • In-memory virtual filesystem • View the kobject hierarchy • View the device topology as a simple filesystem
Adding and Removing kobjects from sysfs • Export a kobject to sysfs • Initializes the given kobject and adds to the object hierarchy • Removing a kobject's sysfs • Both kobject_del() and kobject_put():
Adding Files to sysfs • Default Attributes: • ktype field in kobjects and ksets provide default set of files • Attribute structures: map kernel data to files in sysfs • Creating New Attributes • Destroying New Attributes
sysfs Conventions • To keep sysfs clean and intuitive, conventions must be followed: • First, sysfs attributes should export one value per file • Second, organize data in sysfs in a clean hierarchy • Finally, keep in mind that sysfs provides a kernel-to-user service
The Kernel Events Layer • Implements a kernel-to-user notification system • Hard drive full • Processor is overheating • Partition mounted • send events out to user-space from kernel code:
Conclusion • Subject : device model, sysfs, kobjects, and the kernel event layer • Driver writers need only a peripheral view of these topics • Developers of kernel need a more in-depth understanding of kobjects
Thank you Q & A