From patchwork Tue Feb 21 14:37:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahaf Shuler X-Patchwork-Id: 20650 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 9C22A2BB4; Tue, 21 Feb 2017 15:37:39 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id DF2452A5E for ; Tue, 21 Feb 2017 15:37:37 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 21 Feb 2017 16:37:31 +0200 Received: from arch009.mtl.labs.mlnx (arch009.mtl.labs.mlnx [10.7.12.209]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v1LEbVQV016792; Tue, 21 Feb 2017 16:37:31 +0200 Received: from arch009.mtl.labs.mlnx (localhost [127.0.0.1]) by arch009.mtl.labs.mlnx (8.14.7/8.14.7) with ESMTP id v1LEbV5H017640; Tue, 21 Feb 2017 16:37:31 +0200 Received: (from root@localhost) by arch009.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id v1LEbVJ3017639; Tue, 21 Feb 2017 16:37:31 +0200 From: Shahaf Shuler To: adrien.mazarguil@6wind.com, nelio.laranjeiro@6wind.com Cc: dev@dpdk.org, stable@dpdk.org Date: Tue, 21 Feb 2017 16:37:24 +0200 Message-Id: <1487687844-17595-2-git-send-email-shahafs@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487687844-17595-1-git-send-email-shahafs@mellanox.com> References: <1487687844-17595-1-git-send-email-shahafs@mellanox.com> Subject: [dpdk-dev] [PATCH 2/2] net/mlx5: fix extended statistics wrong number X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The number of extended statistics counters is queried through ETHTOOL. ETHTOOL provides a different number when the link is up or down. Since extended statistics query occurs at device start, segmentation fault might happen when changing the link state before and after the device start. this commit address this issue, and query the number of statistics before every call to ETHTOOL. Fixes: a4193ae3bc4f ("net/mlx5: support extended statistics") CC: stable@dpdk.org Signed-off-by: Shahaf Shuler Acked-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_stats.c | 48 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c index 0c80e4f..60ffbaa 100644 --- a/drivers/net/mlx5/mlx5_stats.c +++ b/drivers/net/mlx5/mlx5_stats.c @@ -166,6 +166,29 @@ struct mlx5_counter_ctrl { } /** + * Query the number of statistics provided by ETHTOOL. + * + * @param priv + * Pointer to private structure. + * + * @return + * Number of statistics on success, -1 on error. + */ +static int +priv_ethtool_get_stats_n(struct priv *priv) { + struct ethtool_drvinfo drvinfo; + struct ifreq ifr; + + drvinfo.cmd = ETHTOOL_GDRVINFO; + ifr.ifr_data = (caddr_t)&drvinfo; + if (priv_ifreq(priv, SIOCETHTOOL, &ifr) != 0) { + WARN("unable to query number of statistics"); + return -1; + } + return drvinfo.n_stats; +} + +/** * Init the structures to read device counters. * * @param priv @@ -178,19 +201,11 @@ struct mlx5_counter_ctrl { unsigned int i; unsigned int j; struct ifreq ifr; - struct ethtool_drvinfo drvinfo; struct ethtool_gstrings *strings = NULL; unsigned int dev_stats_n; unsigned int str_sz; - /* How many statistics are available. */ - drvinfo.cmd = ETHTOOL_GDRVINFO; - ifr.ifr_data = (caddr_t)&drvinfo; - if (priv_ifreq(priv, SIOCETHTOOL, &ifr) != 0) { - WARN("unable to get driver info"); - return; - } - dev_stats_n = drvinfo.n_stats; + dev_stats_n = priv_ethtool_get_stats_n(priv); if (dev_stats_n < 1) { WARN("no extended statistics available"); return; @@ -410,7 +425,15 @@ struct mlx5_counter_ctrl { int ret = xstats_n; if (n >= xstats_n && stats) { + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; + int stats_n; + priv_lock(priv); + stats_n = priv_ethtool_get_stats_n(priv); + if (stats_n < 0) + return -1; + if (xstats_ctrl->stats_n != stats_n) + priv_xstats_init(priv); ret = priv_xstats_get(priv, stats); priv_unlock(priv); } @@ -427,8 +450,15 @@ struct mlx5_counter_ctrl { mlx5_xstats_reset(struct rte_eth_dev *dev) { struct priv *priv = mlx5_get_priv(dev); + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; + int stats_n; priv_lock(priv); + stats_n = priv_ethtool_get_stats_n(priv); + if (stats_n < 0) + return; + if (xstats_ctrl->stats_n != stats_n) + priv_xstats_init(priv); priv_xstats_reset(priv); priv_unlock(priv); }