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 D0FB344052; Fri, 17 May 2024 19:41:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 33FD440A75; Fri, 17 May 2024 19:40:59 +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 0192940695 for ; Fri, 17 May 2024 19:40:54 +0200 (CEST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1e651a9f3ffso15447975ad.1 for ; Fri, 17 May 2024 10:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1715967653; x=1716572453; 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=RQHsK1gWBPW+bM15aASK3G4n/oOoE48zyy1OE2N7qD4=; b=X7fs9+NLvBiGZk1zHreO/HIDYst1qVA3uR0jK3Md8DgBoQCD0VxoVcHsOhnMeusymr drX8O4Xqo1JXTl5SDaWo4YV3s504hi24YINMs+htn4UD6ILIOVnBN8vmGIzDqsCtz0eq 5t2m0AgUBX/GLURb7EISEGOG4/yOyApwAYg1Q8EXQnuisurgYaDZ11zPzgL9hLfP0E+Y y+IT+e0OzQl1wm5JWSbMj76KGTHLdGYEYGg9jrpZksAhvoUVwESVItLEG7yDvqn2BQl9 xRYYO1VNShNHoSS+/IgtCrRZcoznhQfyJZ/Z8x+/Px+3AeUsZeKqHnPnlVAYB05KS3yj I+tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715967653; x=1716572453; 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=RQHsK1gWBPW+bM15aASK3G4n/oOoE48zyy1OE2N7qD4=; b=aZ4/60++bUZ7Uufove1JIIpsRHHAcqCzn+67Vtgo1Cf2y5IFtiDEzudicfESuKrXe2 FoWEFOJGwdt5gqcFeXpXQqT1eRGlMHL7/4/ludnPh1OV+zx2sC6XGV0nB2OYuWkwH7Or ZiTGyawlz7+GU97/dSkcfvog4mhWWtaVJqOpSyVYFuRMuvUdyqvzM6msQxYVyKjUVqIO qLOUo7RecvnYob2xskTFwCmRY+xs9TK4cO11SOGqQiKEI6qzHfJ57vZ4bzoSgs8GjL/l 3guNFFk27pdf1cJIqgucgCO9s9JirstwBGgP8/erN58ok8dHN3ViwDt1zvu5o/c4hvRM bgYQ== X-Gm-Message-State: AOJu0YwBc+DQKBTdMyR8nNVt4fWpTPfwYrbpN4j0ppGOeNyahUt7v5R8 I1Sz9hDblWAP9q+fTwBpHZKwX++UQRuqFd4rj5m4TpxObj61IxfbQMdRPMZ55DSykq07fOLkAXM IX4Y= X-Google-Smtp-Source: AGHT+IHeicD0+gB2h1RrAvFG+4HmSFdW4C6Abft2mLPrceuNGDVEdfuBWat4QUY8CRmXZviSAhkkBw== X-Received: by 2002:a17:902:fc4f:b0:1e8:c962:4f6e with SMTP id d9443c01a7336-1ef43d27f6fmr254015385ad.20.1715967653073; Fri, 17 May 2024 10:40:53 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bf31032sm158830485ad.131.2024.05.17.10.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 10:40:52 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v7 7/9] net/ring: use generic SW stats Date: Fri, 17 May 2024 10:35:14 -0700 Message-ID: <20240517174044.90952-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240517174044.90952-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240517174044.90952-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 generic per-queue infrastructure. This also fixes bug where ring code was not accounting for bytes. Signed-off-by: Stephen Hemminger --- drivers/net/ring/rte_eth_ring.c | 71 +++++++++++++-------------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c index b16f5d55f2..85f14dd679 100644 --- a/drivers/net/ring/rte_eth_ring.c +++ b/drivers/net/ring/rte_eth_ring.c @@ -7,6 +7,7 @@ #include "rte_eth_ring.h" #include #include +#include #include #include #include @@ -44,8 +45,8 @@ enum dev_action { struct ring_queue { struct rte_ring *rng; - RTE_ATOMIC(uint64_t) rx_pkts; - RTE_ATOMIC(uint64_t) tx_pkts; + + struct rte_eth_counters stats; }; struct pmd_internals { @@ -77,12 +78,13 @@ eth_ring_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { void **ptrs = (void *)&bufs[0]; struct ring_queue *r = q; - const uint16_t nb_rx = (uint16_t)rte_ring_dequeue_burst(r->rng, - ptrs, nb_bufs, NULL); - if (r->rng->flags & RING_F_SC_DEQ) - r->rx_pkts += nb_rx; - else - rte_atomic_fetch_add_explicit(&r->rx_pkts, nb_rx, rte_memory_order_relaxed); + uint16_t i, nb_rx; + + nb_rx = (uint16_t)rte_ring_dequeue_burst(r->rng, ptrs, nb_bufs, NULL); + + for (i = 0; i < nb_rx; i++) + rte_eth_count_mbuf(&r->stats, bufs[i]); + return nb_rx; } @@ -90,13 +92,20 @@ static uint16_t eth_ring_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { void **ptrs = (void *)&bufs[0]; + uint32_t *sizes; struct ring_queue *r = q; - const uint16_t nb_tx = (uint16_t)rte_ring_enqueue_burst(r->rng, - ptrs, nb_bufs, NULL); - if (r->rng->flags & RING_F_SP_ENQ) - r->tx_pkts += nb_tx; - else - rte_atomic_fetch_add_explicit(&r->tx_pkts, nb_tx, rte_memory_order_relaxed); + uint16_t i, nb_tx; + + sizes = alloca(sizeof(uint32_t) * nb_bufs); + + for (i = 0; i < nb_bufs; i++) + sizes[i] = rte_pktmbuf_pkt_len(bufs[i]); + + nb_tx = (uint16_t)rte_ring_enqueue_burst(r->rng, ptrs, nb_bufs, NULL); + + for (i = 0; i < nb_tx; i++) + rte_eth_count_packet(&r->stats, sizes[i]); + return nb_tx; } @@ -193,40 +202,16 @@ eth_dev_info(struct rte_eth_dev *dev, static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { - unsigned int i; - unsigned long rx_total = 0, tx_total = 0; - const struct pmd_internals *internal = dev->data->dev_private; - - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && - i < dev->data->nb_rx_queues; i++) { - stats->q_ipackets[i] = internal->rx_ring_queues[i].rx_pkts; - rx_total += stats->q_ipackets[i]; - } - - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && - i < dev->data->nb_tx_queues; i++) { - stats->q_opackets[i] = internal->tx_ring_queues[i].tx_pkts; - tx_total += stats->q_opackets[i]; - } - - stats->ipackets = rx_total; - stats->opackets = tx_total; - - return 0; + return rte_eth_counters_stats_get(dev, offsetof(struct ring_queue, stats), + offsetof(struct ring_queue, stats), + stats); } static int eth_stats_reset(struct rte_eth_dev *dev) { - unsigned int i; - struct pmd_internals *internal = dev->data->dev_private; - - for (i = 0; i < dev->data->nb_rx_queues; i++) - internal->rx_ring_queues[i].rx_pkts = 0; - for (i = 0; i < dev->data->nb_tx_queues; i++) - internal->tx_ring_queues[i].tx_pkts = 0; - - return 0; + return rte_eth_counters_reset(dev, offsetof(struct ring_queue, stats), + offsetof(struct ring_queue, stats)); } static void -- 2.43.0