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 690B346121; Fri, 24 Jan 2025 12:43:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 45CD041153; Fri, 24 Jan 2025 12:43:59 +0100 (CET) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2046.outbound.protection.outlook.com [40.107.95.46]) by mails.dpdk.org (Postfix) with ESMTP id 82487410FA for ; Fri, 24 Jan 2025 12:43:57 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y16sKnCpCG3v85YpnME2r4ZtujVDQyPok49lF4R3Yggn8Vilt5f+TjWHvzucR1PzrGB6N4pQYirL+1uGw0nm6XImomzJWPYGxRr7SeWWHot7ZVyBvYglv5RoIdWCUCLonU6aLA4sXCyvM5MITT08ZQDY2fZFcUeV3Ly9UC+saDrOGVzDiOV2hMBd3aDAae2/6+CMh44XbWgj/RqJx8mRKmVayL5lLAc+f5MxdycQhCLWmzWutDV74FgP0vWKR48CNzBpkmLhu1MP+nBW9Hklp1qsaJH7WK4Tqr1U+DGTp0u75y2Tkx1TPeC7qIR5OY4jiyuB3gX6VEVGfJfFa3X0Ig== 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=qthgYA28fGpEMqEdN4r3M1D7+8Jko8f/IKcVHpiFDps=; b=y8rIJJ4nu7xgrefna365EwNiWqvVEDKpVfXIBgstFQ5va8Ejiarv5aUUZddk64VBSZ1qbzXd2DL91XeKX7bvwKvNn8R0dnw+O5G14c7f6/aZ0OWhkWD1MB+2PitFJ5T0ipigOiCgL1+C/1A7enLutL4UX/8si2BaJ/jl4STaUJS7697nat+HDaTbxmCauDtsgCV9YLvveCvCo2I/gl7DcQf8mNlFHFV4r1MsJA/7wypfZ9f+nREeCYqCPH7/gsT09F1mBI9BT9H0nb4/f+Od903Kxc2K1jJEgtJEM3rtbMgj/qMCM+NA9f9zQDUUQo19tQrZGcILw7JyFM3aBMM4Cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qthgYA28fGpEMqEdN4r3M1D7+8Jko8f/IKcVHpiFDps=; b=G1ZkpK4ggtMv8TOdRnhFVSmB5EM1nFF3WZLnj46EFdpB7WGtTZiExnmjloAKhW+MJUoqP3Q2fc71pr9SRyt0sGLTV55NvYKUHoVJPQy+AR+QEGybUbAu0WrMlcp8BVaVlONybRrGpHh9XpE09xgV9/N3QkBYRkie+D9ykn73NJrehJMioJ/oZQrcJIVmIlXxs1+QpMtzAkNBQvMrhbgYglOR0svk20ZyUvzX1OSwus2u7wwd/uWsSS7fZiUCxn3U7eEBNRgvnNrfFNbaXyuLyJjJrRiVFAJrRM5GIQCTFinVRYrKtZnxCjrrPPeOK7+Yif1J2R+E6coaW7EKOZYn8Q== Received: from MN2PR19CA0047.namprd19.prod.outlook.com (2603:10b6:208:19b::24) by DS0PR12MB8453.namprd12.prod.outlook.com (2603:10b6:8:157::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.17; Fri, 24 Jan 2025 11:43:52 +0000 Received: from BN2PEPF000044A2.namprd02.prod.outlook.com (2603:10b6:208:19b:cafe::68) by MN2PR19CA0047.outlook.office365.com (2603:10b6:208:19b::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.17 via Frontend Transport; Fri, 24 Jan 2025 11:43:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN2PEPF000044A2.mail.protection.outlook.com (10.167.243.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Fri, 24 Jan 2025 11:43:51 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 24 Jan 2025 03:43:44 -0800 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 24 Jan 2025 03:43:43 -0800 Received: from nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4 via Frontend Transport; Fri, 24 Jan 2025 03:43:42 -0800 From: Shani Peretz To: CC: , , Shani Peretz , Thomas Monjalon , "Andrew Rybchenko" Subject: [PATCH v2 1/3] ethdev: add new API to enable/disable xstat by counters ID Date: Fri, 24 Jan 2025 13:43:33 +0200 Message-ID: <20250124114336.16610-2-shperetz@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250124114336.16610-1-shperetz@nvidia.com> References: <20241222153819.62519-1-shperetz@nvidia.com> <20250124114336.16610-1-shperetz@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A2:EE_|DS0PR12MB8453:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c8319cf-05a4-42ce-4348-08dd3c6c5fd2 X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?sYxtkGW9PqelPFIOiz/zT1EGJ1TfGQN59hcJZxevy4eofHqf47nfc+So4dJb?= =?us-ascii?Q?tQ2V85REUIDAZUtwm0mEGu/UALyDaJTCBk59lGrRtxVlkv4IoiVV90NokPLs?= =?us-ascii?Q?aUKiLQDv8UUF90qX9hSQ6KWBQTS6MiK0praTJlH+b2yQzZefxV6NR5HUmtbF?= =?us-ascii?Q?Nh/+dITUHMG75E/szzhFBBJlmuuLJRU2Nb6VOMrGB6uZX4VavGNcNd6yrpza?= =?us-ascii?Q?bsM4qN1IKgW3oH0jnHnG0aKWXjKNKoRIGT70eDMdQJIFY1SpeE6oFIF1aJwg?= =?us-ascii?Q?hcXIQAUghcIW1F1eCe5tOZDcSEAiiRSdUxziXaF0B1ggNDFUF2BB1uMJQ6oZ?= =?us-ascii?Q?rLOMi9aAQA6cWnycDh51xuN/7yhyjQRhJmKhYWb2aWv7xox5xva1sgnevmiw?= =?us-ascii?Q?KMzD5vRhMM1cw0QZfXfM407e5UY6KHHQc0c6IadpmjJjAcXO8w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IU8EKrtlRLNoulgFxEjb/IjbPAxgw9FhG/AxFjF543i9BzQBWK?= =?us-ascii?Q?OH+2llRnoWqMXxFdzg6YN3660IuVplJW6JTNoFiQNakpwMCX2qOC1Klefi16?= =?us-ascii?Q?+YsahGYI7UAv4mBWk6E4L5jOnQvVkp98bGOO+K55eCZlbHS9Um5JXw=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2025 11:43:51.6197 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4c8319cf-05a4-42ce-4348-08dd3c6c5fd2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8453 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 This patch introduces a new API to dynamically enable or disable xstat counters by their IDs. Some counters may require resources that are potentially limited, so providing the ability to toggle them on or off makes sense. In addition, adding an API to query the current state (enabled, disabled, or not supported) of an xstat counter is added. New APIs: - rte_eth_xstats_set_counter (struct rte_eth_dev *dev, uint64_t id, int on_off); - rte_eth_xstats_query_state (struct rte_eth_dev *dev, uint64_t id); Note that by default, generic stats (like those provided by eth_basic_stats_get()) will be considered unsupported and will not be toggleable. Also all xstats will be considered unsupported for dynamic enable/disable, and each PMD will be able to override this in its implementation. Signed-off-by: Shani Peretz --- lib/ethdev/ethdev_driver.h | 13 ++++++++++ lib/ethdev/rte_ethdev.c | 49 ++++++++++++++++++++++++++++++++++++++ lib/ethdev/rte_ethdev.h | 32 +++++++++++++++++++++++++ lib/ethdev/version.map | 2 ++ 4 files changed, 96 insertions(+) diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h index 1fd4562b40..74995df7f4 100644 --- a/lib/ethdev/ethdev_driver.h +++ b/lib/ethdev/ethdev_driver.h @@ -570,6 +570,15 @@ typedef const uint32_t *(*eth_dev_supported_ptypes_get_t)(struct rte_eth_dev *de typedef int (*eth_dev_ptypes_set_t)(struct rte_eth_dev *dev, uint32_t ptype_mask); +/** @internal Enable an xstat of an Ethernet device. */ +typedef int (*eth_xstats_enable_counter_t)(struct rte_eth_dev *dev, uint64_t id); + +/** @internal Disable an xstat of an Ethernet device. */ +typedef int (*eth_xstats_disable_counter_t)(struct rte_eth_dev *dev, uint64_t id); + +/** @internal Query the state of an xstat the can be enabled and disabled in runtime. */ +typedef int (*eth_xstats_query_state_t)(struct rte_eth_dev *dev, uint64_t id); + /** @internal Start Rx and Tx of a queue of an Ethernet device. */ typedef int (*eth_queue_start_t)(struct rte_eth_dev *dev, uint16_t queue_id); @@ -1528,6 +1537,10 @@ struct eth_dev_ops { /** Get name of extended device statistics by ID */ eth_xstats_get_names_by_id_t xstats_get_names_by_id; + eth_xstats_enable_counter_t xstats_enable; + eth_xstats_disable_counter_t xstats_disable; + eth_xstats_query_state_t xstats_query_state; + /** Get Traffic Management (TM) operations */ eth_tm_ops_get_t tm_ops_get; diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 6413c54e3b..c0cfb35126 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -3776,6 +3776,55 @@ rte_eth_xstats_reset(uint16_t port_id) return rte_eth_stats_reset(port_id); } +int +rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off) +{ + struct rte_eth_dev *dev; + unsigned int basic_count; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + + dev = &rte_eth_devices[port_id]; + basic_count = eth_dev_get_xstats_basic_count(dev); + if (id < basic_count) + return -EINVAL; + + if (on_off == 1) { + if (rte_eth_xstats_query_state(port_id, id) == 1) + return -EEXIST; + if (dev->dev_ops->xstats_enable != NULL) + return (*dev->dev_ops->xstats_enable)(dev, id - basic_count); + } else { + if (rte_eth_xstats_query_state(port_id, id) == 0) + return 0; + if (dev->dev_ops->xstats_disable != NULL) + return (*dev->dev_ops->xstats_disable)(dev, id - basic_count); + } + + return -ENOTSUP; +} + + +int +rte_eth_xstats_query_state(uint16_t port_id, uint64_t id) +{ + struct rte_eth_dev *dev; + unsigned int basic_count; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + + dev = &rte_eth_devices[port_id]; + basic_count = eth_dev_get_xstats_basic_count(dev); + if (id < basic_count) + return -ENOTSUP; + + /* implemented by the driver */ + if (dev->dev_ops->xstats_query_state != NULL) + return (*dev->dev_ops->xstats_query_state)(dev, id - basic_count); + + return -ENOTSUP; +} + static int eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx, uint8_t is_rx) diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 1f71cad244..06f8d8cbfa 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -3386,6 +3386,38 @@ int rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, int rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name, uint64_t *id); +/** + * Enable/Disable the xstat counter of the given id. + * + * @param port_id The port to look up statistics from + * @param id The ID of the counter to enable + * @param on_off The state to set the counter to. + * @return + * - (0) on success + * - (-EEXIST) counter already enabled + * - (-ENOTSUP) enable/disable is not implemented + * - (-EINVAL) xstat id is invalid + * - (-EPERM) enabling this counter is not permitted + * - (-ENOSPC) no resources + */ +__rte_experimental +int rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off); + + +/** + * Query the state of the xstat counter. + * + * @param port_id The port to look up statistics from + * @param id The ID of the counter to query + * @return + * - (0) xstat is enabled + * - (1) xstat is disabled + * - (-ENOTSUP) enable/disabling is not implemented + * - (-EINVAL) xstat id is invalid + */ +__rte_experimental +int rte_eth_xstats_query_state(uint16_t port_id, uint64_t id); + /** * Reset extended statistics of an Ethernet device. * diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 12f48c70a0..f96b9e5712 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -337,6 +337,8 @@ EXPERIMENTAL { rte_eth_timesync_adjust_freq; rte_flow_async_create_by_index_with_pattern; rte_tm_node_query; + rte_eth_xstats_set_counter; + rte_eth_xstats_query_state; }; INTERNAL { -- 2.34.1