1

I am trying to use DMA engine in linux kernel.

My machine is x86 64-bit platform and I just want to offload simple memcpy operation to DMA engine. I was wondering if the following sequence is appropriate to active DMA engine and make it to do memcpy operation.

dmaengine_get();
dma_cap_zero(mask);
dma_cap_set(DMA_MEMCPY,mask);
chan = dma_request_channel(mask,NULL,NULL);
if(chan)
    printk(KERN_ALERT "dma channel %s\n", dma_chan_name(ptr_DP->chan));

cookie_temp = dma_async_memcpy_pg_to_pg(chan, dest_pg, 0, src_pg, 0, 0x1000);
if(cookie_temp)
    printk(KERN_ALERT "copy pass?\n")

.....
.....

curr_stat = dma_async_is_tx_complete(chan, cookie_temp, NULL, NULL);
printk(KERN_ALERT "check DMA stat (%d)\n", curr_stat);

/*
tx=async_memcpy(pages, pages, 0, 0, 4096, NULL);
printk(KERN_ALERT "DMA descriptor = %p\n",tx);
if(tx)
    printk(KERN_ALERT "Working!\n");
else 
    printk(KERN_ALERT "No luck...\n");
*/
  1. Get dmaengine with dmaengine_get
  2. Request channel with dma_request_channel(mask, fn, fn_param)
  3. Use dma_async_memcpy_pg_to_pg to do page-to-page memcpy operation
  4. Use dma_async_is_tx_complete to check if copy operation is completed

Edited 7/7 7:21PM I checked DMA channel can be found by dma_find_channel(). But still my kernel does not work very well with dma_async_memcpy_pg_to_pg ... When I check current status of DMA channel by dma_async_is_tx_complete, most of time it is still in progress status. This is kind of weird because I am just copying one page ...

cienlux
  • 13
  • 4
  • Yes, I have read that thread but it does not include information about how to activate DMA ... – cienlux Jul 06 '13 at 14:52
  • Sorry, it's been 10 years since I dealt with dma on linux, but: It looks to me like async_memcpy allocates it's own DMA channel. You may be causing async_memcpy from working by allocating the only dma channel. In any case I don't think there's anything you have to do to "activate" the DMA engine architecture, but you may not have the underlying hardware. – Speed8ump Jul 06 '13 at 23:10
  • So you *do* have I/OAT on your machine? – CL. Jul 07 '13 at 16:08
  • One issue is that DMA uses **physical** memory and avoids the CPU cache. This maybe beneficial depending on the application; It does not seem wise to replace a traditional `memcpy()` by a DMA variant. It is more of a specialized operation where larger amounts are copied. Linux has *copy on write*; I am not sure what the underlying motivation is. – artless noise Jul 07 '13 at 19:20
  • I do have I/OAT and DMA engine on my machine. (Checked from lspci) What I am trying to do is copying a large amount of pages (8 ~ 32 pages) with DMA without polluting data caches. Instead of using `async_memcpy`, I am trying to use `async_memcpy_pg_to_pg` which is able to do page copying. – cienlux Jul 08 '13 at 00:10

0 Answers0