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 EBE7CA0032; Tue, 28 Sep 2021 13:30:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4568E41137; Tue, 28 Sep 2021 13:29:47 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id F1C6C4111A for ; Tue, 28 Sep 2021 13:29:43 +0200 (CEST) Received: by shelob.oktetlabs.ru (Postfix, from userid 122) id C34947F6D5; Tue, 28 Sep 2021 14:29:43 +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 D0AAE7F6D9; Tue, 28 Sep 2021 14:29:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru D0AAE7F6D9 Authentication-Results: shelob.oktetlabs.ru/D0AAE7F6D9; dkim=none; dkim-atps=neutral From: Andrew Rybchenko To: dev@dpdk.org Cc: Ivan Ilchenko Date: Tue, 28 Sep 2021 14:29:08 +0300 Message-Id: <20210928112912.785412-8-andrew.rybchenko@oktetlabs.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210928112912.785412-1-andrew.rybchenko@oktetlabs.ru> References: <20210928112912.785412-1-andrew.rybchenko@oktetlabs.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 07/11] net/sfc: prepare having no some SW stats on an adapter 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 Global description structure of SW stats is used currently. Following patches introduce SW stats that may be unavailable for some adapters, so add per-adapter descriptions to safely work with multiple adapters. Signed-off-by: Ivan Ilchenko Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/sfc.h | 7 ++++ drivers/net/sfc/sfc_sw_stats.c | 65 +++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index b9ff8baed2..5a40a73c7f 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -217,9 +217,16 @@ struct sfc_counter_rxq { struct rte_mempool *mp; }; +struct sfc_sw_stat_data { + const struct sfc_sw_stat_descr *descr; +}; + struct sfc_sw_stats { /* Number extended statistics provided by SW stats */ unsigned int xstats_count; + /* Supported SW statistics */ + struct sfc_sw_stat_data *supp; + unsigned int supp_count; uint64_t *reset_vals; rte_spinlock_t queues_bitmap_lock; diff --git a/drivers/net/sfc/sfc_sw_stats.c b/drivers/net/sfc/sfc_sw_stats.c index 0f93091500..a9ab29064a 100644 --- a/drivers/net/sfc/sfc_sw_stats.c +++ b/drivers/net/sfc/sfc_sw_stats.c @@ -341,6 +341,7 @@ sfc_sw_xstats_get_vals(struct sfc_adapter *sa, unsigned int *nb_supported) { uint64_t *reset_vals = sa->sw_stats.reset_vals; + struct sfc_sw_stats *sw_stats = &sa->sw_stats; unsigned int sw_xstats_offset; unsigned int i; @@ -348,8 +349,8 @@ sfc_sw_xstats_get_vals(struct sfc_adapter *sa, sw_xstats_offset = *nb_supported; - for (i = 0; i < RTE_DIM(sfc_sw_stats_descr); i++) { - sfc_sw_xstat_get_values(sa, &sfc_sw_stats_descr[i], xstats, + for (i = 0; i < sw_stats->xstats_count; i++) { + sfc_sw_xstat_get_values(sa, sw_stats->supp[i].descr, xstats, xstats_count, nb_written, nb_supported); } @@ -366,13 +367,14 @@ sfc_sw_xstats_get_names(struct sfc_adapter *sa, unsigned int *nb_written, unsigned int *nb_supported) { + struct sfc_sw_stats *sw_stats = &sa->sw_stats; unsigned int i; int ret; sfc_adapter_lock(sa); - for (i = 0; i < RTE_DIM(sfc_sw_stats_descr); i++) { - ret = sfc_sw_stat_get_names(sa, &sfc_sw_stats_descr[i], + for (i = 0; i < sw_stats->supp_count; i++) { + ret = sfc_sw_stat_get_names(sa, sw_stats->supp[i].descr, xstats_names, xstats_count, nb_written, nb_supported); if (ret != 0) { @@ -394,6 +396,7 @@ sfc_sw_xstats_get_vals_by_id(struct sfc_adapter *sa, unsigned int *nb_supported) { uint64_t *reset_vals = sa->sw_stats.reset_vals; + struct sfc_sw_stats *sw_stats = &sa->sw_stats; unsigned int sw_xstats_offset; unsigned int i; @@ -401,8 +404,8 @@ sfc_sw_xstats_get_vals_by_id(struct sfc_adapter *sa, sw_xstats_offset = *nb_supported; - for (i = 0; i < RTE_DIM(sfc_sw_stats_descr); i++) { - sfc_sw_xstat_get_values_by_id(sa, &sfc_sw_stats_descr[i], ids, + for (i = 0; i < sw_stats->supp_count; i++) { + sfc_sw_xstat_get_values_by_id(sa, sw_stats->supp[i].descr, ids, values, n, nb_supported); } @@ -421,13 +424,14 @@ sfc_sw_xstats_get_names_by_id(struct sfc_adapter *sa, unsigned int size, unsigned int *nb_supported) { + struct sfc_sw_stats *sw_stats = &sa->sw_stats; unsigned int i; int ret; sfc_adapter_lock(sa); - for (i = 0; i < RTE_DIM(sfc_sw_stats_descr); i++) { - ret = sfc_sw_xstat_get_names_by_id(sa, &sfc_sw_stats_descr[i], + for (i = 0; i < sw_stats->supp_count; i++) { + ret = sfc_sw_xstat_get_names_by_id(sa, sw_stats->supp[i].descr, ids, xstats_names, size, nb_supported); if (ret != 0) { @@ -475,15 +479,15 @@ void sfc_sw_xstats_reset(struct sfc_adapter *sa) { uint64_t *reset_vals = sa->sw_stats.reset_vals; - const struct sfc_sw_stat_descr *sw_stat; + struct sfc_sw_stats *sw_stats = &sa->sw_stats; unsigned int i; SFC_ASSERT(sfc_adapter_is_locked(sa)); - for (i = 0; i < RTE_DIM(sfc_sw_stats_descr); i++) { - sw_stat = &sfc_sw_stats_descr[i]; - sfc_sw_xstat_reset(sa, sw_stat, reset_vals); - reset_vals += sfc_sw_xstat_get_nb_supported(sa, sw_stat); + for (i = 0; i < sw_stats->supp_count; i++) { + sfc_sw_xstat_reset(sa, sw_stats->supp[i].descr, reset_vals); + reset_vals += sfc_sw_xstat_get_nb_supported(sa, + sw_stats->supp[i].descr); } } @@ -491,22 +495,44 @@ int sfc_sw_xstats_configure(struct sfc_adapter *sa) { uint64_t **reset_vals = &sa->sw_stats.reset_vals; + struct sfc_sw_stats *sw_stats = &sa->sw_stats; size_t nb_supported = 0; unsigned int i; + int rc; + + sw_stats->supp_count = RTE_DIM(sfc_sw_stats_descr); + if (sw_stats->supp == NULL) { + sw_stats->supp = rte_malloc(NULL, sw_stats->supp_count * + sizeof(*sw_stats->supp), 0); + if (sw_stats->supp == NULL) + return -ENOMEM; + } + for (i = 0; i < sw_stats->supp_count; i++) + sw_stats->supp[i].descr = &sfc_sw_stats_descr[i]; - for (i = 0; i < RTE_DIM(sfc_sw_stats_descr); i++) + for (i = 0; i < sw_stats->supp_count; i++) nb_supported += sfc_sw_xstat_get_nb_supported(sa, - &sfc_sw_stats_descr[i]); + sw_stats->supp[i].descr); sa->sw_stats.xstats_count = nb_supported; *reset_vals = rte_realloc(*reset_vals, nb_supported * sizeof(**reset_vals), 0); - if (*reset_vals == NULL) - return ENOMEM; + if (*reset_vals == NULL) { + rc = -ENOMEM; + goto fail_reset_vals; + } memset(*reset_vals, 0, nb_supported * sizeof(**reset_vals)); return 0; + +fail_reset_vals: + sa->sw_stats.xstats_count = 0; + rte_free(sw_stats->supp); + sw_stats->supp = NULL; + sw_stats->supp_count = 0; + + return rc; } static void @@ -552,6 +578,8 @@ int sfc_sw_xstats_init(struct sfc_adapter *sa) { sa->sw_stats.xstats_count = 0; + sa->sw_stats.supp = NULL; + sa->sw_stats.supp_count = 0; sa->sw_stats.reset_vals = NULL; return sfc_sw_xstats_alloc_queues_bitmap(sa); @@ -563,5 +591,8 @@ sfc_sw_xstats_close(struct sfc_adapter *sa) sfc_sw_xstats_free_queues_bitmap(sa); rte_free(sa->sw_stats.reset_vals); sa->sw_stats.reset_vals = NULL; + rte_free(sa->sw_stats.supp); + sa->sw_stats.supp = NULL; + sa->sw_stats.supp_count = 0; sa->sw_stats.xstats_count = 0; } -- 2.30.2