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 6C67943F05; Tue, 30 Apr 2024 17:41:42 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E87F14025C; Tue, 30 Apr 2024 17:41:41 +0200 (CEST) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mails.dpdk.org (Postfix) with ESMTP id 287D1400EF for ; Tue, 30 Apr 2024 17:41:40 +0200 (CEST) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2a2d82537efso4062483a91.2 for ; Tue, 30 Apr 2024 08:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1714491699; x=1715096499; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=q8hJBGVhtgF1yQH3NG2ZqTJNslHUE9K+DYFcGr0nXnM=; b=lq6ISv4U/oJSyIwKWNIbSKIIxfFOyaiyGAR1uK0Qu8FJax0nmKEp7ZBiIFrSMrL8pA ANCKCDXQ+moEA/NZ4sbV9cNQAVUHBWn47H/QdUHeSKOahL7rq7fts054C1mw5zzR8AC2 Hfz2xPU37yTbtop5DL8ipylP6ioLTDusrOxvOvr3PxLsp5H6oeJuUc6pqgGH1xAYNDgA B0QKGvqHAl3xXgIPYHHasXvym9UKBJzo43uHzYHGOpQOK3M3nKHyiXaexHiCetv09H6A 1bPFmT4deK05h0y6KH5i1RlF/X3g2r81zgbeqsKA1Tio+bx/sDoLp926fXLhJWWCI8sc 44iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714491699; x=1715096499; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q8hJBGVhtgF1yQH3NG2ZqTJNslHUE9K+DYFcGr0nXnM=; b=VrxwAm7cdwV5PmAv609O9RD1gNKPUdpwBWxrJ65t1a1HX9WenZ4h0Fm/cKSNbYX4Ok RavllBq98mpLXPFz4Jr6jBJfiNV3kDml2OMaE2oE3N5MmX6WylhmI0J6msA8hk8Nwp+n xhNLkfwvFoji6Do92f4uZNvJfdvNql0nX83YZs3xfamykaZAkn4sSgIUu5659KxGZ41o 5DTQr08UZIkE+doPY7zJQqyoGVg8sTUXc7hY3UNtTGmW/0jvcUif1XqSA6t92u0rC+r9 cL9ar6/M6CwE48mLuu8hqaZNfWw/2rBmYiKf1NS/pjLRcrO4JSSO4ILNyLXtiPZLtNpL 3IQg== X-Gm-Message-State: AOJu0YzsIBgrAxxCeTOfeYxn4wZaiaSKO378O6wZzbHRTLfqvUsOAFu6 bduhttMhzHViIMv0y/NAX9P2VHWXFTq8c4KtEm26vycaz/oBsnt92zkplio1drrHE2pMuldAXtO R X-Google-Smtp-Source: AGHT+IFLLWn6F8a5w60iJh1BZBoj2aoC99FEZwGKX1XgVgu0LQX+xWXE9lbzY+HkqA0tdA6niM6ywg== X-Received: by 2002:a17:90a:654c:b0:2ac:dbec:2d6f with SMTP id f12-20020a17090a654c00b002acdbec2d6fmr13731171pjs.39.1714491699103; Tue, 30 Apr 2024 08:41:39 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id z3-20020a170903018300b001ec38cdc133sm1724057plg.260.2024.04.30.08.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:41:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , "John W. Linville" Subject: [PATCH] net/af_packet: fix statistics Date: Tue, 30 Apr 2024 08:39:46 -0700 Message-ID: <20240430154129.7347-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 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 The statistics in af_packet driver do not follow the standard practice of other drivers: - Statistics should be maintained as 64 bit even on 32 bit. - Remove the tx_error counter since it was not correct. When transmit ring is full it is not an error and the driver correctly returns only the number sent. - Query kernel to find the number of packets missed. - Do not mark statistics as volatile. Instead, READ_ONCE() where necessary. Also, the variable namge igb_stats looks like a copy/paste leftover Signed-off-by: Stephen Hemminger --- drivers/net/af_packet/rte_eth_af_packet.c | 82 +++++++++++++---------- 1 file changed, 48 insertions(+), 34 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..0313aee482 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -39,6 +39,10 @@ #define DFLT_FRAME_SIZE (1 << 11) #define DFLT_FRAME_COUNT (1 << 9) +#ifndef READ_ONCE +#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) +#endif + struct pkt_rx_queue { int sockfd; @@ -51,8 +55,8 @@ struct pkt_rx_queue { uint16_t in_port; uint8_t vlan_strip; - volatile unsigned long rx_pkts; - volatile unsigned long rx_bytes; + uint64_t rx_pkts; + uint64_t rx_bytes; }; struct pkt_tx_queue { @@ -64,9 +68,8 @@ 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; + uint64_t tx_pkts; + uint64_t tx_bytes; }; struct pmd_internals { @@ -305,7 +308,6 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) 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,54 +388,66 @@ 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; + unsigned int i; const struct pmd_internals *internal = dev->data->dev_private; + uint64_t bytes, packets; + + for (i = 0; i < internal->nb_queues; i++) { + const struct pkt_rx_queue *rxq = &internal->rx_queue[i]; + struct tpacket_stats pkt_stats; + socklen_t optlen = sizeof(pkt_stats); + int fd = rxq->sockfd; + + bytes = READ_ONCE(rxq->rx_bytes); + packets = READ_ONCE(rxq->rx_pkts); - 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]; + stats->ipackets += packets; + stats->ibytes += bytes; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_ipackets[i] = packets; + stats->q_ibytes[i] = bytes; + } + + if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &pkt_stats, &optlen) < 0) { + PMD_LOG_ERRNO(ERR, "could not getet PACKET_STATISTICS on AF_PACKET socket"); + return -1; + } + stats->imissed = pkt_stats.tp_drops; } - 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]; + for (i = 0; i < internal->nb_queues; i++) { + const struct pkt_tx_queue *txq = &internal->tx_queue[i]; + + bytes = READ_ONCE(txq->tx_bytes); + packets = READ_ONCE(txq->tx_pkts); + + stats->opackets += packets; + stats->obytes += bytes; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_opackets[i] = packets; + stats->q_obytes[i] = bytes; + } } - 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; } static int eth_stats_reset(struct rte_eth_dev *dev) { - unsigned i; + unsigned int 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; } -- 2.43.0