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 5C949460A3; Thu, 16 Jan 2025 17:17:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 038EE402F1; Thu, 16 Jan 2025 17:17:45 +0100 (CET) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2092.outbound.protection.outlook.com [40.107.22.92]) by mails.dpdk.org (Postfix) with ESMTP id DAC804026C for ; Thu, 16 Jan 2025 17:17:43 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HQCpdh1kWc2X9Old4i0q+Ft/YxMjr1z8Dr72dfayB+MrdtM3hgogxrMerJtrjnE8yeX8CCujhvQg/drO8dAq/TP8XhOzl1gEs0ncS9DcvpUTkrrg9k+NxgtJzNWdFTMCk6iGZ5Y3vxGb+wIL1YDt4L8yROtY3Q9B2k9edg/H4ioALBNrOB7sf3AGXFjtayslH3W2BeB2r9HBhuJm32IP1fXIXazic8dX35TCWs9BPI1kSQX7yfp6IB4cm0ywGeR2sc57oGQgkPP+gK3WC6DrDnA7NKWFjNNFVgp24BWzByt9nlXGQ6nK/2MxEJi0fBuzW4Zv088Dov5s3Vohjw0AXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=avVRnY3kMXM3Rrl1xnFjsLEgbKP3xk0jeadwJECqoQ4=; b=l0i5g47sshi+K7kdctbJg6XiF54EuRN/yf601desDUHppAQwrJHvk0Tleyjc0oFBDYQ/Ey5Htl7LNKEI4xdCXj/2Q3rmMcgNV73s8HdQzaixRwbHLJ1zsru6h4gcmGflL4WxfFl+9C5DUAVYVB0FYql7Lsz+0ZFRtrY9ofAUV2rGyKJhmBPsQnsnHFiT9+WkH77l2b0SLTsPKYYYfV+ayHkJZahPrWPB8Gn9S+hnUOZRMGs4mtdJ3EsfzlASwgOOBbauEhpgEh5QNDZfmoj2w2SF5jGZOada8phqMoNyYbxOlwYoXkrP9Fsr8m4CW84WTSetezH3TKCGwZ45ltF48w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 212.183.10.29) smtp.rcpttodomain=tuxdriver.com smtp.mailfrom=omicronenergy.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=omicronenergy.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omicronenergy.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=avVRnY3kMXM3Rrl1xnFjsLEgbKP3xk0jeadwJECqoQ4=; b=rMtizaU4js8Wgu2xfMLJQXL+BZVrSx4k4CypdV5DfQAZpiJFS/HdXT87yNKXWbTI8kKDZUbPy0upYfovvaKxosq1/VQiGWA+j/svgIfa86kfkSIr/R8GPer1Z6HuSdpAtHNfQsohs6dgaYsoHcB2zO5oly/O3Jzcy4e8uETn83g= Received: from AM0P190CA0015.EURP190.PROD.OUTLOOK.COM (2603:10a6:208:190::25) by PAXPR03MB7548.eurprd03.prod.outlook.com (2603:10a6:102:1db::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 16:17:38 +0000 Received: from AM2PEPF0001C717.eurprd05.prod.outlook.com (2603:10a6:208:190:cafe::43) by AM0P190CA0015.outlook.office365.com (2603:10a6:208:190::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.13 via Frontend Transport; Thu, 16 Jan 2025 16:17:38 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 212.183.10.29) smtp.mailfrom=omicronenergy.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=omicronenergy.com; Received-SPF: Fail (protection.outlook.com: domain of omicronenergy.com does not designate 212.183.10.29 as permitted sender) receiver=protection.outlook.com; client-ip=212.183.10.29; helo=outlook.omicron.at; Received: from outlook.omicron.at (212.183.10.29) by AM2PEPF0001C717.mail.protection.outlook.com (10.167.16.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Thu, 16 Jan 2025 16:17:38 +0000 Received: from stelas00wl01.omicron.at (172.22.41.135) by EXC03-ATKLA.omicron.at (172.22.100.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 16 Jan 2025 17:17:36 +0100 From: Stefan Laesser To: "John W. Linville" CC: , Stefan Laesser Subject: [PATCH] net/af_packet: provide packet drop stats Date: Thu, 16 Jan 2025 17:17:03 +0100 Message-ID: <20250116161703.917279-1-stefan.laesser@omicronenergy.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.22.41.135] X-ClientProxiedBy: EXC03-ATKLA.omicron.at (172.22.100.188) To EXC03-ATKLA.omicron.at (172.22.100.188) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM2PEPF0001C717:EE_|PAXPR03MB7548:EE_ X-MS-Office365-Filtering-Correlation-Id: d40123e9-fecd-4f43-85f2-08dd36494bbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Fs4PV9DPQW1+DWQg7asj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?us-ascii?Q?+bniK2MYeOllQRsMu+rWJFU3AzimQYqP1vsx8qhcwdkNdyUOEldq9jFKmTip?= =?us-ascii?Q?NEKf7VVFkOqw1TmDVwCBKuERT0A/S83P/IT5hLm1tXLcC4w7c75uov9xB1ZB?= =?us-ascii?Q?hH78sU9PFqjAZNFtmnIib9cJh85qUyIbVrgO5MtFCkg41EA8nmmhf/il/VZv?= =?us-ascii?Q?ibcbPOEOmNQ0eJvmWnDPzyyHgcxdmdjfz24ZPjwMrB57eWIiLmoslTf46iwv?= =?us-ascii?Q?hZtuRIBRtjljj+U91TQqraZ9gvK0pI692Ezkxr6f2j7HHFryxhail9iwtdtb?= =?us-ascii?Q?DlApW5Vvd5iVgYaHreW2njMz77OcmfCt05JsdsvGpzqKYiG2fJGbrnaoc3Va?= =?us-ascii?Q?xUOXnV0B56Rcpc7xrInQkuNjMIs10nSbxvC58Ej1gZP+/ecGI29CL7FngEQ1?= =?us-ascii?Q?S28DPTDVa/8/oUYecOP/ZTcATaZYmbD5Cr4cPCtCRocJPuWk/mI/+QiPfMJT?= =?us-ascii?Q?UdVsCs66BFqJ86rFUW3/0BSzgj0dkQZgV0CNwSbqkxi5Ye3qBVmtIVtVbpUT?= =?us-ascii?Q?bIISol0C3N8KoxK/rXm3H4M1+UXTBWHxMHh43Vj5avPU5gRBjTO+sdwLasTd?= =?us-ascii?Q?PPY8PqM2w7f2aJE=3D?= X-Forefront-Antispam-Report: CIP:212.183.10.29; CTRY:AT; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:outlook.omicron.at; PTR:212-183-10-29.omicron.at; CAT:NONE; SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1102; X-OriginatorOrg: omicronenergy.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 16:17:38.6987 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d40123e9-fecd-4f43-85f2-08dd36494bbe X-MS-Exchange-CrossTenant-Id: 1357ca9e-a1a5-404b-bb16-554d5d05c5c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=1357ca9e-a1a5-404b-bb16-554d5d05c5c9; Ip=[212.183.10.29]; Helo=[outlook.omicron.at] X-MS-Exchange-CrossTenant-AuthSource: AM2PEPF0001C717.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR03MB7548 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 Linux kernel provides the ability to query the packet drop counter of a socket. This information can be provided when the user requests stats. It is important to note that each call to getsockopt with PACKET_STATISTICS resets the internal counters. So the caller needs to keep track of the total count on its own. Next, I have added a counter for the case when mbuf couldn't be allocated. Signed-off-by: Stefan Laesser --- drivers/net/af_packet/rte_eth_af_packet.c | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index ceb8d9356a..a771dd854d 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -58,6 +58,8 @@ struct __rte_cache_aligned pkt_rx_queue { volatile unsigned long rx_pkts; volatile unsigned long rx_bytes; + volatile unsigned long rx_nombuf; + volatile unsigned long rx_dropped_pkts; }; struct __rte_cache_aligned pkt_tx_queue { @@ -145,8 +147,10 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) /* allocate the next mbuf */ mbuf = rte_pktmbuf_alloc(pkt_q->mb_pool); - if (unlikely(mbuf == NULL)) + if (unlikely(mbuf == NULL)) { + pkt_q->rx_nombuf++; break; + } /* packet will fit in the mbuf, go ahead and receive it */ rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_len(mbuf) = ppd->tp_snaplen; @@ -417,17 +421,37 @@ static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) { unsigned i, imax; - unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0; + 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; + struct tpacket_stats iface_stats; + socklen_t iface_stats_len = sizeof(struct tpacket_stats); + imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS); for (i = 0; i < imax; i++) { + /* 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; + } + igb_stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts; igb_stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes; + igb_stats->q_errors[i] = internal->rx_queue[i].rx_dropped_pkts; + rx_total += igb_stats->q_ipackets[i]; rx_bytes_total += igb_stats->q_ibytes[i]; + rx_dropped_total += igb_stats->q_errors[i]; + rx_nombuf_total += internal->rx_queue[i].rx_nombuf; } imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? @@ -442,6 +466,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) igb_stats->ipackets = rx_total; igb_stats->ibytes = rx_bytes_total; + igb_stats->imissed = rx_dropped_total; + igb_stats->rx_nombuf = rx_nombuf_total; igb_stats->opackets = tx_total; igb_stats->oerrors = tx_err_total; igb_stats->obytes = tx_bytes_total; @@ -457,6 +483,8 @@ eth_stats_reset(struct rte_eth_dev *dev) for (i = 0; i < internal->nb_queues; i++) { internal->rx_queue[i].rx_pkts = 0; internal->rx_queue[i].rx_bytes = 0; + internal->rx_queue[i].rx_nombuf = 0; + internal->rx_queue[i].rx_dropped_pkts = 0; } for (i = 0; i < internal->nb_queues; i++) { -- 2.34.1