From patchwork Mon May 13 18:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140044 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 06A364401D; Mon, 13 May 2024 20:55:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4828640A6B; Mon, 13 May 2024 20:55:07 +0200 (CEST) Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by mails.dpdk.org (Postfix) with ESMTP id 7F5A540695 for ; Mon, 13 May 2024 20:55:03 +0200 (CEST) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5b2baa24c2bso867442eaf.0 for ; Mon, 13 May 2024 11:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1715626503; x=1716231303; 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=zQ+ooLtUkL2XITzIc3SCHv9JSV9L31lszmoiqikUo6c=; b=0fm+uWLEgmUGZboZa2FqIiiS6s5iQLrCib6Hu7xSWzjCS24MkrOVY2+LfCplDWwZ7W pjXHqAfn480WvCJn7Re8+8F10U4UtCNWseoNNIpkPCVFX1ty6a1MZBOl3oD2Ca1OmR7q Va8y/1bAMo6D29eoGeqqrLZbLzrHVfC40t4sZ2Z2jIqCA3Uc1fub1utp0pT6FTHXfb2L DwlS5RmECSxkHFuC3PsItcfca3hR02wbmK1UdkNL89d3yT1osGn/EBrn3BhGk8FaYLBc pxkCd7ag2LoishXruspQdbFc0wsB7p+N5iDB5mZsXlrdoHtT5uX+xz4X8k81xINXkAvz RMuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715626503; x=1716231303; 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=zQ+ooLtUkL2XITzIc3SCHv9JSV9L31lszmoiqikUo6c=; b=nb0TM5k+8D5AT0pd8hnmKTTnT5RhDXVTIp1UwVVXVX1duoxT7NQ7XyA/BZBZ1NJCYs uoplAVyvrHy7zeJQ3HjglXWKKGMEss3K47ckA8SC+UhNcSdnZZ6Ko0uYrd0M6eDvKRbL WFY9k+YdiAI0XoTfc7BDW4juZdKTd7ns8hneedOQZ5/qBGUgWZhWeNss9gUpv8+tixZw BQ7DJcwBikRQJFNfMy3r3OXkMPgCT11qLI30RuUUIrNydST/vjyK/3dkww2hmx6C3Jqj fPKuCq88dGp9HYZsoBGwI0pi+RElJllab/DJXWidLYkgcAJY5re+QRqLp296O4SGzMaV g/hw== X-Gm-Message-State: AOJu0YwxBF1RKK13WV0ACLZqnoXUeWoTnGyhIUNtoV1tyhOV5CkfOtq7 Wfou07sxbndcOKO4qGWMZtmYGBsrD/dSUOKncMPzeJ7LKBnHmhX1DgmxrmfXavE9WBTMmAMUxJA 2YMs7lA== X-Google-Smtp-Source: AGHT+IEiXpt2s7FWSddOmelAWywZnHlbKXjaiS1c2LR4JrXIAvUNixObC6BK8cEqFIyNTPbUQx9mkg== X-Received: by 2002:a05:6358:418b:b0:186:1066:7aa0 with SMTP id e5c5f4694b2df-193bd00844emr1117508355d.29.1715626502516; Mon, 13 May 2024 11:55:02 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-634103f7237sm8154680a12.71.2024.05.13.11.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 11:55:02 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC v2 5/7] net/pcap: use generic SW stats Date: Mon, 13 May 2024 11:52:15 -0700 Message-ID: <20240513185448.120356-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240513185448.120356-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240513185448.120356-1-stephen@networkplumber.org> MIME-Version: 1.0 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 common statistics for SW drivers. Signed-off-by: Stephen Hemminger --- drivers/net/pcap/pcap_ethdev.c | 146 +++++++++++---------------------- 1 file changed, 47 insertions(+), 99 deletions(-) diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index bfec085045..872a3ed9a4 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -48,13 +49,6 @@ static uint8_t iface_idx; static uint64_t timestamp_rx_dynflag; static int timestamp_dynfield_offset = -1; -struct queue_stat { - volatile unsigned long pkts; - volatile unsigned long bytes; - volatile unsigned long err_pkts; - volatile unsigned long rx_nombuf; -}; - struct queue_missed_stat { /* last value retrieved from pcap */ unsigned int pcap; @@ -68,7 +62,7 @@ struct pcap_rx_queue { uint16_t port_id; uint16_t queue_id; struct rte_mempool *mb_pool; - struct queue_stat rx_stat; + struct rte_eth_counters rx_stat; struct queue_missed_stat missed_stat; char name[PATH_MAX]; char type[ETH_PCAP_ARG_MAXLEN]; @@ -80,7 +74,7 @@ struct pcap_rx_queue { struct pcap_tx_queue { uint16_t port_id; uint16_t queue_id; - struct queue_stat tx_stat; + struct rte_eth_counters tx_stat; char name[PATH_MAX]; char type[ETH_PCAP_ARG_MAXLEN]; }; @@ -238,7 +232,6 @@ eth_pcap_rx_infinite(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) { int i; struct pcap_rx_queue *pcap_q = queue; - uint32_t rx_bytes = 0; if (unlikely(nb_pkts == 0)) return 0; @@ -252,39 +245,35 @@ eth_pcap_rx_infinite(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) if (err) return i; + rte_eth_count_mbuf(&pcap_q->rx_stat, pcap_buf); + rte_memcpy(rte_pktmbuf_mtod(bufs[i], void *), rte_pktmbuf_mtod(pcap_buf, void *), pcap_buf->data_len); bufs[i]->data_len = pcap_buf->data_len; bufs[i]->pkt_len = pcap_buf->pkt_len; bufs[i]->port = pcap_q->port_id; - rx_bytes += pcap_buf->data_len; + /* Enqueue packet back on ring to allow infinite rx. */ rte_ring_enqueue(pcap_q->pkts, pcap_buf); } - pcap_q->rx_stat.pkts += i; - pcap_q->rx_stat.bytes += rx_bytes; - return i; } static uint16_t eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) { + struct pcap_rx_queue *pcap_q = queue; + struct rte_eth_dev *dev = &rte_eth_devices[pcap_q->port_id]; + struct pmd_process_private *pp = dev->process_private; + pcap_t *pcap = pp->rx_pcap[pcap_q->queue_id]; unsigned int i; struct pcap_pkthdr header; - struct pmd_process_private *pp; const u_char *packet; struct rte_mbuf *mbuf; - struct pcap_rx_queue *pcap_q = queue; uint16_t num_rx = 0; - uint32_t rx_bytes = 0; - pcap_t *pcap; - - pp = rte_eth_devices[pcap_q->port_id].process_private; - pcap = pp->rx_pcap[pcap_q->queue_id]; if (unlikely(pcap == NULL || nb_pkts == 0)) return 0; @@ -300,7 +289,7 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool); if (unlikely(mbuf == NULL)) { - pcap_q->rx_stat.rx_nombuf++; + ++dev->data->rx_mbuf_alloc_failed; break; } @@ -315,7 +304,7 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) mbuf, packet, header.caplen) == -1)) { - pcap_q->rx_stat.err_pkts++; + rte_eth_count_error(&pcap_q->rx_stat); rte_pktmbuf_free(mbuf); break; } @@ -329,11 +318,10 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) mbuf->ol_flags |= timestamp_rx_dynflag; mbuf->port = pcap_q->port_id; bufs[num_rx] = mbuf; + + rte_eth_count_mbuf(&pcap_q->rx_stat, mbuf); num_rx++; - rx_bytes += header.caplen; } - pcap_q->rx_stat.pkts += num_rx; - pcap_q->rx_stat.bytes += rx_bytes; return num_rx; } @@ -379,8 +367,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *mbuf; struct pmd_process_private *pp; struct pcap_tx_queue *dumper_q = queue; - uint16_t num_tx = 0; - uint32_t tx_bytes = 0; struct pcap_pkthdr header; pcap_dumper_t *dumper; unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN]; @@ -412,8 +398,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) pcap_dump((u_char *)dumper, &header, rte_pktmbuf_read(mbuf, 0, caplen, temp_data)); - num_tx++; - tx_bytes += caplen; + rte_eth_count_mbuf(&dumper_q->tx_stat, mbuf); rte_pktmbuf_free(mbuf); } @@ -423,9 +408,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) * we flush the pcap dumper within each burst. */ pcap_dump_flush(dumper); - dumper_q->tx_stat.pkts += num_tx; - dumper_q->tx_stat.bytes += tx_bytes; - dumper_q->tx_stat.err_pkts += nb_pkts - num_tx; return nb_pkts; } @@ -437,20 +419,16 @@ static uint16_t eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) { unsigned int i; - uint32_t tx_bytes = 0; struct pcap_tx_queue *tx_queue = queue; if (unlikely(nb_pkts == 0)) return 0; for (i = 0; i < nb_pkts; i++) { - tx_bytes += bufs[i]->pkt_len; + rte_eth_count_mbuf(&tx_queue->tx_stat, bufs[i]); rte_pktmbuf_free(bufs[i]); } - tx_queue->tx_stat.pkts += nb_pkts; - tx_queue->tx_stat.bytes += tx_bytes; - return i; } @@ -465,8 +443,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *mbuf; struct pmd_process_private *pp; struct pcap_tx_queue *tx_queue = queue; - uint16_t num_tx = 0; - uint32_t tx_bytes = 0; pcap_t *pcap; unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN]; size_t len; @@ -497,15 +473,11 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) rte_pktmbuf_read(mbuf, 0, len, temp_data), len); if (unlikely(ret != 0)) break; - num_tx++; - tx_bytes += len; + + rte_eth_count_mbuf(&tx_queue->tx_stat, mbuf); rte_pktmbuf_free(mbuf); } - tx_queue->tx_stat.pkts += num_tx; - tx_queue->tx_stat.bytes += tx_bytes; - tx_queue->tx_stat.err_pkts += i - num_tx; - return i; } @@ -746,41 +718,12 @@ static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { unsigned int i; - unsigned long rx_packets_total = 0, rx_bytes_total = 0; - unsigned long rx_missed_total = 0; - unsigned long rx_nombuf_total = 0, rx_err_total = 0; - unsigned long tx_packets_total = 0, tx_bytes_total = 0; - unsigned long tx_packets_err_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_queue[i].rx_stat.pkts; - stats->q_ibytes[i] = internal->rx_queue[i].rx_stat.bytes; - rx_nombuf_total += internal->rx_queue[i].rx_stat.rx_nombuf; - rx_err_total += internal->rx_queue[i].rx_stat.err_pkts; - rx_packets_total += stats->q_ipackets[i]; - rx_bytes_total += stats->q_ibytes[i]; - rx_missed_total += queue_missed_stat_get(dev, i); - } - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && - i < dev->data->nb_tx_queues; i++) { - stats->q_opackets[i] = internal->tx_queue[i].tx_stat.pkts; - stats->q_obytes[i] = internal->tx_queue[i].tx_stat.bytes; - tx_packets_total += stats->q_opackets[i]; - tx_bytes_total += stats->q_obytes[i]; - tx_packets_err_total += internal->tx_queue[i].tx_stat.err_pkts; - } + rte_eth_counters_stats_get(dev, offsetof(struct pcap_tx_queue, tx_stat), + offsetof(struct pcap_rx_queue, rx_stat), stats); - stats->ipackets = rx_packets_total; - stats->ibytes = rx_bytes_total; - stats->imissed = rx_missed_total; - stats->ierrors = rx_err_total; - stats->rx_nombuf = rx_nombuf_total; - stats->opackets = tx_packets_total; - stats->obytes = tx_bytes_total; - stats->oerrors = tx_packets_err_total; + for (i = 0; i < dev->data->nb_rx_queues; i++) + stats->imissed += queue_missed_stat_get(dev, i); return 0; } @@ -789,25 +732,34 @@ 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_queue[i].rx_stat.pkts = 0; - internal->rx_queue[i].rx_stat.bytes = 0; - internal->rx_queue[i].rx_stat.err_pkts = 0; - internal->rx_queue[i].rx_stat.rx_nombuf = 0; - queue_missed_stat_reset(dev, i); - } + rte_eth_counters_reset(dev, offsetof(struct pcap_tx_queue, tx_stat), + offsetof(struct pcap_rx_queue, rx_stat)); - for (i = 0; i < dev->data->nb_tx_queues; i++) { - internal->tx_queue[i].tx_stat.pkts = 0; - internal->tx_queue[i].tx_stat.bytes = 0; - internal->tx_queue[i].tx_stat.err_pkts = 0; - } + for (i = 0; i < dev->data->nb_rx_queues; i++) + queue_missed_stat_reset(dev, i); return 0; } +static int +eth_xstats_get_names(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *names, + __rte_unused unsigned int limit) +{ + return rte_eth_counters_xstats_get_names(dev, names); +} + +static int +eth_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, + unsigned int n) +{ + return rte_eth_counters_xstats_get(dev, offsetof(struct pcap_tx_queue, tx_stat), + offsetof(struct pcap_rx_queue, rx_stat), + xstats, n); +} + + static inline void infinite_rx_ring_free(struct rte_ring *pkts) { @@ -929,13 +881,6 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, pcap_pkt_count); return -EINVAL; } - - /* - * Reset the stats for this queue since eth_pcap_rx calls above - * didn't result in the application receiving packets. - */ - pcap_q->rx_stat.pkts = 0; - pcap_q->rx_stat.bytes = 0; } return 0; @@ -1005,6 +950,9 @@ static const struct eth_dev_ops ops = { .link_update = eth_link_update, .stats_get = eth_stats_get, .stats_reset = eth_stats_reset, + .xstats_get_names = eth_xstats_get_names, + .xstats_get = eth_xstats_get, + .xstats_reset = eth_stats_reset, }; static int