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 A5DD9A0C4E; Thu, 22 Jul 2021 11:55:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 174A9410DB; Thu, 22 Jul 2021 11:55:23 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 83D014113F for ; Thu, 22 Jul 2021 11:55:21 +0200 (CEST) Received: by shelob.oktetlabs.ru (Postfix, from userid 122) id 50FC07F6E3; Thu, 22 Jul 2021 12:55:21 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shelob.oktetlabs.ru X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=ALL_TRUSTED, DKIM_ADSP_DISCARD, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from aros.oktetlabs.ru (aros.oktetlabs.ru [192.168.38.17]) by shelob.oktetlabs.ru (Postfix) with ESMTP id 28B417F6CC; Thu, 22 Jul 2021 12:54:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 28B417F6CC Authentication-Results: shelob.oktetlabs.ru/28B417F6CC; dkim=none; dkim-atps=neutral From: Andrew Rybchenko To: dev@dpdk.org Cc: David Marchand , Ivan Ilchenko , Andy Moreton Date: Thu, 22 Jul 2021 12:54:31 +0300 Message-Id: <20210722095433.1898589-10-andrew.rybchenko@oktetlabs.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722095433.1898589-1-andrew.rybchenko@oktetlabs.ru> References: <20210604144225.287678-1-andrew.rybchenko@oktetlabs.ru> <20210722095433.1898589-1-andrew.rybchenko@oktetlabs.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 09/11] net/sfc: prepare to add more xstats 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 Sender: "dev" From: Ivan Ilchenko Move getting MAC stats code that involves locking to separate functions to simplify addition of new xstats. Signed-off-by: Ivan Ilchenko Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- drivers/net/sfc/sfc.h | 4 ++ drivers/net/sfc/sfc_ethdev.c | 73 ++++---------------------------- drivers/net/sfc/sfc_port.c | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 65 deletions(-) diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 1594f934ba..58b8c2c2ad 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -423,6 +423,10 @@ void sfc_port_stop(struct sfc_adapter *sa); void sfc_port_link_mode_to_info(efx_link_mode_t link_mode, struct rte_eth_link *link_info); int sfc_port_update_mac_stats(struct sfc_adapter *sa, boolean_t manual_update); +int sfc_port_get_mac_stats(struct sfc_adapter *sa, struct rte_eth_xstat *xstats, + unsigned int xstats_count, unsigned int *nb_written); +int sfc_port_get_mac_stats_by_id(struct sfc_adapter *sa, const uint64_t *ids, + uint64_t *values, unsigned int n); int sfc_port_reset_mac_stats(struct sfc_adapter *sa); int sfc_set_rx_mode(struct sfc_adapter *sa); int sfc_set_rx_mode_unchecked(struct sfc_adapter *sa); diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index f0567a71d0..dd7e5c253a 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -726,41 +726,17 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, { struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); struct sfc_port *port = &sa->port; - uint64_t *mac_stats; - int rc; - unsigned int i; - int nstats = 0; - - sfc_adapter_lock(sa); + unsigned int nb_written = 0; + unsigned int nb_supp; if (unlikely(xstats == NULL)) { - nstats = port->mac_stats_nb_supported; - goto unlock; - } - - rc = sfc_port_update_mac_stats(sa, B_FALSE); - if (rc != 0) { - SFC_ASSERT(rc > 0); - nstats = -rc; - goto unlock; - } - - mac_stats = port->mac_stats_buf; - - for (i = 0; i < EFX_MAC_NSTATS; ++i) { - if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) { - if (nstats < (int)xstats_count) { - xstats[nstats].id = nstats; - xstats[nstats].value = mac_stats[i]; - } - nstats++; - } + sfc_adapter_lock(sa); + nb_supp = port->mac_stats_nb_supported; + sfc_adapter_unlock(sa); + return nb_supp; } -unlock: - sfc_adapter_unlock(sa); - - return nstats; + return sfc_port_get_mac_stats(sa, xstats, xstats_count, &nb_written); } static int @@ -798,44 +774,11 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, uint64_t *values, unsigned int n) { struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); - struct sfc_port *port = &sa->port; - uint64_t *mac_stats; - unsigned int i; - int ret; - int rc; if (unlikely(ids == NULL || values == NULL)) return -EINVAL; - sfc_adapter_lock(sa); - - rc = sfc_port_update_mac_stats(sa, B_FALSE); - if (rc != 0) { - SFC_ASSERT(rc > 0); - ret = -rc; - goto unlock; - } - - mac_stats = port->mac_stats_buf; - - SFC_ASSERT(port->mac_stats_nb_supported <= - RTE_DIM(port->mac_stats_by_id)); - - for (i = 0; i < n; i++) { - if (ids[i] < port->mac_stats_nb_supported) { - values[i] = mac_stats[port->mac_stats_by_id[ids[i]]]; - } else { - ret = i; - goto unlock; - } - } - - ret = n; - -unlock: - sfc_adapter_unlock(sa); - - return ret; + return sfc_port_get_mac_stats_by_id(sa, ids, values, n); } static int diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index 8c432c15f5..f6689a17c0 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -636,3 +636,83 @@ sfc_port_link_mode_to_info(efx_link_mode_t link_mode, link_info->link_autoneg = ETH_LINK_AUTONEG; } + +int +sfc_port_get_mac_stats(struct sfc_adapter *sa, struct rte_eth_xstat *xstats, + unsigned int xstats_count, unsigned int *nb_written) +{ + struct sfc_port *port = &sa->port; + uint64_t *mac_stats; + unsigned int i; + int nstats = 0; + int ret; + + sfc_adapter_lock(sa); + + ret = sfc_port_update_mac_stats(sa, B_FALSE); + if (ret != 0) { + SFC_ASSERT(ret > 0); + ret = -ret; + goto unlock; + } + + mac_stats = port->mac_stats_buf; + + for (i = 0; i < EFX_MAC_NSTATS; ++i) { + if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) { + if (nstats < (int)xstats_count) { + xstats[nstats].id = nstats; + xstats[nstats].value = mac_stats[i]; + (*nb_written)++; + } + nstats++; + } + } + ret = nstats; + +unlock: + sfc_adapter_unlock(sa); + + return ret; +} + +int +sfc_port_get_mac_stats_by_id(struct sfc_adapter *sa, const uint64_t *ids, + uint64_t *values, unsigned int n) +{ + struct sfc_port *port = &sa->port; + uint64_t *mac_stats; + unsigned int i; + int ret; + int rc; + + sfc_adapter_lock(sa); + + rc = sfc_port_update_mac_stats(sa, B_FALSE); + if (rc != 0) { + SFC_ASSERT(rc > 0); + ret = -rc; + goto unlock; + } + + mac_stats = port->mac_stats_buf; + + SFC_ASSERT(port->mac_stats_nb_supported <= + RTE_DIM(port->mac_stats_by_id)); + + for (i = 0; i < n; i++) { + if (ids[i] < port->mac_stats_nb_supported) { + values[i] = mac_stats[port->mac_stats_by_id[ids[i]]]; + } else { + ret = i; + goto unlock; + } + } + + ret = n; + +unlock: + sfc_adapter_unlock(sa); + + return ret; +} -- 2.30.2