Skip to contentSkip to conversation

copy_to_user speed from dma_alloc_coherent vs. kmalloc buffer

DISCUSSION Orjan Friberg 2 participants 2 messages Apr 20, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

I have a driver where I do memory to memory DMA between GPMC and SDRAM.
Adding a read function, I found that copy_to_user from a
dma_alloc_coherent buffer is significantly slower than from a kmalloc'd one.

Looking at arch/arm/include/asm/pgtable.h I suspect this difference in speed is due to the fact that the dma_alloc_coherent buffer is unbuffered.

What are my options (besides using mmap)?

* Reserve a portion of memory at boot time to be used as the DMA destination buffer, use ioremap_cached + manual cache flush as needed?
* Turn on buffering for the DMA destination buffer for the duration of the copy_to_user call, then turn it off again (and flush it from the cache)?
* Something else entirely?

This is on a 3730, on Linux 2.6.32.

Thanks,
Orjan

Signature · 2 lines
Orjan Friberg
FlatFrog Laboratories AB
#1 lore raw
Quoted 1 line · Orjan Friberg

What are my options (besides using mmap)?

It looks like kmalloc + dma_map_single for the DMA destination buffer and then dma_sync_single_for_{cpu,device} around the call to copy_to_user pretty much does the trick. At least the %sys load measured with mpstat goes from 13% to 2%.

Signature · 2 lines
Orjan Friberg
FlatFrog Laboratories AB