Skip to content

Commit a5e89a3

Browse files
Binary-Eaterkuba-moo
authored andcommitted
net/mlx5e: Dynamically allocate DIM structure for SQs/RQs
Make it possible for the DIM structure to be torn down while an SQ or RQ is still active. Changing the CQ period mode is an example where the previous sampling done with the DIM structure would need to be invalidated. Co-developed-by: Nabil S. Alramli <dev@nalramli.com> Signed-off-by: Nabil S. Alramli <dev@nalramli.com> Co-developed-by: Joe Damato <jdamato@fastly.com> Signed-off-by: Joe Damato <jdamato@fastly.com> Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://lore.kernel.org/r/20240419080445.417574-4-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent eca1e8a commit a5e89a3

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ struct mlx5e_txqsq {
430430
u16 cc;
431431
u16 skb_fifo_cc;
432432
u32 dma_fifo_cc;
433-
struct dim dim; /* Adaptive Moderation */
433+
struct dim *dim; /* Adaptive Moderation */
434434

435435
/* dirtied @xmit */
436436
u16 pc ____cacheline_aligned_in_smp;
@@ -722,7 +722,7 @@ struct mlx5e_rq {
722722
int ix;
723723
unsigned int hw_mtu;
724724

725-
struct dim dim; /* Dynamic Interrupt Moderation */
725+
struct dim *dim; /* Dynamic Interrupt Moderation */
726726

727727
/* XDP */
728728
struct bpf_prog __rcu *xdp_prog;

drivers/net/ethernet/mellanox/mlx5/core/en_dim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mlx5e_complete_dim_work(struct dim *dim, struct dim_cq_moder moder,
4444
void mlx5e_rx_dim_work(struct work_struct *work)
4545
{
4646
struct dim *dim = container_of(work, struct dim, work);
47-
struct mlx5e_rq *rq = container_of(dim, struct mlx5e_rq, dim);
47+
struct mlx5e_rq *rq = dim->priv;
4848
struct dim_cq_moder cur_moder =
4949
net_dim_get_rx_moderation(dim->mode, dim->profile_ix);
5050

@@ -54,7 +54,7 @@ void mlx5e_rx_dim_work(struct work_struct *work)
5454
void mlx5e_tx_dim_work(struct work_struct *work)
5555
{
5656
struct dim *dim = container_of(work, struct dim, work);
57-
struct mlx5e_txqsq *sq = container_of(dim, struct mlx5e_txqsq, dim);
57+
struct mlx5e_txqsq *sq = dim->priv;
5858
struct dim_cq_moder cur_moder =
5959
net_dim_get_tx_moderation(dim->mode, dim->profile_ix);
6060

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,20 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
962962
}
963963
}
964964

965-
INIT_WORK(&rq->dim.work, mlx5e_rx_dim_work);
966-
rq->dim.mode = params->rx_cq_moderation.cq_period_mode;
965+
rq->dim = kvzalloc_node(sizeof(*rq->dim), GFP_KERNEL, node);
966+
if (!rq->dim) {
967+
err = -ENOMEM;
968+
goto err_unreg_xdp_rxq_info;
969+
}
970+
971+
rq->dim->priv = rq;
972+
INIT_WORK(&rq->dim->work, mlx5e_rx_dim_work);
973+
rq->dim->mode = params->rx_cq_moderation.cq_period_mode;
967974

968975
return 0;
969976

977+
err_unreg_xdp_rxq_info:
978+
xdp_rxq_info_unreg(&rq->xdp_rxq);
970979
err_destroy_page_pool:
971980
page_pool_destroy(rq->page_pool);
972981
err_free_by_rq_type:
@@ -1014,6 +1023,7 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq)
10141023
mlx5e_free_wqe_alloc_info(rq);
10151024
}
10161025

1026+
kvfree(rq->dim);
10171027
xdp_rxq_info_unreg(&rq->xdp_rxq);
10181028
page_pool_destroy(rq->page_pool);
10191029
mlx5_wq_destroy(&rq->wq_ctrl);
@@ -1341,7 +1351,7 @@ void mlx5e_deactivate_rq(struct mlx5e_rq *rq)
13411351

13421352
void mlx5e_close_rq(struct mlx5e_rq *rq)
13431353
{
1344-
cancel_work_sync(&rq->dim.work);
1354+
cancel_work_sync(&rq->dim->work);
13451355
cancel_work_sync(&rq->recover_work);
13461356
mlx5e_destroy_rq(rq);
13471357
mlx5e_free_rx_descs(rq);
@@ -1616,12 +1626,20 @@ static int mlx5e_alloc_txqsq(struct mlx5e_channel *c,
16161626
err = mlx5e_alloc_txqsq_db(sq, cpu_to_node(c->cpu));
16171627
if (err)
16181628
goto err_sq_wq_destroy;
1629+
sq->dim = kvzalloc_node(sizeof(*sq->dim), GFP_KERNEL, cpu_to_node(c->cpu));
1630+
if (!sq->dim) {
1631+
err = -ENOMEM;
1632+
goto err_free_txqsq_db;
1633+
}
16191634

1620-
INIT_WORK(&sq->dim.work, mlx5e_tx_dim_work);
1621-
sq->dim.mode = params->tx_cq_moderation.cq_period_mode;
1635+
sq->dim->priv = sq;
1636+
INIT_WORK(&sq->dim->work, mlx5e_tx_dim_work);
1637+
sq->dim->mode = params->tx_cq_moderation.cq_period_mode;
16221638

16231639
return 0;
16241640

1641+
err_free_txqsq_db:
1642+
mlx5e_free_txqsq_db(sq);
16251643
err_sq_wq_destroy:
16261644
mlx5_wq_destroy(&sq->wq_ctrl);
16271645

@@ -1630,6 +1648,7 @@ static int mlx5e_alloc_txqsq(struct mlx5e_channel *c,
16301648

16311649
void mlx5e_free_txqsq(struct mlx5e_txqsq *sq)
16321650
{
1651+
kvfree(sq->dim);
16331652
mlx5e_free_txqsq_db(sq);
16341653
mlx5_wq_destroy(&sq->wq_ctrl);
16351654
}
@@ -1841,7 +1860,7 @@ void mlx5e_close_txqsq(struct mlx5e_txqsq *sq)
18411860
struct mlx5_core_dev *mdev = sq->mdev;
18421861
struct mlx5_rate_limit rl = {0};
18431862

1844-
cancel_work_sync(&sq->dim.work);
1863+
cancel_work_sync(&sq->dim->work);
18451864
cancel_work_sync(&sq->recover_work);
18461865
mlx5e_destroy_sq(mdev, sq->sqn);
18471866
if (sq->rate_limit) {

drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void mlx5e_handle_tx_dim(struct mlx5e_txqsq *sq)
5555
return;
5656

5757
dim_update_sample(sq->cq.event_ctr, stats->packets, stats->bytes, &dim_sample);
58-
net_dim(&sq->dim, dim_sample);
58+
net_dim(sq->dim, dim_sample);
5959
}
6060

6161
static void mlx5e_handle_rx_dim(struct mlx5e_rq *rq)
@@ -67,7 +67,7 @@ static void mlx5e_handle_rx_dim(struct mlx5e_rq *rq)
6767
return;
6868

6969
dim_update_sample(rq->cq.event_ctr, stats->packets, stats->bytes, &dim_sample);
70-
net_dim(&rq->dim, dim_sample);
70+
net_dim(rq->dim, dim_sample);
7171
}
7272

7373
void mlx5e_trigger_irq(struct mlx5e_icosq *sq)

0 commit comments

Comments
 (0)