I want to use dma using the dma_async_memcpy_buf_to_buf function, which is located in the dmaengine.c file (linux / drivers / dma). To do this, I add a function to the dmatest.c file (linux / drivers / dma) as follows:
void foo () { int index = 0; dma_cookie_t cookie; size_t len = 0x20000; ktime_t start, end, end1, end2, end3; s64 actual_time; u16* dest; u16* src; dest = kmalloc(len, GFP_KERNEL); src = kmalloc(len, GFP_KERNEL); for (index = 0; index < len/2; index++) { dest[index] = 0xAA55; src[index] = 0xDEAD; } start = ktime_get(); cookie = dma_async_memcpy_buf_to_buf(chan, dest, src, len); while (dma_async_is_tx_complete(chan, cookie, NULL, NULL) == DMA_IN_PROGRESS) { dma_sync_wait(chan, cookie); } end = ktime_get(); actual_time = ktime_to_ns(ktime_sub(end, start)); printk("Time taken for function() execution dma: %lld\n",(long long)actual_time); memset(dest, 0 , len); start = ktime_get(); memcpy(dest, src, len); end = ktime_get(); actual_time = ktime_to_ns(ktime_sub(end, start)); printk("Time taken for function() execution non-dma: %lld\n",(long long)actual_time); }
There are some problems in DMA:
Interestingly, the memcpy function execution time is shorter than the dma_async_memcpy_buf_to_buf function. Perhaps this is due to a problem with the ktime_get () function.
Is my method with the foo function right or wrong for performing a DMA operation? I am not sure about that.
How can I measure the number of memcpy and dma_async_memcpy_buf_to_buf function labels in terms of CPU usage?
Finally, is application-level DMA possible? So far I have used at the kernel level, as you can see above (dmatest.c - inserted kernel module)
source share