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 D7AC243F81; Thu, 16 May 2024 17:44:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0DFAB40684; Thu, 16 May 2024 17:43:44 +0200 (CEST) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mails.dpdk.org (Postfix) with ESMTP id 0FAA3402F1 for ; Thu, 16 May 2024 17:43:41 +0200 (CEST) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6f447976de7so346991b3a.1 for ; Thu, 16 May 2024 08:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1715874220; x=1716479020; 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=SUE9fO9/yU42C4wqedNCLbGs+mpPzKdD4hF5j4IP+8c=; b=qfeRvjDvp/14n/HY7glL4PajYtaM6Ja6drHS6Gsu1c1tCfEyk1U++ZF5EpV3jUQe24 QFike5GdJCGyZR5NjWTvznhVwT9w+TKWBsUfP2rhJlZZPnJPHtVnHCmXUDAVS1ox/snR thnMskMGEB+m8RFm0fFQaphjsPPvTrAvPgQtQC/Va9OZUuCVdMRbhb7+N7Vg8mQ7im3N 4kYwQ00Ytg/dy8uQH7ok0ivniNpYDWvYyuOEQ/VWRgypZdoBXAMe3uXZNctfmHl6yZCB /vLi1BxVtoR9M85i5r7HoJYa3TBaz3v9j5UT6pZ9iGMvCh30W4eaw3F4kH6GeaTeMoWP J8XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874220; x=1716479020; 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=SUE9fO9/yU42C4wqedNCLbGs+mpPzKdD4hF5j4IP+8c=; b=xDJbns6jeymEj69eUh82TnfJLxKxlWg/ScM4UK0LtLqok59YuA2SxwrxikpmRtGvG3 ul7h0Jhp0Tqf8Fw3bqY3yJ8LqBKGp35pgBvNu1MOtVtDzYBbXCtJIon3K58DDbDfxDLh rX6ZRpEqEX3myBGlEr3PKoTi89cbow2JIdKYpYQqXpQ5QGJuMphslhNiciPcJzLNi3dE zzaDM7J20xnc4wzWdHhnPcmMObRlLfSPNbFaJth/13VzGVtQIbpDE1ATNiLuAeO7urhA vec5BxMYq343NPqOKJzIXyJWOLfQUX+Q34yWuTTTpcwo9IaDb0vg0RDZcuZ7va+wh7Od WKQQ== X-Gm-Message-State: AOJu0YwIIId7Fmo4xAwJq8XWB+q9LXHTPm2O0s92XGSIT57Xm69xurOu 7Bt34GHxW0bR7mprfXS70/hvxMlqeRd64eJmimxIs+FyRujwVCmHUW0Ig6gv6gSLgUe2MUfY0fA xuD8= X-Google-Smtp-Source: AGHT+IE0hCC6+LRSJefvQ90kx+owV3ehYfhg9zv3CbBhdtW7CcDP+fXzaahwTxc79nZ2pj7pEjj9WA== X-Received: by 2002:a05:6a00:398e:b0:6f4:d079:bb2b with SMTP id d2e1a72fcca58-6f4e02adb90mr19032084b3a.9.1715874220190; Thu, 16 May 2024 08:43:40 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f67b526b44sm2457430b3a.149.2024.05.16.08.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:43:39 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , "John W. Linville" Subject: [PATCH v5 3/9] net/af_packet: use generic SW stats Date: Thu, 16 May 2024 08:40:39 -0700 Message-ID: <20240516154327.64104-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240516154327.64104-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240516154327.64104-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 generic SW stats. Signed-off-by: Stephen Hemminger --- drivers/net/af_packet/rte_eth_af_packet.c | 82 ++++------------------- 1 file changed, 14 insertions(+), 68 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 397a32db58..89b737e7dc 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include + #define ETH_AF_PACKET_IFACE_ARG "iface" #define ETH_AF_PACKET_NUM_Q_ARG "qpairs" #define ETH_AF_PACKET_BLOCKSIZE_ARG "blocksz" @@ -51,8 +53,7 @@ struct pkt_rx_queue { uint16_t in_port; uint8_t vlan_strip; - volatile unsigned long rx_pkts; - volatile unsigned long rx_bytes; + struct rte_eth_counters stats; }; struct pkt_tx_queue { @@ -64,11 +65,10 @@ struct pkt_tx_queue { unsigned int framecount; unsigned int framenum; - volatile unsigned long tx_pkts; - volatile unsigned long err_pkts; - volatile unsigned long tx_bytes; + struct rte_eth_counters stats; }; + struct pmd_internals { unsigned nb_queues; @@ -118,8 +118,6 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *mbuf; uint8_t *pbuf; struct pkt_rx_queue *pkt_q = queue; - uint16_t num_rx = 0; - unsigned long num_rx_bytes = 0; unsigned int framecount, framenum; if (unlikely(nb_pkts == 0)) @@ -164,13 +162,11 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) /* account for the receive frame */ bufs[i] = mbuf; - num_rx++; - num_rx_bytes += mbuf->pkt_len; + rte_eth_count_mbuf(&pkt_q->stats, mbuf); } pkt_q->framenum = framenum; - pkt_q->rx_pkts += num_rx; - pkt_q->rx_bytes += num_rx_bytes; - return num_rx; + + return i; } /* @@ -205,8 +201,6 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) unsigned int framecount, framenum; struct pollfd pfd; struct pkt_tx_queue *pkt_q = queue; - uint16_t num_tx = 0; - unsigned long num_tx_bytes = 0; int i; if (unlikely(nb_pkts == 0)) @@ -285,8 +279,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) framenum = 0; ppd = (struct tpacket2_hdr *) pkt_q->rd[framenum].iov_base; - num_tx++; - num_tx_bytes += mbuf->pkt_len; + rte_eth_count_mbuf(&pkt_q->stats, mbuf); rte_pktmbuf_free(mbuf); } @@ -298,15 +291,9 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) * packets will be considered successful even though only some * are sent. */ - - num_tx = 0; - num_tx_bytes = 0; } pkt_q->framenum = framenum; - pkt_q->tx_pkts += num_tx; - pkt_q->err_pkts += i - num_tx; - pkt_q->tx_bytes += num_tx_bytes; return i; } @@ -386,58 +373,17 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) } 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 i, imax; - unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0; - unsigned long rx_bytes_total = 0, tx_bytes_total = 0; - const struct pmd_internals *internal = dev->data->dev_private; - - imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? - internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS); - for (i = 0; i < imax; i++) { - igb_stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts; - igb_stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes; - rx_total += igb_stats->q_ipackets[i]; - rx_bytes_total += igb_stats->q_ibytes[i]; - } - - imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? - internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS); - for (i = 0; i < imax; i++) { - igb_stats->q_opackets[i] = internal->tx_queue[i].tx_pkts; - igb_stats->q_obytes[i] = internal->tx_queue[i].tx_bytes; - tx_total += igb_stats->q_opackets[i]; - tx_err_total += internal->tx_queue[i].err_pkts; - tx_bytes_total += igb_stats->q_obytes[i]; - } - - igb_stats->ipackets = rx_total; - igb_stats->ibytes = rx_bytes_total; - igb_stats->opackets = tx_total; - igb_stats->oerrors = tx_err_total; - igb_stats->obytes = tx_bytes_total; - return 0; + return rte_eth_counters_stats_get(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats), stats); } static int eth_stats_reset(struct rte_eth_dev *dev) { - unsigned i; - struct pmd_internals *internal = dev->data->dev_private; - - for (i = 0; i < internal->nb_queues; i++) { - internal->rx_queue[i].rx_pkts = 0; - internal->rx_queue[i].rx_bytes = 0; - } - - for (i = 0; i < internal->nb_queues; i++) { - internal->tx_queue[i].tx_pkts = 0; - internal->tx_queue[i].err_pkts = 0; - internal->tx_queue[i].tx_bytes = 0; - } - - return 0; + return rte_eth_counters_reset(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats)); } static int -- 2.43.0