* Patch to parameterize DMA_MIN_BYTES for omap2-mcspi
@ 2015-03-19 5:05 Greg Knight
2015-03-19 9:47 ` Mark Brown
2015-03-19 12:34 ` Peter Ujfalusi
0 siblings, 2 replies; 12+ messages in thread
From: Greg Knight @ 2015-03-19 5:05 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi, linux-omap
[-- Attachment #1: Type: text/plain, Size: 578 bytes --]
Hi, Mark,
I've attached a patch which adds a device-tree field "ti,dma-min-bytes"
which replaces the macro DMA_MIN_BYTES. Adjusting this field addresses
issues we've had where, in our particular use case, the usleep() in the
SPI worker thread eats a full 20% of our CPU (AM3359).
I opted to implement it as a device-tree parameter and keep the original
value (160) as the default, in order to avoid impacting anyone else.
The patch is attached. Patches 1-2 are an unrelated McASP change (see my
other message).
What is the process for getting this upstreamed?
Thanks,
Greg
[-- Attachment #2: 0003-spi-omap2-mcspi-DMA_MIN_BYTES-hashdef-ti-dma-min-byt.patch --]
[-- Type: text/x-patch, Size: 3066 bytes --]
>From 2b51699d1f7f05de45f0f0f065c37da81181f4eb Mon Sep 17 00:00:00 2001
From: Greg Knight <g.knight@symetrica.com>
Date: Mon, 2 Mar 2015 10:44:21 -0500
Subject: [PATCH 3/3] spi-omap2-mcspi: DMA_MIN_BYTES hashdef =>
ti,dma-min-bytes device tree option
---
drivers/spi/spi-omap2-mcspi.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 70cd418..4ac1f3e 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -117,8 +117,7 @@ struct omap2_mcspi_dma {
/* use PIO for small transfers, avoiding DMA setup/teardown overhead and
* cache operations; better heuristics consider wordsize and bitrate.
*/
-#define DMA_MIN_BYTES 160
-
+#define DMA_MIN_BYTES_DEFAULT 160
/*
* Used for context save and restore, structure members to be updated whenever
@@ -141,6 +140,9 @@ struct omap2_mcspi {
struct omap2_mcspi_regs ctx;
int fifo_depth;
unsigned int pin_dir:1;
+
+ /* SPI transfer threshold over which we prefer DMA to PIO */
+ unsigned dma_min_bytes;
};
struct omap2_mcspi_cs {
@@ -1115,7 +1117,7 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
unsigned count;
if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
- (m->is_dma_mapped || t->len >= DMA_MIN_BYTES))
+ (m->is_dma_mapped || t->len >= mcspi->dma_min_bytes))
omap2_mcspi_set_fifo(spi, t, 1);
omap2_mcspi_set_enable(spi, 1);
@@ -1126,7 +1128,7 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
+ OMAP2_MCSPI_TX0);
if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
- (m->is_dma_mapped || t->len >= DMA_MIN_BYTES))
+ (m->is_dma_mapped || t->len >= mcspi->dma_min_bytes))
count = omap2_mcspi_txrx_dma(spi, t);
else
count = omap2_mcspi_txrx_pio(spi, t);
@@ -1216,7 +1218,7 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,
return -EINVAL;
}
- if (m->is_dma_mapped || len < DMA_MIN_BYTES)
+ if (m->is_dma_mapped || len < mcspi->dma_min_bytes)
continue;
if (mcspi_dma->dma_tx && tx_buf != NULL) {
@@ -1331,10 +1333,12 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
mcspi = spi_master_get_devdata(master);
mcspi->master = master;
+ mcspi->dma_min_bytes = DMA_MIN_BYTES_DEFAULT;
match = of_match_device(omap_mcspi_of_match, &pdev->dev);
if (match) {
u32 num_cs = 1; /* default number of chipselect */
+ u32 dma_min_bytes;
pdata = match->data;
of_property_read_u32(node, "ti,spi-num-cs", &num_cs);
@@ -1342,6 +1346,8 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
master->bus_num = bus_num++;
if (of_get_property(node, "ti,pindir-d0-out-d1-in", NULL))
mcspi->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
+ if (!of_property_read_u32(node, "ti,dma-min-bytes", &dma_min_bytes))
+ mcspi->dma_min_bytes = (unsigned) dma_min_bytes;
} else {
pdata = dev_get_platdata(&pdev->dev);
master->num_chipselect = pdata->num_cs;
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: Patch to parameterize DMA_MIN_BYTES for omap2-mcspi
2015-03-19 5:05 Patch to parameterize DMA_MIN_BYTES for omap2-mcspi Greg Knight
@ 2015-03-19 9:47 ` Mark Brown
2015-03-19 12:34 ` Peter Ujfalusi
1 sibling, 0 replies; 12+ messages in thread
From: Mark Brown @ 2015-03-19 9:47 UTC (permalink / raw)
To: Greg Knight
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-omap-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 196 bytes --]
On Thu, Mar 19, 2015 at 01:05:01AM -0400, Greg Knight wrote:
> What is the process for getting this upstreamed?
Please submit the patch following the process in
Documentation/SubmittingPatches.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Patch to parameterize DMA_MIN_BYTES for omap2-mcspi
2015-03-19 5:05 Patch to parameterize DMA_MIN_BYTES for omap2-mcspi Greg Knight
2015-03-19 9:47 ` Mark Brown
@ 2015-03-19 12:34 ` Peter Ujfalusi
2015-03-19 13:16 ` Greg Knight
1 sibling, 1 reply; 12+ messages in thread
From: Peter Ujfalusi @ 2015-03-19 12:34 UTC (permalink / raw)
To: Greg Knight, Mark Brown
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-omap-u79uwXL29TY76Z2rM5mHXA
On 03/19/2015 07:05 AM, Greg Knight wrote:
> Hi, Mark,
>
> I've attached a patch which adds a device-tree field "ti,dma-min-bytes"
> which replaces the macro DMA_MIN_BYTES. Adjusting this field addresses
> issues we've had where, in our particular use case, the usleep() in the
> SPI worker thread eats a full 20% of our CPU (AM3359).
>
> I opted to implement it as a device-tree parameter and keep the original
> value (160) as the default, in order to avoid impacting anyone else.
>
> The patch is attached. Patches 1-2 are an unrelated McASP change (see my
> other message).
>
> What is the process for getting this upstreamed?
Please follow the guidelines in Documentation/SubmittingPatches. Patches as
attachments are not preferred since it makes replying/commenting on the
patches hard.
Strictly speaking the dma-min-bytes should not be in DT, it is a software
parameter for the Linux SPI driver implementation.
Also, when changing DT bindings, please update the documentation as well (and
CC the relevant lists with that).
This threshold of 160 bytes in the omap2-mcspi driver is artificial anyways it
is changed from 8 to 160 by this commit:
8b66c13474e16 spi/omap2_mcspi: change default DMA_MIN_BYTES value to 160
It has been changed because of wl1271, but I'm not sure if banging bytes over
the bus when the transfer is less then 160bytes is that great thing. I would
guess that the sweet spot is at around the low tens.
But if it is really like this that different devices perform better with
different threshold for choosing between PIO or DMA transfer then this setting
should come from the slave device and should only affect the transfer setup
when communicating with that device.
Probably adding a parameter (optional) to spi_device struct, so drivers can
pass dma_over_poi_threshold?
If it is not set, than just use whatever is the default.
But I don't think this setting should be in the DT.
--
Péter
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Patch to parameterize DMA_MIN_BYTES for omap2-mcspi
2015-03-19 12:34 ` Peter Ujfalusi
@ 2015-03-19 13:16 ` Greg Knight
[not found] ` <CAAQQ3un3k-0nY8xaOXKbmCznOk69ZEhbWLd5ZZV1_=rQLOyspg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 12+ messages in thread
From: Greg Knight @ 2015-03-19 13:16 UTC (permalink / raw)
To: Peter Ujfalusi
Cc: Greg Knight, Mark Brown, linux-spi, linux-omap@vger.kernel.org
Will refer to that documentation and update the SPI docs before resubmitting.
Re; Threshold of 160 is artificial: Believe me, I am more than aware
of this. SPI runs in any speed from low kHz to multi MHz. The only
reason I can fathom for having such a high DMA_MIN_BYTES is to
facilitate high-speed low-volume communication (eg read one byte at a
time from userspace without buffering.) The reason I'm looking at this
at all is because we're doing low-speed low-volume communication, for
which the burn in PIO mode causes severe performance degradation.
Internally we'd changed it to 20, but I might try 8. I originally
tried 0, but observed poor behavior for our use cases. DMA_MIN_BYTES
at 8 would be sensible for our application, but at 160 it is not.
The current solution is for everybody who needs to change their device
settings to churn that macro, just as 8b66c1474e16 did. Changing that
values incurs significant risk of excess CPU load (if increased) or
timing slop (if decreased) to all hardware using the McSPI. Moving the
param to DT allows those of us working on custom boards to modify the
value for some hardware without risking the entire ecosystem. Let's
please not keep a bad solution just because no perfect solution
exists...
I think the proper location for this patch might actually be in the
spidev nodes in DT, rather than at the mcspi level - but I don't
understand why this does not belong in DT. DT is, after all, where one
would normally describe the rest of the slave device bindings. A
sensible value for DMA_MIN_BYTES requires the user to know the CPU
clock speed alongside the SPI bus speed, and estimate acceptable
levels of slop in timing. I don't think userspace should need to do
these computations to avoid excess CPU load; could do it in kernel
space, or leave it up to DT or kernel parameters.
How about moving the speed to the spidev DT nodes?
Regards,
Greg
On Thu, Mar 19, 2015 at 8:34 AM, Peter Ujfalusi <peter.ujfalusi@ti.com> wrote:
>
> On 03/19/2015 07:05 AM, Greg Knight wrote:
> > Hi, Mark,
> >
> > I've attached a patch which adds a device-tree field "ti,dma-min-bytes"
> > which replaces the macro DMA_MIN_BYTES. Adjusting this field addresses
> > issues we've had where, in our particular use case, the usleep() in the
> > SPI worker thread eats a full 20% of our CPU (AM3359).
> >
> > I opted to implement it as a device-tree parameter and keep the original
> > value (160) as the default, in order to avoid impacting anyone else.
> >
> > The patch is attached. Patches 1-2 are an unrelated McASP change (see my
> > other message).
> >
> > What is the process for getting this upstreamed?
>
> Please follow the guidelines in Documentation/SubmittingPatches. Patches as
> attachments are not preferred since it makes replying/commenting on the
> patches hard.
>
> Strictly speaking the dma-min-bytes should not be in DT, it is a software
> parameter for the Linux SPI driver implementation.
> Also, when changing DT bindings, please update the documentation as well (and
> CC the relevant lists with that).
>
> This threshold of 160 bytes in the omap2-mcspi driver is artificial anyways it
> is changed from 8 to 160 by this commit:
> 8b66c13474e16 spi/omap2_mcspi: change default DMA_MIN_BYTES value to 160
>
> It has been changed because of wl1271, but I'm not sure if banging bytes over
> the bus when the transfer is less then 160bytes is that great thing. I would
> guess that the sweet spot is at around the low tens.
>
> But if it is really like this that different devices perform better with
> different threshold for choosing between PIO or DMA transfer then this setting
> should come from the slave device and should only affect the transfer setup
> when communicating with that device.
>
> Probably adding a parameter (optional) to spi_device struct, so drivers can
> pass dma_over_poi_threshold?
> If it is not set, than just use whatever is the default.
>
> But I don't think this setting should be in the DT.
>
> --
> Péter
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2016-05-31 5:03 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-19 5:05 Patch to parameterize DMA_MIN_BYTES for omap2-mcspi Greg Knight
2015-03-19 9:47 ` Mark Brown
2015-03-19 12:34 ` Peter Ujfalusi
2015-03-19 13:16 ` Greg Knight
[not found] ` <CAAQQ3un3k-0nY8xaOXKbmCznOk69ZEhbWLd5ZZV1_=rQLOyspg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-19 14:03 ` Mark Brown
2015-03-19 16:23 ` Peter Ujfalusi
[not found] ` <550AF7F6.7080200-l0cyMroinI0@public.gmane.org>
2015-03-19 17:28 ` Greg Knight
2015-03-19 18:51 ` Mark Brown
2015-03-20 13:10 ` Peter Ujfalusi
[not found] ` <550C1C2C.5080204-l0cyMroinI0@public.gmane.org>
2015-03-22 16:31 ` Mark Brown
2015-03-20 12:58 ` Peter Ujfalusi
2016-05-31 5:03 ` Anton Habegger
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).