环形缓冲区和DMA [英] Ring buffers and DMA

查看:186
本文介绍了环形缓冲区和DMA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解从数据包到达NIC到目标应用程序接收到数据包之间发生的所有事情.

I'm trying to understand everything that happens in between the time a packet reaches the NIC until the time the packet is received by the target application.

假设:缓冲区足够大,可以容纳整个数据包. [我知道情况并非总是如此,但我不想介绍太多技术细节]

Assumption: buffers are big enough to hold an entire packet. [I know it is not always the case, but I don't want to introduce too many technical details]

一个选项是:

 1. Packet reaches the NIC.
 2. Interrupt is raised.
 2. Packet is transferred from the NIC buffer to OS's memory by means of DMA.
 3. Interrupt is raised and the OS copies the packet from it's buffer to the relevant application.

上述问题是当数据突然爆发而内核无法跟上步伐时.另一个问题是,每个数据包都会触发一个中断,这对我来说听起来效率很低.

The problem with the above is when there is a short burst of data and the kernel can't keep with the pace. Another problem is that every packet triggers an interrupt which sounds very inefficient to me.

我知道,要解决以上问题中的至少一个问题,可以使用多个缓冲区[ring buffer].但是,我不了解将使之有效的机制. 假设:

I know that to solve at least one of the above problems there is a use of several buffers [ring buffer]. However I don't understand the mechanism which will allow to make this works. Suppose that:

 1. Packet arrives to the NIC.
 2. DMA is triggered and the packet is transfered to one of the buffers [from the ring buffer].
 3. Handling of the packet is then scheduled for latter time [bottom half].

这项工作有效吗? 这是Linux内核中真正的NIC驱动程序中发生的事情吗?

Will this work? Is this is what happened in the real NIC driver within the Linux kernel?

推荐答案

根据此

According to this slideshare the correct sequence of actions are:

  • 网络设备接收帧,并将这些帧传输到DMA环形缓冲区.
  • 现在进行此传输后,将引发一个中断,以使CPU知道已进行了传输.
  • 在中断处理程序例程中,CPU将数据从DMA环形缓冲区传输到CPU网络输入队列,以供以后使用.
  • 处理程序例程的后半部分是处理来自CPU网络输入队列的数据包,并将其传递到适当的层.

因此,与传统的DMA传输相比,在此之后的一个细微变化是关于CPU的参与.

So a slight variant which is followed in this as compared to traditional DMA transfer is regarding the involvement of CPU.

在这种情况下,与传统的DMA传输不同,在数据被传输到DMA环形缓冲区之后,我们涉及CPU,在传统的DMA传输中,我们会在数据可用后立即生成中断,并期望CPU初始化具有适当内存位置的DMA设备以进行数据传输

In this we involve CPU after data gets transferred to the DMA ring buffer unlike traditional DMA transfer where we generate the interrupts as soon as data is available and expect CPU to initialise DMA device with appropriate memory locations to make happen the transfer of data.

也请阅读以下内容: https://www.safaribooksonline.com/library/view/linux-device-drivers/0596000081/ch13s04.html

这篇关于环形缓冲区和DMA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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