Skip to contentSkip to conversation

DMA Offload fixes

PATCH In review Jon Mason 3 participants 15 messages Jun 19, 2013 – Jun 27, 2013 dmaengine

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

cover DMA Offload fixes

These 2 patches address issues encountered while attempting to use the DMA subsystem in the NTB driver. While outside of the scope of that patch (which will be forthcoming), these fixes are necessary to get it working.

Thanks,
Jon

author
#1 lore raw

PATCH 1/2 dmadevices: dma_sync_wait undefined

dma_sync_wait is declared regardless of whether CONFIG_DMA_ENGINE is enabled, but calling the function without CONFIG_DMA_ENGINE enabled results in the following gcc error.
ERROR: "dma_sync_wait" [drivers/ntb/ntb.ko] undefined!

To get around this, declare dma_sync_wait as an inline function if CONFIG_DMA_ENGINE is undefined.

---
 include/linux/dmaengine.h |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/dmaengine.h +5 -1
index 96d3e4a..e3652ac 100644
@@ -963,8 +963,8 @@ dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used,
 	}
 }
 
-enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
 #ifdef CONFIG_DMA_ENGINE
+enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
 enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
 void dma_issue_pending_all(void);
 struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
@@ -972,6 +972,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
 void dma_release_channel(struct dma_chan *chan);
 #else
+static inline enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
+{
+	return DMA_SUCCESS;
+}
 static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
 {
 	return DMA_SUCCESS;
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH 1/2] dmadevices: dma_sync_wait undefined

Quoted 29 lines · Jon Mason

dma_sync_wait is declared regardless of whether CONFIG_DMA_ENGINE is enabled, but calling the function without CONFIG_DMA_ENGINE enabled results in the following gcc error.
ERROR: "dma_sync_wait" [drivers/ntb/ntb.ko] undefined!

To get around this, declare dma_sync_wait as an inline function if CONFIG_DMA_ENGINE is undefined.

---
 include/linux/dmaengine.h |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/dmaengine.h +1 -1
index 96d3e4a..e3652ac 100644
@@ -963,8 +963,8 @@ dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used,
        }
 }
 
-enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
 #ifdef CONFIG_DMA_ENGINE
+enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
 enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
 void dma_issue_pending_all(void);
 struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,

include/linux/dmaengine.h struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, · line 978

Quoted 7 lines
include/linux/dmaengine.h +4 -0
@@ -972,6 +972,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
 void dma_release_channel(struct dma_chan *chan);
 #else
+static inline enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
+{
+       return DMA_SUCCESS;
+}

Seems like something we should fix, but why is this not an indication that the code calling this is missing a "depends on DMA_ENGINE".

On second look dma_sync_wait is a use as last resort hack that probably should not escape its internal use in dmaengine.c. The other escape in drivers/media/platform/timblogiw.c already looks problematic by having a live cpu spin immediately following a sleeping wait, obviously something event based was wanted. What's the use case in NTB?

--
Dan

author
#3 lore raw

Re: [PATCH 1/2] dmadevices: dma_sync_wait undefined

Quoted 32 lines · Dan Williams
Quoted 31 lines · Jon Mason

dma_sync_wait is declared regardless of whether CONFIG_DMA_ENGINE is enabled, but calling the function without CONFIG_DMA_ENGINE enabled results in the following gcc error.
ERROR: "dma_sync_wait" [drivers/ntb/ntb.ko] undefined!

To get around this, declare dma_sync_wait as an inline function if CONFIG_DMA_ENGINE is undefined.

---
 include/linux/dmaengine.h |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/dmaengine.h +1 -1
index 96d3e4a..e3652ac 100644
@@ -963,8 +963,8 @@ dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used,
        }
 }
 
-enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
 #ifdef CONFIG_DMA_ENGINE
+enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
 enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
 void dma_issue_pending_all(void);
 struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
@@ -972,6 +972,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
 void dma_release_channel(struct dma_chan *chan);
Quoted 8 lines

include/linux/dmaengine.h struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, · line 978

Quoted 5 lines
include/linux/dmaengine.h +4 -0
 #else
+static inline enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
+{
+       return DMA_SUCCESS;
+}

Seems like something we should fix, but why is this not an indication that the code calling this is missing a "depends on DMA_ENGINE".

The driver could use CPU or DMA to move data. If there are no free DMA channels or none present, use CPU. In this way, there is no real dependency on DMA_ENGINE being enabled.

Quoted 6 lines

On second look dma_sync_wait is a use as last resort hack that probably should not escape its internal use in dmaengine.c. The other escape in drivers/media/platform/timblogiw.c already looks problematic by having a live cpu spin immediately following a sleeping wait, obviously something event based was wanted. What's the use case in NTB?

NTB is currently using it to flush any pending DMAs. This is needed to allow the DMA engine and the CPU to perform operations on the same "Memory Window". Without this, it is possible for the operations to complete out of order, which is not a desired outcome for any network traffic over NTB. CPU is preferred over DMA engine for small transfers. Also, it provides an alternative for errors in the DMA engine copy process (e.g., DMA mapping, device_prep_dma_memcpy, and dmaengine_submit).

Thanks,
Jon

Quoted 3 lines

--
Dan

#4 lore raw

Re: [PATCH 1/2] dmadevices: dma_sync_wait undefined

Quoted 1 line · Jon Mason

On Tue, Jun 18, 2013 at 06:13:28PM -0700, Dan Williams wrote:

[..]

Quoted 8 lines

NTB is currently using it to flush any pending DMAs. This is needed to allow the DMA engine and the CPU to perform operations on the same "Memory Window". Without this, it is possible for the operations to complete out of order, which is not a desired outcome for any network traffic over NTB. CPU is preferred over DMA engine for small transfers. Also, it provides an alternative for errors in the DMA engine copy process (e.g., DMA mapping, device_prep_dma_memcpy, and dmaengine_submit).

Ok there really isn't a better alternative, is NTB always polling or does it also use completion callbacks?

author
#5 lore raw

Re: [PATCH 1/2] dmadevices: dma_sync_wait undefined

Quoted 12 lines · Dan Williams
Quoted 1 line · Jon Mason

On Tue, Jun 18, 2013 at 06:13:28PM -0700, Dan Williams wrote:

[..]

Quoted 8 lines

NTB is currently using it to flush any pending DMAs. This is needed to allow the DMA engine and the CPU to perform operations on the same "Memory Window". Without this, it is possible for the operations to complete out of order, which is not a desired outcome for any network traffic over NTB. CPU is preferred over DMA engine for small transfers. Also, it provides an alternative for errors in the DMA engine copy process (e.g., DMA mapping, device_prep_dma_memcpy, and dmaengine_submit).

Quoted 2 lines

Ok there really isn't a better alternative, is NTB always polling or does it also use completion callbacks?

It uses the callbacks. I've change the code to use dma_find_channel, and will push it for review as a RFC shortly.

Thanks,
Jon

author
#6 lore raw

PATCH 2/2 ioatdma: add DMA_PRIVATE capabilities flag

In reply to Jon Mason

Set the DMA_PRIVATE dma_transaction_type in the capability mask. This enables the ability to get an exclusive ioatdma DMA channel for any devices that requests one via the dma_request_channel function call.

---
 drivers/dma/ioat/dma_v3.c |    1 +
 1 file changed, 1 insertion(+)
drivers/dma/ioat/dma_v3.c +1 -0
index ca6ea9b..ac2aeef 100644
@@ -1883,6 +1883,7 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
 		dma->copy_align = 6;
 
 	dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
+	dma_cap_set(DMA_PRIVATE, dma->cap_mask);
 	dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
 
 	device->cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET);
Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

Quoted 15 lines · Jon Mason

Set the DMA_PRIVATE dma_transaction_type in the capability mask. This enables the ability to get an exclusive ioatdma DMA channel for any devices that requests one via the dma_request_channel function call.

---
 drivers/dma/ioat/dma_v3.c |    1 +
 1 file changed, 1 insertion(+)
drivers/dma/ioat/dma_v3.c +0 -0
index ca6ea9b..ac2aeef 100644

drivers/dma/ioat/dma_v3.c int ioat3_dma_probe(struct ioatdma_device *device, int dca) · line 1887

Quoted 5 lines
drivers/dma/ioat/dma_v3.c +1 -0
@@ -1883,6 +1883,7 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
                dma->copy_align = 6;
 
        dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
+       dma_cap_set(DMA_PRIVATE, dma->cap_mask);
        dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;

DMA_PRIVATE here keeps all channels private, so they couldn't be used elsewhere, for example raid offload. Do you need a private allocation or can you get away with a dynamically assigned channel?

#8 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

Quoted 18 lines · Dan Williams
Quoted 17 lines · Jon Mason

Set the DMA_PRIVATE dma_transaction_type in the capability mask. This enables the ability to get an exclusive ioatdma DMA channel for any devices that requests one via the dma_request_channel function call.

---
  drivers/dma/ioat/dma_v3.c |    1 +
  1 file changed, 1 insertion(+)
drivers/dma/ioat/dma_v3.c +0 -0
index ca6ea9b..ac2aeef 100644
@@ -1883,6 +1883,7 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
                 dma->copy_align = 6;
 
Quoted 6 lines

drivers/dma/ioat/dma_v3.c int ioat3_dma_probe(struct ioatdma_device *device, int dca) · line 1887

Quoted 3 lines
drivers/dma/ioat/dma_v3.c +1 -0
         dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
+       dma_cap_set(DMA_PRIVATE, dma->cap_mask);
         dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;

DMA_PRIVATE here keeps all channels private, so they couldn't be used elsewhere, for example raid offload. Do you need a private allocation or can you get away with a dynamically assigned channel?

So is there no way to reserve a channel as private if no one is using it? It seems the current setup is async_tx or nothing.

Signature · 4 lines
Dave Jiang
Application Engineer, Storage Divsion
Intel Corp.
[email protected]
author
#9 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

In reply to Dan Williams
Quoted 18 lines · Dan Williams
Quoted 17 lines · Jon Mason

Set the DMA_PRIVATE dma_transaction_type in the capability mask. This enables the ability to get an exclusive ioatdma DMA channel for any devices that requests one via the dma_request_channel function call.

---
 drivers/dma/ioat/dma_v3.c |    1 +
 1 file changed, 1 insertion(+)
drivers/dma/ioat/dma_v3.c +0 -0
index ca6ea9b..ac2aeef 100644
@@ -1883,6 +1883,7 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
                dma->copy_align = 6;
 
Quoted 7 lines

drivers/dma/ioat/dma_v3.c int ioat3_dma_probe(struct ioatdma_device *device, int dca) · line 1887

Quoted 3 lines
drivers/dma/ioat/dma_v3.c +1 -0
        dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
+       dma_cap_set(DMA_PRIVATE, dma->cap_mask);
        dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;

DMA_PRIVATE here keeps all channels private, so they couldn't be used elsewhere, for example raid offload. Do you need a private allocation or can you get away with a dynamically assigned channel?

I would like to have a dedicated DMA engine. async_tx could cause the copies to complete out of order. Do I need to add infrastructure to allow for private channel usage, and when unused allow the channel to be used by async_tx?

Thanks,
Jon

#10 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

Quoted 8 lines · Jon Mason
Quoted 3 lines

DMA_PRIVATE here keeps all channels private, so they couldn't be used elsewhere, for example raid offload. Do you need a private allocation or can you get away with a dynamically assigned channel?

I would like to have a dedicated DMA engine. async_tx could cause the copies to complete out of order. Do I need to add infrastructure to allow for private channel usage, and when unused allow the channel to be used by async_tx?

Can NTB just call dma_find_channel() once and be done? Also, async_tx will only get things out of order if you allow it to pick a new channel for every operation, but as long as you specify a dependency chain it will keep things in order (same as remembering the result of dma_find_channel).

--
Dan

author
#11 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

Quoted 10 lines · Dan Williams
Quoted 8 lines · Jon Mason
Quoted 3 lines

DMA_PRIVATE here keeps all channels private, so they couldn't be used elsewhere, for example raid offload. Do you need a private allocation or can you get away with a dynamically assigned channel?

I would like to have a dedicated DMA engine. async_tx could cause the copies to complete out of order. Do I need to add infrastructure to allow for private channel usage, and when unused allow the channel to be used by async_tx?

Quoted 5 lines

Can NTB just call dma_find_channel() once and be done? Also, async_tx will only get things out of order if you allow it to pick a new channel for every operation, but as long as you specify a dependency chain it will keep things in order (same as remembering the result of dma_find_channel).

Neither of these allow a device exclusive access to a channel. Is this not something that is desired by other users of DMA Engines, or do I have a unique usage model?

Thanks,
Jon

Quoted 3 lines

--
Dan

#12 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

Quoted 17 lines · Jon Mason
Quoted 10 lines · Dan Williams
Quoted 8 lines · Jon Mason
Quoted 3 lines

DMA_PRIVATE here keeps all channels private, so they couldn't be used elsewhere, for example raid offload. Do you need a private allocation or can you get away with a dynamically assigned channel?

I would like to have a dedicated DMA engine. async_tx could cause the copies to complete out of order. Do I need to add infrastructure to allow for private channel usage, and when unused allow the channel to be used by async_tx?

Quoted 5 lines

Can NTB just call dma_find_channel() once and be done? Also, async_tx will only get things out of order if you allow it to pick a new channel for every operation, but as long as you specify a dependency chain it will keep things in order (same as remembering the result of dma_find_channel).

Quoted 4 lines

Neither of these allow a device exclusive access to a channel. Is this not something that is desired by other users of DMA Engines, or do I have a unique usage model?

Yes, ioatdma has never been used in a mixed model. Other platforms are either using devicetree bindings for specifying channels to their master devices or are exclusively slave channels. Other slave usage models require use of a dedicated channel, since NTB is alternating between cpu and dma it seems it could get away with using a "public" channel.

author
#13 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

Quoted 23 lines · Dan Williams
Quoted 17 lines · Jon Mason
Quoted 10 lines · Dan Williams
Quoted 8 lines · Jon Mason
Quoted 3 lines

DMA_PRIVATE here keeps all channels private, so they couldn't be used elsewhere, for example raid offload. Do you need a private allocation or can you get away with a dynamically assigned channel?

I would like to have a dedicated DMA engine. async_tx could cause the copies to complete out of order. Do I need to add infrastructure to allow for private channel usage, and when unused allow the channel to be used by async_tx?

Quoted 5 lines

Can NTB just call dma_find_channel() once and be done? Also, async_tx will only get things out of order if you allow it to pick a new channel for every operation, but as long as you specify a dependency chain it will keep things in order (same as remembering the result of dma_find_channel).

Quoted 4 lines

Neither of these allow a device exclusive access to a channel. Is this not something that is desired by other users of DMA Engines, or do I have a unique usage model?

Quoted 6 lines

Yes, ioatdma has never been used in a mixed model. Other platforms are either using devicetree bindings for specifying channels to their master devices or are exclusively slave channels. Other slave usage models require use of a dedicated channel, since NTB is alternating between cpu and dma it seems it could get away with using a "public" channel.

Unfortunately, the dma_find_channel model does not led itself to optimal usage of the available channels, as it seems to give out the same channel. Adding some randomizer (or other way to spread the channel selection over multiple channels) would be greatly beneficial.

Alternatively, adding an async_memcpy_mmio function (and perhaps some minimal size to use the DMA engine) would provide a solution that would work.

However, dma_find_channel should be sufficient to get NTB use of DMA engines out for review. I'll clean it up and send it out shortly. Thanks for the insight.

Thanks,
Jon

#14 lore raw

Re: [PATCH 2/2] ioatdma: add DMA_PRIVATE capabilities flag

Quoted 5 lines · Jon Mason

Unfortunately, the dma_find_channel model does not led itself to optimal usage of the available channels, as it seems to give out the same channel. Adding some randomizer (or other way to spread the channel selection over multiple channels) would be greatly beneficial.

Right now the allocation scheme is per-cpu. If you have multiple submission contexts on different cpus it should use all available channels.

Quoted 3 lines

Alternatively, adding an async_memcpy_mmio function (and perhaps some minimal size to use the DMA engine) would provide a solution that would work.

It¹s hard. The size is arch and use specific so it may be best to leave it up to the client.

Quoted 3 lines

However, dma_find_channel should be sufficient to get NTB use of DMA engines out for review. I'll clean it up and send it out shortly. Thanks for the insight.

Cool, I¹ll take a look.