[RoCE] 通过QoS对Mellanox网卡进行限速

参考资料:

Quality of Service (QoS) - NVIDIA Docs

【RDMA】RoCE网络QoS|应用层设置PFC等级|Tos|Priority|TC_cma_roce_tos-CSDN博客

【RDMA】mellonx流控配置工具mlnx_qos|PFC-CSDN博客

前言

目标:我有一个Mellanox-5网卡,我想用RoCE,同时对某些qp进行限速。

然而,Mellanox-5网卡在RoCE模式下是无法对每个QP进行单独限速的。

我试了很多方法,但都失败了。最显然的做法是使用 ibv_modify_qp时修改attr.ah_attr.static_rate参数(rdmamojo.com)。然而并没有效果。我尝试了其它一些可能和rate limit有关的API,比如ibv_modify_qp_rate_limit和修改attr.rate_limit,也都没有用。我在官方的perftest(linux-rdma/perftest: Infiniband Verbs Performance Tests (github.com))里设置static_rate参数,结果它告诉我:

The QP failed to accept HW rate limit

我查看网卡的配置,发现:

$ ibv_devinfo -v
hca_id: mlx5_1
		...
        packet_pacing_caps:
                qp_rate_limit_min:      0kbps
                qp_rate_limit_max:      0kbps

qp_rate_limit_minqp_rate_limit_max都是0,这明摆着是用不了rate limit。无奈只得另寻他法。

经过一番寻找,我找到了用QoS进行限速的方法。

使用QoS进行限速

具体的文档可见Quality of Service (QoS) - NVIDIA Docs

1. 查看网卡的QoS信息

ifconfig里,我的网卡名字是ens10f1np1

$ mlnx_qos -i ens10f1np1
DCBX mode: OS controlled
Priority trust state: pcp
default priority:
Receive buffer size (bytes): 0,262016,0,0,0,0,0,0,
Cable len: 7
PFC configuration:
        priority    0   1   2   3   4   5   6   7
        enabled     0   0   0   0   0   0   0   0   
        buffer      1   1   1   1   1   1   1   1   
tc: 1 ratelimit: unlimited, tsa: vendor
         priority:  0
tc: 0 ratelimit: unlimited, tsa: vendor
         priority:  1
tc: 2 ratelimit: unlimited, tsa: vendor
         priority:  2
tc: 3 ratelimit: unlimited, tsa: vendor
         priority:  3
tc: 4 ratelimit: unlimited, tsa: vendor
         priority:  4
tc: 5 ratelimit: unlimited, tsa: vendor
         priority:  5
tc: 6 ratelimit: unlimited, tsa: vendor
         priority:  6
tc: 7 ratelimit: unlimited, tsa: vendor
         priority:  7

QoS有两种trust mode:PCP和DSCP。其中PCP是L2层的,使用vlan包头的一部分。而DSCP是L3层的,使用IP包头的一部分。由于我们想要使用RoCEv2,不包含vlan而包含IP,所以自然用DSCP是更合适的。

网卡默认的trust mode是PCP,这里我们把它改成DSCP。

$ sudo mlnx_qos -i ens10f1np1 --trust dscp
DCBX mode: OS controlled
Priority trust state: dscp
dscp2prio mapping:
        prio:0 dscp:07,06,05,04,03,02,01,00,
        prio:1 dscp:15,14,13,12,11,10,09,08,
        prio:2 dscp:23,22,21,20,19,18,17,16,
        prio:3 dscp:31,30,29,28,27,26,25,24,
        prio:4 dscp:39,38,37,36,35,34,33,32,
        prio:5 dscp:47,46,45,44,43,42,41,40,
        prio:6 dscp:55,54,53,52,51,50,49,48,
        prio:7 dscp:63,62,61,60,59,58,57,56,
default priority:
Receive buffer size (bytes): 0,262016,0,0,0,0,0,0,
Cable len: 7
PFC configuration:
        priority    0   1   2   3   4   5   6   7
        enabled     0   0   0   0   0   0   0   0   
        buffer      1   1   1   1   1   1   1   1   
tc: 1 ratelimit: unlimited, tsa: vendor
         priority:  0
tc: 0 ratelimit: unlimited, tsa: vendor
         priority:  1
tc: 2 ratelimit: unlimited, tsa: vendor
         priority:  2
tc: 3 ratelimit: unlimited, tsa: vendor
         priority:  3
tc: 4 ratelimit: unlimited, tsa: vendor
         priority:  4
tc: 5 ratelimit: unlimited, tsa: vendor
         priority:  5
tc: 6 ratelimit: unlimited, tsa: vendor
         priority:  6
tc: 7 ratelimit: unlimited, tsa: vendor
         priority:  7

可以看到,上面一共包含8个Traffic Class(TC),8个priority,以及8个buffer。由于我们的目标只是限速,所以我们不去修改TC,priority,buffer之间的关系。

2. 设置ToS

在RoCEv2模式下,配置一个qp对应哪个Traffic TC的流程如下。

  1. 在应用层,为每个qp设置一个Type-of-Service(ToS)。
  2. ToS的高6bit为DSCP,低2bit无所谓。
  3. 根据上文的映射表将DSCP映射为TC。

ToS在IP包头中的含义在这里:

image

假如我们想要对TC4进行限速。根据DSCP的映射表,我们可以选取DSCP=32(32到39都行)。因此对应的ToS就是128(128到159都行)。

然后,我们想要把TC4限速为4Gbps。

$ sudo mlnx_qos -i ens10f1np1 --ratelimit=0,0,0,0,4,0,0,0
...
tc: 4 ratelimit: 4.0 Gbps, tsa: vendor
         priority:  4

配置成功。

3. 应用层设置ToS

对于ibverb API的使用者,在设置Address Vector的时候,将attr.ah_attr.grh.traffic_class这一项设置为想要的ToS即可(注意虽然这个参数叫traffic_class,但它的值不是TC,而是ToS)。

对于RDMA CM的使用者,使用rdma_set_option(cma_id, RDMA_OPTION_ID, RDMA_OPTION_ID_TOS, &your_tos, sizeof(uint8_t))即可设置ToS。

测试

我们已经在机器A上配置好了限速,现在测一下从机器A到另一台机器B进行RDMA WRITE的吞吐。

在B上运行(这里mlx5_1是网卡的ib名字,使用ibdev2netdev可以查看)

$ ib_write_bw -d mlx5_1 -x 3

在A上运行

$ ib_write_bw <B_IP> -d mlx5_1 -x 3 --tclass=128

结果

---------------------------------------------------------------------------------------
 #bytes     #iterations    BW peak[MB/sec]    BW average[MB/sec]   MsgRate[Mpps]
 65536      5000             9205.89            450.24             0.007204
---------------------------------------------------------------------------------------

可以发现,确实将平均速度限制到了4Gbps以下。然而,峰值速度貌似是限制不住的(悲)。

而对于其它的ToS:

$ ib_write_bw <B_IP> -d mlx5_1 -x 3 --tclass=0
---------------------------------------------------------------------------------------
 #bytes     #iterations    BW peak[MB/sec]    BW average[MB/sec]   MsgRate[Mpps]
 65536      5000             8501.98            4726.36            0.075622
---------------------------------------------------------------------------------------

速度则不受限制。

posted @ 2024-04-16 19:31  CQzhangyu  阅读(17)  评论(0编辑  收藏  举报