Re: [PATCH v2 0/3] introduce External Connector Class (extcon)

From: NeilBrown
Date: Sun Dec 18 2011 - 02:16:25 EST


On Thu, 15 Dec 2011 14:51:55 +0800 Mark Brown
<broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> On Thu, Dec 15, 2011 at 01:32:29PM +1100, NeilBrown wrote:
>
> j> 3/ The use of extcon_get_extcon_dev() requires that the port device be
> > registered before the device that wants to be notified by it. Ensuring
> > correct ordering of device discovery is (I believe) not always easy -
> > particularly with module loading.
>
> This is a massive problem throughout the kernel

So it seems. I just tripped over it with regulators. When one is supplied by
another they need to be probed in the right order.
Sounds like we need to find a general solution.

>
> > Would it make sense to instead have one device register as a
> > switch-provider and the other device register as a switch-listener and as
> > soon as they both exist they get connected: a bit like how 'devices' and
> > 'drivers' can be registered in any order.
> > Maybe the same device/driver infrastructure could be reused (an extcon
> > bus maybe?) but I'm not really familiar enough with it to say (Greg??).
>
> Grant has a proposal for this which revolves around devices trying to
> acquire their resources and returning a "please retry" error code if
> they don't have all their dependencies. Half the problem here is that
> coming up with the dependency graph (and finding ways to talk about
> devices that haven't been enumerated yet) is a very hard problem.

I can see how an -EAGAIN might work ... and it would exercise a lot of error
paths that otherwise never get called - I wonder if that is a good thing :-)

It doesn't feel quite like the right solution though. Deciding when to retry,
and where to queue the device/driver pairs might be messy.

A possibility I have been thinking about is to multithread do_initcalls() and
have the various request functions (gpio_request, regulator_get, request_irq,
etc) optionally block if the resource isn't available.

We wouldn't create a new thread for every initcall, just when all current
threads are blocked. And threads that have to block die once they finish
their initcall, so there is only ever one that is allowed to move on to the
'next' initcall.

Do we need to talk about devices that haven't been enumerated yet? or was
that just if we wanted to create an explicit dependency graph?

We would need names for resources that haven't been registered yet but that
seems fairly with with simple string names assigned in the board file (or
eventually the device-tree file I guess).

I might try hacking something together and see how badly it breaks.


>
> > Are there other examples of inter-device dependencies that can be used as
> > a model?
>
> The current solution is to fiddle with initcall order so that drivers
> for devices that other devices depend on enumerate first.

:-( I was afraid of that.

NeilBrown

Attachment: signature.asc
Description: PGP signature