网卡RSS功能--转载原文地址:http://blog.chinaunix.net/uid-24830931-id-3352000.html
2015-03-16 14:44
495 查看
在使用pf_ring的过程中,发现pf_ring有自身的rss功能。网卡已经有了rss(receive side scaling)功能,pf_ring的rss有何存在的必要?
通过测试,发现Intel 82599的rss功能不能保证同一个流被分配到队列上 (同一个流的五元组是不同的,IN方向的是[PROTO, SIP, SPORT, DIP, DPORT],out方向的则是[PROTO, DIP, DPORT, SIP, SPORT])。而pf_ring的rss则能确保同一个流的数据进入了同一个ring,参见前文《pf_ring
5.4.0 rss原理、适用场景与局限》。
接下来看一下为什么网卡的rss做不到这一点。
Intel 82599的rss原理主要参考《Intel? 82599 10 GbE Controller Datasheet》,结合源码的分析后续补上
82599网卡rss原理
1)网卡会对数据包进行解包,解析出与源目的ip地址、源目的port信息
2)网卡选根据配置选择一个hash函数
3)将hash值的低7位作为key决定redirection table的下标,同时每个table项有4位,代表rss hash后的queue id(注:实际使用过程中发现82599只能启用16个队列,个人推测与这里的四位redirection table项密切相关)
查看了一下intel 82599驱动的安装手册,果然提到16个队列的限制:
http://www.intel.com/support/cn/network/adapter/pro100/sb/cs-032530.htm
0= 禁用 RSS
1= 启用 RSS, 并将描述符队列计数为 16 或数量的
联机 CPU, 取两者中较小。
2-16= 启用 RSS, 用 2-16 队列
rss函数key类型:
1)TCPIPV4 [SIP, DIP, SPORT, DPROT]
2)IPV4 [SIP, DIP]
3)TCPIPV6 [SIP, DIP, SPORT, DPROT]
4)IPV6 [SIP, DIP]
5)UDPIPV4 [SIP, DIP, SPORT, DPROT]
6)UDPIPV6 [SIP, DIP, SPORT, DPROT]
hash算法
ComputeHash(input[], N)
For hash-input input[] of length N bytes (8N bits) and a random secret key
K of 320 bits
Result = 0;
For each bit b in input[] {
if (b == 1) then Result ^= (left-most 32 bits of K);
shift K left 1 bit position;
}
return Result;
换成文字描述,就是:选取一个320位的随机数K, 对于N字节的每一位,如果该位为1,则Result=Result异或K的最高32为位。否则,Result不变。K左移一位。
那么着N是多少呢?如何组成呢?
对于TCPIPV4,hash函数调用为Result = ComputeHash(Input, 12);
这12字节是[SIP(4Bytes),DIP(4Bytes), SPort(2Bytes), DPort(2Bytes)]
对于UDPIPV4, hash函数调用为Result = ComputeHash(Input, 12);
这12字节是[SIP(4Bytes),DIP(4Bytes), SPort(2Bytes), DPort(2Bytes)]
对于IPV4,hash函数调用Result = ComputeHash(Input, 8)
这8字节是[SIP(4Bytes),DIP(4Bytes)}
从这里可以看出,当同一个流的SIP,DIP,SPort,DPort交换位置时,算出来的hash值是大部分时候不同的,因此也就无法保证hash到同一个队列。
通过测试,发现Intel 82599的rss功能不能保证同一个流被分配到队列上 (同一个流的五元组是不同的,IN方向的是[PROTO, SIP, SPORT, DIP, DPORT],out方向的则是[PROTO, DIP, DPORT, SIP, SPORT])。而pf_ring的rss则能确保同一个流的数据进入了同一个ring,参见前文《pf_ring
5.4.0 rss原理、适用场景与局限》。
接下来看一下为什么网卡的rss做不到这一点。
Intel 82599的rss原理主要参考《Intel? 82599 10 GbE Controller Datasheet》,结合源码的分析后续补上
82599网卡rss原理
1)网卡会对数据包进行解包,解析出与源目的ip地址、源目的port信息
2)网卡选根据配置选择一个hash函数
3)将hash值的低7位作为key决定redirection table的下标,同时每个table项有4位,代表rss hash后的queue id(注:实际使用过程中发现82599只能启用16个队列,个人推测与这里的四位redirection table项密切相关)
查看了一下intel 82599驱动的安装手册,果然提到16个队列的限制:
http://www.intel.com/support/cn/network/adapter/pro100/sb/cs-032530.htm
0= 禁用 RSS
1= 启用 RSS, 并将描述符队列计数为 16 或数量的
联机 CPU, 取两者中较小。
2-16= 启用 RSS, 用 2-16 队列
rss函数key类型:
1)TCPIPV4 [SIP, DIP, SPORT, DPROT]
2)IPV4 [SIP, DIP]
3)TCPIPV6 [SIP, DIP, SPORT, DPROT]
4)IPV6 [SIP, DIP]
5)UDPIPV4 [SIP, DIP, SPORT, DPROT]
6)UDPIPV6 [SIP, DIP, SPORT, DPROT]
hash算法
ComputeHash(input[], N)
For hash-input input[] of length N bytes (8N bits) and a random secret key
K of 320 bits
Result = 0;
For each bit b in input[] {
if (b == 1) then Result ^= (left-most 32 bits of K);
shift K left 1 bit position;
}
return Result;
换成文字描述,就是:选取一个320位的随机数K, 对于N字节的每一位,如果该位为1,则Result=Result异或K的最高32为位。否则,Result不变。K左移一位。
那么着N是多少呢?如何组成呢?
对于TCPIPV4,hash函数调用为Result = ComputeHash(Input, 12);
这12字节是[SIP(4Bytes),DIP(4Bytes), SPort(2Bytes), DPort(2Bytes)]
对于UDPIPV4, hash函数调用为Result = ComputeHash(Input, 12);
这12字节是[SIP(4Bytes),DIP(4Bytes), SPort(2Bytes), DPort(2Bytes)]
对于IPV4,hash函数调用Result = ComputeHash(Input, 8)
这8字节是[SIP(4Bytes),DIP(4Bytes)}
从这里可以看出,当同一个流的SIP,DIP,SPort,DPort交换位置时,算出来的hash值是大部分时候不同的,因此也就无法保证hash到同一个队列。
相关文章推荐
- 网卡多队列-转载原文地址:http://blog.chinaunix.net/uid-24830931-id-3352000.html
- (转)一篇图片处理优化思路 原文地址http://blog.chinaunix.net/uid-20806919-id-132246.html
- 一堂课玩转rpm包的制作(转载自http://blog.chinaunix.net/uid-23069658-id-3944462.html)
- llinux 定时器 转载自 http://blog.chinaunix.net/uid-11848011-id-96374.html
- curl 转自 http://blog.chinaunix.net/uid-22655387-id-3283161.html
- http://blog.chinaunix.net/uid-25737580-id-3182286.html
- fd_set具体是怎样实现的 http://blog.chinaunix.net/uid-20680966-id-1896524.html
- http://blog.chinaunix.net/uid-22666718-id-1771703.html
- 常见的加密算法 (转自: http://blog.chinaunix.net/uid-8735300-id-2017079.html 本文摘自网络 ,如有雷同 请及时联系我 谢谢)
- http://blog.chinaunix.net/uid-25547034-id-3155778.html
- 同步与异步的概念(转自http://blog.chinaunix.net/uid-21411227-id-1826898.html)
- http://blog.chinaunix.net/uid-21222282-id-3244532.html
- vim 颜色设置(转http://blog.chinaunix.net/uid-24929997-id-3065936.html)
- 异步IO接口Libaio的用法http://blog.chinaunix.net/uid-16979052-id-3509393.html
- http://blog.chinaunix.net/uid-8874157-id-2012678.html
- 浅析linux内核中timer定时器的生成和sofirq软中断调用流程(转自http://blog.chinaunix.net/uid-20564848-id-73480.html)
- Linux内核中流量控制 http://blog.chinaunix.net/uid-127037-id-2919583.html
- http://blog.chinaunix.net/uid-25835268-id-3055356.html--makefile
- TCP/IP源码学习(47)——socket与VFS的关联(1) 2 http://blog.chinaunix.net/uid-23629988-id-3080166.html
- 移植自己的printf,scanf函数(引用:http://blog.chinaunix.net/uid-18921523-id-187419.html)