Future Driver core changes
The future of struct class_device
Eventually, the structure class_device is going to be merged into the device structure, and go away. But as this can not happen all at once, here are the different steps that I see happening to achieve this goal:-
Try to move all users that individually create a struct class
on their own, to use the class_create() and
class_destroy() functions
instead. In the future, struct class will become an "opaque"
pointer, and only known by the class core code. No subsystems will be
able to create this structure, except by doing it dynamically. By doing
this step, we will remove the custom hotplug/uevent and release handlers
for the classes, making it easier to convert these structures over to
struct device in the future.
There are only around 20 different places in the current kernel that this will affect. The toughest of these will probably be the input and the network subsystems.
-
Remove all exported class functions in the driver core that are not being used by existing code. This will prevent any new code that gets added during the conversion process from using these functions.
-
Allow struct device to show up as attached to a struct class. This will entail adding a pointer to struct device. When this is done, the different users of struct class_device can be moved over to using struct device easily.
-
As the movement of the different classes are converted to struct device, start adding fields that are present in the struct class_device structure to struct device. At first glance, it looks like only the dev_t field (which holds the major/minor pair for the device) will need to be moved. All of the other fields in struct class_device look like they will match up with existing fields, but only by converting the different subsystems will this be known for sure.
-
struct class_interface is going to be "difficult". As only CardBus/PCMCIA and SCSI is using these functions and structures, how they are used there will have to be evaluated for how they can be converted away. The first thing that comes to mind would be a virtual bus for these types of devices, much like how the virtual USB Serial bus works. That would allow the PCMCIA and SCSI cores to still get notification of when a device is added or removed, which is what struct class_interface is used for.
-
A number of the things in /sys/class/ do not correspond directly with "real" devices that are currently in the /sys/device/ directory tree. The items in /sys/class/mem/ are examples of this type of device. For them, a new place in the /sys/device/ hierarchy will have to be found. Current ideas have moving them to the /sys/device/system/ tree, but others have proposed /sys/device/virtual/ instead, as they are not really "system" devices. Still others have said that it would be better to just put them all in the /sys/devices/ directory. It is unclear what will be the final resting place for these devices.
After all of these steps are complete, the last few holdouts of the class_device structure can be removed, and replaced with struct device, and then the class device structures and functions can finally be deleted.
The main point of this process is that it is going to happen one subsystem at a time, hopefully in such a manner that no users ever notice the difference.
Trees of symlinks
After the previously mentioned steps have been complete, the /sys/class/ directories will only contain subdirectories of symlinks back to the /sys/device tree. For example, for the 2.6.15 kernel release, the /sys/class/usb_host tree looks like:/sys/class/usb_host/ |-- usb_host1 | |-- device -> ../../../devices/pci0000:00/0000:00:1d.0 | `-- uevent |-- usb_host2 | |-- device -> ../../../devices/pci0000:00/0000:00:1d.1 | `-- uevent |-- usb_host3 | |-- device -> ../../../devices/pci0000:00/0000:00:1d.2 | `-- uevent `-- usb_host4 |-- device -> ../../../devices/pci0000:00/0000:00:1d.3 `-- ueventOnce the conversion process is done, it will look like this:
/sys/class/usb_host/ |-- usb_host1 -> ../../devices/pci0000:00/0000:00:1d.0/usb_host:usb_host1 |-- usb_host2 -> ../../devices/pci0000:00/0000:00:1d.1/usb_host:usb_host2 |-- usb_host3 -> ../../devices/pci0000:00/0000:00:1d.2/usb_host:usb_host3 `-- usb_host4 -> ../../devices/pci0000:00/0000:00:1d.3/usb_host:usb_host4With the usb_host1 class device moving to:
/sys/devices/pci0000:00/0000:00:1d.0/usb_host:usb_host1 |-- device -> ../../0000:00:1d.0 `-- ueventNote how the existing symlink in the device directory that points back to the class device (usb_host:usbhost1 is for the first usb host class device) is now a subdirectory in the device tree. Hopefully this will prevent any userspace program that is relying on the current structure of sysfs from breaking.
kobject/kset/subsystem/attribute diet
As anyone who has tried to understand the tangled web of interlocking pointers and dependencies between the kobject, kset, and subsystem structures and helper functions knows, a lot of work could be done here to make it simpler and easier to use and understand. Along with this, the attribute system of how to create files for kobjects in sysfs is quite complex. Any rework that can be done in this area, while ensuring that all of the current users of these core structures still work properly, will be done. As of this writing, no concrete plans for exactly what needs to be done here have been finalized.
Easier and more APIs
The current driver model is very flexible and powerful. Unfortunately along with this power and flexibility comes the ability to use it in incorrect ways very easily. The driver core does try to warn if somethings are not set up properly (like the lack of a release function), but it is still quite easy to get around these limited checks. So, on the Rusty scale of good kernel api levels, the driver core is very low on the list.
Again, like the kset maze, no concrete plans for exactly what will be done in this area have been finalized, but an example of what things might look like would be the current class_device_create() and class_device_destroy() functions. These functions push all of the nasty reference counting logic and class handling code into the driver core, and let the driver author worry about getting their driver specific logic correct. The driver author is no longer forced to become intimate with the driver core inner workings.
Better documentation
Due to the complexity of the current driver model code, much better documentation is needed to help developers who do want to use the core functions figure out how things should be done. The documentation that is in the current kernel tree (in Documentation/driver-model/) is woefully out of date. Hopefully the majority of this documentation can be moved to sit next to the driver core code itself, in kerneldoc format, which will help prevent any future changes from going undocumented.
Other subsystems have converted over to this format, with very great success, USB being one good example of this.
Out of tree subsystems
All of these changes will hopefully be done without breaking any
userspace utilities (although, there will probably be a few udev updates
needed along the way.) Any in-kernel code will be fixed up along the
way, preventing any build or usage breakage, and then the unused
structures and functions will be removed from the kernel tree. For
driver subsystems that live outside of the main kernel tree, this means
that their individual authors will have to update them to handle the new
changes that are happening, or they can just submit them for inclusion
in the main kernel tree, so that their code will be converted for them.
Index entries for this article | |
---|---|
GuestArticles | Kroah-Hartman, Greg |
Posted Dec 1, 2005 11:11 UTC (Thu)
by smurf (subscriber, #17840)
[Link] (6 responses)
Ummm... yeah. ;-)
Posted Dec 1, 2005 16:57 UTC (Thu)
by gregkh (subscriber, #8)
[Link] (3 responses)
Posted Dec 1, 2005 17:31 UTC (Thu)
by smurf (subscriber, #17840)
[Link] (2 responses)
Read literally, your intention seems to be to have *everything* break.
Posted Dec 1, 2005 17:38 UTC (Thu)
by gregkh (subscriber, #8)
[Link]
Posted Jan 12, 2006 20:10 UTC (Thu)
by k8to (guest, #15413)
[Link]
All I'm saying here is humans are not CPUs, and can handle these issues fine, but it doesn't hurt to tighten up your language.
Posted Dec 1, 2005 21:46 UTC (Thu)
by cook (subscriber, #4)
[Link]
Posted Jan 29, 2006 9:12 UTC (Sun)
by landley (guest, #6789)
[Link]
Posted Dec 2, 2005 20:21 UTC (Fri)
by skybrian (guest, #365)
[Link] (1 responses)
Posted Dec 4, 2005 0:18 UTC (Sun)
by ddaa (guest, #5338)
[Link]
The whole presentation can be found there:
It's definitely worth reading entirely, very funny and insightful.
In particular, this anecdote says much about communication issue in community projects (this slide and the few following):
The scale in a nutshell is found on those two slides:
But you should probably start reading it from this page:
Posted Dec 8, 2005 8:52 UTC (Thu)
by akukula (guest, #3862)
[Link] (1 responses)
$.02
Posted Jan 12, 2006 19:28 UTC (Thu)
by gregkh (subscriber, #8)
[Link]
>> Hopefully this will prevent any userspace program that is relying on the current structure of sysfs to not break.Please don't not break
Well, that's the goal. Do you know of programs relying on the current sysfs class structure that would break with these proposed changes?Please don't not break
You are missing the keyword "double negation". ;-)Please don't not break
Doh!Please don't not break
Ok, sorry, I didn't mean that, thanks for pointing it out to me.
Just to be a nudge: double negation in english is ambiguous. It is commonly used in a manner interpreted to be nonconflicting, and this nonconflicting behavior is considered proper in most languages.Please don't not break
Sorry, that slipped by me in the editing pass, the text has been fixed.Please don't not break
Actually, it'll break mdev in busybox. We were traversing the block and Please don't not break
class directory hierarchies to find dev nodes, but were avoiding
traversing symlinks because following device and bridge can lead to
endless loops.
Now we apparently have to know _which_ symlinks to follow, which sucks
deeply.
What is the "Rusty scale of good kernel api levels"?Rusty scale?
It's a part of a classic presentation by Rusty Russell.Rusty scale?
http://ozlabs.org/~rusty/ols-2003-keynote/ols-keynote-200...
http://ozlabs.org/~rusty/ols-2003-keynote/img15.html
http://ozlabs.org/~rusty/ols-2003-keynote/img48.html
http://ozlabs.org/~rusty/ols-2003-keynote/img56.html
http://ozlabs.org/~rusty/ols-2003-keynote/img39.html
"struct class" is one of the worst names I can imagine. Not only it is too general and more precise name would be better -- e.g. "struct devclass". It also confuses a typical C++ programmer. There's only one which is more stupid: "struct struct".Future Driver core changes
And what would you suggest using instead?Future Driver core changes