Skip to contentSkip to conversation

iio: buffer-dmaengine: adjust `bytes_used` with residue info

PATCH In review Lars-Peter Clausen 3 participants 5 messages Aug 26, 2020 – Aug 30, 2020 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: buffer-dmaengine: adjust `bytes_used` with residue info

From: Alexandru Ardelean <[email protected]>

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.

---
 drivers/iio/buffer/industrialio-buffer-dmaengine.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/buffer/industrialio-buffer-dmaengine.c +4 -2
index 6dedf12b69a4..5789bda0745b 100644
@@ -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);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 7 lines · Lars-Peter Clausen

From: Alexandru Ardelean <[email protected]>

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

Quoted 40 lines
---
 drivers/iio/buffer/industrialio-buffer-dmaengine.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/buffer/industrialio-buffer-dmaengine.c +4 -3
index 6dedf12b69a4..5789bda0745b 100644
@@ -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

maintainer
#2 lore raw
Quoted 4 lines · On Wed, 26 Aug 2020 09:36:39 +0300 Alexandru Ardelean <[email protected]>…
Quoted 3 lines · Lars-Peter Clausen

From: Alexandru Ardelean <[email protected]>

Quoted 10 lines
Quoted 4 lines

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

Quoted 2 lines

"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

Quoted 38 lines
Quoted 38 lines
---
 drivers/iio/buffer/industrialio-buffer-dmaengine.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/buffer/industrialio-buffer-dmaengine.c +4 -3
index 6dedf12b69a4..5789bda0745b 100644
@@ -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

#3 lore raw
Quoted 13 lines · Jonathan Cameron
Quoted 10 lines · On Wed, 26 Aug 2020 09:36:39 +0300 Alexandru Ardelean <[email protected]>…
Quoted 6 lines · Lars-Peter Clausen

From: Alexandru Ardelean <[email protected]>

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

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

"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

maintainer
#4 lore raw
Quoted 23 lines · On Sat, 29 Aug 2020 20:30:04 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 13 lines · Jonathan Cameron
Quoted 10 lines · On Wed, 26 Aug 2020 09:36:39 +0300 Alexandru Ardelean <[email protected]>…
Quoted 6 lines · Lars-Peter Clausen

From: Alexandru Ardelean <[email protected]>

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

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

"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 :)

Quoted 7 lines

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

Quoted 3 lines

- Lars