V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
amiwrong123
V2EX  ›  程序员

Linux 的 Consistent DMA mappings 的底层实现原理到底是什么?

  •  
  •   amiwrong123 · Aug 23, 2023 · 1221 views
    This topic created in 977 days ago, the information mentioned may be changed or developed.

    https://blog.csdn.net/rlk8888/article/details/120115477

    在这篇博客里提到:一个简单的想法就是,我们在做 DMA 传输的时候,这段 buffer 我把 cache 给关闭了,这个就是 kernel 实现的一致性的 DMA buffer mapping 的(英文叫做:Consistent DMA mappings )。这里 consistent 的意思是 synchronize 或者 conherent 的意思,CPU 和 DMA 这两个哥们都能同时看到数据的改变,不需要软件做额外的一些 flush 动作。

    当然了,对特定的 buffer 关闭了 cache 功能,就会导致 CPU 写时会直接写到 ddr 里而不是写到 cache 里,读时总是从 ddr 里面读而不是 cache 里读。

    但我想知道使用dma_alloc_coherent得到的地址,真的底层原理这么简单吗?是不是直接看dma_alloc_coherent的源码实现就能找到答案,但现在看起来有点费劲。

    2 replies    2023-08-24 12:41:30 +08:00
    zzz22333
        1
    zzz22333  
       Aug 24, 2023
    可以通过 MMU 配置内存属性为 uncache
    amiwrong123
        2
    amiwrong123  
    OP
       Aug 24, 2023
    @zzz22333
    我的关键点在于,我还以为 Consistent DMA mappings 用到了什么高深的东西呢,比如 缓存一致性协议什么的。
    结果只是 暴力把 cache 关掉了而已。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3081 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 14:48 · PVG 22:48 · LAX 07:48 · JFK 10:48
    ♥ Do have faith in what you're doing.