Skip to contentSkip to conversation

net/mlx5e: TX, Do not open a multi-packet WQE for a single packet

PATCH In review Xuanqiang Luo 4 participants 4 messages Nov 23 – Nov 25

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/mlx5e: TX, Do not open a multi-packet WQE for a single packet

From: Xuanqiang Luo <[email protected]>

A multi-packet WQE (MPWQE, added by commit 5af75c747e2a ("net/mlx5e:
Enhanced TX MPWQE for SKBs")) lets several packets share one WQE, so the control and Ethernet segments are fetched by the device once per batch instead of once per packet. This saves PCIe bandwidth and CPU cycles, but only if the WQE carries more than one packet.

With skb_tx_mpwqe enabled, which is the default, mlx5e_xmit() sends every skb accepted by mlx5e_tx_skb_supports_mpwqe() through an MPWQE session. A session stays open between two calls only while the stack sets xmit_more. A packet without xmit_more closes the session and rings the doorbell. Hence a packet that comes without xmit_more while no session is open opens a session just for itself and closes it right away. Such a WQE takes one WQEBB, as a regular WQE does for the same packet, and the doorbell is rung for each packet either way, so nothing is saved.

This is the case for the IP fragments of a large UDP datagram and for UDP request/response traffic, which reach the driver one packet at a time. With pktgen and burst 1 every MPWQE carries one packet (mpwqe_blks equals mpwqe_pkts, xmit_more is 0) and the packet rate is 15% lower than with skb_tx_mpwqe turned off.

Use the regular WQE path for a packet that has no xmit_more and no open session. Packets with xmit_more still open and extend a session, and the last packet of a batch still closes it, so batching is unchanged.

The only visible change besides the performance is in the statistics:
tx*_mpwqe_blks and tx*_mpwqe_pkts no longer count a packet sent alone. Such a packet is counted in tx*_packets, as any packet sent with a regular WQE.

netperf and pktgen between two 10G ConnectX-5 hosts, 2-socket Hygon C86-4G 7490 sender on net-next, the patch switched at run time by a temporary module parameter (not part of this patch) so that before and after run in the same boot, mean of 3 boots x 2 rounds. "far" is a sender on the other socket than the NIC, "near" one on the NIC NUMA node:

test before after change

  UDP_STREAM 65507, far, Mbps            3255     3815   +17.2%
  UDP_STREAM 65507, near, Mbps           5619     5870    +4.5%
  UDP_RR 1 B, far, trans/s              57667    60688    +5.2%
  UDP_RR 1 B, near, trans/s             70538    71230    +1.0%
  TCP_RR 1 B, far, trans/s              56822    57124    +0.5%
  TCP_RR 1 B, near, trans/s             70048    70011    -0.1%
  pktgen 64 B burst 1, kpps              1487     1748   +17.5%
  pktgen 64 B burst 16, kpps             3192     3194    +0.1%

Batches do not regress: with burst 16, which uses xmit_more, the rate is unchanged. TCP_RR does not change beyond the noise, its skbs carry the data in page fragments and cannot use MPWQE.

The price is that the regular path runs a little more code for a packet than a single packet MPWQE does (mlx5e_sq_calc_wqe_attr(), mlx5e_accel_tx_finish()): the instructions per byte of UDP_STREAM 65507 go up by 0.3-0.4%, which the gains above outweigh.

---
Changes:
v2:
- Check xmit_more and the open session first, so that a lone packet skips the skb checks. (Suggested by Tariq.)
- Run the tests again with the new code and add netperf results to the commit message. (Suggested by Tariq.)
- Rebase onto the latest net-next/main.

v1: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/mellanox/mlx5/core/en_tx.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +6 -3
index 14479da98f42..5b5651c14750 100644
@@ -646,6 +646,7 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct mlx5e_priv *priv = netdev_priv(dev);
 	struct mlx5e_accel_tx_state accel = {};
+	bool xmit_more = netdev_xmit_more();
 	struct mlx5e_tx_wqe_attr wqe_attr;
 	struct mlx5e_tx_attr attr;
 	struct mlx5e_tx_wqe *wqe;
@@ -678,11 +679,13 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
 	mlx5e_sq_xmit_prepare(sq, skb, &accel, &attr);
 
 	if (test_bit(MLX5E_SQ_STATE_MPWQE, &sq->state)) {
-		if (mlx5e_tx_skb_supports_mpwqe(skb, &attr)) {
+		/* An MPWQE for a lone packet saves nothing, use a regular WQE. */
+		if ((xmit_more || mlx5e_tx_mpwqe_session_is_active(sq)) &&
+		    mlx5e_tx_skb_supports_mpwqe(skb, &attr)) {
 			struct mlx5_wqe_eth_seg eseg = {};
 
 			mlx5e_txwqe_build_eseg(priv, sq, skb, &accel, &eseg, attr.ihs);
-			mlx5e_sq_xmit_mpwqe(sq, skb, &eseg, netdev_xmit_more());
+			mlx5e_sq_xmit_mpwqe(sq, skb, &eseg, xmit_more);
 			return NETDEV_TX_OK;
 		}
 
@@ -697,7 +700,7 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
 	mlx5e_accel_tx_finish(sq, wqe, &accel,
 			      (struct mlx5_wqe_inline_seg *)(wqe->data + wqe_attr.ds_cnt_inl));
 	mlx5e_txwqe_build_eseg(priv, sq, skb, &accel, &wqe->eth, attr.ihs);
-	mlx5e_sq_xmit_wqe(sq, skb, &attr, &wqe_attr, wqe, pi, netdev_xmit_more());
+	mlx5e_sq_xmit_wqe(sq, skb, &attr, &wqe_attr, wqe, pi, xmit_more);
 
 	return NETDEV_TX_OK;
 }
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 20 lines

From: Xuanqiang Luo <[email protected]>

A multi-packet WQE (MPWQE, added by commit 5af75c747e2a ("net/mlx5e:
Enhanced TX MPWQE for SKBs")) lets several packets share one WQE, so the control and Ethernet segments are fetched by the device once per batch instead of once per packet. This saves PCIe bandwidth and CPU cycles, but only if the WQE carries more than one packet.

With skb_tx_mpwqe enabled, which is the default, mlx5e_xmit() sends every skb accepted by mlx5e_tx_skb_supports_mpwqe() through an MPWQE session. A session stays open between two calls only while the stack sets xmit_more. A packet without xmit_more closes the session and rings the doorbell. Hence a packet that comes without xmit_more while no session is open opens a session just for itself and closes it right away. Such a WQE takes one WQEBB, as a regular WQE does for the same packet, and the [ ... ]
than a single packet MPWQE does (mlx5e_sq_calc_wqe_attr(), mlx5e_accel_tx_finish()): the instructions per byte of UDP_STREAM 65507 go up by 0.3-0.4%, which the gains above outweigh.

Quoted 1 line

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v2 1/1
#2 lore raw
In reply to Xuanqiang Luo
Quoted 23 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

A multi-packet WQE (MPWQE, added by commit 5af75c747e2a ("net/mlx5e:
Enhanced TX MPWQE for SKBs")) lets several packets share one WQE, so the control and Ethernet segments are fetched by the device once per batch instead of once per packet. This saves PCIe bandwidth and CPU cycles, but only if the WQE carries more than one packet.

With skb_tx_mpwqe enabled, which is the default, mlx5e_xmit() sends every skb accepted by mlx5e_tx_skb_supports_mpwqe() through an MPWQE session. A session stays open between two calls only while the stack sets xmit_more. A packet without xmit_more closes the session and rings the doorbell. Hence a packet that comes without xmit_more while no session is open opens a session just for itself and closes it right away. Such a WQE takes one WQEBB, as a regular WQE does for the same packet, and the doorbell is rung for each packet either way, so nothing is saved.

This is the case for the IP fragments of a large UDP datagram and for UDP request/response traffic, which reach the driver one packet at a time. With pktgen and burst 1 every MPWQE carries one packet (mpwqe_blks equals mpwqe_pkts, xmit_more is 0) and the packet rate is 15% lower than with skb_tx_mpwqe turned off.

Quoted 9 lines

Use the regular WQE path for a packet that has no xmit_more and no open session. Packets with xmit_more still open and extend a session, and the last packet of a batch still closes it, so batching is unchanged.

The only visible change besides the performance is in the statistics:
tx*_mpwqe_blks and tx*_mpwqe_pkts no longer count a packet sent alone. Such a packet is counted in tx*_packets, as any packet sent with a regular WQE.

I don't think that this paragraph is needed. Not worth a respin.

Quoted 7 lines

netperf and pktgen between two 10G ConnectX-5 hosts, 2-socket Hygon C86-4G 7490 sender on net-next, the patch switched at run time by a temporary module parameter (not part of this patch) so that before and after run in the same boot, mean of 3 boots x 2 rounds. "far" is a sender on the other socket than the NIC, "near" one on the NIC NUMA node:

test before after change

Quoted 9 lines
  UDP_STREAM 65507, far, Mbps            3255     3815   +17.2%
  UDP_STREAM 65507, near, Mbps           5619     5870    +4.5%
  UDP_RR 1 B, far, trans/s              57667    60688    +5.2%
  UDP_RR 1 B, near, trans/s             70538    71230    +1.0%
  TCP_RR 1 B, far, trans/s              56822    57124    +0.5%
  TCP_RR 1 B, near, trans/s             70048    70011    -0.1%
  pktgen 64 B burst 1, kpps              1487     1748   +17.5%
  pktgen 64 B burst 16, kpps             3192     3194    +0.1%

I didn't have a setup with 2 NUMAs at hand. But on a CX7 system with Intel Xeon Platinum 8380 I measured the near results:

    test                                 before    after   change
    UDP_STREAM 65507, Mbps                19755    20455    +3.5%
    UDP_STREAM 64, Mbps                     496      496    +0.1%
    UDP_RR 1 B, trans/s                   56317    56386    +0.1%
    TCP_RR 1 B, trans/s                   54084    54229    +0.3%
    pktgen 64 B burst 1, kpps              3014     3112    +3.3%
    pktgen 64 B burst 16, kpps            12530    12420    -0.9%

And the 16 packet burst is also a bit noisy so the degradation is less.

Quoted 53 lines

Batches do not regress: with burst 16, which uses xmit_more, the rate is unchanged. TCP_RR does not change beyond the noise, its skbs carry the data in page fragments and cannot use MPWQE.

The price is that the regular path runs a little more code for a packet than a single packet MPWQE does (mlx5e_sq_calc_wqe_attr(), mlx5e_accel_tx_finish()): the instructions per byte of UDP_STREAM 65507 go up by 0.3-0.4%, which the gains above outweigh.

---
Changes:
v2:
- Check xmit_more and the open session first, so that a lone packet skips the skb checks. (Suggested by Tariq.)
- Run the tests again with the new code and add netperf results to the commit message. (Suggested by Tariq.)
- Rebase onto the latest net-next/main.

v1: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/mellanox/mlx5/core/en_tx.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +5 -2
index 14479da98f42..5b5651c14750 100644
@@ -646,6 +646,7 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct mlx5e_priv *priv = netdev_priv(dev);
 	struct mlx5e_accel_tx_state accel = {};
+	bool xmit_more = netdev_xmit_more();
 	struct mlx5e_tx_wqe_attr wqe_attr;
 	struct mlx5e_tx_attr attr;
 	struct mlx5e_tx_wqe *wqe;
@@ -678,11 +679,13 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
 	mlx5e_sq_xmit_prepare(sq, skb, &accel, &attr);
 
 	if (test_bit(MLX5E_SQ_STATE_MPWQE, &sq->state)) {
-		if (mlx5e_tx_skb_supports_mpwqe(skb, &attr)) {
+		/* An MPWQE for a lone packet saves nothing, use a regular WQE. */
+		if ((xmit_more || mlx5e_tx_mpwqe_session_is_active(sq)) &&
+		    mlx5e_tx_skb_supports_mpwqe(skb, &attr)) {
 			struct mlx5_wqe_eth_seg eseg = {};
 
 			mlx5e_txwqe_build_eseg(priv, sq, skb, &accel, &eseg, attr.ihs);
-			mlx5e_sq_xmit_mpwqe(sq, skb, &eseg, netdev_xmit_more());
+			mlx5e_sq_xmit_mpwqe(sq, skb, &eseg, xmit_more);
 			return NETDEV_TX_OK;
 		}
 

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev) · line 706

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -1
@@ -697,7 +700,7 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
 	mlx5e_accel_tx_finish(sq, wqe, &accel,
 			      (struct mlx5_wqe_inline_seg *)(wqe->data + wqe_attr.ds_cnt_inl));
 	mlx5e_txwqe_build_eseg(priv, sq, skb, &accel, &wqe->eth, attr.ihs);
-	mlx5e_sq_xmit_wqe(sq, skb, &attr, &wqe_attr, wqe, pi, netdev_xmit_more());
+	mlx5e_sq_xmit_wqe(sq, skb, &attr, &wqe_attr, wqe, pi, xmit_more);
 
 	return NETDEV_TX_OK;
 }

The change makes sense to me:

Thanks for your patch!
Dragos

maintainer Reviewed-by
#3 lore raw
Quoted 124 lines · Dragos Tatulea
Quoted 23 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

A multi-packet WQE (MPWQE, added by commit 5af75c747e2a ("net/mlx5e:
Enhanced TX MPWQE for SKBs")) lets several packets share one WQE, so the control and Ethernet segments are fetched by the device once per batch instead of once per packet. This saves PCIe bandwidth and CPU cycles, but only if the WQE carries more than one packet.

With skb_tx_mpwqe enabled, which is the default, mlx5e_xmit() sends every skb accepted by mlx5e_tx_skb_supports_mpwqe() through an MPWQE session. A session stays open between two calls only while the stack sets xmit_more. A packet without xmit_more closes the session and rings the doorbell. Hence a packet that comes without xmit_more while no session is open opens a session just for itself and closes it right away. Such a WQE takes one WQEBB, as a regular WQE does for the same packet, and the doorbell is rung for each packet either way, so nothing is saved.

This is the case for the IP fragments of a large UDP datagram and for UDP request/response traffic, which reach the driver one packet at a time. With pktgen and burst 1 every MPWQE carries one packet (mpwqe_blks equals mpwqe_pkts, xmit_more is 0) and the packet rate is 15% lower than with skb_tx_mpwqe turned off.

Quoted 9 lines

Use the regular WQE path for a packet that has no xmit_more and no open session. Packets with xmit_more still open and extend a session, and the last packet of a batch still closes it, so batching is unchanged.

The only visible change besides the performance is in the statistics:
tx*_mpwqe_blks and tx*_mpwqe_pkts no longer count a packet sent alone. Such a packet is counted in tx*_packets, as any packet sent with a regular WQE.

I don't think that this paragraph is needed. Not worth a respin.

Quoted 6 lines

netperf and pktgen between two 10G ConnectX-5 hosts, 2-socket Hygon C86-4G 7490 sender on net-next, the patch switched at run time by a temporary module parameter (not part of this patch) so that before and after run in the same boot, mean of 3 boots x 2 rounds. "far" is a sender on the other socket than the NIC, "near" one on the NIC NUMA node:

Quoted 10 lines
   test                                 before    after   change
   UDP_STREAM 65507, far, Mbps            3255     3815   +17.2%
   UDP_STREAM 65507, near, Mbps           5619     5870    +4.5%
   UDP_RR 1 B, far, trans/s              57667    60688    +5.2%
   UDP_RR 1 B, near, trans/s             70538    71230    +1.0%
   TCP_RR 1 B, far, trans/s              56822    57124    +0.5%
   TCP_RR 1 B, near, trans/s             70048    70011    -0.1%
   pktgen 64 B burst 1, kpps              1487     1748   +17.5%
   pktgen 64 B burst 16, kpps             3192     3194    +0.1%

I didn't have a setup with 2 NUMAs at hand. But on a CX7 system with Intel Xeon Platinum 8380 I measured the near results:

     test                                 before    after   change
     UDP_STREAM 65507, Mbps                19755    20455    +3.5%
     UDP_STREAM 64, Mbps                     496      496    +0.1%
     UDP_RR 1 B, trans/s                   56317    56386    +0.1%
     TCP_RR 1 B, trans/s                   54084    54229    +0.3%
     pktgen 64 B burst 1, kpps              3014     3112    +3.3%
     pktgen 64 B burst 16, kpps            12530    12420    -0.9%

And the 16 packet burst is also a bit noisy so the degradation is less.

Quoted 59 lines

Batches do not regress: with burst 16, which uses xmit_more, the rate is unchanged. TCP_RR does not change beyond the noise, its skbs carry the data in page fragments and cannot use MPWQE.

The price is that the regular path runs a little more code for a packet than a single packet MPWQE does (mlx5e_sq_calc_wqe_attr(), mlx5e_accel_tx_finish()): the instructions per byte of UDP_STREAM 65507 go up by 0.3-0.4%, which the gains above outweigh.

---
Changes:
v2:
- Check xmit_more and the open session first, so that a lone packet skips the skb checks. (Suggested by Tariq.)
- Run the tests again with the new code and add netperf results to the commit message. (Suggested by Tariq.)
- Rebase onto the latest net-next/main.

v1: https://lore.kernel.org/all/[email protected]/

  drivers/net/ethernet/mellanox/mlx5/core/en_tx.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +6 -3
index 14479da98f42..5b5651c14750 100644
@@ -646,6 +646,7 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
  {
  	struct mlx5e_priv *priv = netdev_priv(dev);
  	struct mlx5e_accel_tx_state accel = {};
+	bool xmit_more = netdev_xmit_more();
  	struct mlx5e_tx_wqe_attr wqe_attr;
  	struct mlx5e_tx_attr attr;
  	struct mlx5e_tx_wqe *wqe;
@@ -678,11 +679,13 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
  	mlx5e_sq_xmit_prepare(sq, skb, &accel, &attr);
 
  	if (test_bit(MLX5E_SQ_STATE_MPWQE, &sq->state)) {
-		if (mlx5e_tx_skb_supports_mpwqe(skb, &attr)) {
+		/* An MPWQE for a lone packet saves nothing, use a regular WQE. */
+		if ((xmit_more || mlx5e_tx_mpwqe_session_is_active(sq)) &&
+		    mlx5e_tx_skb_supports_mpwqe(skb, &attr)) {
  			struct mlx5_wqe_eth_seg eseg = {};
 
  			mlx5e_txwqe_build_eseg(priv, sq, skb, &accel, &eseg, attr.ihs);
-			mlx5e_sq_xmit_mpwqe(sq, skb, &eseg, netdev_xmit_more());
+			mlx5e_sq_xmit_mpwqe(sq, skb, &eseg, xmit_more);
  			return NETDEV_TX_OK;
  		}
 
@@ -697,7 +700,7 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
  	mlx5e_accel_tx_finish(sq, wqe, &accel,
  			      (struct mlx5_wqe_inline_seg *)(wqe->data + wqe_attr.ds_cnt_inl));
  	mlx5e_txwqe_build_eseg(priv, sq, skb, &accel, &wqe->eth, attr.ihs);
-	mlx5e_sq_xmit_wqe(sq, skb, &attr, &wqe_attr, wqe, pi, netdev_xmit_more());
+	mlx5e_sq_xmit_wqe(sq, skb, &attr, &wqe_attr, wqe, pi, xmit_more);
 
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev) · line 706

Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +0 -0
  	return NETDEV_TX_OK;
  }

The change makes sense to me:

Thanks for your patch!
Dragos

Thanks.