tags:

views:

386

answers:

3

Is there any asynchronous memcpy function in linux? I want it to work with DMA and notify me when it gets completed.

+5  A: 

As far as I know, CPU doesn't/can't do DMA to itself. So you need an external hardware on the bus to do the trick for you.

However most hardware cannot address all physical memory, so an exact memcpy clone isn't possible unless you have very strict definitions of memory address ranges in your use case. Otherwise kernel would have to memcpy the block to your own memory block itself which would kill the purpose of cloning memcpy in the first place :)

But still if you want to create a "clone" of a memory block without using memcpy (still a bad idea by the way because DMA memory access is usually slower than the CPU's) you can send the memory block to video card and pull it back to another buffer. You might even be able to put the block in video memory (putbitmap()? :)) and do a hardware accelerated bitblt() to create a copy on the fly.

Do you mind sharing your actual goal so maybe people can come up with smarter/better tricks?

ssg
@ssg, My actual goal is to create optimized video player, In it I copy my YUV data to its queue. Now that copy takes 2 secs, If this copy happens through DMA than In this time In another thread I can do audio decoding.
Sunny
@Sunny Shah, You should be looking at a zero copy solution perhaps using shared memory? Why are you copying such big chunks of memory around?
Dipstick
FFMPEG outputs YUVFrame as decode function output. when you want next YUVFrame, it just edits existing YUVFrame to create new. So what I do is, I copy YUVFrame to queue of buffers and will show frame from queue when its time comes. This copy takes around 7% of processing time.
Sunny
+3  A: 

On a multicore processor or even just a processor with hyper-threading, you can sort of have what you want by executing the usual (synchronous) memcpy in a separate thread. I'm not saying it's a good idea, just pointing out the obvious.

Pascal Cuoq
+1  A: 

You can do some plays with mremap. Or you can hack FFmpeg to use different buffers for different frames.

osgx