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 574BD43FEC; Fri, 10 May 2024 07:05:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6FAF940685; Fri, 10 May 2024 07:05:18 +0200 (CEST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id A6E2E40395 for ; Fri, 10 May 2024 07:05:14 +0200 (CEST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1ed41eb3382so11862695ad.0 for ; Thu, 09 May 2024 22:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1715317514; x=1715922314; 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=LLMszliOaj8mteL5ALmEOeHR8g/+1DUpiL1DIWKZMxE=; b=jLpjZ4fy9NN8BgsGIk1h6Zlnf7CZgMl0vuS4iNkkbJsmaBCmb2uSC93k1jNaay5QzL xP2ypaDI/Kz+6OH0hhcnJsQ744SuM6hkzYg5rPmGxeI9gruwswTXbDjklhZp0BDHh6wh 1fEyPx0KdXOuMLwsZ2dueSifg8XUQb3q/umWLLHTx1TsJSyIpDxP4TPagQGgsxWOVMSf eVpBnp0He044rxA5NIFvL4XqGuGcF8vmbRpllBQUv8o/YvqOPrOTdZKFAi8/fDL4Soux FHy0J6XfOuXKsyPkbhwnGQ25WPdoi3gk0lkWEW3Dq++4XlZmmLizCosZUIe9y8KWFlcN 36sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715317514; x=1715922314; 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=LLMszliOaj8mteL5ALmEOeHR8g/+1DUpiL1DIWKZMxE=; b=HEG8d+lHtFraAQaOSFkn5xOyHqM5QF+mO+NQaVl0bnH12HJiox5yxOks5zC5ZQPS6+ DG9FJuYcj1R6gLaDHOXXbsujcs7bYD0LhfJLjM7lwhfz9fccgZ9g7rs7S+YOFHWIcnE2 BbcaQVk+ep2M0SCH8wHmV4mYxLFtZOVwoYi1goPCswPleKMVS52NHoGG8AIybriXOqIO o4EHl+1jq6ru1o/W/P4tf7m9qnX0axo7lAjP8utApLT7uEDK0eqQPB1wsufujBWuTZvL Kytihp++NghNTlza7sTw+ZzHAZYgbLd8ugwADoHRMOzVRlKAcx/GbnFj29ZRefjYQDTC ePXQ== X-Gm-Message-State: AOJu0YxAGlDqLAiYLThvFPS5kQ1x23Xfz/SGtpSgWxJPRnmZGO3kw6pv X6JgQygjllnZy+2nHhDnE+sv63ZRHCFxmGmAcjZbhkwHvAaCXUX8tVVuT1jXUh/0tEBv9kLC5Y2 +vbw= X-Google-Smtp-Source: AGHT+IEi/C5oT19Dplssh6sQGmxRN+pL3BUEIOJOYjhJ1tgqxVw59TThAQp1ZhxG6Yx0kEbrPBEYMA== X-Received: by 2002:a17:903:1c2:b0:1e2:bbc0:a671 with SMTP id d9443c01a7336-1ef43f4e22amr25020925ad.52.1715317513875; Thu, 09 May 2024 22:05:13 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c25566asm23007385ad.283.2024.05.09.22.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 22:05:13 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC 3/3] net/tap: use generic SW stats Date: Thu, 9 May 2024 22:01:23 -0700 Message-ID: <20240510050507.14381-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240510050507.14381-1-stephen@networkplumber.org> References: <20240425174617.2126159-1-ferruh.yigit@amd.com> <20240510050507.14381-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 new common sw statistics. Signed-off-by: Stephen Hemminger --- drivers/net/tap/rte_eth_tap.c | 100 ++++++---------------------------- drivers/net/tap/rte_eth_tap.h | 17 ++---- 2 files changed, 21 insertions(+), 96 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 69d9da695b..faf978b59e 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -432,7 +432,6 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rx_queue *rxq = queue; struct pmd_process_private *process_private; uint16_t num_rx; - unsigned long num_rx_bytes = 0; uint32_t trigger = tap_trigger; if (trigger == rxq->trigger_seen) @@ -455,7 +454,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) /* Packet couldn't fit in the provided mbuf */ if (unlikely(rxq->pi.flags & TUN_PKT_STRIP)) { - rxq->stats.ierrors++; + rte_eth_qsw_error_inc(&rxq->stats); continue; } @@ -467,7 +466,9 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp); if (unlikely(!buf)) { - rxq->stats.rx_nombuf++; + struct rte_eth_dev *dev = &rte_eth_devices[rxq->in_port]; + ++dev->data->rx_mbuf_alloc_failed; + /* No new buf has been allocated: do nothing */ if (!new_tail || !seg) goto end; @@ -509,11 +510,9 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) /* account for the receive frame */ bufs[num_rx++] = mbuf; - num_rx_bytes += mbuf->pkt_len; + rte_eth_qsw_update(&rxq->stats, mbuf); } end: - rxq->stats.ipackets += num_rx; - rxq->stats.ibytes += num_rx_bytes; if (trigger && num_rx < nb_pkts) rxq->trigger_seen = trigger; @@ -523,8 +522,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) static inline int tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, - struct rte_mbuf **pmbufs, - uint16_t *num_packets, unsigned long *num_tx_bytes) + struct rte_mbuf **pmbufs) { struct pmd_process_private *process_private; int i; @@ -647,8 +645,7 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, if (n <= 0) return -1; - (*num_packets)++; - (*num_tx_bytes) += rte_pktmbuf_pkt_len(mbuf); + rte_eth_qsw_update(&txq->stats, mbuf); } return 0; } @@ -660,8 +657,6 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) { struct tx_queue *txq = queue; uint16_t num_tx = 0; - uint16_t num_packets = 0; - unsigned long num_tx_bytes = 0; uint32_t max_size; int i; @@ -693,7 +688,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) tso_segsz = mbuf_in->tso_segsz + hdrs_len; if (unlikely(tso_segsz == hdrs_len) || tso_segsz > *txq->mtu) { - txq->stats.errs++; + rte_eth_qsw_error_inc(&txq->stats); break; } gso_ctx->gso_size = tso_segsz; @@ -728,10 +723,10 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) num_mbufs = 1; } - ret = tap_write_mbufs(txq, num_mbufs, mbuf, - &num_packets, &num_tx_bytes); + ret = tap_write_mbufs(txq, num_mbufs, mbuf); if (ret == -1) { - txq->stats.errs++; + rte_eth_qsw_error_inc(&txq->stats); + /* free tso mbufs */ if (num_tso_mbufs > 0) rte_pktmbuf_free_bulk(mbuf, num_tso_mbufs); @@ -749,10 +744,6 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } } - txq->stats.opackets += num_packets; - txq->stats.errs += nb_pkts - num_tx; - txq->stats.obytes += num_tx_bytes; - return num_tx; } @@ -1052,68 +1043,6 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) return 0; } -static int -tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats) -{ - unsigned int i, imax; - unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0; - unsigned long rx_bytes_total = 0, tx_bytes_total = 0; - unsigned long rx_nombuf = 0, ierrors = 0; - const struct pmd_internals *pmd = dev->data->dev_private; - - /* rx queue statistics */ - imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? - dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; - for (i = 0; i < imax; i++) { - tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets; - tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes; - rx_total += tap_stats->q_ipackets[i]; - rx_bytes_total += tap_stats->q_ibytes[i]; - rx_nombuf += pmd->rxq[i].stats.rx_nombuf; - ierrors += pmd->rxq[i].stats.ierrors; - } - - /* tx queue statistics */ - imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? - dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; - - for (i = 0; i < imax; i++) { - tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets; - tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes; - tx_total += tap_stats->q_opackets[i]; - tx_err_total += pmd->txq[i].stats.errs; - tx_bytes_total += tap_stats->q_obytes[i]; - } - - tap_stats->ipackets = rx_total; - tap_stats->ibytes = rx_bytes_total; - tap_stats->ierrors = ierrors; - tap_stats->rx_nombuf = rx_nombuf; - tap_stats->opackets = tx_total; - tap_stats->oerrors = tx_err_total; - tap_stats->obytes = tx_bytes_total; - return 0; -} - -static int -tap_stats_reset(struct rte_eth_dev *dev) -{ - int i; - struct pmd_internals *pmd = dev->data->dev_private; - - for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) { - pmd->rxq[i].stats.ipackets = 0; - pmd->rxq[i].stats.ibytes = 0; - pmd->rxq[i].stats.ierrors = 0; - pmd->rxq[i].stats.rx_nombuf = 0; - - pmd->txq[i].stats.opackets = 0; - pmd->txq[i].stats.errs = 0; - pmd->txq[i].stats.obytes = 0; - } - - return 0; -} static int tap_dev_close(struct rte_eth_dev *dev) @@ -1917,8 +1846,11 @@ static const struct eth_dev_ops ops = { .mac_addr_set = tap_mac_set, .mtu_set = tap_mtu_set, .set_mc_addr_list = tap_set_mc_addr_list, - .stats_get = tap_stats_get, - .stats_reset = tap_stats_reset, + .stats_get = rte_eth_qsw_stats_get, + .stats_reset = rte_eth_qsw_stats_reset, + .xstats_get_names = rte_eth_qsw_xstats_get_names, + .xstats_get = rte_eth_qsw_xstats_get, + .xstats_reset = rte_eth_qsw_stats_reset, .dev_supported_ptypes_get = tap_dev_supported_ptypes_get, .rss_hash_update = tap_rss_hash_update, .flow_ops_get = tap_dev_flow_ops_get, diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index 5ac93f93e9..c05a89a6ab 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include "tap_log.h" @@ -32,22 +33,13 @@ enum rte_tuntap_type { ETH_TUNTAP_TYPE_MAX, }; -struct pkt_stats { - uint64_t opackets; /* Number of output packets */ - uint64_t ipackets; /* Number of input packets */ - uint64_t obytes; /* Number of bytes on output */ - uint64_t ibytes; /* Number of bytes on input */ - uint64_t errs; /* Number of TX error packets */ - uint64_t ierrors; /* Number of RX error packets */ - uint64_t rx_nombuf; /* Nb of RX mbuf alloc failures */ -}; - struct rx_queue { + struct rte_eth_qsw_stats stats; /* MUST BE FIRST */ + struct rte_mempool *mp; /* Mempool for RX packets */ uint32_t trigger_seen; /* Last seen Rx trigger value */ uint16_t in_port; /* Port ID */ uint16_t queue_id; /* queue ID*/ - struct pkt_stats stats; /* Stats for this RX queue */ uint16_t nb_rx_desc; /* max number of mbufs available */ struct rte_eth_rxmode *rxmode; /* RX features */ struct rte_mbuf *pool; /* mbufs pool for this queue */ @@ -56,10 +48,11 @@ struct rx_queue { }; struct tx_queue { + struct rte_eth_qsw_stats stats; /* MUST BE FIRST */ + int type; /* Type field - TUN|TAP */ uint16_t *mtu; /* Pointer to MTU from dev_data */ uint16_t csum:1; /* Enable checksum offloading */ - struct pkt_stats stats; /* Stats for this TX queue */ struct rte_gso_ctx gso_ctx; /* GSO context */ uint16_t out_port; /* Port ID */ uint16_t queue_id; /* queue ID*/ -- 2.43.0