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 6371AA0C4E; Thu, 22 Jul 2021 11:55:01 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C6420410E1; Thu, 22 Jul 2021 11:54:56 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 7B4AA410E4; Thu, 22 Jul 2021 11:54:55 +0200 (CEST) Received: by shelob.oktetlabs.ru (Postfix, from userid 122) id 52ECF7F6D2; Thu, 22 Jul 2021 12:54:55 +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 AC02C7F596; Thu, 22 Jul 2021 12:54:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru AC02C7F596 Authentication-Results: shelob.oktetlabs.ru/AC02C7F596; dkim=none; dkim-atps=neutral From: Andrew Rybchenko To: dev@dpdk.org, Robert Stonehouse , Andrew Lee Cc: David Marchand , Ivan Ilchenko , stable@dpdk.org, Andy Moreton Date: Thu, 22 Jul 2021 12:54:24 +0300 Message-Id: <20210722095433.1898589-3-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 02/11] net/sfc: fix reading adapter state without locking 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 Update MAC stats function reads adapter state with MAC stats locking but without adapter locking. Add adapter locking before calling this function and remove MAC stats locking since there's no point to have it together with adapter locking. The second place MAC stats locking is used is MAC stats reset function. It's called with adapter being already locked so there's no point to use MAC stats locking anymore. Fixes: 1caab2f1e68 ("net/sfc: add basic statistics") Cc: stable@dpdk.org Signed-off-by: Ivan Ilchenko Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- drivers/net/sfc/sfc.h | 1 - drivers/net/sfc/sfc_ethdev.c | 28 ++++++++++++++++++++-------- drivers/net/sfc/sfc_port.c | 9 +++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 546739bd4a..c7b0e5a30d 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -130,7 +130,6 @@ struct sfc_port { unsigned int nb_mcast_addrs; uint8_t *mcast_addrs; - rte_spinlock_t mac_stats_lock; uint64_t *mac_stats_buf; unsigned int mac_stats_nb_supported; efsys_mem_t mac_stats_dma_mem; diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index d4ac61ff76..d5417e5e65 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -613,7 +613,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) uint64_t *mac_stats; int ret; - rte_spinlock_lock(&port->mac_stats_lock); + sfc_adapter_lock(sa); ret = sfc_port_update_mac_stats(sa); if (ret != 0) @@ -686,7 +686,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) } unlock: - rte_spinlock_unlock(&port->mac_stats_lock); + sfc_adapter_unlock(sa); SFC_ASSERT(ret >= 0); return -ret; } @@ -698,12 +698,15 @@ sfc_stats_reset(struct rte_eth_dev *dev) struct sfc_port *port = &sa->port; int rc; + sfc_adapter_lock(sa); + if (sa->state != SFC_ADAPTER_STARTED) { /* * The operation cannot be done if port is not started; it * will be scheduled to be done during the next port start */ port->mac_stats_reset_pending = B_TRUE; + sfc_adapter_unlock(sa); return 0; } @@ -711,6 +714,8 @@ sfc_stats_reset(struct rte_eth_dev *dev) if (rc != 0) sfc_err(sa, "failed to reset statistics (rc = %d)", rc); + sfc_adapter_unlock(sa); + SFC_ASSERT(rc >= 0); return -rc; } @@ -726,7 +731,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, unsigned int i; int nstats = 0; - rte_spinlock_lock(&port->mac_stats_lock); + sfc_adapter_lock(sa); rc = sfc_port_update_mac_stats(sa); if (rc != 0) { @@ -748,7 +753,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, } unlock: - rte_spinlock_unlock(&port->mac_stats_lock); + sfc_adapter_unlock(sa); return nstats; } @@ -789,7 +794,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, int ret; int rc; - rte_spinlock_lock(&port->mac_stats_lock); + sfc_adapter_lock(sa); if (unlikely(values == NULL) || unlikely(ids == NULL && n < port->mac_stats_nb_supported)) { @@ -819,7 +824,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, ret = nb_written; unlock: - rte_spinlock_unlock(&port->mac_stats_lock); + sfc_adapter_unlock(sa); return ret; } @@ -835,9 +840,14 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, unsigned int nb_written = 0; unsigned int i; + sfc_adapter_lock(sa); + if (unlikely(xstats_names == NULL) || - unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) - return port->mac_stats_nb_supported; + unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) { + nb_supported = port->mac_stats_nb_supported; + sfc_adapter_unlock(sa); + return nb_supported; + } for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) { if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) @@ -853,6 +863,8 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, ++nb_supported; } + sfc_adapter_unlock(sa); + return nb_written; } diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index ac117f9c48..cdc0f94f19 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -43,7 +43,7 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa) unsigned int nb_attempts = 0; int rc; - SFC_ASSERT(rte_spinlock_is_locked(&port->mac_stats_lock)); + SFC_ASSERT(sfc_adapter_is_locked(sa)); if (sa->state != SFC_ADAPTER_STARTED) return EINVAL; @@ -103,14 +103,13 @@ sfc_port_reset_sw_stats(struct sfc_adapter *sa) int sfc_port_reset_mac_stats(struct sfc_adapter *sa) { - struct sfc_port *port = &sa->port; int rc; - rte_spinlock_lock(&port->mac_stats_lock); + SFC_ASSERT(sfc_adapter_is_locked(sa)); + rc = efx_mac_stats_clear(sa->nic); if (rc == 0) sfc_port_reset_sw_stats(sa); - rte_spinlock_unlock(&port->mac_stats_lock); return rc; } @@ -416,8 +415,6 @@ sfc_port_attach(struct sfc_adapter *sa) goto fail_mcast_addr_list_buf_alloc; } - rte_spinlock_init(&port->mac_stats_lock); - rc = ENOMEM; port->mac_stats_buf = rte_calloc_socket("mac_stats_buf", EFX_MAC_NSTATS, sizeof(uint64_t), 0, -- 2.30.2