Grant Likely | 22 Sep 2011 20:51
Picon

[RFC PATCH v3] drivercore: Add driver probe deferral mechanism

Allow drivers to report at probe time that they cannot get all the resources
required by the device, and should be retried at a later time.

This should completely solve the problem of getting devices
initialized in the right order.  Right now this is mostly handled by
mucking about with initcall ordering which is a complete hack, and
doesn't even remotely handle the case where device drivers are in
modules.  This approach completely sidesteps the issues by allowing
driver registration to occur in any order, and any driver can request
to be retried after a few more other drivers get probed.

v3: - Hold off workqueue scheduling until late_initcall so that the bulk
      of driver probes are complete before we start retrying deferred devices.
    - Tested with simple use cases.  Still needs more testing though.
      Using it to get rid of the gpio early_initcall madness, or to replace
      the ASoC internal probe deferral code would be ideal.
v2: - added locking so it should no longer be utterly broken in that regard
    - remove device from deferred list at device_del time.
    - Still completely untested with any real use case, but has been
      boot tested.

TODO: - Create a separate singlethread_workqueue so that drivers can't
        mess things up by calling flush_work().
      - Maybe this should be wrapped with a kconfig symbol so it can
        be compiled out on systems that don't care.

Signed-off-by: Grant Likely <grant.likely <at> secretlab.ca>
Cc: Greg Kroah-Hartman <greg <at> kroah.com>
Cc: Mark Brown <broonie <at> opensource.wolfsonmicro.com>
Cc: Arnd Bergmann <arnd <at> arndb.de>
(Continue reading)

Joe Perches | 22 Sep 2011 20:58

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Thu, 2011-09-22 at 12:51 -0600, Grant Likely wrote:
> Allow drivers to report at probe time that they cannot get all the resources
> required by the device, and should be retried at a later time.
[]
> I would appreciate
> any feedback.

trivia:

> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
[]
> +static void driver_deferred_probe_add(struct device *dev)
> +{
> +	mutex_lock(&deferred_probe_mutex);
> +	if (list_empty(&dev->deferred_probe)) {
> +		dev_dbg(dev, "Added to deferred list\n");

These messages might be more intelligible as
"Added to deferred probe list\n"

> +void driver_deferred_probe_del(struct device *dev)
> +{
> +	mutex_lock(&deferred_probe_mutex);
> +	if (!list_empty(&dev->deferred_probe)) {
> +		dev_dbg(dev, "Removed from deferred list\n");

"Removed from deferred probe list\n"

David Daney | 22 Sep 2011 21:28

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

Thanks Grant, This is sorely needed.

On 09/22/2011 11:51 AM, Grant Likely wrote:
> Allow drivers to report at probe time that they cannot get all the resources
> required by the device, and should be retried at a later time.
>
> This should completely solve the problem of getting devices
> initialized in the right order.  Right now this is mostly handled by
> mucking about with initcall ordering which is a complete hack, and
> doesn't even remotely handle the case where device drivers are in
> modules.  This approach completely sidesteps the issues by allowing
> driver registration to occur in any order, and any driver can request
> to be retried after a few more other drivers get probed.
>
> v3: - Hold off workqueue scheduling until late_initcall so that the bulk
>        of driver probes are complete before we start retrying deferred devices.
>      - Tested with simple use cases.  Still needs more testing though.
>        Using it to get rid of the gpio early_initcall madness, or to replace
>        the ASoC internal probe deferral code would be ideal.
> v2: - added locking so it should no longer be utterly broken in that regard
>      - remove device from deferred list at device_del time.
>      - Still completely untested with any real use case, but has been
>        boot tested.
>
> TODO: - Create a separate singlethread_workqueue so that drivers can't
>          mess things up by calling flush_work().
>        - Maybe this should be wrapped with a kconfig symbol so it can
>          be compiled out on systems that don't care.
>
> Signed-off-by: Grant Likely<grant.likely <at> secretlab.ca>
(Continue reading)

Alan Cox | 22 Sep 2011 22:29
Face
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

Definitely what is needed for some of the x86 SoC stuff and would let us
rip out some of the special case magic for the SCU discovery.

First thing that strikes me is driver_bound kicks the processing queue
again. That seems odd - surely this isn't needed because any driver that
does initialise this time and may allow something else to get going will
queue the kick itself. Thus this seems to just add overhead.

It all looks a bit O(N²) if we don't expect the drivers that might
trigger something else binding to just say 'hey I'm one of the
troublemakers'

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel <at> lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Grant Likely | 22 Sep 2011 23:19
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Thu, Sep 22, 2011 at 2:29 PM, Alan Cox <alan <at> lxorguk.ukuu.org.uk> wrote:
> Definitely what is needed for some of the x86 SoC stuff and would let us
> rip out some of the special case magic for the SCU discovery.
>
> First thing that strikes me is driver_bound kicks the processing queue
> again. That seems odd - surely this isn't needed because any driver that
> does initialise this time and may allow something else to get going will
> queue the kick itself. Thus this seems to just add overhead.
>
> It all looks a bit O(N²) if we don't expect the drivers that might
> trigger something else binding to just say 'hey I'm one of the
> troublemakers'

The way I read it, absolute worst case is when every device but one
depends on another device.  In that case I believe it will be
O(Nlog(N)).  (Every device gets probed on the first pass, but only the
last one gets probed.  Then it goes through N-1 devices to the result
of only 1 more device getting probed, then N-2, etc.).  Actual usage
won't be anywhere near that complexity because there tends to be a
small number of devices on these SoCs that a lot of other devices
depend on, so I expect that there will be somewhere on the order of
3-4 passes for the typical embedded SoCs that I've seen.

driver_bound is used to kick off the process because anytime a new
device becomes active (bound to a driver), there is a high likelyhood
that one of the devices in the pending list can now be probed.
However, the re-probing is performed in a workqueue to make sure that
it is somewhat serialized to prevent the *entire* pending list to be
processed for every driver_bound() call.  Instead, by kicking a
workqueue, it guarantees that all the pending items are retried, but
(Continue reading)

Valdis.Kletnieks | 23 Sep 2011 19:50
Picon
Favicon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Thu, 22 Sep 2011 15:19:01 MDT, Grant Likely said:
> On Thu, Sep 22, 2011 at 2:29 PM, Alan Cox <alan <at> lxorguk.ukuu.org.uk> wrote:
> > Definitely what is needed for some of the x86 SoC stuff and would let us
> > rip out some of the special case magic for the SCU discovery.
> >
> > First thing that strikes me is driver_bound kicks the processing queue
> > again. That seems odd - surely this isn't needed because any driver that
> > does initialise this time and may allow something else to get going will
> > queue the kick itself. Thus this seems to just add overhead.
> >
> > It all looks a bit O(N²) if we don't expect the drivers that might
> > trigger something else binding to just say 'hey I'm one of the
> > troublemakers'
> 
> The way I read it, absolute worst case is when every device but one
> depends on another device.  In that case I believe it will be
> O(Nlog(N)).  (Every device gets probed on the first pass, but only the
> last one gets probed.  Then it goes through N-1 devices to the result
> of only 1 more device getting probed, then N-2, etc.). 

That is indeed O(N**2) not Nlog(N).  The total number of probes is (N+1)(N)/2
To get it to O(Nlog(N)), you'd have to probe N devices the first pass, N/2 devices
on the second pass, N/4 on the third, and so on.

Grant Likely | 24 Sep 2011 01:18
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Fri, Sep 23, 2011 at 01:50:23PM -0400, Valdis.Kletnieks <at> vt.edu wrote:
> On Thu, 22 Sep 2011 15:19:01 MDT, Grant Likely said:
> > On Thu, Sep 22, 2011 at 2:29 PM, Alan Cox <alan <at> lxorguk.ukuu.org.uk> wrote:
> > > Definitely what is needed for some of the x86 SoC stuff and would let us
> > > rip out some of the special case magic for the SCU discovery.
> > >
> > > First thing that strikes me is driver_bound kicks the processing queue
> > > again. That seems odd - surely this isn't needed because any driver that
> > > does initialise this time and may allow something else to get going will
> > > queue the kick itself. Thus this seems to just add overhead.
> > >
> > > It all looks a bit O(N²) if we don't expect the drivers that might
> > > trigger something else binding to just say 'hey I'm one of the
> > > troublemakers'
> > 
> > The way I read it, absolute worst case is when every device but one
> > depends on another device.  In that case I believe it will be
> > O(Nlog(N)).  (Every device gets probed on the first pass, but only the
> > last one gets probed.  Then it goes through N-1 devices to the result
> > of only 1 more device getting probed, then N-2, etc.). 
> 
> That is indeed O(N**2) not Nlog(N).  The total number of probes is (N+1)(N)/2
> To get it to O(Nlog(N)), you'd have to probe N devices the first pass, N/2 devices
> on the second pass, N/4 on the third, and so on.
> 

Ah, indeed, you are correct.  It's been too long since my engineering
CS class.

Still, I'm not even remotely worried about this algorithm for the
(Continue reading)

David Daney | 22 Sep 2011 23:19

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On 09/22/2011 01:29 PM, Alan Cox wrote:
> Definitely what is needed for some of the x86 SoC stuff and would let us
> rip out some of the special case magic for the SCU discovery.
>
> First thing that strikes me is driver_bound kicks the processing queue
> again. That seems odd - surely this isn't needed because any driver that
> does initialise this time and may allow something else to get going will
> queue the kick itself. Thus this seems to just add overhead.
>

Do you mean explicitly kick the queue?

How would a given driver know that something else is waiting for it?  Or 
would we add the explicit kick to each and every driver in the tree?

> It all looks a bit O(N²) if we don't expect the drivers that might
> trigger something else binding to just say 'hey I'm one of the
> troublemakers'

I think it probably is O(N²), but N is small...

> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo <at> vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

Alan Cox | 23 Sep 2011 00:47
Face
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

> How would a given driver know that something else is waiting for it?  Or 
> would we add the explicit kick to each and every driver in the tree?

I think there are very very few drivers that have this property and don't
already implicitly cause a probe by creating a new bus or device.

Those drivers that set something up for another device really should
know what is going on because they are making a guarantee that they are
ready for the other device to call into them or whatever is going on at
some point, either explicitly in the kick or implicitly in returning from
their probe method.

I know which I think is clearer and easier for a 3rd party to see and not
miss completely when updating code.

Alan
David Daney | 23 Sep 2011 18:55
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On 09/22/2011 03:47 PM, Alan Cox wrote:
>> How would a given driver know that something else is waiting for it?  Or
>> would we add the explicit kick to each and every driver in the tree?
>
> I think there are very very few drivers that have this property and don't
> already implicitly cause a probe by creating a new bus or device.
>

These are precisely the drivers of concern.  However it is not 
individual drivers, but whole classes of drivers.  In my case we are 
talking about GPIO drivers.

If there is a dependency on GPIO devices, we don't know which 
device/driver will be providing the GPIO services, so at a minimum *all* 
GPIO drivers would have to add the explicit kick.

> Those drivers that set something up for another device really should
> know what is going on because they are making a guarantee that they are
> ready for the other device to call into them or whatever is going on at
> some point, either explicitly in the kick or implicitly in returning from
> their probe method.

Really the driver framework is there to do all this already.  Once the 
probe method is called, the device is usually presented as 'ready' in 
some sense.

The problem this patch solves is to make it work when there are ad hoc 
relationships between the devices that cannot be represented in a tree 
like structure presented by the bus/driver topology of the driver framework.

(Continue reading)

Grant Likely | 23 Sep 2011 07:02
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Thu, Sep 22, 2011 at 11:47:37PM +0100, Alan Cox wrote:
> > How would a given driver know that something else is waiting for it?  Or 
> > would we add the explicit kick to each and every driver in the tree?
> 
> I think there are very very few drivers that have this property and don't
> already implicitly cause a probe by creating a new bus or device.
> 
> Those drivers that set something up for another device really should
> know what is going on because they are making a guarantee that they are
> ready for the other device to call into them or whatever is going on at
> some point, either explicitly in the kick or implicitly in returning from
> their probe method.

I disagree.  There are lots of situations we're hitting where the
providing driver and the consuming driver don't have any details about
each other except for the name/reference of the resource (be it gpio,
phy, clock, regulator; each with a different API).

Example 1: ALSA SoC complex.  A codec sitting on an i2c bus that gets
bound to an i2c_driver and attached to a memory-mapped I2S controller
driven by a platform_driver.  The sound device cannot be created until
both the i2c codec and the i2s controller are bound to their drivers.

Example 2: an SDHCI controller which uses a couple of GPIO lines for
card detect and write protect, but the board designer may choose to
use any available gpio line, such as on an spi gpio expander.

Example 3: An Ethernet controller attached to a phy on a completely
independent MDIO bus.  The Ethernet driver uses the phylib api to
access the phy, but cannot do so until after the phy device is bound
(Continue reading)

Mark Brown | 26 Sep 2011 16:16
Favicon
Gravatar

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Thu, Sep 22, 2011 at 12:51:23PM -0600, Grant Likely wrote:
> Allow drivers to report at probe time that they cannot get all the resources
> required by the device, and should be retried at a later time.

> This should completely solve the problem of getting devices
> initialized in the right order.  Right now this is mostly handled by
> mucking about with initcall ordering which is a complete hack, and
> doesn't even remotely handle the case where device drivers are in
> modules.  This approach completely sidesteps the issues by allowing
> driver registration to occur in any order, and any driver can request
> to be retried after a few more other drivers get probed.

So, one issue I did think of the other day while putting some support in
the regulator core for using this: what happens with devices which can
optionally use a resource but don't rely on it?  One example here is
that a lot of the MMC drivers have an optional regulator to control some
of the supplies for the cards.  If the reglator isn't there it won't be
used but it's not a blocker for anything.  Devices doing this would need
some way to figure out if they should -EBUSY or fail otherwise.
Russell King - ARM Linux | 26 Sep 2011 17:12
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Mon, Sep 26, 2011 at 03:16:43PM +0100, Mark Brown wrote:
> On Thu, Sep 22, 2011 at 12:51:23PM -0600, Grant Likely wrote:
> > Allow drivers to report at probe time that they cannot get all the resources
> > required by the device, and should be retried at a later time.
> 
> > This should completely solve the problem of getting devices
> > initialized in the right order.  Right now this is mostly handled by
> > mucking about with initcall ordering which is a complete hack, and
> > doesn't even remotely handle the case where device drivers are in
> > modules.  This approach completely sidesteps the issues by allowing
> > driver registration to occur in any order, and any driver can request
> > to be retried after a few more other drivers get probed.
> 
> So, one issue I did think of the other day while putting some support in
> the regulator core for using this: what happens with devices which can
> optionally use a resource but don't rely on it?  One example here is
> that a lot of the MMC drivers have an optional regulator to control some
> of the supplies for the cards.  If the reglator isn't there it won't be
> used but it's not a blocker for anything.  Devices doing this would need
> some way to figure out if they should -EBUSY or fail otherwise.

Just to avoid confusion - ITYM -EAGAIN there.  -EBUSY is already used
by drivers to mean "someone else claimed a resource I need" be it the
IO region or an IRQ resource...
Mark Brown | 26 Sep 2011 17:26
Favicon
Gravatar

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Mon, Sep 26, 2011 at 04:12:10PM +0100, Russell King - ARM Linux wrote:
> On Mon, Sep 26, 2011 at 03:16:43PM +0100, Mark Brown wrote:

> > used but it's not a blocker for anything.  Devices doing this would need
> > some way to figure out if they should -EBUSY or fail otherwise.

> Just to avoid confusion - ITYM -EAGAIN there.  -EBUSY is already used
> by drivers to mean "someone else claimed a resource I need" be it the
> IO region or an IRQ resource...

Yes, I do - sorry.
Grant Likely | 26 Sep 2011 17:48
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Mon, Sep 26, 2011 at 9:26 AM, Mark Brown
<broonie <at> opensource.wolfsonmicro.com> wrote:
> On Mon, Sep 26, 2011 at 04:12:10PM +0100, Russell King - ARM Linux wrote:
>> On Mon, Sep 26, 2011 at 03:16:43PM +0100, Mark Brown wrote:
>
>> > used but it's not a blocker for anything.  Devices doing this would need
>> > some way to figure out if they should -EBUSY or fail otherwise.
>
>> Just to avoid confusion - ITYM -EAGAIN there.  -EBUSY is already used
>> by drivers to mean "someone else claimed a resource I need" be it the
>> IO region or an IRQ resource...
>
> Yes, I do - sorry.

Actually, in the next iteration, I'm thinking it would be a good idea
to create a new #define to only be used by probe deferral.  I want it
to be easy to find all the drivers that are using this mechanism
without needing to filter all the unrelated hits.  However, this is a
kernel-only thing so it is probably not appropriate to add it to
include/asm-generic/errno.h.  I could use some guidance/advice as to
the best way to handle this.

g.
Arnd Bergmann | 27 Sep 2011 15:50
Picon
Gravatar

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Monday 26 September 2011, Grant Likely wrote:
> Actually, in the next iteration, I'm thinking it would be a good idea
> to create a new #define to only be used by probe deferral.  I want it
> to be easy to find all the drivers that are using this mechanism
> without needing to filter all the unrelated hits.  However, this is a
> kernel-only thing so it is probably not appropriate to add it to
> include/asm-generic/errno.h.  I could use some guidance/advice as to
> the best way to handle this.

include/linux/errno.h already has a bunch of kernel-internal error
codes that are never supposed to be seen in user space. Just
add one there, the next free one right now is 517, after
ERESTART_RESTARTBLOCK.

	Arnd
Grant Likely | 27 Sep 2011 23:08
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Tue, Sep 27, 2011 at 03:50:36PM +0200, Arnd Bergmann wrote:
> On Monday 26 September 2011, Grant Likely wrote:
> > Actually, in the next iteration, I'm thinking it would be a good idea
> > to create a new #define to only be used by probe deferral.  I want it
> > to be easy to find all the drivers that are using this mechanism
> > without needing to filter all the unrelated hits.  However, this is a
> > kernel-only thing so it is probably not appropriate to add it to
> > include/asm-generic/errno.h.  I could use some guidance/advice as to
> > the best way to handle this.
> 
> include/linux/errno.h already has a bunch of kernel-internal error
> codes that are never supposed to be seen in user space. Just
> add one there, the next free one right now is 517, after
> ERESTART_RESTARTBLOCK.

Okay, will do.  How does EPROBE_DEFER 518 sound?

g.
Mark Brown | 28 Sep 2011 00:13
Favicon
Gravatar

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Tue, Sep 27, 2011 at 03:08:49PM -0600, Grant Likely wrote:

> Okay, will do.  How does EPROBE_DEFER 518 sound?

Note that I'm not sure this answers the issue I was raising - the issue
isn't that the caller doesn't know what the error code means, the issue
is that in some cases the driver needs to take a decision about what
failure to get a resource means.  Does it mean that the driver can work
fine and be slightly less featureful or should it cause a deferral?
Arnd Bergmann | 28 Sep 2011 15:04
Picon
Gravatar

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Wednesday 28 September 2011, Mark Brown wrote:
> On Tue, Sep 27, 2011 at 03:08:49PM -0600, Grant Likely wrote:
> 
> > Okay, will do.  How does EPROBE_DEFER 518 sound?
> 
> Note that I'm not sure this answers the issue I was raising - the issue
> isn't that the caller doesn't know what the error code means, the issue
> is that in some cases the driver needs to take a decision about what
> failure to get a resource means.  Does it mean that the driver can work
> fine and be slightly less featureful or should it cause a deferral?

Can you think of cases where this information cannot be put into the
device tree or platform_data? If a board provides an optional feature,
I think that should be a property of the device that the driver gets,
so it can return an error when that feature is not around, or continue
when it knows that the feature will never become available.

	Arnd
Mark Brown | 28 Sep 2011 15:20
Favicon
Gravatar

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Wed, Sep 28, 2011 at 03:04:34PM +0200, Arnd Bergmann wrote:
> On Wednesday 28 September 2011, Mark Brown wrote:

> > Note that I'm not sure this answers the issue I was raising - the issue
> > isn't that the caller doesn't know what the error code means, the issue
> > is that in some cases the driver needs to take a decision about what
> > failure to get a resource means.  Does it mean that the driver can work
> > fine and be slightly less featureful or should it cause a deferral?

> Can you think of cases where this information cannot be put into the
> device tree or platform_data? If a board provides an optional feature,
> I think that should be a property of the device that the driver gets,
> so it can return an error when that feature is not around, or continue
> when it knows that the feature will never become available.

Not off the top of my head, most of the cases I'm aware of were cases
where the supply is mandatory but soft control is optional so don't need
to make this decision in the driver at all.  In the MMC case I didn't
push this as working with the people concerned was extremely painful.
Grant Likely | 29 Sep 2011 01:14
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Tue, Sep 27, 2011 at 11:13:10PM +0100, Mark Brown wrote:
> On Tue, Sep 27, 2011 at 03:08:49PM -0600, Grant Likely wrote:
> 
> > Okay, will do.  How does EPROBE_DEFER 518 sound?
> 
> Note that I'm not sure this answers the issue I was raising - the issue
> isn't that the caller doesn't know what the error code means, the issue
> is that in some cases the driver needs to take a decision about what
> failure to get a resource means.  Does it mean that the driver can work
> fine and be slightly less featureful or should it cause a deferral?

Right. That was answering a different question.

For your question, I still think it is the driver that gets to make
the decision.  If it can proceed without a resource, then it should go
ahead and succeed on the probe, and then arrange to either be notified
of new gpio controller (or whatever) registrations, or poll for the
resource to be set up.

g.
Mark Brown | 29 Sep 2011 13:00
Favicon
Gravatar

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Wed, Sep 28, 2011 at 06:14:10PM -0500, Grant Likely wrote:

> For your question, I still think it is the driver that gets to make
> the decision.  If it can proceed without a resource, then it should go
> ahead and succeed on the probe, and then arrange to either be notified
> of new gpio controller (or whatever) registrations, or poll for the
> resource to be set up.

Right, I do tend to agree.  This is something we'll have to bear in mind
when deploying this stuff - drivers that are doing this sort of stuff
are going to get surprised.
Kevin Hilman | 4 Oct 2011 01:02
Picon
Favicon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

Grant Likely <grant.likely <at> secretlab.ca> writes:

> Allow drivers to report at probe time that they cannot get all the resources
> required by the device, and should be retried at a later time.
>
> This should completely solve the problem of getting devices
> initialized in the right order.  Right now this is mostly handled by
> mucking about with initcall ordering which is a complete hack, and
> doesn't even remotely handle the case where device drivers are in
> modules.  This approach completely sidesteps the issues by allowing
> driver registration to occur in any order, and any driver can request
> to be retried after a few more other drivers get probed.

This is great work, thanks!

For the TODO list:

While the proposed patch should solve probe order dependencies, I don't
think it will solve the suspend/resume ordering dependencies, which are
typically the same.

Currenly suspend/resume order is based on the order devices are *added*
(device_add() -> device_pm_add() -> device added to dpm_list), so
unfortunately, deferring probe isn't going to affect suspend/resume
ordering.

Extending this to also address suspend/resume ordering by also changing
when the device is added to the dpm_list (or possibly creating another
list) should probably be explored as well.

(Continue reading)

Grant Likely | 4 Oct 2011 17:52
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Mon, Oct 3, 2011 at 5:02 PM, Kevin Hilman <khilman <at> ti.com> wrote:
> Grant Likely <grant.likely <at> secretlab.ca> writes:
>
>> Allow drivers to report at probe time that they cannot get all the resources
>> required by the device, and should be retried at a later time.
>>
>> This should completely solve the problem of getting devices
>> initialized in the right order.  Right now this is mostly handled by
>> mucking about with initcall ordering which is a complete hack, and
>> doesn't even remotely handle the case where device drivers are in
>> modules.  This approach completely sidesteps the issues by allowing
>> driver registration to occur in any order, and any driver can request
>> to be retried after a few more other drivers get probed.
>
> This is great work, thanks!
>
> For the TODO list:
>
> While the proposed patch should solve probe order dependencies, I don't
> think it will solve the suspend/resume ordering dependencies, which are
> typically the same.
>
> Currenly suspend/resume order is based on the order devices are *added*
> (device_add() -> device_pm_add() -> device added to dpm_list), so
> unfortunately, deferring probe isn't going to affect suspend/resume
> ordering.
>
> Extending this to also address suspend/resume ordering by also changing
> when the device is added to the dpm_list (or possibly creating another
> list) should probably be explored as well.
(Continue reading)

G, Manjunath Kondaiah | 4 Oct 2011 16:51
Picon
Favicon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

Hi Grant,

On Thu, Sep 22, 2011 at 12:51:23PM -0600, Grant Likely wrote:
> Allow drivers to report at probe time that they cannot get all the resources
> required by the device, and should be retried at a later time.
> 
> This should completely solve the problem of getting devices
> initialized in the right order.  Right now this is mostly handled by
> mucking about with initcall ordering which is a complete hack, and
> doesn't even remotely handle the case where device drivers are in
> modules.  This approach completely sidesteps the issues by allowing
> driver registration to occur in any order, and any driver can request
> to be retried after a few more other drivers get probed.
> 
> v3: - Hold off workqueue scheduling until late_initcall so that the bulk
>       of driver probes are complete before we start retrying deferred devices.
>     - Tested with simple use cases.  Still needs more testing though.
>       Using it to get rid of the gpio early_initcall madness, or to replace
>       the ASoC internal probe deferral code would be ideal.
> v2: - added locking so it should no longer be utterly broken in that regard
>     - remove device from deferred list at device_del time.
>     - Still completely untested with any real use case, but has been
>       boot tested.
> 
> TODO: - Create a separate singlethread_workqueue so that drivers can't
>         mess things up by calling flush_work().
>       - Maybe this should be wrapped with a kconfig symbol so it can
>         be compiled out on systems that don't care.
> 
> Signed-off-by: Grant Likely <grant.likely <at> secretlab.ca>
(Continue reading)

Grant Likely | 4 Oct 2011 17:58
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Tue, Oct 4, 2011 at 8:51 AM, G, Manjunath Kondaiah <manjugk <at> ti.com> wrote:
> On Thu, Sep 22, 2011 at 12:51:23PM -0600, Grant Likely wrote:
>> Hi Manjunath,
>>
>> Here's the current state of the patch.  The major think that needs to
>> be done is to convert it to use a separate workqueue as described in
>> the TODO above.  It also needs some users adapted to it.  One of the
>> gpio drivers would work; preferably one of the newer drivers that
>> doesn't have a lot of drivers depending on the early_initcall()
>> behaviour yet.
>
> I have tested this patch on omap3 beagle board by making:
> 1. omap-gpio driver init as late_initcall instead of postcore_initcall
> 2. mmc driver probe will request gpio through gpio_request and gpio driver
> returns -EDEFER_PROBE which in turn makes mmc driver to request deferral probe.
> 3. When deferral probe gets activated, it scans driver entries and it will not
> find any match for mmc driver probe.

Looks like drivers/mmc/host/omap.c is using platform_driver_probe()
instead of platform_driver_register().  Add the probe hook to the
platform_driver structure and change it to call
platform_driver_register() and it should work.  Don't forget to change
mmc_omap_probe from __init to __devinit.

g.
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

(Continue reading)

G, Manjunath Kondaiah | 4 Oct 2011 20:35
Picon
Favicon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Tue, Oct 04, 2011 at 09:58:10AM -0600, Grant Likely wrote:
> On Tue, Oct 4, 2011 at 8:51 AM, G, Manjunath Kondaiah <manjugk <at> ti.com> wrote:
> > On Thu, Sep 22, 2011 at 12:51:23PM -0600, Grant Likely wrote:
> >> Hi Manjunath,
> >>
> >> Here's the current state of the patch.  The major think that needs to
> >> be done is to convert it to use a separate workqueue as described in
> >> the TODO above.  It also needs some users adapted to it.  One of the
> >> gpio drivers would work; preferably one of the newer drivers that
> >> doesn't have a lot of drivers depending on the early_initcall()
> >> behaviour yet.
> >
> > I have tested this patch on omap3 beagle board by making:
> > 1. omap-gpio driver init as late_initcall instead of postcore_initcall
> > 2. mmc driver probe will request gpio through gpio_request and gpio driver
> > returns -EDEFER_PROBE which in turn makes mmc driver to request deferral probe.
> > 3. When deferral probe gets activated, it scans driver entries and it will not
> > find any match for mmc driver probe.
> 
> Looks like drivers/mmc/host/omap.c is using platform_driver_probe()
> instead of platform_driver_register().  Add the probe hook to the
> platform_driver structure and change it to call
> platform_driver_register() and it should work.  Don't forget to change
> mmc_omap_probe from __init to __devinit.

Yes. After changing it into platform_driver_register, I can see mmc probe is
getting completed from deferred probe list. But, MMC upper layer will check 
probe and it waits for ever since probe_count is not getting incremented.

Log:
(Continue reading)

Grant Likely | 5 Oct 2011 01:35
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Wed, Oct 05, 2011 at 12:05:16AM +0530, G, Manjunath Kondaiah wrote:
> On Tue, Oct 04, 2011 at 09:58:10AM -0600, Grant Likely wrote:
> > On Tue, Oct 4, 2011 at 8:51 AM, G, Manjunath Kondaiah <manjugk <at> ti.com> wrote:
> > > On Thu, Sep 22, 2011 at 12:51:23PM -0600, Grant Likely wrote:
> > >> Hi Manjunath,
> > >>
> > >> Here's the current state of the patch.  The major think that needs to
> > >> be done is to convert it to use a separate workqueue as described in
> > >> the TODO above.  It also needs some users adapted to it.  One of the
> > >> gpio drivers would work; preferably one of the newer drivers that
> > >> doesn't have a lot of drivers depending on the early_initcall()
> > >> behaviour yet.
> > >
> > > I have tested this patch on omap3 beagle board by making:
> > > 1. omap-gpio driver init as late_initcall instead of postcore_initcall
> > > 2. mmc driver probe will request gpio through gpio_request and gpio driver
> > > returns -EDEFER_PROBE which in turn makes mmc driver to request deferral probe.
> > > 3. When deferral probe gets activated, it scans driver entries and it will not
> > > find any match for mmc driver probe.
> > 
> > Looks like drivers/mmc/host/omap.c is using platform_driver_probe()
> > instead of platform_driver_register().  Add the probe hook to the
> > platform_driver structure and change it to call
> > platform_driver_register() and it should work.  Don't forget to change
> > mmc_omap_probe from __init to __devinit.
> 
> Yes. After changing it into platform_driver_register, I can see mmc probe is
> getting completed from deferred probe list. But, MMC upper layer will check 
> probe and it waits for ever since probe_count is not getting incremented.
> 
(Continue reading)

G, Manjunath Kondaiah | 7 Oct 2011 05:31
Picon
Favicon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Tue, Oct 04, 2011 at 05:35:04PM -0600, Grant Likely wrote:
> On Wed, Oct 05, 2011 at 12:05:16AM +0530, G, Manjunath Kondaiah wrote:
> > On Tue, Oct 04, 2011 at 09:58:10AM -0600, Grant Likely wrote:
> > > On Tue, Oct 4, 2011 at 8:51 AM, G, Manjunath Kondaiah <manjugk <at> ti.com> wrote:
> > > > On Thu, Sep 22, 2011 at 12:51:23PM -0600, Grant Likely wrote:
> > > >> Hi Manjunath,
> > > >>
> > > >> Here's the current state of the patch.  The major think that needs to
> > > >> be done is to convert it to use a separate workqueue as described in
> > > >> the TODO above.  It also needs some users adapted to it.  One of the
> > > >> gpio drivers would work; preferably one of the newer drivers that
> > > >> doesn't have a lot of drivers depending on the early_initcall()
> > > >> behaviour yet.
> > > >
> > > > I have tested this patch on omap3 beagle board by making:
> > > > 1. omap-gpio driver init as late_initcall instead of postcore_initcall
> > > > 2. mmc driver probe will request gpio through gpio_request and gpio driver
> > > > returns -EDEFER_PROBE which in turn makes mmc driver to request deferral probe.
> > > > 3. When deferral probe gets activated, it scans driver entries and it will not
> > > > find any match for mmc driver probe.
> > > 
> > > Looks like drivers/mmc/host/omap.c is using platform_driver_probe()
> > > instead of platform_driver_register().  Add the probe hook to the
> > > platform_driver structure and change it to call
> > > platform_driver_register() and it should work.  Don't forget to change
> > > mmc_omap_probe from __init to __devinit.
> > 
> > Yes. After changing it into platform_driver_register, I can see mmc probe is
> > getting completed from deferred probe list. But, MMC upper layer will check 
> > probe and it waits for ever since probe_count is not getting incremented.
(Continue reading)

Andrew Morton | 11 Oct 2011 22:47

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Thu, 22 Sep 2011 12:51:23 -0600
Grant Likely <grant.likely <at> secretlab.ca> wrote:

> Allow drivers to report at probe time that they cannot get all the resources
> required by the device, and should be retried at a later time.
> 
> This should completely solve the problem of getting devices
> initialized in the right order.  Right now this is mostly handled by
> mucking about with initcall ordering which is a complete hack, and
> doesn't even remotely handle the case where device drivers are in
> modules.  This approach completely sidesteps the issues by allowing
> driver registration to occur in any order, and any driver can request
> to be retried after a few more other drivers get probed.

What happens is there is a circular dependency, or if a driver's
preconditions are never met?  AFAICT the code keeps running the probe
function for ever.

If so: bad.  The kernel should detect such situations, should
exhaustively report them and if possible, fix them up and struggle
onwards.

>
> ...
>
> +	 * This bit is tricky.  We want to process every device in the
> +	 * deferred list, but devices can be removed from the list at any
> +	 * time while inside this for-each loop.  There are two things that
> +	 * need to be protected against:
> +	 * - if the device is removed from the deferred_probe_list, then we
(Continue reading)

David Daney | 11 Oct 2011 23:07

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On 10/11/2011 01:47 PM, Andrew Morton wrote:
> On Thu, 22 Sep 2011 12:51:23 -0600
> Grant Likely<grant.likely <at> secretlab.ca>  wrote:
>
>> Allow drivers to report at probe time that they cannot get all the resources
>> required by the device, and should be retried at a later time.
>>
>> This should completely solve the problem of getting devices
>> initialized in the right order.  Right now this is mostly handled by
>> mucking about with initcall ordering which is a complete hack, and
>> doesn't even remotely handle the case where device drivers are in
>> modules.  This approach completely sidesteps the issues by allowing
>> driver registration to occur in any order, and any driver can request
>> to be retried after a few more other drivers get probed.
>
> What happens is there is a circular dependency, or if a driver's
> preconditions are never met?  AFAICT the code keeps running the probe
> function for ever.
>

The deferred probe functions are only run once per (other) driver 
binding event.  So once you quit registering new drivers, no further 
probing is done.  There is no endless loop happening here.

If the preconditions are never met, the driver will just sit in the list 
waiting.

> If so: bad.  The kernel should detect such situations, should
> exhaustively report them and if possible, fix them up and struggle
> onwards.
(Continue reading)

Grant Likely | 13 Oct 2011 06:19
Picon

Re: [RFC PATCH v3] drivercore: Add driver probe deferral mechanism

On Tue, Oct 11, 2011 at 02:07:41PM -0700, David Daney wrote:
> On 10/11/2011 01:47 PM, Andrew Morton wrote:
> >On Thu, 22 Sep 2011 12:51:23 -0600
> >Grant Likely<grant.likely <at> secretlab.ca>  wrote:
> >
> >>Allow drivers to report at probe time that they cannot get all the resources
> >>required by the device, and should be retried at a later time.
> >>
> >>This should completely solve the problem of getting devices
> >>initialized in the right order.  Right now this is mostly handled by
> >>mucking about with initcall ordering which is a complete hack, and
> >>doesn't even remotely handle the case where device drivers are in
> >>modules.  This approach completely sidesteps the issues by allowing
> >>driver registration to occur in any order, and any driver can request
> >>to be retried after a few more other drivers get probed.
> >
> >What happens is there is a circular dependency, or if a driver's
> >preconditions are never met?  AFAICT the code keeps running the probe
> >function for ever.
> >
> 
> The deferred probe functions are only run once per (other) driver
> binding event.  So once you quit registering new drivers, no further
> probing is done.  There is no endless loop happening here.
> 
> If the preconditions are never met, the driver will just sit in the
> list waiting.

Plus, as an optimization, walking the deferred list doesn't begin
until late initcall time so that the first pass over the device
(Continue reading)


Gmane