net/mlx5e: Batch RCU grace periods on channel open and close
Subsystems (7)
Tariq Toukan
maintainerv3 cover net/mlx5e: Batch RCU grace periods on channel open and close
Hi,
This series by Carolina reduces the time mlx5e spends waiting for RCU grace periods when bringing an interface up or down with many channels.
Today the channel open and close flows call synchronize_net() per object. On close, RQ, ICOSQ, TX SQ and NAPI teardown each require a grace period, so the number of waits scales with the number of channels. TX SQ teardown adds a wait per traffic class, and XDP and QoS can add more. On activation, mlx5e_activate_channels() triggers the ICOSQ of every channel, and each trigger waits for its own grace period. With a large channel count this makes link down and link up slow.
Patch 1 batches the waits on channel close. Channel deactivate and close are split into pre_sync and post_sync phases: the ENABLED state is first cleared on all queues of all channels, a single grace period is awaited, and only then does the teardown continue. Once NAPI is disabled on all channels, one more grace period is awaited, as the poll may still arm the CQs after napi_complete_done(). The queues are then closed and the NAPI instances are unlinked with __netif_napi_del_locked(), followed by one synchronize_net() before the channels are freed. The existing per object synchronize_net() calls are kept for single queue paths. The change touches the regular channels as well as the PTP, QoS, XDP and XSK queues.
Patch 2 does the same for the ICOSQ trigger on activation: all channel ICOSQs are first marked as requiring locking, one grace period is awaited, and then all of them are triggered. mlx5e_trigger_napi_icosq() keeps its existing semantics for standalone callers.
Results with 248 channels and rcu_normal=1:
- ip link set eth2 down: 11.837s before, 0.817s after.
- ip link set eth2 up: 4.087s before, 1.080s after.
Regards,
Tariq
V3:
- Wait for one more grace period after napi_disable() in deactivate, so close can destroy the queues before its single synchronize_net(). This fixes the page pool and PTP SQ recovery issues from V2, and makes the close path simpler and cleaner, with no separate page pool unlink step.
- Drop the synchronize_net() in mlx5e_close_xdpsq() instead of splitting it, as its callers already wait for a grace period or run before NAPI is enabled.
- Test and clear the XSK state bit once on close, instead of using xsk_pool to decide on XSK teardown.
- Add a sync_needed parameter to mlx5e_qos_close_queues() instead of a separate variant without the wait.
- Keep the original mlx5e_xdp_tx_disable() name instead of renaming it to _pre_sync, and only drop its synchronize_net().
- Build the single object paths from pre_sync, synchronize_net() and post_sync, and keep mlx5e_close_locked() calling the existing wrappers.
- Remove the priv level deactivate wrappers.
- Order the new functions as pre_sync, post_sync, then the wrapper.
V2:
https://lore.kernel.org/all/[email protected]/
V1:
https://lore.kernel.org/all/[email protected]/
Carolina Jubran (2):
net/mlx5e: Batch NAPI RCU grace periods on channel close net/mlx5e: Batch ICOSQ trigger RCU synchronization
drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 + .../net/ethernet/mellanox/mlx5/core/en/ptp.c | 27 ++- .../net/ethernet/mellanox/mlx5/core/en/ptp.h | 4 +- .../net/ethernet/mellanox/mlx5/core/en/qos.c | 42 ++++- .../net/ethernet/mellanox/mlx5/core/en/qos.h | 5 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 2 - .../mellanox/mlx5/core/en/xsk/setup.c | 22 ++- .../mellanox/mlx5/core/en/xsk/setup.h | 2 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 154 ++++++++++++++---- 9 files changed, 207 insertions(+), 55 deletions(-)
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH v3 1/2 net/mlx5e: Batch NAPI RCU grace periods on channel close
From: Carolina Jubran <[email protected]>
Channel close currently invokes synchronize_net() repeatedly while tearing down each channel. RQ, ICOSQ, TX SQ and NAPI teardown each require a grace period, causing the number of waits to scale with the number of channels. TX SQ teardown adds a wait for each traffic class, while XDP and QoS can add further calls.
Batch these waits across all channels. Split channel deactivate and close into pre_sync and post_sync phases. First clear the ENABLED state on all queues, then wait for a single grace period before continuing with the teardown. Once NAPI is disabled on all channels, wait for one more grace period, as the poll may still arm the CQs after napi_complete_done().
Similarly, close the queues and unlink all NAPI instances with __netif_napi_del_locked(), issue one synchronize_net() after all of them have been unlinked, and only then free the channels.
Keep the existing per object synchronize_net() calls for single queue paths. Drop the one in mlx5e_close_xdpsq(), as its callers already wait for a grace period or run before NAPI is enabled.
248 channels, rcu_normal=1, ip link set eth2 down:
Before: 11.837s
After: 0.817s (~14.5x faster)
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 + .../net/ethernet/mellanox/mlx5/core/en/ptp.c | 27 +++- .../net/ethernet/mellanox/mlx5/core/en/ptp.h | 4 +- .../net/ethernet/mellanox/mlx5/core/en/qos.c | 42 +++++- .../net/ethernet/mellanox/mlx5/core/en/qos.h | 5 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 2 - .../mellanox/mlx5/core/en/xsk/setup.c | 22 ++- .../mellanox/mlx5/core/en/xsk/setup.h | 2 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 126 ++++++++++++++---- 9 files changed, 185 insertions(+), 49 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +4 -0
@@ -1158,8 +1158,10 @@ int mlx5e_ptp_rx_manage_fs_ctx(struct mlx5e_priv *priv, void *ctx);int mlx5e_flush_rq (struct mlx5e_rq *rq,int curr_state);void mlx5e_activate_rq (struct mlx5e_rq *rq); +void mlx5e_deactivate_rq_pre_sync (struct mlx5e_rq *rq);void mlx5e_deactivate_rq (struct mlx5e_rq *rq);void mlx5e_activate_icosq (struct mlx5e_icosq *icosq); +void mlx5e_deactivate_icosq_pre_sync (struct mlx5e_icosq *icosq);void mlx5e_deactivate_icosq (struct mlx5e_icosq *icosq); int mlx5e_modify_sq(struct mlx5_core_dev *mdev, u32 sqn,
@@ -1169,6 +1171,8 @@ int mlx5e_open_txqsq(struct mlx5e_channel *c, u32 tisn, int txq_ix, struct mlx5e_txqsq *sq, int tc, u16 qos_queue_group_id, struct mlx5e_sq_stats *sq_stats);void mlx5e_activate_txqsq (struct mlx5e_txqsq *sq); +void mlx5e_deactivate_txqsq_pre_sync (struct mlx5e_txqsq *sq); +void mlx5e_deactivate_txqsq_post_sync (struct mlx5e_txqsq *sq);void mlx5e_deactivate_txqsq (struct mlx5e_txqsq *sq);void mlx5e_free_txqsq (struct mlx5e_txqsq *sq);void mlx5e_tx_disable_queue (struct netdev_queue *txq);
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c +22 -5
@@ -928,10 +928,17 @@ int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,return err; } -void mlx5e_ptp_close (struct mlx5e_ptp *c) +void mlx5e_ptp_close_pre_sync (struct mlx5e_ptp *c) { +/* NAPI is disabled and synced, or was never enabled. */ mlx5e_ptp_close_queues (c); -netif_napi_del_locked (&c->napi); +__netif_napi_del_locked (&c->napi); +} + +void mlx5e_ptp_close (struct mlx5e_ptp *c) +{ +mlx5e_ptp_close_pre_sync (c); +synchronize_net ();/* Sync with NAPI and page pool readers. */ kvfree (c); }
@@ -954,18 +961,28 @@ void mlx5e_ptp_activate_channel(struct mlx5e_ptp *c)mlx5e_trigger_napi_sched (&c->napi); } -void mlx5e_ptp_deactivate_channel (struct mlx5e_ptp *c) +void mlx5e_ptp_deactivate_channel_pre_sync (struct mlx5e_ptp *c) {int tc;if (test_bit (MLX5E_PTP_STATE_RX , c->state)) {netif_queue_set_napi (c->netdev, c->rq.ix,NETDEV_QUEUE_TYPE_RX ,NULL ); -mlx5e_deactivate_rq (&c->rq); +mlx5e_deactivate_rq_pre_sync (&c->rq); + } + +if (test_bit (MLX5E_PTP_STATE_TX , c->state)) { +for (tc =0 ; tc < c->num_tc; tc++) +mlx5e_deactivate_txqsq_pre_sync (&c->ptpsq[tc].txqsq); } +} + +void mlx5e_ptp_deactivate_channel_post_sync (struct mlx5e_ptp *c) +{ +int tc;if (test_bit (MLX5E_PTP_STATE_TX , c->state)) {for (tc =0 ; tc < c->num_tc; tc++) -mlx5e_deactivate_txqsq (&c->ptpsq[tc].txqsq); +mlx5e_deactivate_txqsq_post_sync (&c->ptpsq[tc].txqsq); }napi_disable_locked (&c->napi);
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.h +3 -1
@@ -128,9 +128,11 @@ static inline bool mlx5e_ptpsq_metadata_freelist_empty(struct mlx5e_ptpsq *ptpsqint mlx5e_ptp_open (struct mlx5e_priv *priv,struct mlx5e_params *params,u8 lag_port,struct mlx5e_ptp **cp); +void mlx5e_ptp_close_pre_sync (struct mlx5e_ptp *c);void mlx5e_ptp_close (struct mlx5e_ptp *c);void mlx5e_ptp_activate_channel (struct mlx5e_ptp *c); -void mlx5e_ptp_deactivate_channel (struct mlx5e_ptp *c); +void mlx5e_ptp_deactivate_channel_pre_sync (struct mlx5e_ptp *c); +void mlx5e_ptp_deactivate_channel_post_sync (struct mlx5e_ptp *c);int mlx5e_ptp_get_rqn (struct mlx5e_ptp *c,u32 *rqn);int mlx5e_ptp_alloc_rx_fs (struct mlx5e_flow_steering *fs,const struct mlx5e_profile *profile);
drivers/net/ethernet/mellanox/mlx5/core/en/qos.c +35 -7
81 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/qos.h +3 -2
@@ -28,9 +28,10 @@ void mlx5e_reset_qdisc(struct net_device *dev, u16 qid);int mlx5e_qos_open_queues (struct mlx5e_priv *priv,struct mlx5e_channels *chs);void mlx5e_qos_activate_queues (struct mlx5e_priv *priv); -void mlx5e_qos_deactivate_queues (struct mlx5e_channel *c); +void mlx5e_qos_deactivate_queues_pre_sync (struct mlx5e_channel *c); +void mlx5e_qos_deactivate_queues_post_sync (struct mlx5e_channel *c);void mlx5e_qos_deactivate_all_queues (struct mlx5e_channels *chs); -void mlx5e_qos_close_queues (struct mlx5e_channel *c); +void mlx5e_qos_close_queues (struct mlx5e_channel *c,bool sync_needed);void mlx5e_qos_close_all_queues (struct mlx5e_channels *chs);int mlx5e_qos_alloc_queues (struct mlx5e_priv *priv,struct mlx5e_channels *chs);
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h +0 -2
@@ -136,8 +136,6 @@ static inline void mlx5e_xdp_tx_disable(struct mlx5e_priv *priv)clear_bit (MLX5E_STATE_XDP_ACTIVE , &priv->state);clear_bit (MLX5E_STATE_XDP_TX_ENABLED , &priv->state); -/* Let other device's napi(s) and XSK wakeups see our new state. */ -synchronize_net (); }static inline bool mlx5e_xdp_tx_is_enabled (struct mlx5e_priv *priv)
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +16 -6
@@ -163,11 +163,9 @@ int mlx5e_open_xsk(struct mlx5e_priv *priv, struct mlx5e_params *params,return err; } -void mlx5e_close_xsk (struct mlx5e_channel *c) +void mlx5e_close_xsk_queues (struct mlx5e_channel *c) { -clear_bit (MLX5E_CHANNEL_STATE_XSK , c->state); -synchronize_net ();/* Sync with NAPI. */ - +/* Caller guarantees that NAPI can no longer access the XSK queues. */ mlx5e_close_rq (&c->xskrq);mlx5e_close_cq (&c->xskrq.cq);mlx5e_close_xdpsq (&c->xsksq);
@@ -177,6 +175,13 @@ void mlx5e_close_xsk(struct mlx5e_channel *c)memset (&c->xsksq,0 ,sizeof (c->xsksq)); } +void mlx5e_close_xsk (struct mlx5e_channel *c) +{ +clear_bit (MLX5E_CHANNEL_STATE_XSK , c->state); +synchronize_net ();/* Sync with NAPI. */ +mlx5e_close_xsk_queues (c); +} +void mlx5e_activate_xsk (struct mlx5e_channel *c) {/* ICOSQ recovery deactivates RQs. Suspend the recovery to avoid
@@ -189,7 +194,7 @@ void mlx5e_activate_xsk(struct mlx5e_channel *c)/* TX queue is created active. */ } -void mlx5e_deactivate_xsk (struct mlx5e_channel *c) +void mlx5e_deactivate_xsk_pre_sync (struct mlx5e_channel *c) {/* ICOSQ recovery may reactivate XSKRQ if clear_bit is called in the * middle of recovery. Suspend the recovery to avoid it.
@@ -197,7 +202,12 @@ void mlx5e_deactivate_xsk(struct mlx5e_channel *c)mlx5e_reporter_icosq_suspend_recovery (c);clear_bit (MLX5E_RQ_STATE_ENABLED , &c->xskrq.state);mlx5e_reporter_icosq_resume_recovery (c); -synchronize_net ();/* Sync with NAPI to prevent mlx5e_post_rx_wqes. */ /* TX queue is disabled on close. */ } + +void mlx5e_deactivate_xsk (struct mlx5e_channel *c) +{ +mlx5e_deactivate_xsk_pre_sync (c); +synchronize_net ();/* Sync with NAPI to prevent mlx5e_post_rx_wqes. */ +}
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.h +2 -0
@@ -16,8 +16,10 @@ int mlx5e_open_xsk(struct mlx5e_priv *priv, struct mlx5e_params *params,struct mlx5e_channel_param *cparam, struct xsk_buff_pool *pool, struct mlx5e_channel *c); +void mlx5e_close_xsk_queues (struct mlx5e_channel *c);void mlx5e_close_xsk (struct mlx5e_channel *c);void mlx5e_activate_xsk (struct mlx5e_channel *c); +void mlx5e_deactivate_xsk_pre_sync (struct mlx5e_channel *c);void mlx5e_deactivate_xsk (struct mlx5e_channel *c);#endif /* __MLX5_EN_XSK_SETUP_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +100 -26
219 lines not on this page · raw message
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net-next V3 1/2] net/mlx5e: Batch NAPI RCU grace periods on channel close
Sashiko has reviewed this patch and found no issues.
Quoted 23 lines
From: Carolina Jubran <[email protected]>
Channel close currently invokes
synchronize_net()repeatedly while tearing down each channel. RQ, ICOSQ, TX SQ and NAPI teardown each require a grace period, causing the number of waits to scale with the number of channels. TX SQ teardown adds a wait for each traffic class, while XDP and QoS can add further calls.Batch these waits across all channels. Split channel deactivate and close into
pre_syncandpost_syncphases. First clear the ENABLED state on all queues, then wait for a single grace period before continuing with the teardown. Once NAPI is disabled on all channels, wait for one more grace period, as the poll may still arm the CQs afternapi_complete_done().Similarly, close the queues and unlink all NAPI instances with
__netif_napi_del_locked(), issue onesynchronize_net()after all of them have been unlinked, and only then free the channels.Keep the existing per object
synchronize_net()calls for single queue paths. Drop the one inmlx5e_close_xdpsq(), as its callers already wait for a grace period or run before NAPI is enabled.
Quoted 6 lines
248 channels, rcu_normal=1, ip link set eth2 down:
Before: 11.837s
After: 0.817s (~14.5x faster)Signed-off-by Carolina Jubran <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Tariq Toukan
maintainerPATCH v3 2/2 net/mlx5e: Batch ICOSQ trigger RCU synchronization
In reply to Tariq ToukanFrom: Carolina Jubran <[email protected]>
During channel activation, mlx5e_activate_channels() triggers the ICOSQ once for every channel in order to kick NAPI. mlx5e_trigger_napi_icosq() sets MLX5E_SQ_STATE_LOCK_NEEDED and waits for an RCU grace period before serializing the trigger with ICOSQ users in NAPI context.
Mark all channel ICOSQs as requiring locking first, wait for a single grace period, and then trigger all of them.
Keep mlx5e_trigger_napi_icosq() with its existing synchronization semantics for standalone callers.
248 channels, rcu_normal=1, ip link set eth2 up:
Before: 4.087s After: 1.080s (~3.8x faster)
--- .../net/ethernet/mellanox/mlx5/core/en_main.c | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +22 -6
@@ -2799,14 +2799,11 @@ static int mlx5e_channel_stats_alloc(struct mlx5e_priv *priv, int ix, int cpu)return 0 ; } -void mlx5e_trigger_napi_icosq (struct mlx5e_channel *c) +static void mlx5e_trigger_napi_icosq_post_sync (struct mlx5e_channel *c) {struct mlx5e_icosq *sq = &c->icosq;bool locked; -set_bit (MLX5E_SQ_STATE_LOCK_NEEDED , &sq->state); -synchronize_net (); - locked =mlx5e_icosq_sync_lock (sq);mlx5e_trigger_irq (sq);mlx5e_icosq_sync_unlock (sq, locked);
@@ -2814,6 +2811,13 @@ void mlx5e_trigger_napi_icosq(struct mlx5e_channel *c)clear_bit (MLX5E_SQ_STATE_LOCK_NEEDED , &sq->state); } +void mlx5e_trigger_napi_icosq (struct mlx5e_channel *c) +{ +set_bit (MLX5E_SQ_STATE_LOCK_NEEDED , &c->icosq.state); +synchronize_net (); +mlx5e_trigger_napi_icosq_post_sync (c); +} +void mlx5e_trigger_napi_async_icosq (struct mlx5e_channel *c) {struct mlx5e_icosq *sq = c->async_icosq;
@@ -3057,6 +3061,19 @@ int mlx5e_open_channels(struct mlx5e_priv *priv,return err; } +static void mlx5e_trigger_napi_icosqs (struct mlx5e_channels *chs) +{ +int i; + +for (i =0 ; i < chs->num; i++) +set_bit (MLX5E_SQ_STATE_LOCK_NEEDED , &chs->c[i]->icosq.state); + +synchronize_net (); + +for (i =0 ; i < chs->num; i++) +mlx5e_trigger_napi_icosq_post_sync (chs->c[i]); +} +static void mlx5e_activate_channels (struct mlx5e_priv *priv,struct mlx5e_channels *chs) {int i;
@@ -3067,8 +3084,7 @@ static void mlx5e_activate_channels(struct mlx5e_priv *priv, struct mlx5e_channeif (priv->htb)mlx5e_qos_activate_queues (priv); -for (i =0 ; i < chs->num; i++) -mlx5e_trigger_napi_icosq (chs->c[i]); +mlx5e_trigger_napi_icosqs (chs);if (chs->ptp)mlx5e_ptp_activate_channel (chs->ptp);
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net-next V3 2/2] net/mlx5e: Batch ICOSQ trigger RCU synchronization
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines
From: Carolina Jubran <[email protected]>
During channel activation,
mlx5e_activate_channels()triggers the ICOSQ once for every channel in order to kick NAPI.mlx5e_trigger_napi_icosq()setsMLX5E_SQ_STATE_LOCK_NEEDEDand waits for an RCU grace period before serializing the trigger with ICOSQ users in NAPI context.Mark all channel ICOSQs as requiring locking first, wait for a single grace period, and then trigger all of them.
Keep
mlx5e_trigger_napi_icosq()with its existing synchronization semantics for standalone callers.
Quoted 6 lines
248 channels, rcu_normal=1, ip link set eth2 up:
Before: 4.087s After: 1.080s (~3.8x faster)Signed-off-by Carolina Jubran <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2