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 0A22541CF1; Mon, 20 Feb 2023 22:11:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 996104310D; Mon, 20 Feb 2023 22:11:11 +0100 (CET) Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by mails.dpdk.org (Postfix) with ESMTP id 4E4D643108 for ; Mon, 20 Feb 2023 22:11:10 +0100 (CET) Received: by mail-ed1-f50.google.com with SMTP id cq23so9153929edb.1 for ; Mon, 20 Feb 2023 13:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ld5jjGjxxpHI8zTXzURdRFY2fXzfvJT+TvEp5aSnmSk=; b=qqTgru6uZlwjd89MSiev6NdfaDcH4mevNpvrRoFb/fCr0yh0HF+9KptzzyxlDMg4zB ZHiboNZvjNGjHilMLwGAmBjHNEcM0WwjXl808g9P0t7/lc3vZ350WnngQT97qnZieJfD LnngBlP0wF+vp+hu3JMaVmgZvtZZDuegwsUEiVIFiu47SYI1meflKFgJ0atTEexy0Lbo 9lZAOsLA5JfyCyX9GoZj+YmxwRqEaZOmDZXJ4cpafT+IzQJxJzsKRW0/DTnlD7g5yQk3 o7Y1Hb9I0riUc/J0hYN4tT2m+2Arlfk4irTJnBCyiO5qIo5Rj/MvKz4N66pR+QSlSyUm TOfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ld5jjGjxxpHI8zTXzURdRFY2fXzfvJT+TvEp5aSnmSk=; b=5DzpIdc/mBkpmwC/7LxJjJiH2OWByhZE8sNf652lspENFQ8GpRoXm3QxOsLfmlm4ZT LEfLTzIaRoUSUIWEz0nP2aHPNHkNmG/5+BO/VjD8mOufo6t4zO65vUzMb9+dUwC5U4fb r02d5is5B1DEuEt1qJyW/rSVd1KoBOqdikwgvSww4G8Spl2JX3vjUXwNWHtEhELfZ3Ca IoOCU1JbuUEF59u4VR3DUqwIr6UWa8UXgoHN4ejSrG1Y3cduC8MTxhyeyC3B+gyg/L1K I1rsSpnkCwMDtle27ByuH0Rm1ZQyDDsfj4s+90aY/F+KD8wE5El+D0s3F5jKAg10O3cZ pj2w== X-Gm-Message-State: AO0yUKUVdPLlt17VchOXn22Nqqjyzk0p+yG15LxFm7OJek9zi2x39SGF Oq/S/QJk+PJsI0elz9Y4VDs= X-Google-Smtp-Source: AK7set+qtrYY/rdM2W7VFkj3UEWvaetV1Pf/F2AGoFCSzQC5igcZzVc1wLhzahr4JJVxuaazH1DRCg== X-Received: by 2002:a05:6402:355:b0:4ae:e547:e563 with SMTP id r21-20020a056402035500b004aee547e563mr3345574edw.36.1676927469946; Mon, 20 Feb 2023 13:11:09 -0800 (PST) Received: from localhost.localdomain ([176.41.28.141]) by smtp.gmail.com with ESMTPSA id o1-20020a50c281000000b004aef4f3bc26sm2430093edf.87.2023.02.20.13.11.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 20 Feb 2023 13:11:09 -0800 (PST) From: Levend Sayar To: junfeng.guo@intel.com Cc: dev@dpdk.org, Levend Sayar Subject: [PATCH v3 2/2] net/gve: add Rx/Tx queue stats as extended stats Date: Tue, 21 Feb 2023 00:11:02 +0300 Message-Id: <20230220211103.8282-2-levendsayar@gmail.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230220211103.8282-1-levendsayar@gmail.com> References: <20230220151936.2716-1-levendsayar@gmail.com> <20230220211103.8282-1-levendsayar@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Google Virtual NIC rx/tx queue stats are added as extended stats. Signed-off-by: Levend Sayar --- drivers/net/gve/gve_ethdev.c | 143 +++++++++++++++++++++++++++++++---- drivers/net/gve/gve_ethdev.h | 27 +++++-- drivers/net/gve/gve_rx.c | 10 +-- drivers/net/gve/gve_tx.c | 11 +-- 4 files changed, 160 insertions(+), 31 deletions(-) diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c index fef2458a16..8b6e4b1322 100644 --- a/drivers/net/gve/gve_ethdev.c +++ b/drivers/net/gve/gve_ethdev.c @@ -9,6 +9,18 @@ const char gve_version_str[] = GVE_VERSION; static const char gve_version_prefix[] = GVE_VERSION_PREFIX; +static const struct gve_xstats_name_offset tx_xstats_name_offset[] = { + { "packets", offsetof(struct gve_tx_stats, packets) }, + { "bytes", offsetof(struct gve_tx_stats, bytes) }, + { "errors", offsetof(struct gve_tx_stats, errors) }, +}; + +static const struct gve_xstats_name_offset rx_xstats_name_offset[] = { + { "packets", offsetof(struct gve_rx_stats, packets) }, + { "bytes", offsetof(struct gve_rx_stats, bytes) }, + { "errors", offsetof(struct gve_rx_stats, errors) }, +}; + static void gve_write_version(uint8_t *driver_version_register) { @@ -328,9 +340,9 @@ gve_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) if (txq == NULL) continue; - stats->opackets += txq->packets; - stats->obytes += txq->bytes; - stats->oerrors += txq->errors; + stats->opackets += txq->stats.packets; + stats->obytes += txq->stats.bytes; + stats->oerrors += txq->stats.errors; } for (i = 0; i < dev->data->nb_rx_queues; i++) { @@ -338,10 +350,10 @@ gve_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) if (rxq == NULL) continue; - stats->ipackets += rxq->packets; - stats->ibytes += rxq->bytes; - stats->ierrors += rxq->errors; - stats->rx_nombuf += rxq->no_mbufs; + stats->ipackets += rxq->stats.packets; + stats->ibytes += rxq->stats.bytes; + stats->ierrors += rxq->stats.errors; + stats->rx_nombuf += rxq->stats.no_mbufs; } return 0; @@ -357,9 +369,7 @@ gve_dev_stats_reset(struct rte_eth_dev *dev) if (txq == NULL) continue; - txq->packets = 0; - txq->bytes = 0; - txq->errors = 0; + memset(&txq->stats, 0, sizeof(txq->stats)); } for (i = 0; i < dev->data->nb_rx_queues; i++) { @@ -367,10 +377,7 @@ gve_dev_stats_reset(struct rte_eth_dev *dev) if (rxq == NULL) continue; - rxq->packets = 0; - rxq->bytes = 0; - rxq->errors = 0; - rxq->no_mbufs = 0; + memset(&rxq->stats, 0, sizeof(rxq->stats)); } return 0; @@ -403,6 +410,112 @@ gve_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) return 0; } +static int +gve_xstats_count(struct rte_eth_dev *dev) +{ + uint16_t i, count = 0; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + if (dev->data->tx_queues[i]) + count += RTE_DIM(tx_xstats_name_offset); + } + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + if (dev->data->rx_queues[i]) + count += RTE_DIM(rx_xstats_name_offset); + } + + return count; +} + +static int +gve_xstats_get(struct rte_eth_dev *dev, + struct rte_eth_xstat *xstats, + unsigned int size) +{ + uint16_t i, count = 0; + + if (!xstats) + return (size == 0) ? gve_xstats_count(dev) : -EINVAL; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + const struct gve_tx_queue *txq = dev->data->tx_queues[i]; + if (!txq) + continue; + + if (count >= size) + break; + + uint16_t j = 0; + const char *stats = (const char *)&txq->stats; + for (j = 0; j < RTE_DIM(tx_xstats_name_offset); j++, count++) { + xstats[count].id = count; + xstats[count].value = *(const uint64_t *) + (stats + tx_xstats_name_offset[j].offset); + } + } + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + const struct gve_rx_queue *rxq = dev->data->rx_queues[i]; + if (!rxq) + continue; + + if (count >= size) + break; + + uint16_t j = 0; + const char *stats = (const char *)&rxq->stats; + for (j = 0; j < RTE_DIM(rx_xstats_name_offset); j++, count++) { + xstats[count].id = count; + xstats[count].value = *(const uint64_t *) + (stats + rx_xstats_name_offset[j].offset); + } + } + + return count; +} + +static int +gve_xstats_get_names(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names, + unsigned int size) +{ + uint16_t i, count = 0; + + if (!xstats_names) + return (size == 0) ? gve_xstats_count(dev) : -EINVAL; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + if (!dev->data->tx_queues[i]) + continue; + + if (count >= size) + break; + + uint16_t j = 0; + for (; j < RTE_DIM(tx_xstats_name_offset); j++) + snprintf(xstats_names[count++].name, + RTE_ETH_XSTATS_NAME_SIZE, + "tx_q%u_%s", i, tx_xstats_name_offset[j].name); + } + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + if (!dev->data->rx_queues[i]) + continue; + + if (count >= size) + break; + + uint16_t j = 0; + for (; j < RTE_DIM(rx_xstats_name_offset); j++) + snprintf(xstats_names[count++].name, + RTE_ETH_XSTATS_NAME_SIZE, + "rx_q%u_%s", i, rx_xstats_name_offset[j].name); + } + + return count; +} + static const struct eth_dev_ops gve_eth_dev_ops = { .dev_configure = gve_dev_configure, .dev_start = gve_dev_start, @@ -417,6 +530,8 @@ static const struct eth_dev_ops gve_eth_dev_ops = { .stats_get = gve_dev_stats_get, .stats_reset = gve_dev_stats_reset, .mtu_set = gve_dev_mtu_set, + .xstats_get = gve_xstats_get, + .xstats_get_names = gve_xstats_get_names, }; static void diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h index 64e571bcae..bc351d808b 100644 --- a/drivers/net/gve/gve_ethdev.h +++ b/drivers/net/gve/gve_ethdev.h @@ -67,6 +67,24 @@ struct gve_tx_iovec { uint32_t iov_len; }; +struct gve_tx_stats { + uint64_t packets; + uint64_t bytes; + uint64_t errors; +}; + +struct gve_rx_stats { + uint64_t packets; + uint64_t bytes; + uint64_t errors; + uint64_t no_mbufs; +}; + +struct gve_xstats_name_offset { + char name[RTE_ETH_XSTATS_NAME_SIZE]; + unsigned int offset; +}; + struct gve_tx_queue { volatile union gve_tx_desc *tx_desc_ring; const struct rte_memzone *mz; @@ -93,9 +111,7 @@ struct gve_tx_queue { struct gve_tx_iovec *iov_ring; /* stats items */ - uint64_t packets; - uint64_t bytes; - uint64_t errors; + struct gve_tx_stats stats; uint16_t port_id; uint16_t queue_id; @@ -136,10 +152,7 @@ struct gve_rx_queue { struct gve_queue_page_list *qpl; /* stats items */ - uint64_t packets; - uint64_t bytes; - uint64_t errors; - uint64_t no_mbufs; + struct gve_rx_stats stats; struct gve_priv *hw; const struct rte_memzone *qres_mz; diff --git a/drivers/net/gve/gve_rx.c b/drivers/net/gve/gve_rx.c index d346efa57c..b52f924689 100644 --- a/drivers/net/gve/gve_rx.c +++ b/drivers/net/gve/gve_rx.c @@ -27,7 +27,7 @@ gve_rx_refill(struct gve_rx_queue *rxq) rxq->sw_ring[idx + i] = nmb; } if (i != nb_alloc) { - rxq->no_mbufs += nb_alloc - i; + rxq->stats.no_mbufs += nb_alloc - i; nb_alloc = i; } } @@ -62,7 +62,7 @@ gve_rx_refill(struct gve_rx_queue *rxq) rxq->sw_ring[idx + i] = nmb; } if (i != nb_alloc) { - rxq->no_mbufs += nb_alloc - i; + rxq->stats.no_mbufs += nb_alloc - i; nb_alloc = i; } } @@ -106,7 +106,7 @@ gve_rx_burst(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) break; if (rxd->flags_seq & GVE_RXF_ERR) { - rxq->errors++; + rxq->stats.errors++; continue; } @@ -154,8 +154,8 @@ gve_rx_burst(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) gve_rx_refill(rxq); if (nb_rx) { - rxq->packets += nb_rx; - rxq->bytes += bytes; + rxq->stats.packets += nb_rx; + rxq->stats.bytes += bytes; } return nb_rx; diff --git a/drivers/net/gve/gve_tx.c b/drivers/net/gve/gve_tx.c index 9b41c59358..fee3b939c7 100644 --- a/drivers/net/gve/gve_tx.c +++ b/drivers/net/gve/gve_tx.c @@ -366,9 +366,9 @@ gve_tx_burst_qpl(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) txq->tx_tail = tx_tail; txq->sw_tail = sw_id; - txq->packets += nb_tx; - txq->bytes += bytes; - txq->errors += nb_pkts - nb_tx; + txq->stats.packets += nb_tx; + txq->stats.bytes += bytes; + txq->stats.errors += nb_pkts - nb_tx; } return nb_tx; @@ -455,8 +455,9 @@ gve_tx_burst_ra(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) rte_write32(rte_cpu_to_be_32(tx_tail), txq->qtx_tail); txq->tx_tail = tx_tail; - txq->packets += nb_tx; - txq->bytes += bytes; + txq->stats.packets += nb_tx; + txq->stats.bytes += bytes; + txq->stats.errors += nb_pkts - nb_tx; } return nb_tx; -- 2.37.1 (Apple Git-137.1)