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 5723A4401D; Mon, 13 May 2024 20:55:42 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7990540A70; Mon, 13 May 2024 20:55:08 +0200 (CEST) Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) by mails.dpdk.org (Postfix) with ESMTP id 25C36402F1 for ; Mon, 13 May 2024 20:55:04 +0200 (CEST) Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-5b27c5603ddso2226094eaf.1 for ; Mon, 13 May 2024 11:55:04 -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=LU+R+s5lrkS/n7Y7WnI42Hrf1kiafOz4s5fGKJUBiq0=; b=smDOVn2gs6MBy/+dC6S+pogDAhQt+/2qiF1w8V4ssvQH4sqFvwE0qNakuMp1Xn8R3Q 70Zm0TS8Hb89smx8q+8zfKJS0o5gb5kQ1da9thXsOOpbESwMwG7zPyK7rLuR6RTomiU1 spNlKsyq9f3lbMC5MtyaItoNX7HrQGon70nC9GA/AcArIzsee6svZ10KRFFXvupoi9Xw zcHFL6CwjxSzgjVcotCx/TPtr2a9OagxamMiWq3/NT9270SGTD8ItI2T0vlrFKEaf6FD 5TIYQEbld5wtG0lcwTpQ1lyz8mFUx+BNUvKsgu/Gytjt2+HBf72N4j1JgGwNm3da8V/r NE6Q== 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=LU+R+s5lrkS/n7Y7WnI42Hrf1kiafOz4s5fGKJUBiq0=; b=e/v2dxxem1g5RdBF5TEOHzm4OxqJZ8IZkxS5Y/hSk6U05vkEeNNXO6HkFUJHG8fdAO 3gzbSqbpHtIhBHUlXIdaQrUDQ+sfumIi4RubpzHWAwp81QmMGSsFk8auQ2jOQU8ZpRAX /jhrgLZlxwLVRqR80ITstI+/ELNyaGgVTvQ57PSAd3mfEp9x2vSMkdGNydYkDnqqq34y A00X9WZEesahRBrYxaElCVEWQBIYWLNiQDBhW2AbiUGkpr79mLBgx7dxuMG3iG+8I/1Q ovAdWKG85gos20kBqu/BirBzN8vPd+bwR0XtHnaojwVc/rJgICkSZxi1KYvC3ky2t/5M wdTA== X-Gm-Message-State: AOJu0YxmcGwuefqN4lN5GNZ7qOItR69ELEXmgmKPT05DsRmX7ONAMuty T+5qcY/UNHDzwQbGxnrxSbsJbbq6yWUFFizmDBZj74kpwH8o83+mGm7dlMokdVmPz8oCtFXy5Rt WHKdA7A== X-Google-Smtp-Source: AGHT+IF4xUgV2Tk1FK+wG/N68uCXFWS4Pey03sD1t6IMGFPbSezMJO1lCPhSs7teAcbQKvbaNY6k+Q== X-Received: by 2002:a05:6358:9386:b0:186:119d:8c16 with SMTP id e5c5f4694b2df-193bcfe3671mr1165636355d.23.1715626503459; Mon, 13 May 2024 11:55:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 11:55:03 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Ciara Loftus Subject: [RFC v2 6/7] net/af_xdp: use generic SW stats Date: Mon, 13 May 2024 11:52:16 -0700 Message-ID: <20240513185448.120356-7-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 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 common code for all SW stats. Signed-off-by: Stephen Hemminger --- drivers/net/af_xdp/rte_eth_af_xdp.c | 115 +++++++++++----------------- 1 file changed, 44 insertions(+), 71 deletions(-) diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c index 268a130c49..9420420aa4 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -120,19 +121,13 @@ struct xsk_umem_info { uint32_t max_xsks; }; -struct rx_stats { - uint64_t rx_pkts; - uint64_t rx_bytes; - uint64_t rx_dropped; -}; - struct pkt_rx_queue { struct xsk_ring_cons rx; struct xsk_umem_info *umem; struct xsk_socket *xsk; struct rte_mempool *mb_pool; - struct rx_stats stats; + struct rte_eth_counters stats; struct xsk_ring_prod fq; struct xsk_ring_cons cq; @@ -143,17 +138,11 @@ struct pkt_rx_queue { int busy_budget; }; -struct tx_stats { - uint64_t tx_pkts; - uint64_t tx_bytes; - uint64_t tx_dropped; -}; - struct pkt_tx_queue { struct xsk_ring_prod tx; struct xsk_umem_info *umem; - struct tx_stats stats; + struct rte_eth_counters stats; struct pkt_rx_queue *pair; int xsk_queue_idx; @@ -308,7 +297,6 @@ af_xdp_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct xsk_ring_prod *fq = &rxq->fq; struct xsk_umem_info *umem = rxq->umem; uint32_t idx_rx = 0; - unsigned long rx_bytes = 0; int i; struct rte_mbuf *fq_bufs[ETH_AF_XDP_RX_BATCH_SIZE]; @@ -363,16 +351,13 @@ af_xdp_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) rte_pktmbuf_pkt_len(bufs[i]) = len; rte_pktmbuf_data_len(bufs[i]) = len; - rx_bytes += len; + + rte_eth_count_mbuf(&rxq->stats, bufs[i]); } xsk_ring_cons__release(rx, nb_pkts); (void)reserve_fill_queue(umem, nb_pkts, fq_bufs, fq); - /* statistics */ - rxq->stats.rx_pkts += nb_pkts; - rxq->stats.rx_bytes += rx_bytes; - return nb_pkts; } #else @@ -384,7 +369,6 @@ af_xdp_rx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct xsk_umem_info *umem = rxq->umem; struct xsk_ring_prod *fq = &rxq->fq; uint32_t idx_rx = 0; - unsigned long rx_bytes = 0; int i; uint32_t free_thresh = fq->size >> 1; struct rte_mbuf *mbufs[ETH_AF_XDP_RX_BATCH_SIZE]; @@ -424,16 +408,13 @@ af_xdp_rx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) rte_ring_enqueue(umem->buf_ring, (void *)addr); rte_pktmbuf_pkt_len(mbufs[i]) = len; rte_pktmbuf_data_len(mbufs[i]) = len; - rx_bytes += len; + rte_eth_count_mbuf(&rxq->stats, mbufs[i]); + bufs[i] = mbufs[i]; } xsk_ring_cons__release(rx, nb_pkts); - /* statistics */ - rxq->stats.rx_pkts += nb_pkts; - rxq->stats.rx_bytes += rx_bytes; - return nb_pkts; } #endif @@ -527,9 +508,8 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct pkt_tx_queue *txq = queue; struct xsk_umem_info *umem = txq->umem; struct rte_mbuf *mbuf; - unsigned long tx_bytes = 0; int i; - uint32_t idx_tx; + uint32_t idx_tx, pkt_len; uint16_t count = 0; struct xdp_desc *desc; uint64_t addr, offset; @@ -541,6 +521,7 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) for (i = 0; i < nb_pkts; i++) { mbuf = bufs[i]; + pkt_len = rte_pktmbuf_pkt_len(mbuf); if (mbuf->pool == umem->mb_pool) { if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) { @@ -589,17 +570,13 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) count++; } - tx_bytes += mbuf->pkt_len; + rte_eth_count_packet(&txq->stats, pkt_len); } out: xsk_ring_prod__submit(&txq->tx, count); kick_tx(txq, cq); - txq->stats.tx_pkts += count; - txq->stats.tx_bytes += tx_bytes; - txq->stats.tx_dropped += nb_pkts - count; - return count; } #else @@ -610,7 +587,6 @@ af_xdp_tx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct xsk_umem_info *umem = txq->umem; struct rte_mbuf *mbuf; void *addrs[ETH_AF_XDP_TX_BATCH_SIZE]; - unsigned long tx_bytes = 0; int i; uint32_t idx_tx; struct xsk_ring_cons *cq = &txq->pair->cq; @@ -640,7 +616,8 @@ af_xdp_tx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) pkt = xsk_umem__get_data(umem->mz->addr, desc->addr); rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), desc->len); - tx_bytes += mbuf->pkt_len; + rte_eth_qsw_update(&txq->stats, mbuf); + rte_pktmbuf_free(mbuf); } @@ -648,9 +625,6 @@ af_xdp_tx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) kick_tx(txq, cq); - txq->stats.tx_pkts += nb_pkts; - txq->stats.tx_bytes += tx_bytes; - return nb_pkts; } @@ -847,39 +821,26 @@ 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 *stats) { - struct pmd_internals *internals = dev->data->dev_private; struct pmd_process_private *process_private = dev->process_private; - struct xdp_statistics xdp_stats; - struct pkt_rx_queue *rxq; - struct pkt_tx_queue *txq; - socklen_t optlen; - int i, ret, fd; + unsigned int i; - for (i = 0; i < dev->data->nb_rx_queues; i++) { - optlen = sizeof(struct xdp_statistics); - rxq = &internals->rx_queues[i]; - txq = rxq->pair; - stats->q_ipackets[i] = rxq->stats.rx_pkts; - stats->q_ibytes[i] = rxq->stats.rx_bytes; + rte_eth_counters_stats_get(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats), stats); - stats->q_opackets[i] = txq->stats.tx_pkts; - stats->q_obytes[i] = txq->stats.tx_bytes; + for (i = 0; i < dev->data->nb_rx_queues; i++) { + struct xdp_statistics xdp_stats; + socklen_t optlen = sizeof(xdp_stats); + int fd; - stats->ipackets += stats->q_ipackets[i]; - stats->ibytes += stats->q_ibytes[i]; - stats->imissed += rxq->stats.rx_dropped; - stats->oerrors += txq->stats.tx_dropped; fd = process_private->rxq_xsk_fds[i]; - ret = fd >= 0 ? getsockopt(fd, SOL_XDP, XDP_STATISTICS, - &xdp_stats, &optlen) : -1; - if (ret != 0) { + if (fd < 0) + continue; + if (getsockopt(fd, SOL_XDP, XDP_STATISTICS, + &xdp_stats, &optlen) < 0) { AF_XDP_LOG(ERR, "getsockopt() failed for XDP_STATISTICS.\n"); return -1; } stats->imissed += xdp_stats.rx_dropped; - - stats->opackets += stats->q_opackets[i]; - stats->obytes += stats->q_obytes[i]; } return 0; @@ -888,19 +849,28 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) static int eth_stats_reset(struct rte_eth_dev *dev) { - struct pmd_internals *internals = dev->data->dev_private; - int i; + return rte_eth_counters_reset(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats)); +} - for (i = 0; i < internals->queue_cnt; i++) { - memset(&internals->rx_queues[i].stats, 0, - sizeof(struct rx_stats)); - memset(&internals->tx_queues[i].stats, 0, - sizeof(struct tx_stats)); - } +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); +} - return 0; +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 pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats), + xstats, n); } + #ifdef RTE_NET_AF_XDP_LIBBPF_XDP_ATTACH static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags) @@ -1899,6 +1869,9 @@ static const struct eth_dev_ops ops_cni = { .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, .get_monitor_addr = eth_get_monitor_addr, }; -- 2.43.0