网卡性能分析-Intel8257X芯片手册读后感

转载自:  http://blog.csdn.net/dog250/article/details/6313854 

引:在《《OpenVPN性能》之后,我进一步阅读了硬件的解决方案,希望能得到一些思想,然后进一步的改进我的设计,由于工作的便利性和实际工作的需要,我阅读了intel的82571EB,82574L,82575等以太网芯片的datesheet的相关特性描述部分(由于我不打算亲自写驱动,因此我没有阅读寄存器以及存储器细节,更多的是我不相信自己的驱动比intel的工程师们的更高效),得到了很多感觉,以下是我的一些摘录和读后感。

一,网络应用开销
1.协议栈处理开销:分层模型各个层次的OS实现开销
2.内存拷贝开销:网卡,内核内存,用户态内存之间的拷贝
3.系统层面的开销:中断,缓存管理,系统调用
二,局部的解决方案
1.dma-针对内存拷贝,需要锁定总线,此时cpu就好像被拔除了一样(《Intel微处理器》中原话),如果网卡数据芯片没有cpu高效,除了省去了一次cpu中转之外,性能反而降低。
2.硬中断负载均衡-针对多cpu的利用率(希望多cpu全部用来处理协议栈),此带来软中断负载均衡(在硬中断cpu上触发软中断),做的不好没有效果,造成某个cpu高负载,其它cpu空闲,做的好的话,会造成基于顺序的协议包乱序,这就是cpu并行和tcp串行之间的冲突。
3.TOE-针对pci总线访问延迟过高,tcp卸载引擎,这种方案对于经常传输小包的情形来说无疑是不好的,因此在网卡中大量处理tcp协议会造成收发速率降低。
4.NAPI-针对中断频发导致切换过多,最终影响处理器cache的热度。但是依赖dma,依赖网卡芯片,依赖网络状况。局部的解决方案很多都造成治聋致哑的结局,原因就是各因素之间的影响是隔离的,因此必然需要一种全局的方案,各因素之间相互配合达到最好的效果。其中intel提出一种io加速方案,那就是ioat。
三,一种全局的方案-IOAT
1.quick data,QD可以在不阻塞cpu的情况下异步执行dma操作,而dma却是一种同步的方式独占总线。和DMA相比,芯片速率比cpu更高或者根本无需挂起处理器。
2.RSS,多队列网卡,将不同的流负载到不同的cpu上,同一流始终在同一cpu上,避免tcp的顺序性和cpu的并行性的冲突。基于流的负载均衡,解决顺序协议和cpu并行的冲突以及cache热度问题。
3.DCA,直接将数据放入RSS绑定的cpu的缓存中,更加有利于后期cpu处理协议栈流程时对数据的访问。和频度中断一起解决cache热度问题。dca基于pcie,由于pcie是基于协议消息的,因此很容易封装一个复杂的消息交由前端译码器(root complex)触发处理器的预取,只需要它解析消息即可,可以想象如果在并行的总线上,设计如此复杂的机制是不可能的,要考虑多少时序啊!
4.频度中断,如果数据包不断到来则积累中断,为了不使某积累中的包延迟过大,需要一个权衡出来的可编程硬件timer,到期后定期中断,并且为了为一些特殊包提供特殊服务,需要保留随时中断的机制。多种中断方案,可以使得cpu切换最小化,cache热度最大化。
5.Header Splitting,将数据包头和数据包内容分开拷贝到不同的dma或者qd内存区域,这样cpu就可以直接使用包头了,而不用再从数据包中解析包头了,加上dca机制,包头信息载入绑定cpu的cache,cpu在接下来处理过程中会提高效率。
1-5.ioat的组成部分,其中RSS和DCA可以拥有软件方案,对于rss而言,在收到包时解析包并将包归为某一个流,然后将softirq分发到该流绑定的cpu上即可,然而解析流的效率并不理想,因此硬件解决方案比较好,intel的82575及以上的网卡实现了rss。其中的频度中断思想类似于《OpenVPN性能-OpenVPN的第一个瓶颈在tun驱动》中对tun驱动进行修改的思想。
四,硬件实现:
82571/2没有rss,82574有了rss(2个队列),但是需要驱动程序完成cpu绑定,82575由硬件完成了rss(4个队列)的cpu绑定。花了很多时间阅读了intel8257x网卡芯片的手册,很有感觉。
1.摘录一段82575手册中的描述中断的语句:
The 82575 implements interrupt moderation to reduce the number of interrupts software processes. The moderation scheme is based on EITR. Each time an interrupt event happens, the corresponding bit in the EICR is activated. However, an interrupt message is not sent out on the PCIe* interface until the EITR counter assigned to that EICR bit has counted down to zero. As soon as the interrupt is issued, the EITR counter is reloaded with its initial value and the process repeats again. The interrupt flow should follow as shown in Figure 20.
*******************
inter1  
*******************
For cases where the 82575 is connected to a small number of clients, it is desirable to initiate the interrupt as soon as possible with minimum latency. For these cases, when the EITR counter counts down to zero and no interrupt event has happened, then the EITR counter is not reset but stays at zero.Therefore, the next interrupt event triggers an immediate interrupt (see Figure 21 and Figure 22).
*******************
 
*******************
2.针对header split,82575手册上有很好的描述,
This feature consists of splitting or replicating a packet’s header to a different memory space. This helps the host to fetch headers only for processing: headers are replicated through a regular snoop transaction, in order to be processed by the host processor. It is recommended to perform this transaction with the DCA feature enabled.The packet (header + payload) is stored in memory through an optional non-snoop transaction.
**************
 
***************
如果不是很理解,微软的msdn上也有描述,截图如下: 
**************
 
*****************
3.82574L中就已经集成了RSS,然则却很不完善,有很多的事情还是需要软件来完成的,所谓的软件完成其实就是驱动程序来完成,不管怎样,这一步使rss在ioat中的地位日趋确立,82574L中的描述如下:
The 82574L provides two hardware receive queues and filters each receive packet into one of the queues based on criteria that is described as follows. Classification of packets into receive queues have several uses, such as:
 Receive Side Scaling (RSS)
 Generic multiple receive queues
 Priority receive queues.
...
When multiple receive queues are enabled, the 82574 provides software with several types of information. Some are requirements of Microsoft* RSS while others are provided for software device driver assistance:
 A Dword result of the Microsoft* RSS hash function, to be used by the stack for flow classification, is written into the receive packet descriptor (required by Microsoft* RSS).
 A 4-bit RSS Type field conveys the hash function used for the specific packet (required by Microsoft* RSS).
 A mechanism to issue an interrupt to one or more CPUs (section 7.1.11). #注意这一句
Figure 33 shows the process of classifying a packet into a receive queue:
1. The receive packet is parsed into the header fields used by the hash operation (such as, IP addresses, TCP port, etc.).
2. A hash calculation is performed. The 82574L supports a single hash function, as defined by Microsoft* RSS. The 82574L therefore does not indicate to the software device driver which hash function is used. The 32-bit result is fed into the packet receive descriptor.
3. The seven LSBs of the hash result are used as an index into a 128-entries redirection table. Each entry in the table contains a 5-bit CPU number. This 5-bit value is fed into the packet receive descriptor. In addition, each entry provides a single bit queue number, which denotes that queue into which the packet is routed.
***************
 
***************
而在82575中,rss完善了,加上了多cpu之间的自动绑定,先附上一幅图,基本原理也就明白了:
****************
 
*****************
82575数据手册如是说:
It is assumed that each queue is associated with a specific processor, even when there are more
processors than queues.
附上一副更加清晰的图:
*****************
 
**************
3.82571EB开始了提速,只不过在该版本中还是传统的修补,没有什么大的动作,其中TOE中增加了许多东西,很

多计算都可以从cpu上offload了
4.对于性能测试,先后看了一些资料,不过既然瞄准了intel的解决方案,还是看intel的数据吧,首先贴两张开

销分析图:
****************
 
****************
 
**************
然后是ioat的结果,没有给出数据,但是给出了ioat针对哪些病症部位下了手:
****************
 
*****************
结:
1.和外设通信的方式有:
1.1.中断
1.2.轮询
1.3.DMA
然而这些都是教科书上的方法,正如cisc和risc一样,很教条,真正的方式已经将中断和轮询结合成了napi,intel也结合了DMA和多cpu形成了QuickData,根本上ioat也是napi和quickdata的结合加上其它的机制,我们可以看到,很多时候,ioat颠覆了分层的网络模型,物理网卡怎么能处理tcp流呢?这在传统教条卫道士那里是不可饶恕的。
2.崇拜intel
上学那会儿,装机,我用了intel的奔四cpu,1000多买的,同寝室的后来装机都用了amd的,3200+的性能比我的竟然还好,又不挑电源,又便宜很多,MD当时我就不平衡了,同寝的都认为amd要彻底超越intel了,加上amd在64位技术上走在了前面,我渐渐的也认为intel不行了。然而工作了很久之后,我发现intel不仅仅是做微处理器的,人家主要是定标准的,不管是pc领域还是服务器领域的。还真别说,intel的方案有时候就是好,大公司养得起猛士,因此做事绝不含糊。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值