在网络应用中,如果同一个连接的双向报文在开启RSS之后被分发到同一个CPU上处理,这种RSS就称为对称RSS。对于需要为连接保存一些信息的网络应用来说,对称RSS对性能提升有很大帮助。例如:{sip: 1.1.1.1, dip: 2.2.2.2, sport: 123, dport: 456}和{sip: 2.2.2.2, dip: 1.1.1.1, sport: 456, dport: 123}经过对称RSS会被分发到相同的接收队列,由同一个CPU进行处理。
目前软件dpdk中已经基于Toeplitz hash函数构建了对称rss的算法,根据输入数据的大小端序的不同分为两种形式,具体代码如下
static inline unit32_t
rte_softrss_be( unint32_t *input_tuple, unint32_t input_len, const unint8_t *rss_key)
{ uint32_t i, k, map, ret =0;
for (k=0; k < input_len; k++) {
for (map = input_tuple[k]; map; map &= (map -1)) {
i = (uint32_t)_builtin_ctz(map);
ret^= ((const uint32_t *) rss_key)[k] << (31 -i) |
(unint32_t)((uint64_t)(((const uint32_t *)rss_key)[k+1]) >> (i+1)) ;
}
}
return ret ; (dpdk-rss 小端序)
static inline unit32_t
rte_softrss_be( unint32_t *input_tuple, unint32_t input_len, const unint8_t *rss_key)
{ uint32_t i, k, map, ret =0;
for (k=0; k < input_len; k++) {
for (map = input_tuple[k]; map; map &= (map -1)) {
i = (uint32_t)_builtin_ctz(map);
ret^=notohl(((const uint32_t *) rss_key)[k]) << (31 -i) |
(unint32_t)((uint64_t)(((const uint32_t *)rss_key)[k+1]) >> (i+1)) ;
}
}
return ret ; (dpdk-rss大端序)
为了保证软件硬件在对称rss算法的一直,那么在硬件设计上就需要得到和软件相同的结果。这里采用FPGA硬件中的verilog语音进行硬件对称rss算法的设计,相应的硬件大小端序具体代码如下
function [31:0] hash_toep(input [12*8-1:0] data, input [5:0] len, input [40*8-1:0] key);
integer i, k;
begin
hash_toep = 0;
for (i = len; i > 0; i = i - 1) begin
for (k = 0; k< 8; k= k+ 1) begin
if (data[(i-1)*8 + (7-k)]) begin
hash_toep = hash_toep ^ key[(i+4)*8 -32- k +: 32];
end
end
end
end
endfunction ( verilog-rss小端序)
function [31:0] hash_toep(input [37*8-1:0] data, input [5:0] len, input [42*8-1:0] key);
integer i, k;
begin
hash_toep = 0;
for (i = 0; i < len; i = i + 1) begin
for (k = 0; k < 8; k = k+ 1) begin
if (data[i*8 + (7-k)]) begin
hash_toep = hash_toep ^ key[42*8 - 32 - i*8 - k +: 32];
end
end
end
end
endfunction (verilog-rss大端序)
针对相应的代码,进行软硬件协同测试:
- 输入数据格式:{sip,dip,sport,dport}
- 输入数据内容:sip:96'h0,8'h1,8'h1,8'h1,8’h1; dip:96'h0,8'h2,8'h2,8'h2,8’h2;sport:8'h0,8'h11;dport:8'h0,8'h22
- 输入16组数据:sport采用递增方式,其他字段保持不变
测试结果:
dpdk-rss大端序 |
dpdk-rss小端序 |
verilog-rss大端序 |
verilog-rss小端序 |
17241724 |
24172417 |
17241724 |
24172417 |
badfbadf |
dfbadfba |
badfbadf |
dfbadfba |
8c728c72 |
728c728c |
8c728c72 |
728c728c |
6c226c22 |
226c226c |
6c226c22 |
226c226c |
5a8f5a8f |
8f5a8f5a |
5a8f5a8f |
8f5a8f5a |
f774f774 |
74f774f7 |
f774f774 |
74f774f7 |
c1d9c1d9 |
d9c1d9c1 |
c1d9c1d9 |
d9c1d9c1 |
875c875c |
5c875c87 |
875c875c |
5c875c87 |
b1f1b1f1 |
f1b1f1b1 |
b1f1b1f1 |
f1b1f1b1 |
1c0a1c0a |
0a1c0a1c |
1c0a1c0a |
0a1c0a1c |
2aa72aa7 |
a72aa72a |
2aa72aa7 |
a72aa72a |
caf7caf7 |
f7caf7ca |
caf7caf7 |
f7caf7ca |
fc5afc5a |
5afc5afc |
fc5afc5a |
5afc5afc |
51a151a1 |
a151a151 |
51a151a1 |
a151a151 |
670c670c |
0c670c67 |
670c670c |
0c670c67 |
9b569b56 |
569b569b |
9b569b56 |
569b569b |