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 9890244099; Wed, 22 May 2024 18:15:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 751AA40A7A; Wed, 22 May 2024 18:14:51 +0200 (CEST) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 003C640693 for ; Wed, 22 May 2024 18:14:44 +0200 (CEST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1ee12baa01cso11490415ad.0 for ; Wed, 22 May 2024 09:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394484; x=1716999284; darn=dpdk.org; 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=x5UrdrHW9F6pfrhHclD4PQZwg1NEIRxD5Iursp/d81w=; b=Q0dWzEjXlpPzP1zJXrDPcoPquHdlFT6FgPlsUxLZxfDEK0/o2Up857AWjA9Wqv1w6x Jaxqmsa5ViArWicCWwFbH7ONYkAv7AMdK/z+F/v02B2GIIF00b6MVmaZwIBqWBmFmMAu hrU5XwnfCkLZVn8awDtBQxiXq9lriWCkoyj5XECr9nh3USUXGSAPkNGIkrFsPFbSNsAa ZFdyly+E9HQYTPQFtqoCwsxEoiDuhEOBXY7uP1D1wJ1jEtDPWhNi5/tpDPM6ndx/StFI 5tk54p2rQ7RN4OSya/5d0oZk+AaEojYyz/rAcmm7Dpghq6vsbdmzxi3IoI2yKWcv0HJ2 mbtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394484; x=1716999284; 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=x5UrdrHW9F6pfrhHclD4PQZwg1NEIRxD5Iursp/d81w=; b=SrA6XDq5hjjXJq6le73+55gnAl4c6tn2LAF0YpRqkwJ+xpvddaq1zB3T777MPHRf6U KMW/3kTe/1EdFLHLQRVj7kdnAyfJUPGLF7kFJnm9+2bEfHiPsfxXUdPnmEL0oOitc0QQ 9fgJSKE6w4F+qU5EmBhdZNDE6Y4f4Ih9JOWupQVtnFa7wVEuzF7kp5atYQPMrKRVt5+o x8IE9pHgqRycF5zcNCqceZMtEDIGpR7ljU2Q5c3DRkLbKzvQwB91mL5PQ0m0bwpJCXS0 Uj1ogrce13mZCyqZEXJM/+RO8687rVuedtQxvOb6dksyl5dSljy4wfqSHMqizHUGJoJq gCeQ== X-Gm-Message-State: AOJu0YzLueiqig8gJKBmkVl8495rRbc50lGmqgnbyGx1yE5oOJ0Lj8Ge CqUX01qJkDWhi9VG8UT7ZL+Xosghs8I3aEMikAMGArmYwe9E7giv+yRItv0g60KoTS0kWeBGmO2 rGiw= X-Google-Smtp-Source: AGHT+IHzkMXCm6fErkqLmzk6hYSE6BZlWnFdpCyDGaIogsRhGwRzS7F0H5OxKmJOqrU5sqb7Z54HtQ== X-Received: by 2002:a17:903:2311:b0:1e3:c419:35c2 with SMTP id d9443c01a7336-1f31c9a55f5mr26141365ad.34.1716394484135; Wed, 22 May 2024 09:14:44 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tetsuya Mukawa Subject: [PATCH v10 8/8] net/null: use generic SW stats Date: Wed, 22 May 2024 09:12:32 -0700 Message-ID: <20240522161427.64568-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-1-stephen@networkplumber.org> 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 Use the new common code for statistics. This also fixes the bug that this driver was not accounting for bytes. Signed-off-by: Stephen Hemminger --- drivers/net/null/rte_eth_null.c | 83 +++++++++------------------------ 1 file changed, 21 insertions(+), 62 deletions(-) diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c index f4ed3b8a7f..83add9c819 100644 --- a/drivers/net/null/rte_eth_null.c +++ b/drivers/net/null/rte_eth_null.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -37,8 +38,8 @@ struct null_queue { struct rte_mempool *mb_pool; struct rte_mbuf *dummy_packet; - RTE_ATOMIC(uint64_t) rx_pkts; - RTE_ATOMIC(uint64_t) tx_pkts; + struct rte_eth_counters tx_stats; + struct rte_eth_counters rx_stats; }; struct pmd_options { @@ -101,9 +102,7 @@ eth_null_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) bufs[i]->port = h->internals->port_id; } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->rx_pkts, i, rte_memory_order_seq_cst); - + rte_eth_count_packets(&h->rx_stats, i, i * packet_size); return i; } @@ -129,8 +128,7 @@ eth_null_copy_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) bufs[i]->port = h->internals->port_id; } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->rx_pkts, i, rte_memory_order_seq_cst); + rte_eth_count_packets(&h->rx_stats, i, i * packet_size); return i; } @@ -147,16 +145,17 @@ eth_null_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { int i; struct null_queue *h = q; + uint32_t tx_bytes = 0; if ((q == NULL) || (bufs == NULL)) return 0; - for (i = 0; i < nb_bufs; i++) + for (i = 0; i < nb_bufs; i++) { + tx_bytes += rte_pktmbuf_pkt_len(bufs[i]); rte_pktmbuf_free(bufs[i]); + } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->tx_pkts, i, rte_memory_order_seq_cst); - + rte_eth_count_packets(&h->tx_stats, i, tx_bytes); return i; } @@ -166,20 +165,20 @@ eth_null_copy_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) int i; struct null_queue *h = q; unsigned int packet_size; + uint32_t tx_bytes = 0; if ((q == NULL) || (bufs == NULL)) return 0; packet_size = h->internals->packet_size; for (i = 0; i < nb_bufs; i++) { + tx_bytes += rte_pktmbuf_pkt_len(bufs[i]); rte_memcpy(h->dummy_packet, rte_pktmbuf_mtod(bufs[i], void *), packet_size); rte_pktmbuf_free(bufs[i]); } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->tx_pkts, i, rte_memory_order_seq_cst); - + rte_eth_count_packets(&h->tx_stats, i, tx_bytes); return i; } @@ -322,60 +321,20 @@ eth_dev_info(struct rte_eth_dev *dev, } static int -eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) +eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { - unsigned int i, num_stats; - unsigned long rx_total = 0, tx_total = 0; - const struct pmd_internals *internal; - - if ((dev == NULL) || (igb_stats == NULL)) - return -EINVAL; - - internal = dev->data->dev_private; - num_stats = RTE_MIN((unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS, - RTE_MIN(dev->data->nb_rx_queues, - RTE_DIM(internal->rx_null_queues))); - for (i = 0; i < num_stats; i++) { - /* NOTE: review for atomic access */ - igb_stats->q_ipackets[i] = - internal->rx_null_queues[i].rx_pkts; - rx_total += igb_stats->q_ipackets[i]; - } - - num_stats = RTE_MIN((unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS, - RTE_MIN(dev->data->nb_tx_queues, - RTE_DIM(internal->tx_null_queues))); - for (i = 0; i < num_stats; i++) { - /* NOTE: review for atomic access */ - igb_stats->q_opackets[i] = - internal->tx_null_queues[i].tx_pkts; - tx_total += igb_stats->q_opackets[i]; - } - - igb_stats->ipackets = rx_total; - igb_stats->opackets = tx_total; - - return 0; + return rte_eth_counters_stats_get(dev, + offsetof(struct null_queue, tx_stats), + offsetof(struct null_queue, rx_stats), + stats); } static int eth_stats_reset(struct rte_eth_dev *dev) { - unsigned int i; - struct pmd_internals *internal; - - if (dev == NULL) - return -EINVAL; - - internal = dev->data->dev_private; - for (i = 0; i < RTE_DIM(internal->rx_null_queues); i++) - /* NOTE: review for atomic access */ - internal->rx_null_queues[i].rx_pkts = 0; - for (i = 0; i < RTE_DIM(internal->tx_null_queues); i++) - /* NOTE: review for atomic access */ - internal->tx_null_queues[i].tx_pkts = 0; - - return 0; + return rte_eth_counters_reset(dev, + offsetof(struct null_queue, tx_stats), + offsetof(struct null_queue, rx_stats)); } static void -- 2.43.0