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 7050F460E0; Wed, 22 Jan 2025 08:29:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F878402A9; Wed, 22 Jan 2025 08:29:03 +0100 (CET) Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11021131.outbound.protection.outlook.com [52.101.65.131]) by mails.dpdk.org (Postfix) with ESMTP id ADCC1402A4 for ; Wed, 22 Jan 2025 08:29:01 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VkDqZlEWJ81UyuO2viXtIhD/f5LiCs9BKR+1MYI8ED3rxS2jkIf8DR8g3B5iYNFdRR7H89XM5kr31MOcXnPMWqhtS7KWP/ey7GwMToroCBQ9bE0SUw4dl1Y2V5Xv+z482kw9NRu9dRYjuoYrXhpUmAn53izP7yJTGkaSRJB38hT2cVDwTnC8rTM9xDmRA+bSoggKm+T/FwT+PqyigvYfnacK4J27gaqBfnKLtacfArXZuskMUen4XsC+hodWPNz3BFToWGLJQxy0W7ZkUmvXH95Totaw9TQqSqujJCQ1KXRh0xg3idAWO1HfwvdbC0FPec/Hr869I1cfBWaU2s4bgg== 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=DZ0N/nj/seFefxUV/VxIzeiVdBLrUxt0bzGGyaFRcgc=; b=LxP+pMNMDVQysCTO5CCmSG4yAan1dZ9kRtUO9Qt3PeSWnoFac7ImTMJtJW6VKf2skzgntcCWc6+8d3s+hU9F1MWuubKmho5UN4TsovvBazrUETQCYUeVEhz3Mj415kq3FOYpdyH3JofO4DfF8t7L7hQpzau1Tg0vii9gw/ANBEDrqukSV1pylKKgxuxLQJzqK4OtYOXdsse0hU094r0/3TKtJh49YKV4HPjHXD3JOE5dkiRC0Tc8Hw+Nxu9XygMOZosz7UGXTGHhLWh3UuhkGwzDNVcUA7HR6sTZcWGXJxfL1tMyXxNATwcYnwMk7x6tuB7v48DAFzymnfBix/bHcg== 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=DZ0N/nj/seFefxUV/VxIzeiVdBLrUxt0bzGGyaFRcgc=; b=B4Mc5jZHM5rdl0Gv0wqplm8MO80qstm4ioHSckylzloCwDiWN4U56f0mdiqpvs8yfj28/E3J7+zVR1OHFQxOR1wbW70kQHNA99wXDZpOczUM9x8132kW+hboTZw2eKM2iDCnL1I0h0OdaGHIQaUkuJ88F++aZEvpY29bA4/02cw= Received: from AM6P195CA0051.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:87::28) by DBBPR03MB7068.eurprd03.prod.outlook.com (2603:10a6:10:20e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.23; Wed, 22 Jan 2025 07:28:57 +0000 Received: from AMS0EPF000001B1.eurprd05.prod.outlook.com (2603:10a6:209:87:cafe::94) by AM6P195CA0051.outlook.office365.com (2603:10a6:209:87::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.22 via Frontend Transport; Wed, 22 Jan 2025 07:28:56 +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 AMS0EPF000001B1.mail.protection.outlook.com (10.167.16.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8377.8 via Frontend Transport; Wed, 22 Jan 2025 07:28:56 +0000 Received: from stelas00wl01.omicron.at (172.22.41.139) by EXC04-ATKLA.omicron.at (172.22.100.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 22 Jan 2025 08:28:53 +0100 From: Stefan Laesser To: CC: , Stefan Laesser Subject: [PATCH v3] net/af_packet: provide packet drop stats Date: Wed, 22 Jan 2025 08:28:45 +0100 Message-ID: <20250122072845.714800-1-stefan.laesser@omicronenergy.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250121122616.301666-1-stefan.laesser@omicronenergy.com> References: <20250121122616.301666-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: EXC03-ATKLA.omicron.at (172.22.100.188) To EXC04-ATKLA.omicron.at (172.22.100.189) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001B1:EE_|DBBPR03MB7068:EE_ X-MS-Office365-Filtering-Correlation-Id: e0ec79c2-b301-4b17-5387-08dd3ab66e63 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|1800799024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9I3wCpdFyyD5poXd3MvnhCaPNLJeipvJQ1symUB7GUdksWsywORwaokf?= =?us-ascii?Q?ILBUv5EUH4MlFNoqfugxTmAbnj6R7P0du8aM9FHCiu80/Qf8H0oCggBWagpw?= =?us-ascii?Q?WStsrYYT4MiVy0TtVrmDScS+CyH4NrYVs4wArjxUP5U2BkLWIZeChQ66laa8?= =?us-ascii?Q?Lm98HLjLco6nt3sqvdOnfodmKBHf689ObX0t6eSsSei43kEDgAjKm0e8ZEWx?= =?us-ascii?Q?2Q16v8AUB6kF8kzQGwbXvIc8rws8j8oZITo6YLUniQqmuJiBNAHSJK8bRl8a?= =?us-ascii?Q?N4Rm6WYsLWSACXnC3MQZxfnDAOk6rcTayQOJwmSVgHgdCbKHF4I7baRZ0HLt?= =?us-ascii?Q?lEFqaNvxbx1RI6oVrA8hwsQhsIUDNzamiyTnLJju675vj4W5I+gwJ+ErtSBf?= =?us-ascii?Q?v6lCB+bqWOJJw3ZOLGwsamSmpHHfhKOvKItoDzqGWjxuQSBmZDhLIAkJNh6j?= =?us-ascii?Q?pdOeLZPiaO77rCAZ5RH2x0Rgn08Ult74Pv9iQ/F09VZdNgqVUylINluKzZCU?= =?us-ascii?Q?0Nby0AFywr4OCt4gzUGnY9JrSRKv+MPV0aGRS4A4pCf6J4N2nwHr7Yd5Rjp7?= =?us-ascii?Q?iqE6LrWckY85I7gnsX8VwlRio60bptJOjPp896lcd1lxUQRXLK0fsmKCuPKn?= =?us-ascii?Q?nSrHkHWZFRVuCtI=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)(82310400026)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1102; X-OriginatorOrg: omicronenergy.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2025 07:28:56.6315 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0ec79c2-b301-4b17-5387-08dd3ab66e63 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: AMS0EPF000001B1.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR03MB7068 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 --- v3: * Introduced function for querying socket dropped counter and use it also to reset internal state when stats are reset. * Combined the for-loops in in eth_stats_get and eth_stats_reset. * Count all queues to total counters, but only add up to RTE_ETHDEV_QUEUE_STAT_CNTRS values to queue stats. 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 | 86 ++++++++++++++++------- 1 file changed, 60 insertions(+), 26 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..c088deb587 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; @@ -413,38 +417,65 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) return 0; } + +/* + * Query dropped packets counter from socket. + * Reading drop count clears the value of the 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 *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 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++) { - 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]; - } + for (i = 0; i < internal->nb_queues; i++) { + /* reading drop count clears the value, therefore keep total value */ + internal->rx_queue[i].rx_dropped_pkts += + packet_drop_count(internal->rx_queue[i].sockfd); + + rx_total += internal->rx_queue[i].rx_pkts; + rx_bytes_total += internal->rx_queue[i].rx_bytes; + 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]; + tx_total += internal->tx_queue[i].tx_pkts; tx_err_total += internal->tx_queue[i].err_pkts; - tx_bytes_total += igb_stats->q_obytes[i]; + tx_bytes_total += internal->tx_queue[i].tx_bytes; + + 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; + } } - 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; } @@ -455,11 +486,14 @@ eth_stats_reset(struct rte_eth_dev *dev) struct pmd_internals *internal = dev->data->dev_private; for (i = 0; i < internal->nb_queues; i++) { + /* clear socket counter */ + 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; + internal->rx_queue[i].rx_dropped_pkts = 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.34.1