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 B8CB9460D5; Tue, 21 Jan 2025 16:48:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5783E40264; Tue, 21 Jan 2025 16:48:19 +0100 (CET) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mails.dpdk.org (Postfix) with ESMTP id 0B4654021F for ; Tue, 21 Jan 2025 16:48:17 +0100 (CET) Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2ee989553c1so9997271a91.3 for ; Tue, 21 Jan 2025 07:48:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737474497; x=1738079297; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=6hPDWN3QUAv4Oh4n4WsjeeScY6w9dzSO0YdrTYWirHA=; b=kw8SXUdlaZSQiA6cBUhysSpzit9U4rbXWvm6NeKfVfbMevRxKtIlztQE27HpHJH1I4 b5qNWUGYj4AilTtOaVxntSCeL8USIbI8Y2mWNowAxSpuluO+1ReyE0oeuD4vRjTvy560 gs01T7C9lRt53zXSYMFirCTTT7mywCnXkdy9vVRVGJ6suKuwEdYH0PCRLNyM0/0eAb9s nHPHQi8GNuub9qzsHnZ9JNJu5oC+M96rPt6u1opuw0XZhqfokiHaZBhAQ+RTZwFxd1rP K+JZ7xiXSgPAgUgwiGVWEOwl8wHUiC/NAGflUyaOSUcwJtO4tsCCA2YW87h7ijCI+Apm Y2lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737474497; x=1738079297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6hPDWN3QUAv4Oh4n4WsjeeScY6w9dzSO0YdrTYWirHA=; b=cVJpFghwL0BS/vpOtUOFbXr6l7TB+CyINcmyTetN6Qleh8IxXQdGAfqdB9gPl7Fykr jpm7nAjPZKZu24BTWsscRcTyElZtOPWTUe9XhnsYL2AxFYHwtDehARWV9pHgFLEPMcjq ThLjDrl1oePgohfOvkqKg6WT8QTgRUyUZkVDAxPHfPBFtYaOp6IrCxUIV92/YUBiG+UW GUFZ+Y1sU8E6gOUU8NPz0QM6RnM3WZmHpSpoQQxg1UzWoLd4/bMAESQmKOpBq94V3RUS cODevS+BYVpQwl9lu//DPgKRdri3KkMyw4ZFUGjNNDo2aBLrCYLiUPEhAvWWPj6A9CJp mvFQ== X-Gm-Message-State: AOJu0YyC8Efpl/ILaNJsAx22brgQGd3zfWg4JGdNKTZiYgsUyJdUzxRO zWXoKc5BBgVDQB80rAoStG8Dtk3RN7G9gZRQGXkDRgutJlIAirznITfYVIE0Nsg= X-Gm-Gg: ASbGnct9LORG5ylpCSnoztffle/5enUpFIh50xsOe71VAyVCbg1HyaSna4r8DJK+ug3 +Z6oXareaZOIOL7+bAMkWd3gf0FRBHzX2WLSgn1ZCN5BgotEksdSfikULzO6G45so2VgB4wjI6c xAuqOj84zYBVRa7onA8nHEAUmNq6ROAz79pkkmwB5efDMk7euYkKi3ih6AXDwHgB2wuQBanGYAp R3ybZmIIgI3nOAaDpiGRjkkTpS9Rwl10YvbNpo411jadTDObuqTsQoS4GnnQsT3sMNNSk7ijTSr EiLke3auYPWSIO2xPbKjj7o1ON6J6wjbzRtUgQuyMxDVOOE= X-Google-Smtp-Source: AGHT+IHpbC0M+sdjdLq0ZyutEnAp2BmHD2j7JSYQqGdGEBUYKjuLMw9zvmVPEa2VI5pKJpp++CqONA== X-Received: by 2002:a05:6a00:2184:b0:72a:8cc8:34aa with SMTP id d2e1a72fcca58-72daf88b65dmr27131236b3a.0.1737474497012; Tue, 21 Jan 2025 07:48:17 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab9c8f24sm9404880b3a.108.2025.01.21.07.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 07:48:16 -0800 (PST) Date: Tue, 21 Jan 2025 07:48:15 -0800 From: Stephen Hemminger To: Stefan Laesser Cc: Subject: Re: [PATCH v2] net/af_packet: provide packet drop stats Message-ID: <20250121074815.536fbaf9@hermes.local> In-Reply-To: <20250121122616.301666-1-stefan.laesser@omicronenergy.com> References: <20250116161703.917279-1-stefan.laesser@omicronenergy.com> <20250121122616.301666-1-stefan.laesser@omicronenergy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Tue, 21 Jan 2025 13:26:16 +0100 Stefan Laesser wrote: > + /* query dropped packets counter from socket */ > + if (internal->rx_queue[i].sockfd != -1 && > + getsockopt(internal->rx_queue[i].sockfd, SOL_PACKET, > + PACKET_STATISTICS, &iface_stats, > + &iface_stats_len) > -1) { > + /* > + * keep total because each call to getsocketopt with PACKET_STATISTICS > + * reset the counter of the socket > + */ > + internal->rx_queue[i].rx_dropped_pkts += iface_stats.tp_drops; > + } Since reading the value clears it, maybe stats_reset should call as well? Also, queues greater that the RTE_ETHDEV_STAT_CNTRS should still count against the total. And the two loops could be combined. Maybe something like this? diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 7033910df8..af08e893f1 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -417,50 +417,51 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) return 0; } +/* query dropped packets counter from socket */ +static unsigned int +packet_drop_count(int sockfd) +{ + struct tpacket_stats pkt_stats; + socklen_t pkt_stats_len = sizeof(struct tpacket_stats); + + if (sockfd == -1) + return 0; + + if (getsockopt(sockfd, SOL_PACKET, PACKET_STATISTICS, &pkt_stats, &pkt_stats_len) < -1) + return 0; + + return pkt_stats.tp_drops; +} + static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { - unsigned i, imax; + unsigned int i; unsigned long rx_total = 0, rx_dropped_total = 0, rx_nombuf_total = 0; unsigned long 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++) { - struct tpacket_stats iface_stats; - socklen_t iface_stats_len = sizeof(struct tpacket_stats); - - /* query dropped packets counter from socket */ - if (internal->rx_queue[i].sockfd != -1 && - getsockopt(internal->rx_queue[i].sockfd, SOL_PACKET, - PACKET_STATISTICS, &iface_stats, - &iface_stats_len) > -1) { - /* - * keep total because each call to getsocketopt with PACKET_STATISTICS - * reset the counter of the socket - */ - internal->rx_queue[i].rx_dropped_pkts += iface_stats.tp_drops; - } - - stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts; - stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes; + for (i = 0; i < internal->nb_queues; i++) { + /* reading drop count clears the value */ + internal->rx_queue[i].rx_dropped_pkts += + packet_drop_count(internal->rx_queue[i].sockfd); rx_total += stats->q_ipackets[i]; rx_bytes_total += stats->q_ibytes[i]; rx_dropped_total += internal->rx_queue[i].rx_dropped_pkts; rx_nombuf_total += internal->rx_queue[i].rx_nombuf; - } - imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? - internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS); - for (i = 0; i < imax; i++) { - stats->q_opackets[i] = internal->tx_queue[i].tx_pkts; - stats->q_obytes[i] = internal->tx_queue[i].tx_bytes; tx_total += stats->q_opackets[i]; tx_err_total += internal->tx_queue[i].err_pkts; tx_bytes_total += stats->q_obytes[i]; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts; + stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes; + stats->q_opackets[i] = internal->tx_queue[i].tx_pkts; + stats->q_obytes[i] = internal->tx_queue[i].tx_bytes; + } } stats->ipackets = rx_total; @@ -480,6 +481,7 @@ eth_stats_reset(struct rte_eth_dev *dev) struct pmd_internals *internal = dev->data->dev_private; for (i = 0; i < internal->nb_queues; i++) { + packet_drop_count(internal->rx_queue[i].sockfd); internal->rx_queue[i].rx_pkts = 0; internal->rx_queue[i].rx_bytes = 0; internal->rx_queue[i].rx_nombuf = 0;