免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1785 | 回复: 1
打印 上一主题 下一主题

[硬件及驱动] 一个关于DMA memory sync的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-03-29 15:18 |只看该作者 |倒序浏览
本帖最后由 lyl19 于 2013-03-29 15:18 编辑

一般分配普通内存的话,在DMA之前会sync一下。
如果我分配的内存是consistent或者,分配的是non cache的,那在DMA之前,我还是把它sync了一下,想问一下,这个操作在处理器那里会占用和正常内存一样的时间吗,或者处理器认为这块内存本来就不需要同步,就不会做sync的操作?
谢谢

论坛徽章:
0
2 [报告]
发表于 2013-04-13 17:10 |只看该作者
回复 1# lyl19
在没有开启IOMMU功能时(Intel VT-d技术)时,内核对于DMA的sync统一使用的是flush_write_buffers函数
  1. static void nommu_sync_single_for_device(struct device *dev,
  2.                         dma_addr_t addr, size_t size,
  3.                         enum dma_data_direction dir)
  4. {
  5.         flush_write_buffers();
  6. }


  7. static void nommu_sync_sg_for_device(struct device *dev,
  8.                         struct scatterlist *sg, int nelems,
  9.                         enum dma_data_direction dir)
  10. {
  11.         flush_write_buffers();
  12. }

  13. struct dma_map_ops nommu_dma_ops = {
  14.         .alloc_coherent                = dma_generic_alloc_coherent,
  15.         .free_coherent                = nommu_free_coherent,
  16.         .map_sg                        = nommu_map_sg,
  17.         .map_page                = nommu_map_page,
  18.         .sync_single_for_device = nommu_sync_single_for_device,
  19.         .sync_sg_for_device        = nommu_sync_sg_for_device,
  20.         .is_phys                = 1,
  21. };
复制代码
在flush_write_buffer函数中会进行锁总线并对目标地址进行加0操作以同步cache与内存之间的内容
  1. static inline void flush_write_buffers(void)
  2. {
  3. #if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
  4.         asm volatile("lock; addl $0,0(%%esp)": : :"memory");
  5. #endif
  6. }
复制代码
因此,对于no-cache类型的内存,cpu在执行这条指令时少了个写入cache的动作,会比标志cache的内存快一点点

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP