From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6BA7DA00C3; Fri, 13 May 2022 05:00:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 66A974283A; Fri, 13 May 2022 04:59:57 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 7C08D40698 for ; Fri, 13 May 2022 04:59:53 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Kztdp1ZQmzhZ2V; Fri, 13 May 2022 10:59:10 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:51 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 1/9] ethdev: specify return value of xstats-get API Date: Fri, 13 May 2022 10:53:49 +0800 Message-ID: <20220513025357.52275-2-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Currently the value returned when xstats is NULL of rte_eth_xstats_get() is not specified, some PMDs (eg. hns3/ipn3ke/mvpp2/axgbe) return zero while others return the required number of elements. In this patch, special parameter combinations are restricted: 1. specify that xstats is NULL if and only if n is 0. 2. specify that if n is lower than the required number of elements, the function returns the required number of elements. 3. specify that if n is zero, the xstats must be NULL, the function returns the required number of elements. This patch also makes sure that xstats is NULL if n is lower or equal to the number of basic stats when invoke driver's ops. Fixes: ce757f5c9a4d ("ethdev: new method to retrieve extended statistics") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- lib/ethdev/rte_ethdev.c | 4 +++- lib/ethdev/rte_ethdev.h | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 29a3d80466..d9661bd64f 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -2973,6 +2973,8 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (xstats == NULL && n > 0) + return -EINVAL; dev = &rte_eth_devices[port_id]; nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); @@ -2989,7 +2991,7 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, * xstats struct. */ xcount = (*dev->dev_ops->xstats_get)(dev, - xstats ? xstats + count : NULL, + (n > count) ? xstats + count : NULL, (n > count) ? n - count : 0); if (xcount < 0) diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 04cff8ee10..04225bba4d 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -3174,9 +3174,13 @@ int rte_eth_xstats_get_names(uint16_t port_id, * @param xstats * A pointer to a table of structure of type *rte_eth_xstat* * to be filled with device statistics ids and values. - * This parameter can be set to NULL if n is 0. + * This parameter can be set to NULL if and only if n is 0. * @param n * The size of the xstats array (number of elements). + * If lower than the required number of elements, the function returns + * the required number of elements. + * If equal to zero, the xstats must be NULL, the function returns the + * required number of elements. * @return * - A positive value lower or equal to n: success. The return value * is the number of entries filled in the stats table. -- 2.33.0