linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: buffer-dmaengine: adjust `bytes_used` with residue info
@ 2020-08-26  5:20 Lars-Peter Clausen
  2020-08-26  6:36 ` Alexandru Ardelean
  0 siblings, 1 reply; 5+ messages in thread
From: Lars-Peter Clausen @ 2020-08-26  5:20 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Peter Meerwald-Stadler, Alexandru Ardelean,
	linux-iio, Lars-Peter Clausen

From: Alexandru Ardelean <alexandru.ardelean@analog.com>

A transfer may fall shorter than the bytes in the block.
This information is available in the residue from the DMA engine, so we can
compute actual `bytes_used` with that by subtracting the residue.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/buffer/industrialio-buffer-dmaengine.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
index 6dedf12b69a4..5789bda0745b 100644
--- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
+++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
@@ -45,7 +45,8 @@ static struct dmaengine_buffer *iio_buffer_to_dmaengine_buffer(
 	return container_of(buffer, struct dmaengine_buffer, queue.buffer);
 }
 
-static void iio_dmaengine_buffer_block_done(void *data)
+static void iio_dmaengine_buffer_block_done(void *data,
+		const struct dmaengine_result *result)
 {
 	struct iio_dma_buffer_block *block = data;
 	unsigned long flags;
@@ -53,6 +54,7 @@ static void iio_dmaengine_buffer_block_done(void *data)
 	spin_lock_irqsave(&block->queue->list_lock, flags);
 	list_del(&block->head);
 	spin_unlock_irqrestore(&block->queue->list_lock, flags);
+	block->bytes_used -= result->residue;
 	iio_dma_buffer_block_done(block);
 }
 
@@ -74,7 +76,7 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
 	if (!desc)
 		return -ENOMEM;
 
-	desc->callback = iio_dmaengine_buffer_block_done;
+	desc->callback_result = iio_dmaengine_buffer_block_done;
 	desc->callback_param = block;
 
 	cookie = dmaengine_submit(desc);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: buffer-dmaengine: adjust `bytes_used` with residue info
  2020-08-26  5:20 [PATCH] iio: buffer-dmaengine: adjust `bytes_used` with residue info Lars-Peter Clausen
@ 2020-08-26  6:36 ` Alexandru Ardelean
  2020-08-29 15:51   ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandru Ardelean @ 2020-08-26  6:36 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Hartmut Knaack, Peter Meerwald-Stadler,
	Alexandru Ardelean, linux-iio

On Wed, Aug 26, 2020 at 8:22 AM Lars-Peter Clausen <lars@metafoo.de> wrote:
>
> From: Alexandru Ardelean <alexandru.ardelean@analog.com>
>
> A transfer may fall shorter than the bytes in the block.
> This information is available in the residue from the DMA engine, so we can
> compute actual `bytes_used` with that by subtracting the residue.
>

This was in my pipeline as well [obviously].
Thanks :)

> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>  drivers/iio/buffer/industrialio-buffer-dmaengine.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> index 6dedf12b69a4..5789bda0745b 100644
> --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> @@ -45,7 +45,8 @@ static struct dmaengine_buffer *iio_buffer_to_dmaengine_buffer(
>         return container_of(buffer, struct dmaengine_buffer, queue.buffer);
>  }
>
> -static void iio_dmaengine_buffer_block_done(void *data)
> +static void iio_dmaengine_buffer_block_done(void *data,
> +               const struct dmaengine_result *result)
>  {
>         struct iio_dma_buffer_block *block = data;
>         unsigned long flags;
> @@ -53,6 +54,7 @@ static void iio_dmaengine_buffer_block_done(void *data)
>         spin_lock_irqsave(&block->queue->list_lock, flags);
>         list_del(&block->head);
>         spin_unlock_irqrestore(&block->queue->list_lock, flags);
> +       block->bytes_used -= result->residue;
>         iio_dma_buffer_block_done(block);
>  }
>
> @@ -74,7 +76,7 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
>         if (!desc)
>                 return -ENOMEM;
>
> -       desc->callback = iio_dmaengine_buffer_block_done;
> +       desc->callback_result = iio_dmaengine_buffer_block_done;
>         desc->callback_param = block;
>
>         cookie = dmaengine_submit(desc);
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: buffer-dmaengine: adjust `bytes_used` with residue info
  2020-08-26  6:36 ` Alexandru Ardelean
@ 2020-08-29 15:51   ` Jonathan Cameron
  2020-08-29 18:30     ` Lars-Peter Clausen
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2020-08-29 15:51 UTC (permalink / raw)
  To: Alexandru Ardelean
  Cc: Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald-Stadler,
	Alexandru Ardelean, linux-iio

On Wed, 26 Aug 2020 09:36:39 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> On Wed, Aug 26, 2020 at 8:22 AM Lars-Peter Clausen <lars@metafoo.de> wrote:
> >
> > From: Alexandru Ardelean <alexandru.ardelean@analog.com>
> >
> > A transfer may fall shorter than the bytes in the block.
> > This information is available in the residue from the DMA engine, so we can
> > compute actual `bytes_used` with that by subtracting the residue.
> >  
> 
> This was in my pipeline as well [obviously].
> Thanks :)
> 
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

"smells" like a fix.  Is it?  Or are we looking at something that
only matters for some future hardware, or an optmization?

If it's a fix, where is the fixes tag?

Thanks, 

Jonathan

> > ---
> >  drivers/iio/buffer/industrialio-buffer-dmaengine.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> > index 6dedf12b69a4..5789bda0745b 100644
> > --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> > +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> > @@ -45,7 +45,8 @@ static struct dmaengine_buffer *iio_buffer_to_dmaengine_buffer(
> >         return container_of(buffer, struct dmaengine_buffer, queue.buffer);
> >  }
> >
> > -static void iio_dmaengine_buffer_block_done(void *data)
> > +static void iio_dmaengine_buffer_block_done(void *data,
> > +               const struct dmaengine_result *result)
> >  {
> >         struct iio_dma_buffer_block *block = data;
> >         unsigned long flags;
> > @@ -53,6 +54,7 @@ static void iio_dmaengine_buffer_block_done(void *data)
> >         spin_lock_irqsave(&block->queue->list_lock, flags);
> >         list_del(&block->head);
> >         spin_unlock_irqrestore(&block->queue->list_lock, flags);
> > +       block->bytes_used -= result->residue;
> >         iio_dma_buffer_block_done(block);
> >  }
> >
> > @@ -74,7 +76,7 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
> >         if (!desc)
> >                 return -ENOMEM;
> >
> > -       desc->callback = iio_dmaengine_buffer_block_done;
> > +       desc->callback_result = iio_dmaengine_buffer_block_done;
> >         desc->callback_param = block;
> >
> >         cookie = dmaengine_submit(desc);
> > --
> > 2.20.1
> >  


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: buffer-dmaengine: adjust `bytes_used` with residue info
  2020-08-29 15:51   ` Jonathan Cameron
@ 2020-08-29 18:30     ` Lars-Peter Clausen
  2020-08-30 11:10       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Lars-Peter Clausen @ 2020-08-29 18:30 UTC (permalink / raw)
  To: Jonathan Cameron, Alexandru Ardelean
  Cc: Hartmut Knaack, Peter Meerwald-Stadler, Alexandru Ardelean, linux-iio

On 8/29/20 5:51 PM, Jonathan Cameron wrote:
> On Wed, 26 Aug 2020 09:36:39 +0300
> Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
>
>> On Wed, Aug 26, 2020 at 8:22 AM Lars-Peter Clausen <lars@metafoo.de> wrote:
>>> From: Alexandru Ardelean <alexandru.ardelean@analog.com>
>>>
>>> A transfer may fall shorter than the bytes in the block.
>>> This information is available in the residue from the DMA engine, so we can
>>> compute actual `bytes_used` with that by subtracting the residue.
>>>   
>> This was in my pipeline as well [obviously].
>> Thanks :)
>>
>>> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
>>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> "smells" like a fix.  Is it?  Or are we looking at something that
> only matters for some future hardware, or an optmization?
>
> If it's a fix, where is the fixes tag?

It's a feature :)

When we first added the IIO DMA buffer support this API did not exist in 
dmaengine. So for the longest time most DMA drivers did not have the 
ability to report short transfers. Primarily because in many cases the 
hardware doesn't even support it.

Now with this patch the IIO DMA buffer implementation supports systems 
where the DMA can generate short transfers.

- Lars


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: buffer-dmaengine: adjust `bytes_used` with residue info
  2020-08-29 18:30     ` Lars-Peter Clausen
@ 2020-08-30 11:10       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2020-08-30 11:10 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Alexandru Ardelean, Hartmut Knaack, Peter Meerwald-Stadler,
	Alexandru Ardelean, linux-iio

On Sat, 29 Aug 2020 20:30:04 +0200
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 8/29/20 5:51 PM, Jonathan Cameron wrote:
> > On Wed, 26 Aug 2020 09:36:39 +0300
> > Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
> >  
> >> On Wed, Aug 26, 2020 at 8:22 AM Lars-Peter Clausen <lars@metafoo.de> wrote:  
> >>> From: Alexandru Ardelean <alexandru.ardelean@analog.com>
> >>>
> >>> A transfer may fall shorter than the bytes in the block.
> >>> This information is available in the residue from the DMA engine, so we can
> >>> compute actual `bytes_used` with that by subtracting the residue.
> >>>     
> >> This was in my pipeline as well [obviously].
> >> Thanks :)
> >>  
> >>> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> >>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>  
> > "smells" like a fix.  Is it?  Or are we looking at something that
> > only matters for some future hardware, or an optmization?
> >
> > If it's a fix, where is the fixes tag?  
> 
> It's a feature :)
> 
> When we first added the IIO DMA buffer support this API did not exist in 
> dmaengine. So for the longest time most DMA drivers did not have the 
> ability to report short transfers. Primarily because in many cases the 
> hardware doesn't even support it.
> 
> Now with this patch the IIO DMA buffer implementation supports systems 
> where the DMA can generate short transfers.
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> 
> - Lars
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-30 11:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26  5:20 [PATCH] iio: buffer-dmaengine: adjust `bytes_used` with residue info Lars-Peter Clausen
2020-08-26  6:36 ` Alexandru Ardelean
2020-08-29 15:51   ` Jonathan Cameron
2020-08-29 18:30     ` Lars-Peter Clausen
2020-08-30 11:10       ` Jonathan Cameron

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).