From patchwork Thu Dec 12 11:47:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 13905026 X-Patchwork-Delegate: kuba@kernel.org Received: from njjs-sys-mailin01.njjs.baidu.com (mx315.baidu.com [180.101.52.204]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C628158DB1 for ; Thu, 12 Dec 2024 11:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=180.101.52.204 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734004059; cv=none; b=VET/CM9ZNqf3TkbR8XUFjEviw0WNEYj9c1ia1G/GxrJamOudHrGtsaicZMaH42CfbQ1Rz1zMdtlXJ8tb66E0nO4nJS1TBK7iZJiiXOlGo0ggRrHPnDQ/r4gtBUHKUw23Zo/xt3clrfMYFqtzYW/jV+A2jyNSdqUwMGNZg/OA1G0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734004059; c=relaxed/simple; bh=vxemn+dWccA8WDl7TjdH5dLFJOSlbDcfvDOBikqsoJo=; h=From:To:Cc:Subject:Date:Message-Id; b=JVz8mQ9sRY6aM7Gy6i5/HQ68/ZatIum20d3Xc8pg8qV2K1oGZZAmeWH6TmG8dHTMiEVKvBfeQadoHgw+zNeWqy/RBi7RfI66lQhmsfReuFRtbXKLRVBWokiePeyElSkxBYscLiB88JRVRBHTKfVwlxPpJdQ4ipHYCH4HTlGEQYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; arc=none smtp.client-ip=180.101.52.204 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com Received: from localhost (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by njjs-sys-mailin01.njjs.baidu.com (Postfix) with ESMTP id 9F04D7F0004B; Thu, 12 Dec 2024 19:47:25 +0800 (CST) From: Li RongQing To: saeedm@nvidia.com, tariqt@nvidia.com, leon@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, andrew+netdev@lunn.ch Cc: Li RongQing , Shuo Li Subject: [PATCH][net-next] net/mlx5e: avoid to call net_dim and dim_update_sample Date: Thu, 12 Dec 2024 19:47:23 +0800 Message-Id: <20241212114723.38844-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.9.4 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-Patchwork-Delegate: kuba@kernel.org High cpu usage for net_dim is seen still after commit 61bf0009a765 ("dim: pass dim_sample to net_dim() by reference"), the calling net_dim can be avoid under network low throughput or pingpong mode by checking the event counter, even under high throughput, it maybe only rx or tx direction And don't initialize dim_sample variable, since it will gets overwritten by dim_update_sample Signed-off-by: Li RongQing Signed-off-by: Shuo Li --- drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c index 7610829..7c525e9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c @@ -49,11 +49,19 @@ static inline bool mlx5e_channel_no_affinity_change(struct mlx5e_channel *c) static void mlx5e_handle_tx_dim(struct mlx5e_txqsq *sq) { struct mlx5e_sq_stats *stats = sq->stats; - struct dim_sample dim_sample = {}; + struct dim_sample dim_sample; + u16 nevents; if (unlikely(!test_bit(MLX5E_SQ_STATE_DIM, &sq->state))) return; + if (sq->dim->state == DIM_MEASURE_IN_PROGRESS) { + nevents = BIT_GAP(BITS_PER_TYPE(u16), sq->cq.event_ctr, + sq->dim->start_sample.event_ctr); + if (nevents < DIM_NEVENTS) + return; + } + dim_update_sample(sq->cq.event_ctr, stats->packets, stats->bytes, &dim_sample); net_dim(sq->dim, &dim_sample); } @@ -61,11 +69,19 @@ static void mlx5e_handle_tx_dim(struct mlx5e_txqsq *sq) static void mlx5e_handle_rx_dim(struct mlx5e_rq *rq) { struct mlx5e_rq_stats *stats = rq->stats; - struct dim_sample dim_sample = {}; + struct dim_sample dim_sample; + u16 nevents; if (unlikely(!test_bit(MLX5E_RQ_STATE_DIM, &rq->state))) return; + if (rq->dim->state == DIM_MEASURE_IN_PROGRESS) { + nevents = BIT_GAP(BITS_PER_TYPE(u16), rq->cq.event_ctr, + rq->dim->start_sample.event_ctr); + if (nevents < DIM_NEVENTS) + return; + } + dim_update_sample(rq->cq.event_ctr, stats->packets, stats->bytes, &dim_sample); net_dim(rq->dim, &dim_sample); }