Skip to content

Commit 9908aa2

Browse files
Tariq Toukandavem330
authored andcommitted
net/mlx5e: CQE based moderation
In this mode the moderation timer will restart upon new completion (CQE) generation rather than upon interrupt generation. The outcome is that for bursty traffic the period timer will never expire and thus only the moderation frames counter will dictate interrupt generation, thus the interrupt rate will be relative to the incoming packets size. If the burst seizes for "moderation period" time then an interrupt will be issued immediately. CQE based moderation is off by default and can be controlled via ethtool set_priv_flags. Performance tested on ConnectX4-Lx 50G. Less packet loss in netperf UDP and TCP tests, with no bw degradation, for both single and multi streams, with message sizes of 64, 1024, 1472 and 32768 byte. Signed-off-by: Tariq Toukan <tariqt@mellanox.com> Signed-off-by: Achiad Shochat <achiad@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Gal Pressman <galp@mellanox.com> Signed-off-by: Gil Rockah <gilr@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4e59e28 commit 9908aa2

3 files changed

Lines changed: 95 additions & 33 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/en.h‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979

8080
#define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (64 * 1024)
8181
#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10
82+
#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3
8283
#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20
8384
#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC 0x10
8485
#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20
@@ -145,11 +146,11 @@ struct mlx5e_umr_wqe {
145146
};
146147

147148
static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = {
148-
"nop",
149+
"rx_cqe_moder",
149150
};
150151

151152
enum mlx5e_priv_flag {
152-
MLX5E_PFLAG_NOP = (1 << 0),
153+
MLX5E_PFLAG_RX_CQE_BASED_MODER = (1 << 0),
153154
};
154155

155156
#define MLX5E_SET_PRIV_FLAG(priv, pflag, enable) \
@@ -165,6 +166,11 @@ enum mlx5e_priv_flag {
165166
#define MLX5E_MIN_BW_ALLOC 1 /* Min percentage of BW allocation */
166167
#endif
167168

169+
struct mlx5e_cq_moder {
170+
u16 usec;
171+
u16 pkts;
172+
};
173+
168174
struct mlx5e_params {
169175
u8 log_sq_size;
170176
u8 rq_wq_type;
@@ -173,12 +179,11 @@ struct mlx5e_params {
173179
u8 log_rq_size;
174180
u16 num_channels;
175181
u8 num_tc;
182+
u8 rx_cq_period_mode;
176183
bool rx_cqe_compress_admin;
177184
bool rx_cqe_compress;
178-
u16 rx_cq_moderation_usec;
179-
u16 rx_cq_moderation_pkts;
180-
u16 tx_cq_moderation_usec;
181-
u16 tx_cq_moderation_pkts;
185+
struct mlx5e_cq_moder rx_cq_moderation;
186+
struct mlx5e_cq_moder tx_cq_moderation;
182187
u16 min_rx_wqes;
183188
bool lro_en;
184189
u32 lro_wqe_sz;
@@ -667,6 +672,9 @@ void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
667672
int num_channels);
668673
int mlx5e_get_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
669674

675+
void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params,
676+
u8 cq_period_mode);
677+
670678
static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
671679
struct mlx5_wqe_ctrl_seg *ctrl, int bf_sz)
672680
{

‎drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c‎

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ static int mlx5e_get_coalesce(struct net_device *netdev,
524524
if (!MLX5_CAP_GEN(priv->mdev, cq_moderation))
525525
return -ENOTSUPP;
526526

527-
coal->rx_coalesce_usecs = priv->params.rx_cq_moderation_usec;
528-
coal->rx_max_coalesced_frames = priv->params.rx_cq_moderation_pkts;
529-
coal->tx_coalesce_usecs = priv->params.tx_cq_moderation_usec;
530-
coal->tx_max_coalesced_frames = priv->params.tx_cq_moderation_pkts;
527+
coal->rx_coalesce_usecs = priv->params.rx_cq_moderation.usec;
528+
coal->rx_max_coalesced_frames = priv->params.rx_cq_moderation.pkts;
529+
coal->tx_coalesce_usecs = priv->params.tx_cq_moderation.usec;
530+
coal->tx_max_coalesced_frames = priv->params.tx_cq_moderation.pkts;
531531

532532
return 0;
533533
}
@@ -545,10 +545,11 @@ static int mlx5e_set_coalesce(struct net_device *netdev,
545545
return -ENOTSUPP;
546546

547547
mutex_lock(&priv->state_lock);
548-
priv->params.tx_cq_moderation_usec = coal->tx_coalesce_usecs;
549-
priv->params.tx_cq_moderation_pkts = coal->tx_max_coalesced_frames;
550-
priv->params.rx_cq_moderation_usec = coal->rx_coalesce_usecs;
551-
priv->params.rx_cq_moderation_pkts = coal->rx_max_coalesced_frames;
548+
549+
priv->params.tx_cq_moderation.usec = coal->tx_coalesce_usecs;
550+
priv->params.tx_cq_moderation.pkts = coal->tx_max_coalesced_frames;
551+
priv->params.rx_cq_moderation.usec = coal->rx_coalesce_usecs;
552+
priv->params.rx_cq_moderation.pkts = coal->rx_max_coalesced_frames;
552553

553554
if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
554555
goto out;
@@ -1279,9 +1280,37 @@ static int mlx5e_get_module_eeprom(struct net_device *netdev,
12791280

12801281
typedef int (*mlx5e_pflag_handler)(struct net_device *netdev, bool enable);
12811282

1282-
static int set_pflag_nop(struct net_device *netdev, bool enable)
1283+
static int set_pflag_rx_cqe_based_moder(struct net_device *netdev, bool enable)
12831284
{
1284-
return 0;
1285+
struct mlx5e_priv *priv = netdev_priv(netdev);
1286+
struct mlx5_core_dev *mdev = priv->mdev;
1287+
bool rx_mode_changed;
1288+
u8 rx_cq_period_mode;
1289+
int err = 0;
1290+
bool reset;
1291+
1292+
rx_cq_period_mode = enable ?
1293+
MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
1294+
MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
1295+
rx_mode_changed = rx_cq_period_mode != priv->params.rx_cq_period_mode;
1296+
1297+
if (rx_cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE &&
1298+
!MLX5_CAP_GEN(mdev, cq_period_start_from_cqe))
1299+
return -ENOTSUPP;
1300+
1301+
if (!rx_mode_changed)
1302+
return 0;
1303+
1304+
reset = test_bit(MLX5E_STATE_OPENED, &priv->state);
1305+
if (reset)
1306+
mlx5e_close_locked(netdev);
1307+
1308+
mlx5e_set_rx_cq_mode_params(&priv->params, rx_cq_period_mode);
1309+
1310+
if (reset)
1311+
err = mlx5e_open_locked(netdev);
1312+
1313+
return err;
12851314
}
12861315

12871316
static int mlx5e_handle_pflag(struct net_device *netdev,
@@ -1315,8 +1344,9 @@ static int mlx5e_set_priv_flags(struct net_device *netdev, u32 pflags)
13151344

13161345
mutex_lock(&priv->state_lock);
13171346

1318-
err = mlx5e_handle_pflag(netdev, pflags, MLX5E_PFLAG_NOP,
1319-
set_pflag_nop);
1347+
err = mlx5e_handle_pflag(netdev, pflags,
1348+
MLX5E_PFLAG_RX_CQE_BASED_MODER,
1349+
set_pflag_rx_cqe_based_moder);
13201350

13211351
mutex_unlock(&priv->state_lock);
13221352
return err ? -EINVAL : 0;

‎drivers/net/ethernet/mellanox/mlx5/core/en_main.c‎

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct mlx5e_cq_param {
5555
u32 cqc[MLX5_ST_SZ_DW(cqc)];
5656
struct mlx5_wq_param wq;
5757
u16 eq_ix;
58+
u8 cq_period_mode;
5859
};
5960

6061
struct mlx5e_channel_param {
@@ -896,6 +897,7 @@ static int mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param)
896897

897898
mlx5_vector2eqn(mdev, param->eq_ix, &eqn, &irqn_not_used);
898899

900+
MLX5_SET(cqc, cqc, cq_period_mode, param->cq_period_mode);
899901
MLX5_SET(cqc, cqc, c_eqn, eqn);
900902
MLX5_SET(cqc, cqc, uar_page, mcq->uar->index);
901903
MLX5_SET(cqc, cqc, log_page_size, cq->wq_ctrl.buf.page_shift -
@@ -925,8 +927,7 @@ static void mlx5e_disable_cq(struct mlx5e_cq *cq)
925927
static int mlx5e_open_cq(struct mlx5e_channel *c,
926928
struct mlx5e_cq_param *param,
927929
struct mlx5e_cq *cq,
928-
u16 moderation_usecs,
929-
u16 moderation_frames)
930+
struct mlx5e_cq_moder moderation)
930931
{
931932
int err;
932933
struct mlx5e_priv *priv = c->priv;
@@ -942,8 +943,8 @@ static int mlx5e_open_cq(struct mlx5e_channel *c,
942943

943944
if (MLX5_CAP_GEN(mdev, cq_moderation))
944945
mlx5_core_modify_cq_moderation(mdev, &cq->mcq,
945-
moderation_usecs,
946-
moderation_frames);
946+
moderation.usec,
947+
moderation.pkts);
947948
return 0;
948949

949950
err_destroy_cq:
@@ -972,8 +973,7 @@ static int mlx5e_open_tx_cqs(struct mlx5e_channel *c,
972973

973974
for (tc = 0; tc < c->num_tc; tc++) {
974975
err = mlx5e_open_cq(c, &cparam->tx_cq, &c->sq[tc].cq,
975-
priv->params.tx_cq_moderation_usec,
976-
priv->params.tx_cq_moderation_pkts);
976+
priv->params.tx_cq_moderation);
977977
if (err)
978978
goto err_close_tx_cqs;
979979
}
@@ -1110,6 +1110,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
11101110
struct mlx5e_channel_param *cparam,
11111111
struct mlx5e_channel **cp)
11121112
{
1113+
struct mlx5e_cq_moder icosq_cq_moder = {0, 0};
11131114
struct net_device *netdev = priv->netdev;
11141115
int cpu = mlx5e_get_cpu(priv, ix);
11151116
struct mlx5e_channel *c;
@@ -1133,7 +1134,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
11331134

11341135
netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
11351136

1136-
err = mlx5e_open_cq(c, &cparam->icosq_cq, &c->icosq.cq, 0, 0);
1137+
err = mlx5e_open_cq(c, &cparam->icosq_cq, &c->icosq.cq, icosq_cq_moder);
11371138
if (err)
11381139
goto err_napi_del;
11391140

@@ -1142,8 +1143,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
11421143
goto err_close_icosq_cq;
11431144

11441145
err = mlx5e_open_cq(c, &cparam->rx_cq, &c->rq.cq,
1145-
priv->params.rx_cq_moderation_usec,
1146-
priv->params.rx_cq_moderation_pkts);
1146+
priv->params.rx_cq_moderation);
11471147
if (err)
11481148
goto err_close_tx_cqs;
11491149

@@ -1308,6 +1308,8 @@ static void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
13081308
}
13091309

13101310
mlx5e_build_common_cq_param(priv, param);
1311+
1312+
param->cq_period_mode = priv->params.rx_cq_period_mode;
13111313
}
13121314

13131315
static void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
@@ -1318,6 +1320,8 @@ static void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
13181320
MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_sq_size);
13191321

13201322
mlx5e_build_common_cq_param(priv, param);
1323+
1324+
param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
13211325
}
13221326

13231327
static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
@@ -1329,6 +1333,8 @@ static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
13291333
MLX5_SET(cqc, cqc, log_cq_size, log_wq_size);
13301334

13311335
mlx5e_build_common_cq_param(priv, param);
1336+
1337+
param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
13321338
}
13331339

13341340
static void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
@@ -2856,6 +2862,20 @@ static bool cqe_compress_heuristic(u32 link_speed, u32 pci_bw)
28562862
(pci_bw < 40000) && (pci_bw < link_speed));
28572863
}
28582864

2865+
void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode)
2866+
{
2867+
params->rx_cq_period_mode = cq_period_mode;
2868+
2869+
params->rx_cq_moderation.pkts =
2870+
MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
2871+
params->rx_cq_moderation.usec =
2872+
MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC;
2873+
2874+
if (cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE)
2875+
params->rx_cq_moderation.usec =
2876+
MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE;
2877+
}
2878+
28592879
static void mlx5e_build_netdev_priv(struct mlx5_core_dev *mdev,
28602880
struct net_device *netdev,
28612881
int num_channels)
@@ -2908,13 +2928,13 @@ static void mlx5e_build_netdev_priv(struct mlx5_core_dev *mdev,
29082928

29092929
priv->params.min_rx_wqes = mlx5_min_rx_wqes(priv->params.rq_wq_type,
29102930
BIT(priv->params.log_rq_size));
2911-
priv->params.rx_cq_moderation_usec =
2912-
MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC;
2913-
priv->params.rx_cq_moderation_pkts =
2914-
MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
2915-
priv->params.tx_cq_moderation_usec =
2931+
2932+
mlx5e_set_rx_cq_mode_params(&priv->params,
2933+
MLX5_CQ_PERIOD_MODE_START_FROM_EQE);
2934+
2935+
priv->params.tx_cq_moderation.usec =
29162936
MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC;
2917-
priv->params.tx_cq_moderation_pkts =
2937+
priv->params.tx_cq_moderation.pkts =
29182938
MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS;
29192939
priv->params.tx_max_inline = mlx5e_get_max_inline_cap(mdev);
29202940
priv->params.num_tc = 1;
@@ -2929,6 +2949,10 @@ static void mlx5e_build_netdev_priv(struct mlx5_core_dev *mdev,
29292949
priv->params.lro_wqe_sz =
29302950
MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
29312951

2952+
/* Initialize pflags */
2953+
MLX5E_SET_PRIV_FLAG(priv, MLX5E_PFLAG_RX_CQE_BASED_MODER,
2954+
priv->params.rx_cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE);
2955+
29322956
priv->mdev = mdev;
29332957
priv->netdev = netdev;
29342958
priv->params.num_channels = num_channels;

0 commit comments

Comments
 (0)