Page MenuHomeFreeBSD

kobj: allow multiple inheritance with per-class softc
Needs ReviewPublic

Authored by mmel on Sun, Aug 23, 7:00 AM.
Tags
None
Referenced Files
F169956102: D59115.id184765.diff
Thu, Sep 3, 2:35 AM
F169802439: D59115.diff
Wed, Sep 2, 3:01 PM
F169766970: D59115.id.diff
Wed, Sep 2, 12:21 PM
Unknown Object (File)
Tue, Sep 1, 8:43 PM
Unknown Object (File)
Tue, Sep 1, 2:07 AM
Unknown Object (File)
Tue, Sep 1, 1:48 AM
Unknown Object (File)
Mon, Aug 31, 9:50 PM
Unknown Object (File)
Mon, Aug 31, 3:12 PM
Subscribers

Details

Summary

Add support for hierarchical softc layout so that a leaf class and each
of its base classes owns a private softc region inside a single
allocation.

device_get_softc_class(dev, cls) returns a pointer to the softc that
belongs to the requested class. The classic device_get_softc() still
returns the leaf softc and remains fully compatible with existing
drivers.

Existing drivers are unaffected; they simply obtain a slightly larger

(but still zeroed) softc block when they inherit from base classes.

MFC after: 2 months

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 76372
Build 73255: arc lint + arc unit

Event Timeline

mmel requested review of this revision.Sun, Aug 23, 7:00 AM

kobj should not mention 'softc', it is not limited to the driver support. It should be named more generally.

sys/kern/subr_kobj.c
410

Extra blank line.

So what does this method have over the existing practice of having the base-class' softc be the first element of the softc for derived classes?

In D59115#1355807, @kib wrote:

kobj should not mention 'softc', it is not limited to the driver support. It should be named more generally.

Completely agree, but despite my best efforts, I can't figure out which word to use instead of “softc”

In D59115#1356419, @imp wrote:

So what does this method have over the existing practice of having the base-class' softc be the first element of the softc for derived classes?

Using the base class's softc as the first element of the softc for the derived class only works in a single-inheritance cases.
However, with "modern" DT, final drivers should be composed of multiple functions. Typically, but not exclusively, the final driver is a combination of a 'real function' driver, syscon and simplebus. This is impossible with the current machinery.

Another example is the clock driver group. Currently, we have base clock classes for the divider, the multiplexer and the gate. However, we also need a class that combines these three functions into one complex clock class.

In D59115#1355807, @kib wrote:

kobj should not mention 'softc', it is not limited to the driver support. It should be named more generally.

Completely agree, but despite my best efforts, I can't figure out which word to use instead of “softc”

May be loan the terminology directly from the OOP crowd, like 'base class', and 'subclass'?

This is one of my dilemmas. KOBJ consistently uses 'baseclass', but 'kobj_offsetof_baseclass' or 'kobj_baseclass_offsetof' looks ugly, especially since these could also be used for the main/leaf class.

What about 'kobj_offsetof_class' and 'kobj_sizeof_class'?

This is one of my dilemmas. KOBJ consistently uses 'baseclass', but 'kobj_offsetof_baseclass' or 'kobj_baseclass_offsetof' looks ugly, especially since these could also be used for the main/leaf class.

What about 'kobj_offsetof_class' and 'kobj_sizeof_class'?

It is probably not class, but class data, am I right? Then might be kobj_instance_data_offset and kobj_total_data_size would be good?

kobj_total_data_size looks good — thanks!
kobj_instance_data_offset seems too long to me, and 'instance' is not entirely precise. Can we shorten it to kobj_data_offset?

kobj_total_data_size looks good — thanks!
kobj_instance_data_offset seems too long to me, and 'instance' is not entirely precise. Can we shorten it to kobj_data_offset?

I would prefer than to use kobj_instance_offset instead.

I'm also fine with it, thanks. Is the device_get_softc_class() function OK? That's actually the one I had the most trouble with.

I'm also fine with it, thanks. Is the device_get_softc_class() function OK? That's actually the one I had the most trouble with.

Do you mean 'the name for device_get_softc_class()'? IMO yes, because the function operates on softc.

  • Rename the functions as agreed during the discussion.
  • Precompute the total size of class data.
  • Implement support for nested classes with optimisation for the most common cases.
mmel edited the summary of this revision. (Show Details)