mmap 物理连续内存
我在这里可能有一些误解,所以请耐心等待。
我编写了一个从相机捕获图像的程序。我正在使用 mmap
在相机和我的应用程序之间共享内存,正如我在 V4L2 中找到的那样文档。这很好用。现在我的处理器(TI的DM3730)也有一个DSP。我想使用 DSP,但它需要物理连续内存。 TI 提供了分配内存的驱动程序。我的问题是,现在我浪费了很多时间将 mmap 内存复制到物理连续内存中。有没有办法告诉 mmap 它不应该自己分配内存,但我告诉 mmap 使用我分配的内存。
为了让您了解我在做什么(当然缺少很多代码,但我非常接近 V4L2 文档。我希望这足以理解我的问题):
//reserve physical contiguous memory
dsp_buffer = Memory_alloc(buffer_length, &myParams);
...
//reserve memory for buffer, but not contiguous
buffers[n_buffers].start =
mmap (NULL , /* start anywhere */
buf.length,
PROT_READ | PROT_WRITE , /* required */
MAP_SHARED , /* recommended */
fd, buf.m.offset);
之后,我将内存复制出每当帧准备好时,将非连续内存放入连续内存中。
...
//wait until frame is ready in memory
r = select (fd + 1, &fds, NULL, NULL, &tv);
...
//copy the memory over to the physically contiguous memory
memcpy(dsp_buffer,buffers[buf.index].start,size);
...
我怎样才能立即将帧放入物理连续内存中?
I might have some misconceptions here, so bear with me.
I wrote a program that captures images from a camera. I am sharing the memory between the camera and my application with mmap
as I found in the V4L2 documentation. This works great. Now my processor (it's TI's DM3730) also has a DSP. I want to use the DSP, but it requires physical contiguous memory. TI provides drivers to allocate the memory. My problem is that right now I lose a lot of time to copy the mmap'ed memory into the physical contiguous memory. Is there a way to tell mmap that it should not allocate memory itself, but that I tell mmap to use memory that I allocate.
To give you an idea of what I am doing (There is a lot of code missing of course, but I stuck very close to the V4L2 documentation. I hope this is enough to understand my problem):
//reserve physical contiguous memory
dsp_buffer = Memory_alloc(buffer_length, &myParams);
...
//reserve memory for buffer, but not contiguous
buffers[n_buffers].start =
mmap (NULL , /* start anywhere */
buf.length,
PROT_READ | PROT_WRITE , /* required */
MAP_SHARED , /* recommended */
fd, buf.m.offset);
After that I copy the memory out of the non-contiguous memory into the contiguous memory, whenever a frame is ready.
...
//wait until frame is ready in memory
r = select (fd + 1, &fds, NULL, NULL, &tv);
...
//copy the memory over to the physically contiguous memory
memcpy(dsp_buffer,buffers[buf.index].start,size);
...
How could I get the frames into the physical contiguous memory right away?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法将
Memory_alloc()
的结果作为第一个参数传递给mmap()
(例如,如果它也使用 mmap() ,则将无法进行映射再次到该内存),您可能应该使用 给定示例中的另一种流 I/O 方法< /a> -IO_METHOD_USERPTR
变体。它使用与 IO_METHOD_MMAP 相同的 ioctl 来捕获帧,并且应该提供类似的效率。If you cannot pass the result of
Memory_alloc()
as first argument to yourmmap()
(for example, if it also uses mmap() that would make it impossible to map to that memory again), you probably should use another streaming I/O method from the given example -IO_METHOD_USERPTR
variation. It uses the sameioctl
as IO_METHOD_MMAP to capture frames and should provide the similar efficiency.您需要相机驱动程序的驱动程序支持。
mmap
从它映射的任何驱动程序(本例中为相机)获取它映射的物理页面。您不能告诉 mmap 使用某些预分配的页面,因为必须告诉底层驱动程序使用这些预分配的页面。You would need driver support from the camera driver.
mmap
gets the physical pages it maps from whatever driver it's mapping - the camera in this case. You cannot tell mmap to use some pre-allocated pages, because the underlying driver would have to be told to use these pre-allocated pages.