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 55EB144044; Fri, 17 May 2024 02:14:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 384EE40A7F; Fri, 17 May 2024 02:13:35 +0200 (CEST) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTP id 59AA44067D for ; Fri, 17 May 2024 02:13:20 +0200 (CEST) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5c6bd3100fcso552963a12.3 for ; Thu, 16 May 2024 17:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1715904799; x=1716509599; 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=F1v3feu5BR4POSxHAthIeXNE69YI+TXuZU380J4Tk78=; b=dwNTnaLDHVrKv3S+nQvYgSSq6uXpOT+tXkCKdXn5vBFg8IdE9XFu8Zk8VTk6cDrUOr de5h+VFckNYCL5FJjaOD34BWESBef6of3sNKoRS1HeiybFIwR1DJs9WW2d3N9n0Bq2lU ohdwh23b7UGAW1db/a6fGy0SOvgTwGQ8bBOmDjxe9+CPWMz/RVPI2q1DcM3mBDj0qnBl lr9loaZ+tbKEAIbc//VC7EvNRSu5+7bw/3noxUf9BEFIa1ctS7qGgR9Q/TLB3claab42 aoeW2fuBuvpBdBcG869en7IwA6lmSGVaUNVZVke8vGKBmpdMCD+tNRheRkAGC737K45N u7gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715904799; x=1716509599; 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=F1v3feu5BR4POSxHAthIeXNE69YI+TXuZU380J4Tk78=; b=U9VaDJ15Co8VnLSt9EWhxawcEQde1tzv7PPWk9lkkWSM0bx/54e7GEK2nRB7OIULwI kqaDVNsVHnPJOe8AsbwO9wGzk63mFjxubUQMGfWCiHNO2FH8QY7FaeTH22D+vJvYpFSK EqTED4iritDwzBnNx9BridhidGVuq3+MUKEr+D3uHLRN+21qOoF1785gEp5xJ8WVXe77 vF3ozJUWHxk7WqmUaZqqezpiwoPwXSwmRgRUkdT/D3q5wJeZfTZ0Mcnsgu16wMuV9pQn NKANvgJcxsz10u/GDz0KGZNM4wUAsEUO6iKf4f+hhf5SxDRQN1seL/itTu1/XAh1LFcp A25w== X-Gm-Message-State: AOJu0YzqSTJCIW1xbJfhs030MB++ndtfCDkqpzeAP6aBW6b5nXXj6tKP YaPw6ZJRxl6J1USD41mwQVhQ3Gp1UZ+kw56ufwocSPOk6YrnwZ3ZAvDRNBetYIKOegdzIooO/Hg zxdU= X-Google-Smtp-Source: AGHT+IFbZxZhQrCC/BTVe7VPoFv9B+seQoGLAwoNHOylu2i8UN4bSM5FMy7/aP8T0ARlUh+7nhk5dA== X-Received: by 2002:a17:90a:f2d8:b0:2b9:f6bc:e4c1 with SMTP id 98e67ed59e1d1-2b9f6bceda6mr4783545a91.28.1715904799495; Thu, 16 May 2024 17:13:19 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b9f5820ce9sm3337495a91.56.2024.05.16.17.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 17:13:19 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tetsuya Mukawa Subject: [PATCH v6 9/9] net/null: use generic SW stats Date: Thu, 16 May 2024 17:12:09 -0700 Message-ID: <20240517001302.65514-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240517001302.65514-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240517001302.65514-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 | 80 +++++++-------------------------- 1 file changed, 17 insertions(+), 63 deletions(-) diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c index 7c46004f1e..7786982732 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; - uint64_t rx_pkts; - uint64_t tx_pkts; + struct rte_eth_counters tx_stats; + struct rte_eth_counters rx_stats; }; struct pmd_options { @@ -99,11 +100,9 @@ eth_null_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) bufs[i]->data_len = (uint16_t)packet_size; bufs[i]->pkt_len = packet_size; bufs[i]->port = h->internals->port_id; + rte_eth_count_mbuf(&h->rx_stats, bufs[i]); } - /* NOTE: review for potential ordering optimization */ - __atomic_fetch_add(&h->rx_pkts, i, __ATOMIC_SEQ_CST); - return i; } @@ -127,11 +126,9 @@ eth_null_copy_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) bufs[i]->data_len = (uint16_t)packet_size; bufs[i]->pkt_len = packet_size; bufs[i]->port = h->internals->port_id; + rte_eth_count_mbuf(&h->rx_stats, bufs[i]); } - /* NOTE: review for potential ordering optimization */ - __atomic_fetch_add(&h->rx_pkts, i, __ATOMIC_SEQ_CST); - return i; } @@ -151,11 +148,10 @@ eth_null_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) if ((q == NULL) || (bufs == NULL)) return 0; - for (i = 0; i < nb_bufs; i++) + for (i = 0; i < nb_bufs; i++) { + rte_eth_count_mbuf(&h->tx_stats, bufs[i]); rte_pktmbuf_free(bufs[i]); - - /* NOTE: review for potential ordering optimization */ - __atomic_fetch_add(&h->tx_pkts, i, __ATOMIC_SEQ_CST); + } return i; } @@ -174,12 +170,10 @@ eth_null_copy_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) for (i = 0; i < nb_bufs; i++) { rte_memcpy(h->dummy_packet, rte_pktmbuf_mtod(bufs[i], void *), packet_size); + rte_eth_count_mbuf(&h->tx_stats, bufs[i]); rte_pktmbuf_free(bufs[i]); } - /* NOTE: review for potential ordering optimization */ - __atomic_fetch_add(&h->tx_pkts, i, __ATOMIC_SEQ_CST); - return i; } @@ -322,60 +316,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