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 20323460CF; Tue, 21 Jan 2025 13:29:13 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D5C942D7F; Tue, 21 Jan 2025 13:29:13 +0100 (CET) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2100.outbound.protection.outlook.com [40.107.21.100]) by mails.dpdk.org (Postfix) with ESMTP id C44C7427C6 for ; Tue, 21 Jan 2025 13:29:11 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gif3MJmUn55cZeziTQzaNPbOZyCvWhBiYgY70dFU9qhvhPJUnhigbQbSqZ7+HyxpgkET9DrBIcANoVvAGym1NnDfSa5IKqUxxFIg07oKbeof1JKtHmwrSm17Q0Rqr3RKMHA0OO2yAXB+ujmKaCPmxOFflxvklIFWQBO227lTa7i2JO4Tqe2ufuAcVGUrr5Bs7AIgSlDWCvEkD/yTviyKxva0rcHPybOi+7MpW442QNplwThO3XcVS2o007v7lbrdSlBJRRapTdlLFQgIk6OzJQ29dDVo/S6xKUtSdSp3dGq/t9N8/gVVdTradKN+bWveIUQvouNTdO6Dpd+lp6GOfg== 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=eYCsvWB2qclc7YAaL5jP+1jHmvmZnULsZgmRV3mcJi0=; b=QbkaH42F+TAQi0Sb+FxMvQtt5ygSKPno7MDDthZyz4i13EQVQ1BVTbxm03AI5yoE3dw06g9o5ejOLzQyaWWH74WnfY1XfxK1F7Y+EzNKgTNbs2ikzTl7lGnEZek+0lQsWCHbJn/hNMHnpNJhUVM8Hkbu3h070AzBNYrn6agbyXowq/OBBOR0GqG8k48D+kHKGBQIASg4VtWupiW6dqq2Bq3lMILXmlPehuujhnu2lM+enuKPOy1lcHpFpCkubEKy6Aps8ZlPEwDhD+KgA1+pUiOgDJTd66pxFj1zcuQb3mKQ8ALSoTPIcnKfooi4NIggZQLruaZysiUWllXG0N216A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 212.183.10.29) smtp.rcpttodomain=dpdk.org 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=eYCsvWB2qclc7YAaL5jP+1jHmvmZnULsZgmRV3mcJi0=; b=tCavRqExVNQASyRMqKubjrg8bXDVEYLkOAp5nWyjOfCyGntzyhLuPKX/NbrBDEwriUqK2aLXo/BSbICk+xxPG0wRaED9v8sJBUA8sq/D4YF0ROOW/U0jYo9CSczJoUhP0Z84F9fdWIqeJMGtMDQitf88TDoXsLcMJWZnz1vUWzE= Received: from AS9PR05CA0321.eurprd05.prod.outlook.com (2603:10a6:20b:491::14) by DB9PR03MB7809.eurprd03.prod.outlook.com (2603:10a6:10:2c0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.21; Tue, 21 Jan 2025 12:29:06 +0000 Received: from AM3PEPF0000A799.eurprd04.prod.outlook.com (2603:10a6:20b:491:cafe::88) by AS9PR05CA0321.outlook.office365.com (2603:10a6:20b:491::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.22 via Frontend Transport; Tue, 21 Jan 2025 12:29:06 +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 AM3PEPF0000A799.mail.protection.outlook.com (10.167.16.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8377.8 via Frontend Transport; Tue, 21 Jan 2025 12:29:06 +0000 Received: from stelas00wl01.omicron.at (172.22.41.139) 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; Tue, 21 Jan 2025 13:29:03 +0100 From: Stefan Laesser To: CC: , Stefan Laesser Subject: [PATCH v2] net/af_packet: provide packet drop stats Date: Tue, 21 Jan 2025 13:26:16 +0100 Message-ID: <20250121122616.301666-1-stefan.laesser@omicronenergy.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250116161703.917279-1-stefan.laesser@omicronenergy.com> References: <20250116161703.917279-1-stefan.laesser@omicronenergy.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.22.41.139] X-ClientProxiedBy: EXC04-ATKLA.omicron.at (172.22.100.189) To EXC03-ATKLA.omicron.at (172.22.100.188) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A799:EE_|DB9PR03MB7809:EE_ X-MS-Office365-Filtering-Correlation-Id: e84d6db4-6c46-4b50-b5fa-08dd3a17327e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?3lwA7TM3GndTX30ui9zl5+37rBUStsatX72R7D3tcJ43IYxhQIUtLrHm4Zh8?= =?us-ascii?Q?tkWNqd40Yn0EehjFAcp6YJ+Js76eOl8qFCHypaXQktn2fvcGNOA2orCtZgxD?= =?us-ascii?Q?Mu2OiR9a3vftPvfGMXInUaQD878zAKWp7qzEBiUrrm21FMIkZABpkq7HDP7Z?= =?us-ascii?Q?nfC5Wwkievbc9dFux2i1cBHsku4xcnnadp4CfbvYG9h0EGH2TPSbsdZ6BrEc?= =?us-ascii?Q?MQg77M0LCo1I0WsMHXbN8E9Xtd8dbm685IXIG36ynxFBhiW+mpaARui8CxXO?= =?us-ascii?Q?X/ZIRQSvgszWOSB6oUxgwtRHKdrBKQY++Nh71D/q54sjGyaoEqzknSvVVcOH?= =?us-ascii?Q?90aZH6aX2wNrW9i7/7mmS8w/DMoNdfaruUEnqwOD7ENwWkakwf9/QONlRzVF?= =?us-ascii?Q?E70ay9/8Ern2/s41mFW/v6h+PFV7xyq97j4d1sDVoJ1RotYJRy06FgjG9e64?= =?us-ascii?Q?wePncypu2/BuvpJcMyeM2h72wBF2vdg8EFZh2mNlXMVxPHpX2+AFO2QXf5KQ?= =?us-ascii?Q?8p0BeKAy2d6jZwv+dIz16w1S+Qpc5lxq2Qnnn08jaYSwYXNK7ev25ggjY0ci?= =?us-ascii?Q?tx2sx23OyZC36DVs3chjpFj82yRI8SG9wjYgHklmrXTlXpIkywJIBlIf+iB6?= =?us-ascii?Q?HtshIhPgWfLChpG1V+tY0ixyOwTzleUmCIQyVaLF5+LWAJujDiBv9T57S4yK?= =?us-ascii?Q?bE9+awURAoE/ieXhcZprlGwxqK82t7r3fmWWIae5j0lIcAJhB8hbEHW7nxHO?= =?us-ascii?Q?IaAfJ6W74MpWRijp/CARZ3uKte//CnAx79XSrRXu/GQ4Sv13WqqptHOlMHoO?= =?us-ascii?Q?h+v0iD07Gfi0fNKxtHTF1EoKT5qxXu3bGGrjDGR7OgwNuNfZWfwdQN5VMO+G?= =?us-ascii?Q?0xmKcfCUX0E+z2e7tPpm220sHtW9+oUareFsZOVjVBGp7Z6iHBFMH99wxk2R?= =?us-ascii?Q?xjP3P0qqM8X0q2uODiKFu/0E3GOtLbcgWWBgm0UPM7ul2EtUw1F+SsD9tKHS?= =?us-ascii?Q?X6oj04Bfp6SWxeBLfdJS3NCYmhbK9wiujmfMJ/XCQ9xya1sPmGL2lv9Ai73v?= =?us-ascii?Q?H3/mTU6hlr+n9wbRl9pxIt1S4GGj/r5JinWEvrAGYnvR94xhBxzm+HS+UMXJ?= =?us-ascii?Q?PlydjAVRwBv7yCE1XNJYs+UwrlphKZ268cTAMqRsYZyggvaK60plXwXR9oh3?= =?us-ascii?Q?cCOCL2qn9BUJyjpDDpnUNBU0lH0sC+YXyG0G80v2Vb2OKwpslBfbx3xodgdb?= =?us-ascii?Q?ZnpIOgurCv3FB97NUenMDv3vapNuqMeL03RSo1ZjNV/sYibeV6JHOH7zHIL4?= =?us-ascii?Q?xocE2SZSiKC2uw42tV9tZqE1h/Sq5MpireEyNkIV35E1t+yBq9EzE6LNO9fz?= =?us-ascii?Q?fxTJ8fvZpVldpwveolHPJtgXJvv27aT2bQFTLZHUx9iCWFwDPYN9xSYOj/Rf?= =?us-ascii?Q?CD3vQfNB2bAcbBznyYPQLQ2xkHEcu+VJQbBIW17WNiZcJE0nE0QMrwiFL8DB?= =?us-ascii?Q?Rp8nEeRZamaDh6A=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)(36860700013)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1102; X-OriginatorOrg: omicronenergy.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2025 12:29:06.1520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e84d6db4-6c46-4b50-b5fa-08dd3a17327e 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: AM3PEPF0000A799.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR03MB7809 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 could not be allocated. Signed-off-by: Stefan Laesser --- v2: * Limited scope of tpacket_stats and socklen_t variables and moved them inside the for-loop in function eth_stats_get. * Removed q_errors counting as dropped packets should not be counted as errors. * Renamed parameter igb_stats of function eth_stats_get to stats since it was a copy/paste issue. drivers/net/af_packet/rte_eth_af_packet.c | 59 +++++++++++++++++------ 1 file changed, 43 insertions(+), 16 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..7033910df8 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; @@ -414,37 +418,58 @@ 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_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++) { - 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]; + 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; + + 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++) { - 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]; + 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 += igb_stats->q_obytes[i]; + tx_bytes_total += stats->q_obytes[i]; } - 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; + stats->ipackets = rx_total; + stats->ibytes = rx_bytes_total; + stats->imissed = rx_dropped_total; + stats->rx_nombuf = rx_nombuf_total; + stats->opackets = tx_total; + stats->oerrors = tx_err_total; + stats->obytes = tx_bytes_total; return 0; } @@ -457,6 +482,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