当数据大小较小时,内存到内存 DMA 传输是否存在折衷? [英] Is there a trade-off for memory to memory DMA transfer when the data size is small?

查看:36
本文介绍了当数据大小较小时,内存到内存 DMA 传输是否存在折衷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 STM32 F4 微控制器.我试图找出使用 DMA 的限制.

I am learning about the STM32 F4 microcontroller. I'm trying to find out about limitations for using DMA.

根据我的理解和研究,我知道如果数据量小(即设备使用DMA产生或消耗少量数据),开销会增加,因为DMA传输需要DMA控制器来执行操作,从而不必要地增加系统成本.

Per my understanding and research, I know that if the data size is small (that is, the device uses DMA to generate or consume a small amount of data), the overhead is increased because DMA transfer requires the DMA controller to perform operations, thereby unnecessarily increasing system cost.

我做了一些研究,发现了以下内容:

I did some reaserch and found the following:

DMA 的限制

CPU 将其所有线路置于高阻抗状态,以便 DMA 控制器可以直接在设备和内存之间传输数据,而无需 CPU 干预.显然,它更适合磁盘等数据传输率高的设备.通过串行接口,数据一次一位传输,这使得使用 DMA 速度很慢.

CPU puts all its lines at high impedance state so that the DMA controller can then transfer data directly between device and memory without CPU intervention. Clearly, it is more suitable for device with high data transfer rates like a disk. Over a serial interface, data is transferred one bit at a time which makes it slow to use DMA.

这样对吗?我还需要知道什么?

Is that correct? What else do I need to know?

推荐答案

正如@Vinci 和@0____________ (f.k.a. @P__J__) 已经指出的那样,

As @Vinci and @0___________ (f.k.a. @P__J__) already pointed out,

  1. DMA 控制器自主工作,不会在它所补充的 CPU 上产生开销(至少不会单独产生开销).但是:

  1. A DMA controller works autonomously and doesn't create overhead on the CPU it supplements (at least not by itself). But:

CPU/软件必须执行一些指令来配置 DMA 并触发它或让它由某些外设触发.为此,它需要 CPU 时间和程序存储空间(通常是 ROM).此外,它通常需要一些额外的 RAM 变量来管理围绕 DMA 的软件.

The CPU/software must perform some instructions to configure the DMA and to trigger it or have it triggered by some peripheral. For this, it needs CPU time and program memory space (usually ROM). Besides, it usually needs some additional RAM in variables to manage the software around the DMA.

因此,您是对的,使用 DMA 会带来一些开销.

Hence, you are right, using a DMA comes with some kinds of overhead.

此外,

  1. DMA 传输利用将相关存储器/寄存器/外设连接到 DMA 控制器的存储器总线.也就是说,当 DMA 控制器完成自己的工作时,它可能会导致它试图卸载的 CPU 同时停顿,至少在传输数据字时的短时间内停止(这反过来总结为更长的传输...).


另一方面,DMA 不仅可以帮助您减少 CPU 负载(关于实现某些功能的总 CPU 时间).如果以一种聪明的方式"使用,它可以帮助您减少软件延迟以实现不同的功能,因为实现的一部分可以被隐藏"到其他地方.在另一部分的 DMA 驱动数据传输背后(除非两者都依赖相同的总线资源 - 见上文...).


On the other hand, a DMA doesn't only help you to reduce the CPU load (regarding total CPU time to implement some feature). If used "in a smart way", it helps you to reduce software latencies to implement different functions because one part of the implementation can be "hidden" behind the DMA-driven data transfer of another part (unless, both rely on the same bus resources - see above...).

这篇关于当数据大小较小时,内存到内存 DMA 传输是否存在折衷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆