linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Martin Sperl <martin-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: Depreciated spi_master.transfer and "prepared spi messages" for an optimized pipelined-SPI-DMA-driver
Date: Thu, 14 Nov 2013 01:50:09 +0000	[thread overview]
Message-ID: <20131114015009.GB26614@sirena.org.uk> (raw)
In-Reply-To: <52823E73.503-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 10220 bytes --]

On Tue, Nov 12, 2013 at 03:42:59PM +0100, Martin Sperl wrote:

> This "chaining" is _obviously_ not possible with the transfer_one
> message BUS-master-API (or it would require some "ugly hacks" to
> make use of transfer_one_message API)

Meh, it doesn't seem that urgently different to be honest.  The basic
flow of interactions with the device is very much typical of SPI
controllers.

In any case while it's not entirely clearly explained here I *think* the
major thing that's being done differently here is that the register
writes to the controller are being done using DMA.  Is that the case?

That's certainly a bit of an innovation and I don't think it's actually
all that device specific - while reusing the same channel for things
other than the actual data transfer is a bit cute I can't see any
obvious reason why it shouldn't work and it's something that I'd expect
a great proportion of DMA controllers would be able to support.  The
delays are a bit dodgy for that but for untimed delays could probably be
implemented with dummy memcpy() type transfers easily enough.

I'd expect this to integrate nicely with the general stuff to split out
the pushing of transfers and configuration of transfers that I'd been
kicking around - transfer_one() is intended to be split into two for
this, one bit to configure the transfer and another bit to actually do
it.  The original idea was more around recognising and exploiting
scatter/gather patterns but pipelining the DMAs for configuration would
allow that to be extended a bit.

One thing that does concern me is the overhead of all the DMA work for
smaller transfers - once there's a queue built up it's more clearly
useful but without a queue it's not obvious that the effort is going to
be worth it.

> Well - as said I am wondering if the DMA engine can really can help
> - especially if you want to keep the "prepare" code fast. I am using
> dmapool for memory alloc/free, but I fear we would need to run 2 mallocs
> if I was using DMA-engine and more setup/tear-down overhead, as well
> as more code that needs to get executed to go via DMA-engine.

The big win from dmaengine is that it means that you don't need to
implement essentially the same DMA code in each and every driver, all
the DMA drivers end up with a uniform API.  Since by and by large the
process of mapping a SPI message for DMA is the same no matter what the
controller is this ends up being a win and we don't require each and
every master driver author to jump through the same hoops.

If it doesn't do what's desired we should fix it to make it better (same
as here).

> As said: I will keep it as is for now and first implement the full DMA
> chaining approach. then we can see how much the move to DMA-Engine
> is costing...

That's fine for experimentation but for an actual merged API I think it
does need to be generally applicable so that it's worth the effort for
client drivers to support it.

> not the prime "candidates" for the improvement in the first place.
> If they want to run with minimal latencies, they HAVE to run spi_async.
> Anything else is not very efficient as it requires several context
> switches by the way of the current design.

Well, the benefits of submitting things asynchronously are as much about
giving the stack something to play with and reducing turnaround time as
anything else - it means the stack can submit the next transfer to the
hardware before it tells the caller that the current one completed which
reduces the idle time on the bus and means that there's much more scope
for reducing needless context switching.  Right now we're not doing as
good a job of that as we can in most drivers though frankly even the
current state is an improvement on what we had.

> >The other bit of easy to implement that concerns me is making sure that
> >it's easy to implement for the stack as a whole - one of the big

> If you can get away from the idea that prepare is ONLY related to
> the Master, then it may provide additional "advantages". Also when
> you do have a non-prepared message, you can still can call the
> prepare code from the framework and afterwards unprepare it - like I
> had proposed.

> That way any "checks" the driver would need to do to see if it can
> handle the message, it can do immediately in the "prepare" code.

I'm having a really hard time getting excited about the improvements
from saving the checks though, they just seem so small for the effort by
themselves.  You are right, they do exist, but they seem so small in
relation to the overall transfer time.  That said if a patch were to
appear which did that and didn't provide any master side hooks I think
that'd probably be OK.

> whatever the driver may find helpful for its own purpose. One
> candidate here could be also implement dma_map_single in the prepare
> call...

Of course this reduces the range of situations where the calling driver
can reuse a prepared message since it means if they want to access the
data they have to unprepare and then reprepare the message which rather
seems to defeat the point of having them worry about doing that.  This
is why I was asking about nailing down the sematics, I was worried about
this.

> So separating things out immediately reducing code of the individual
> drivers if they move to the newer interface of schedule_message...
> if they do not need prepare/unprepare, then it is (almost) a NOP.

Except for all the actually configuring the hardware stuff on
configuration changes if the register writes aren't DMAed (which is
going to be the common case unless it's frameworked).

> >Adding new interfaces is a change too, on the driver side as well.

> Which is optional and would get first used only by device-drivers
> that need high tru-put. And those device-drivers that need this,
> should already be heavily optimized to avoid memory allocations
> (even if it is just on the heap) and message setup for every call.

Equally well is it really worth their while if you don't get much win
without a specially optimised controller driver?  Extra advantages with
a good driver are one thing but requiring it makes it a harder sell to
drivers using the API.

> >These seem rather artificial and I'm not sure they'd tell us much about
> >why the effects were being observed.  What would be more interesting
> >would be seeing where the time is being spent at the minute for real
> >loads (for example by using trace points like those that are currently
> >being added in mainline for examining the behaviour of the message pump)

> well - my use case is exactly that CAN issue where I have message loss
> when only sending 5 packets in sequence in 30% of all cases with
> stock drivers. That is why I started investigating the issue in the
> first place - so do not tell me it is academic!

Sure, there's room for improvement but let's make that as general an
improvement as possible.  Something that flows better for existing
drivers is much more of a win there.  I'm getting alarm bells that the
gains for this one system might be hard to realise on other systems.

> The proposed SPI-test driver is academic to some extent, but it
> still tries to simulate "real" device traffic with optimal thru-put.
> Or do you think that reading an ADC as fast as possible is an
> academic exercise? (the test driver would essentially mimic that and
> allow for
> scheduling mechanism to work that allow high thruput (if you
> configure multiple messages)

I'm suspicous of benchmarks which limit so that you end up running so
fast you don't have time to actually do anything with the data, you can
end up tuning things so that more realistic users suffer (spending too
much time in interrupt context for example).

> >- if we really are spending a noticeable proportion of the time in setup
> >then that's obviously a good case for optimising it but right now I
> >don't feel I understand which bits are slow enough to register in the
> >context of the overall transaction and hence if the suggested approach
> >is the best way to optimise them.

> well - you see the setup I have to make to transfer 2 writes 10 reads?
> that is 10+ calls to dmapool_alloc, then filling in the structure.
> That takes some time (cant remember how many usec right now).
> And then tearing it down I need to do the same again - ok mostly
> dmapool_release...

Yes, but then this is because the driver is doing lots of really small
DMAs when most only DMA for larger transfers and then only the data.  I
can see can be a benefit if you have a big enough DMA queue to be busy
for extended periods but that's not always going to be the case and then
you get into wondering about how much you can keep mapped and so on.

Like I say I can see this being a technique which is useful over a range
of drivers but there's going to be a point where it's simpler to just do
the I/O.

> >An implementation that avoided the need to have the master drivers
> >updated in order to get benefits would be a lot more interesting since
> >that would make this much more generally useful, and of course concrete
> >patches would be good too, but the main thing I'm missing is clarity on
> >how the gains are being made.

> a master driver will never be able to profit from the new interface,
> besides the "small" gain of not having to validate the messages
> every time in __spi_async (if the device-driver does call prepare)

What about all the DMA pipelining stuff for the register I/O and so on?
That seems to be the biggest part of the win here.

> And as said: all the spi_sync methods are candidates to optimization
> of this - at the cost of some memory used for caching multiple
> messages.
> (say having 16 times 1xspi_message+1xspi_transfer structures for
> transfer length 1 to 16 in spi_write. Similar for spi_read. Or 256
> 1xspi_message+2xspi_transfer to transfer 1-16 writes and 1-16 reads.
> plus some memory copy for the reads and writes)

But then that's a memory plus cache management cost (per master), not to
mention complexity.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  parent reply	other threads:[~2013-11-14  1:50 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <F70C4469-6325-48D5-A7CA-52CC1FC404BD@sperl.org>
     [not found] ` <CACRpkdb6y=o4__snBs2DR1f=xW_u7KdkHg3fb7XN5e2gicBJeg@mail.gmail.com>
     [not found]   ` <CACRpkdb6y=o4__snBs2DR1f=xW_u7KdkHg3fb7XN5e2gicBJeg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-29 16:59     ` Fwd: Depreciated spi_master.transfer and "prepared spi messages" for an optimized pipelined-SPI-DMA-driver Linus Walleij
     [not found]       ` <CACRpkdb7y88oq7XyVFc_0Nx4pXtaebPe7KB2yizBRJGwWLqJig-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-29 17:56         ` Mark Brown
2013-10-29 21:18         ` Martin Sperl
     [not found]           ` <06C7F4D3-EC91-46CF-90BE-FC24D54F2389-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-29 22:53             ` Mark Brown
     [not found]               ` <20131029225353.GB11424-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-10-30 17:11                 ` Martin Sperl
     [not found]                   ` <F64AD25A-C7EC-4A0D-9169-850C12F4D8A3-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-30 21:51                     ` Mark Brown
2013-10-30  8:40             ` Martin Sperl
     [not found]               ` <02BFF0F6-3836-4DEC-AA53-FF100E037DE9-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-30 17:19                 ` Mark Brown
     [not found]                   ` <20131030171902.GL2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-10-30 18:33                     ` Martin Sperl
     [not found]                       ` <8D8B0BAD-0E00-4147-B4C8-FBB18F060C96-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-30 21:57                         ` Mark Brown
     [not found]                           ` <20131030215716.GV2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-10-30 22:52                             ` Martin Sperl
     [not found]                               ` <3342FD19-4438-463B-89B2-A83D3475AC22-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-31  0:10                                 ` Mark Brown
     [not found]                                   ` <20131031001004.GW2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-04 17:33                                     ` Martin Sperl
     [not found]                                       ` <18639D9A-630E-44F3-AA7A-ADFF5D5E8B56-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-04 18:45                                         ` Mark Brown
     [not found]                                           ` <20131104184511.GR2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-04 21:43                                             ` Martin Sperl
     [not found]                                               ` <5A55A832-5313-499C-A483-BF5A6649D69D-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-05  1:03                                                 ` Linus Walleij
2013-11-06  9:48                                                 ` Mark Brown
     [not found]                                                   ` <20131106094854.GF11602-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-06 11:28                                                     ` Martin Sperl
     [not found]                                                       ` <844EDAEA-3FDC-48D0-B59E-CECC0A83761E-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-06 11:32                                                         ` Mark Brown
     [not found]                                                           ` <20131106113219.GJ11602-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-06 12:10                                                             ` Martin Sperl
     [not found]                                                               ` <C6C68042-63A0-40FD-8363-B4553ECB4774-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-06 16:24                                                                 ` Mark Brown
     [not found]                                                                   ` <20131106162410.GB2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-06 19:54                                                                     ` Martin Sperl
     [not found]                                                                       ` <3B0EDE3F-3386-4879-8D89-2E4577860073-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-06 23:26                                                                         ` Mark Brown
     [not found]                                                                           ` <20131106232605.GC2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-07  0:43                                                                             ` Martin Sperl
     [not found]                                                                               ` <72D635F5-4229-4D78-8AA3-1392D5D80127-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-07 20:31                                                                                 ` Mark Brown
     [not found]                                                                                   ` <20131107203127.GB2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-08 14:16                                                                                     ` Martin Sperl
     [not found]                                                                                       ` <86AE15B6-05AF-4EFF-8B8F-10806A7C148B-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-08 16:19                                                                                         ` Mark Brown
     [not found]                                                                                           ` <20131108161957.GP2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-08 17:31                                                                                             ` Martin Sperl
     [not found]                                                                                               ` <5F70E708-89B9-4DCF-A31A-E688BAA0E062-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-08 18:09                                                                                                 ` Mark Brown
     [not found]                                                                                                   ` <20131108180934.GQ2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-08 19:18                                                                                                     ` Martin Sperl
     [not found]                                                                                                       ` <C375DEE6-1AEC-4AFB-A9D6-583DCB4476A3-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-09 18:30                                                                                                         ` Mark Brown
     [not found]                                                                                                           ` <20131109183056.GU2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-10 10:54                                                                                                             ` Martin Sperl
     [not found]                                                                                                               ` <6C7903B3-8563-490E-AD7D-BA5D65FFB9BC-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-12  1:19                                                                                                                 ` Mark Brown
     [not found]                                                                                                                   ` <20131112011954.GH2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-12 14:42                                                                                                                     ` Martin Sperl
     [not found]                                                                                                                       ` <52823E73.503-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-12 17:59                                                                                                                         ` Martin Sperl
     [not found]                                                                                                                           ` <2252E63E-176C-43F7-B259-D1C3A142DAFE-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-13 15:43                                                                                                                             ` Mark Brown
     [not found]                                                                                                                               ` <20131113154346.GT878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-13 18:35                                                                                                                                 ` Martin Sperl
     [not found]                                                                                                                                   ` <ED58E869-A9F6-4BB2-8EC6-D71F946509DC-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-13 19:33                                                                                                                                     ` Mark Brown
     [not found]                                                                                                                                       ` <20131113193320.GE878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-13 21:31                                                                                                                                         ` Martin Sperl
2013-11-13 15:11                                                                                                                         ` Mark Brown
     [not found]                                                                                                                           ` <20131113151102.GS878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-13 15:48                                                                                                                             ` Martin Sperl
     [not found]                                                                                                                               ` <77070979-0CE4-4C76-B12E-DA94B2577172-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-13 16:59                                                                                                                                 ` Mark Brown
2013-11-14  1:50                                                                                                                         ` Mark Brown [this message]
     [not found]                                                                                                                           ` <20131114015009.GB26614-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-14 19:47                                                                                                                             ` Martin Sperl
     [not found]                                                                                                                               ` <9640F4C7-7F82-453E-9D83-5875A1559A20-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-15 11:15                                                                                                                                 ` Martin Sperl
     [not found]                                                                                                                                   ` <5286026B.2090903-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-16 14:23                                                                                                                                     ` Mark Brown
     [not found]                                                                                                                                       ` <20131116142356.GY15393-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-19 13:11                                                                                                                                         ` Martin Sperl
     [not found]                                                                                                                                           ` <528B6370.9000903-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-19 15:02                                                                                                                                             ` Mark Brown
     [not found]                                                                                                                                               ` <20131119150204.GA2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-19 15:13                                                                                                                                                 ` Martin Sperl
2013-11-15 13:33                                                                                                                                 ` Mark Brown
     [not found]                                                                                                                                   ` <20131115133312.GE26614-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-15 14:52                                                                                                                                     ` Martin Sperl
     [not found]                                                                                                                                       ` <0BA2243C-2F22-492A-B517-76E243535549-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-16 12:56                                                                                                                                         ` Mark Brown
2013-11-10 11:05                                                                                                             ` Mark Brown
     [not found]                                                                                                               ` <20131110110524.GA878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-10 16:41                                                                                                                 ` Martin Sperl
     [not found]                                                                                                                   ` <3361A01A-C7D0-4689-AFBD-085D3E62A67C-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-11 11:18                                                                                                                     ` Mark Brown
     [not found]                                                                                                                       ` <20131111111842.GE2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-11 11:44                                                                                                                         ` Martin Sperl
     [not found] ` <F70C4469-6325-48D5-A7CA-52CC1FC404BD-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-29 19:09   ` Fwd: " Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131114015009.GB26614@sirena.org.uk \
    --to=broonie-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=martin-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).