net/mlx5: add option to reduce Tx datapath compilation time
PATCH 1/1 net/mlx5: add option to reduce Tx datapath compilation time
The mlx5 Tx datapath compiles 42 variants of the burst function, each a specialization of mlx5_tx_burst_tmpl() with a different combination of offload flags. The compiler must instantiate and optimize the entire 3800+ line template for every variant, which dominates build time for all the code base.
When MLX5_MINIMAL_TX is defined, only 11 variants are compiled instead of 42. Two new "full without inline" superset variants (full_noi and full_noi_empw) are introduced to satisfy the selection algorithm constraint that the INLINE bit must match exactly between request and variant. The remaining 9 variants are existing ones that already cover all reachable combinations of the EMPW, MPW, INLINE and TXPP flags.
The selection function is unchanged. At runtime, it picks the best matching variant from whatever is available. With the minimal set, each selected variant may include a few unnecessary offload checks compared to the precisely-tailored original, which has negligible impact on performance since modern branch predictors handle static never-taken branches well.
Compilation times (MM:SS) measured on Intel Core Ultra 7 165U with GCC 16.0.1:
FILE BUILD BEFORE AFTER DELTA
================= ============== ======== ======= ===============
mlx5_tx_mpw.c debug 00:31 00:22 -00:09 (-29.0%) mlx5_tx_txpp.c 00:39 00:25 -00:14 (-35.9%) mlx5_tx_empw.c 01:11 00:19 -00:52 (-73.2%) mlx5_tx_nompw.c 01:13 00:16 -00:57 (-78.1%) ----------------- -------------- -------- ------- --------------- mlx5_tx_mpw.c debug+asan 03:15 02:45 -00:30 (-15.4%) mlx5_tx_txpp.c *06:28* 03:13 -03:15 (-50.3%) mlx5_tx_empw.c *12:07* 01:55 -10:12 (-84.2%) mlx5_tx_nompw.c *12:54* 01:45 -11:09 (-86.4%) ----------------- -------------- -------- ------- --------------- mlx5_tx_mpw.c release 00:12 00:09 -00:03 (-25.0%) mlx5_tx_txpp.c 00:31 00:24 -00:07 (-22.6%) mlx5_tx_empw.c 00:32 00:18 -00:14 (-43.8%) mlx5_tx_nompw.c 00:34 00:16 -00:18 (-52.9%) ----------------- -------------- -------- ------- --------------- mlx5_tx_mpw.c release+asan 00:25 00:23 -00:02 (-8.0%) mlx5_tx_empw.c 01:24 00:42 -00:42 (-50.0%) mlx5_tx_txpp.c 01:32 00:59 -00:33 (-35.9%) mlx5_tx_nompw.c 01:38 00:37 -01:01 (-62.2%)
To enable, pass -DMLX5_MINIMAL_TX via c_args:
meson setup build -Dc_args='-DMLX5_MINIMAL_TX'
--- drivers/net/mlx5/mlx5_tx.c | 23 +++++++++++++++++++++++ drivers/net/mlx5/mlx5_tx.h | 12 ++++++++++++ drivers/net/mlx5/mlx5_tx_empw.c | 10 ++++++++++ drivers/net/mlx5/mlx5_tx_mpw.c | 2 ++ drivers/net/mlx5/mlx5_tx_nompw.c | 9 +++++++++ drivers/net/mlx5/mlx5_tx_txpp.c | 2 ++ 6 files changed, 58 insertions(+)
drivers/net/mlx5/mlx5_tx.c +23 -0
@@ -294,6 +294,14 @@ MLX5_TXOFF_INFO(full_empw, MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW) +#ifdef MLX5_MINIMAL_TX +MLX5_TXOFF_INFO (full_noi_empw, +MLX5_TXOFF_CONFIG_MULTI |MLX5_TXOFF_CONFIG_TSO | +MLX5_TXOFF_CONFIG_SWP |MLX5_TXOFF_CONFIG_CSUM | +MLX5_TXOFF_CONFIG_VLAN |MLX5_TXOFF_CONFIG_METADATA | + MLX5_TXOFF_CONFIG_EMPW) +#else +MLX5_TXOFF_INFO (none_empw,MLX5_TXOFF_CONFIG_NONE |MLX5_TXOFF_CONFIG_EMPW )
@@ -355,6 +363,8 @@ MLX5_TXOFF_INFO(iv_empw, MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW) +#endif /* !MLX5_MINIMAL_TX */ +MLX5_TXOFF_INFO (full_ts_nompw,MLX5_TXOFF_CONFIG_FULL |MLX5_TXOFF_CONFIG_TXPP )
@@ -374,6 +384,7 @@ MLX5_TXOFF_INFO(full_ts_noi, MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW) +#ifndef MLX5_MINIMAL_TX MLX5_TXOFF_INFO (none_ts,MLX5_TXOFF_CONFIG_NONE |MLX5_TXOFF_CONFIG_TXPP |MLX5_TXOFF_CONFIG_EMPW )
@@ -392,6 +403,7 @@ MLX5_TXOFF_INFO(mtiv_ts, MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW) +#endif MLX5_TXOFF_INFO(full, MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
@@ -399,6 +411,13 @@ MLX5_TXOFF_INFO(full, MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA) +#ifdef MLX5_MINIMAL_TX +MLX5_TXOFF_INFO (full_noi, +MLX5_TXOFF_CONFIG_MULTI |MLX5_TXOFF_CONFIG_TSO | +MLX5_TXOFF_CONFIG_SWP |MLX5_TXOFF_CONFIG_CSUM | + MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA) +#else +MLX5_TXOFF_INFO (none,MLX5_TXOFF_CONFIG_NONE )
@@ -460,6 +479,8 @@ MLX5_TXOFF_INFO(iv, MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA) +#endif /* !MLX5_MINIMAL_TX */ +MLX5_TXOFF_INFO (none_mpw,MLX5_TXOFF_CONFIG_NONE |MLX5_TXOFF_CONFIG_EMPW |MLX5_TXOFF_CONFIG_MPW )
@@ -473,9 +494,11 @@ MLX5_TXOFF_INFO(mc_mpw, MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_CSUM | MLX5_TXOFF_CONFIG_EMPW | MLX5_TXOFF_CONFIG_MPW) +#ifndef MLX5_MINIMAL_TX MLX5_TXOFF_INFO (i_mpw,MLX5_TXOFF_CONFIG_INLINE |MLX5_TXOFF_CONFIG_EMPW | MLX5_TXOFF_CONFIG_MPW) +#endif };/**
drivers/net/mlx5/mlx5_tx.h +12 -0
@@ -244,6 +244,9 @@ int mlx5_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,/* mlx5_tx_empw.c */ MLX5_TXOFF_PRE_DECL (full_empw); +#ifdef MLX5_MINIMAL_TX +MLX5_TXOFF_PRE_DECL (full_noi_empw); +#else MLX5_TXOFF_PRE_DECL (none_empw);MLX5_TXOFF_PRE_DECL (md_empw);MLX5_TXOFF_PRE_DECL (mt_empw);
@@ -258,10 +261,14 @@ MLX5_TXOFF_PRE_DECL(sciv_empw);MLX5_TXOFF_PRE_DECL (i_empw);MLX5_TXOFF_PRE_DECL (v_empw);MLX5_TXOFF_PRE_DECL (iv_empw); +#endif /* mlx5_tx_nompw.c */ MLX5_TXOFF_PRE_DECL (full); +#ifdef MLX5_MINIMAL_TX +MLX5_TXOFF_PRE_DECL (full_noi); +#else MLX5_TXOFF_PRE_DECL (none);MLX5_TXOFF_PRE_DECL (md);MLX5_TXOFF_PRE_DECL (mt);
@@ -276,6 +283,7 @@ MLX5_TXOFF_PRE_DECL(sciv);MLX5_TXOFF_PRE_DECL (i);MLX5_TXOFF_PRE_DECL (v);MLX5_TXOFF_PRE_DECL (iv); +#endif /* mlx5_tx_txpp.c */
@@ -283,17 +291,21 @@ MLX5_TXOFF_PRE_DECL(full_ts_nompw);MLX5_TXOFF_PRE_DECL (full_ts_nompwi);MLX5_TXOFF_PRE_DECL (full_ts);MLX5_TXOFF_PRE_DECL (full_ts_noi); +#ifndef MLX5_MINIMAL_TX MLX5_TXOFF_PRE_DECL (none_ts);MLX5_TXOFF_PRE_DECL (mdi_ts);MLX5_TXOFF_PRE_DECL (mti_ts);MLX5_TXOFF_PRE_DECL (mtiv_ts); +#endif /* mlx5_tx_mpw.c */ MLX5_TXOFF_PRE_DECL (none_mpw);MLX5_TXOFF_PRE_DECL (mci_mpw);MLX5_TXOFF_PRE_DECL (mc_mpw); +#ifndef MLX5_MINIMAL_TX MLX5_TXOFF_PRE_DECL (i_mpw); +#endif static __rte_always_inline struct mlx5_uar_data *mlx5_tx_bfreg (struct mlx5_txq_data *txq)
drivers/net/mlx5/mlx5_tx_empw.c +10 -0
@@ -9,6 +9,14 @@MLX5_TXOFF_DECL (full_empw, MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_EMPW) +#ifdef MLX5_MINIMAL_TX +MLX5_TXOFF_DECL (full_noi_empw, +MLX5_TXOFF_CONFIG_MULTI |MLX5_TXOFF_CONFIG_TSO | +MLX5_TXOFF_CONFIG_SWP |MLX5_TXOFF_CONFIG_CSUM | +MLX5_TXOFF_CONFIG_VLAN |MLX5_TXOFF_CONFIG_METADATA | + MLX5_TXOFF_CONFIG_EMPW) +#else +MLX5_TXOFF_DECL (none_empw,MLX5_TXOFF_CONFIG_NONE |MLX5_TXOFF_CONFIG_EMPW )
@@ -69,3 +77,5 @@ MLX5_TXOFF_DECL(v_empw,MLX5_TXOFF_DECL (iv_empw,MLX5_TXOFF_CONFIG_INLINE |MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW) + +#endif /* !MLX5_MINIMAL_TX */
drivers/net/mlx5/mlx5_tx_mpw.c +2 -0
@@ -29,6 +29,8 @@ MLX5_TXOFF_DECL(mc_mpw, MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_CSUM | MLX5_TXOFF_CONFIG_EMPW | MLX5_TXOFF_CONFIG_MPW) +#ifndef MLX5_MINIMAL_TX MLX5_TXOFF_DECL (i_mpw,MLX5_TXOFF_CONFIG_INLINE |MLX5_TXOFF_CONFIG_EMPW | MLX5_TXOFF_CONFIG_MPW) +#endif
drivers/net/mlx5/mlx5_tx_nompw.c +9 -0
@@ -9,6 +9,13 @@MLX5_TXOFF_DECL (full, MLX5_TXOFF_CONFIG_FULL) +#ifdef MLX5_MINIMAL_TX +MLX5_TXOFF_DECL (full_noi, +MLX5_TXOFF_CONFIG_MULTI |MLX5_TXOFF_CONFIG_TSO | +MLX5_TXOFF_CONFIG_SWP |MLX5_TXOFF_CONFIG_CSUM | + MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA) +#else +MLX5_TXOFF_DECL (none,MLX5_TXOFF_CONFIG_NONE )
@@ -69,3 +76,5 @@ MLX5_TXOFF_DECL(v,MLX5_TXOFF_DECL (iv,MLX5_TXOFF_CONFIG_INLINE |MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA) + +#endif /* !MLX5_MINIMAL_TX */
drivers/net/mlx5/mlx5_tx_txpp.c +2 -0
@@ -25,6 +25,7 @@ MLX5_TXOFF_DECL(full_ts_noi, MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW) +#ifndef MLX5_MINIMAL_TX MLX5_TXOFF_DECL (none_ts,MLX5_TXOFF_CONFIG_NONE |MLX5_TXOFF_CONFIG_TXPP |MLX5_TXOFF_CONFIG_EMPW )
@@ -43,3 +44,4 @@ MLX5_TXOFF_DECL(mtiv_ts, MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW) +#endif /* !MLX5_MINIMAL_TX */
Signature · 1 line
2.53.0
Quoted 5 lines · On Tue, 21 Apr 2026 23:23:55 +0200 Robin Jarry <[email protected]> wrote:
The mlx5 Tx datapath compiles 42 variants of the burst function, each a specialization of
mlx5_tx_burst_tmpl()with a different combination of offload flags. The compiler must instantiate and optimize the entire 3800+ line template for every variant, which dominates build time for all the code base.
PS: I am going to reject any new drivers that do this kind of nonsense. The cnxk and mlx5 drivers are setting a bad precedent.
Quoted 45 lines · Robin Jarry
The mlx5 Tx datapath compiles 42 variants of the burst function, each a specialization of
mlx5_tx_burst_tmpl()with a different combination of offload flags. The compiler must instantiate and optimize the entire 3800+ line template for every variant, which dominates build time for all the code base.When
MLX5_MINIMAL_TXis defined, only 11 variants are compiled instead of 42. Two new "full without inline" superset variants (full_noiandfull_noi_empw) are introduced to satisfy the selection algorithm constraint that the INLINE bit must match exactly between request and variant. The remaining 9 variants are existing ones that already cover all reachable combinations of the EMPW, MPW, INLINE and TXPP flags.The selection function is unchanged. At runtime, it picks the best matching variant from whatever is available. With the minimal set, each selected variant may include a few unnecessary offload checks compared to the precisely-tailored original, which has negligible impact on performance since modern branch predictors handle static never-taken branches well.
Compilation times (MM:SS) measured on Intel Core Ultra 7 165U with GCC 16.0.1:
FILE BUILD BEFORE AFTER DELTA
================= ============== ======== ======= ===============mlx5_tx_mpw.c debug 00:31 00:22 -00:09 (-29.0%) mlx5_tx_txpp.c 00:39 00:25 -00:14 (-35.9%) mlx5_tx_empw.c 01:11 00:19 -00:52 (-73.2%) mlx5_tx_nompw.c 01:13 00:16 -00:57 (-78.1%) ----------------- -------------- -------- ------- --------------- mlx5_tx_mpw.c debug+asan 03:15 02:45 -00:30 (-15.4%) mlx5_tx_txpp.c *06:28* 03:13 -03:15 (-50.3%) mlx5_tx_empw.c *12:07* 01:55 -10:12 (-84.2%) mlx5_tx_nompw.c *12:54* 01:45 -11:09 (-86.4%) ----------------- -------------- -------- ------- --------------- mlx5_tx_mpw.c release 00:12 00:09 -00:03 (-25.0%) mlx5_tx_txpp.c 00:31 00:24 -00:07 (-22.6%) mlx5_tx_empw.c 00:32 00:18 -00:14 (-43.8%) mlx5_tx_nompw.c 00:34 00:16 -00:18 (-52.9%) ----------------- -------------- -------- ------- --------------- mlx5_tx_mpw.c release+asan 00:25 00:23 -00:02 (-8.0%) mlx5_tx_empw.c 01:24 00:42 -00:42 (-50.0%) mlx5_tx_txpp.c 01:32 00:59 -00:33 (-35.9%) mlx5_tx_nompw.c 01:38 00:37 -01:01 (-62.2%)
Quoted 5 lines
To enable, pass -DMLX5_MINIMAL_TX via
c_args:meson setup build -Dc_args='-DMLX5_MINIMAL_TX'
Signed-off-by Robin Jarry <[email protected]>
Out of interest, do you have any numbers for the performance delta between the release builds with and without the new flag? I'm just wondering if the flag can be the default to speed up builds generally? [Not that it should affect me that much, I generally use -Denable_drivers flag when configuring my builds to only select the specific drivers I want]
/Bruce
Bruce Richardson, Apr 22, 2026 at 09:27:
Quoted 3 lines
Out of interest, do you have any numbers for the performance delta between the release builds with and without the new flag? I'm just wondering if the flag can be the default to speed up builds generally?
The raw performance will depend on which offload features are enabled. I have tested with the hardware I have at hand and these 3 TX offload combinations:
0x10000: FAST_FREE0x10020: FAST_FREE TCP_TSO0x1008f: FAST_FREE TCP_TSO UDP_TSO UDP_CKSUM TCP_CKSUM IPV4_CKSUM VLAN_INSERT
MINIMAL_TX TX_OFFLOADS TX_FUNC NON_DROP_RATE
============ ============== ============================ ==============
off 0x10000 mlx5_tx_burst_none_empw 42.4M off 0x10020 mlx5_tx_burst_mt_empw 39.4M off 0x1008f mlx5_tx_burst_sciv_empw 30.2M on 0x10000 mlx5_tx_burst_full_noi_empw 36.2M on 0x10020 mlx5_tx_burst_full_noi_empw 36.2M on 0x1008f mlx5_tx_burst_full_empw 30.2M
There is obviously something wrong with my patch. I need to make sure the *no offload* case does not result in -15% of performance.
Quoted 3 lines
[Not that it should affect me that much, I generally use -Denable_drivers flag when configuring my builds to only select the specific drivers I want]
I usually do this too but it turns out I *always* need mlx5 ;)