From patchwork Tue Oct 1 10:37:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13817741 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2076.outbound.protection.outlook.com [40.107.237.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1ECF19CC08 for ; Tue, 1 Oct 2024 10:37:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779067; cv=fail; b=ao3wklKeLTiPJO9HtSRCk2r44CxyAZC3xXBKm5r+vfjKT9lRHVUcbwx0WF0qYj1VcLhm2RYn8sz/4odNeHVgdb9sgaCO4lb2qXG8GcnnzpsUCRyevm9gj01RlW1ki6Fw5+uyh82SowjEGs6gNB/qrb7GbUU231XF/738LPIFyNM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779067; c=relaxed/simple; bh=6ZEiGDNlPKvKxH5ltGrs3qN6p5kBne8z5cFSwX6sN5M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XR42lM8JRUSOypwuiMIdhccSRdAFbbETBp4inxgkYmBBQXjlSaY9b5ytq5rdvDpBGmWFQDh61NFfe50MrjM3JQBx5SpZcn3m5W/byqBSPJcDYUNs8O8Pd20T7BtrniyIEpLPBiUCv2ZXjZNdSjp6ujKTR1GfYt6C08sumg2nfTM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=uCwi6eX9; arc=fail smtp.client-ip=40.107.237.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="uCwi6eX9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pz7wl4hKYrCBfvMQvc/KtKuGh5I15PsOs9SZVsjPPGFgEF9+HxyfJ19t0D0n9ZRhzS534JdrIPPDYBtPet0vyqMe/n2L7X7OlfNdG8SmNS+GSX2aZ34u4gaj1lAbFyzVauT4kMT67tNALhRVPBl8kL6u8Pz1qUBxD2r2DtDNlJoBSwonMZqOWzMBpheutsUEIfnnpxCbOnyV04naS4B8zWpkOvjxo9hYx6utvvKrI29sKdgfFwEyAMEa/a+LDThhuP2AVyWqorWcFX6c/SVNsBjqOmyWAmN7pcsaqbbYEIrF8Ir+jVHogb5u9XOEgr0hCeRBrKBLIm10CIbvXwOnSw== 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=kbnQoE7qCA+NyZr0UDfdueOECUFxCJWCt/ArNgBDZgU=; b=r2g8VJQfyYGQRxBIgKC6xh8806bmRNhb9ShiExyw1DD8Lvse0nMwIEzJk71U+0mevB4x6wLeS9COXOs1uwTcB+SIdUmVLofOrnOGRxPOr5q5t4LK1oItGha24HpCag6CHB8K9YWziFkQr+XTzzYIHnEJIPpHQk5MPJH5vDlFtWfsvtk6ulc2M4SxaFalgKo35AfriQbrGUdaTDux62lxJiUqgs1YrjyQtBxKDv+r6PDoMzjsvb1cgoSjkpMmOJg+CKC0OKZRqNXmprp1lXHaAMHtDl2vDkD65PtGXpsTfivfDqrhsnzJkyXiUiT7Gd/3EIaI12CjG6DO7f34Ssj5PA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=davemloft.net 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=kbnQoE7qCA+NyZr0UDfdueOECUFxCJWCt/ArNgBDZgU=; b=uCwi6eX9oV6Lk9rkm2WmPPXCM8fT1ws2bdYVtuEuMFhqb49G0xErqKo22dw6spP2RnbebI/8ra+D56ZYlDi3FwtYVvPzZ4DP8hTWX6xY5DdoKe66+vIHaAlo9929s1ihwQoovAEjgEqmQs0WnTkCzlCfvbEOTvjQlG0q2NGrhAi9exumfWQhODha7ZaJTxcpdfTL8HifNPPoTudTUdfYSFqrJX3fr2FpFIptKYtjIlfzJrLeezFfvXHGfV5wS9XDgZ+Y3gly8qihy/PLdNYqQlnjeGojFKDXtMNrY5q0vg7sbOxlQqSaLMuYqbtn+ylMaiwZm5yOlU+p3XatMdOiBQ== Received: from CH0PR07CA0005.namprd07.prod.outlook.com (2603:10b6:610:32::10) by CY8PR12MB7434.namprd12.prod.outlook.com (2603:10b6:930:52::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Tue, 1 Oct 2024 10:37:40 +0000 Received: from CH2PEPF0000009D.namprd02.prod.outlook.com (2603:10b6:610:32:cafe::c0) by CH0PR07CA0005.outlook.office365.com (2603:10b6:610:32::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15 via Frontend Transport; Tue, 1 Oct 2024 10:37:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CH2PEPF0000009D.mail.protection.outlook.com (10.167.244.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 10:37:39 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:39 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:38 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 1 Oct 2024 03:37:35 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Simon Horman , Cosmin Ratiu , Tariq Toukan Subject: [PATCH net-next V2 1/6] net/mlx5: hw counters: Make fc_stats & fc_pool private Date: Tue, 1 Oct 2024 13:37:04 +0300 Message-ID: <20241001103709.58127-2-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241001103709.58127-1-tariqt@nvidia.com> References: <20241001103709.58127-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009D:EE_|CY8PR12MB7434:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a0a1f27-71a9-41cd-a8f4-08dce20512c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: J/W/6DmHL32asU8y5W+lWARMHW3bOs+RdF3Bul24RHPmvRtVYuEdKK0wO3SCJCTAJ49QBuerXm7BZ7upMcBawJfm6Z0MADST1NEYut2JyQleLJRXqKOdKe414DLN1Io2oaSkr2A0sgXD1W/gbZJBoKm9SD4fgcLolq8qPisbb9bI+6qtF8LOcEA7lytH6ea46z6TNv+gZQG9GoA0W7xF5IfSzaJZGIm5PmGUmT4lcM9EAx9FvFrjSJjUqPTneteY0YkrnQu06HvX117TF3MU9RcFzA1b2WQVM9SIUOhQ3gfMCic0+e9QNpxxFEtjXqCKkCjssJFYtrsWeIllhkkwxQgGDdcZ8EaeG9fbAgekLPrfEWFLDHlVS7xASofdm7qxnDK5ezGF8K1ZZ2rg3xKbpTJzIg//4aEKCzX8rvQCouylfMjM9822topkRUPx+vMq2LOalsWIvnkEUnpVUCnYgx6IOQxWJNSondLaMKtfDZZ4/eaRFsYUoOEoyK0ZoO0HjUoz6IZWX70ip6l7fbnHF223tYLUU5uCG+n3SWpnHbzK6QmyWpGigD6UvZwiYz//b2br06Bs+6eGtTYT3cvVyKDkX/1BPD1V2ltVmKfjG/ncvXJGtAyqGvNSO7AN/Q/n8WhMP3Hu/YQQv1YMVBPATHCOJ8dOE6mTJC1BzqJPSOGkIeqJfZgBDBayaVq71wjZT11j4I8hBE3Yg+e3DK/8KaPutnfN8LBO2bu5MuKg2pRrcV+lBasmqDyUIwXCBg6KZ/R9Xy3+l0KOaTDHw+mZt7AG4IJqS0qcc2urIPHx3MvO3gzBfxoGbX910OvnSusRfQMISIeqL0WBltRGeTYUBWdd5Cl/kHWLctDQgNuSvJwKiMu9gauu24sJbZvhQYAgl9cW8YES3gj7GlK5ih8JZ02lTJ2PHnv4jvaaTrVOZjc++rX2ezFXYw/EkuMxF/fP+4qn7tKPlF7ZTb0/VPa6t3D2/3MchqHNvF2RxZoQl6WNz5+2jtg8O6Ix5aSoWsxo5jIAh1X9wxTyzeAUZtWkQmM0e37msJvRu+xo/u73/oq0R5LWfXU8NR/UkIuuUbyk6yeQ2f/zXC6m2BRAGD1feff5WQzgdYuyQLbf71JGOyKZ9fMj75IbZrxbOfgv5sh/ihOSG03dAGwuYAQXwPKHVGyysSHn7xrUm3Zxg/W/AQlJUG8QzDlC0PLxJWK+MtbSaFhzg1rrN+Tj6drC4a6usoVEG1NhxA9pXjRojtYt2tg2b1J6sEwljRoihrmdYWZtR3aENj3iwao38dMNV2jeZU4LQ9cgEvSOxAptH4U+Nwdp8AeAcoOdzaKDHKhac+Qrem2KmaKAed4WIKKP75BkhBJMhrjeGI+cGyZ6k9OuH+n0LRlVA3BvurhgiLrCABS1syCA6O2iSwHywc8gFLHyr7OXljK7RRIADuSTQWdKzmUa+ddkSmJcBRak18fTP+xJ X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 10:37:39.5757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5a0a1f27-71a9-41cd-a8f4-08dce20512c1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7434 X-Patchwork-Delegate: kuba@kernel.org From: Cosmin Ratiu The mlx5_fc_stats and mlx5_fc_pool structs are only used from fs_counters.c. As such, make them private there. mlx5_fc_pool is not used or referenced at all outside fs_counters. mlx5_fc_stats is referenced from mlx5_core_dev, so instead of having it as a direct member (which requires exporting it from fs_counters), store a pointer to it, allocate it on init and clear it on destroy. One caveat is that a simple container_of to get from a 'work' struct to the outermost mlx5_core_dev struct directly no longer works, so an extra pointer had to be added to mlx5_fc_stats back to the parent dev. Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- .../ethernet/mellanox/mlx5/core/fs_counters.c | 79 ++++++++++++++----- include/linux/mlx5/driver.h | 33 +------- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c index 0c26d707eed2..7d6174d0f260 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c @@ -69,6 +69,36 @@ struct mlx5_fc { struct mlx5_fc_cache cache ____cacheline_aligned_in_smp; }; +struct mlx5_fc_pool { + struct mlx5_core_dev *dev; + struct mutex pool_lock; /* protects pool lists */ + struct list_head fully_used; + struct list_head partially_used; + struct list_head unused; + int available_fcs; + int used_fcs; + int threshold; +}; + +struct mlx5_fc_stats { + spinlock_t counters_idr_lock; /* protects counters_idr */ + struct idr counters_idr; + struct list_head counters; + struct llist_head addlist; + struct llist_head dellist; + + struct workqueue_struct *wq; + struct delayed_work work; + unsigned long next_query; + unsigned long sampling_interval; /* jiffies */ + u32 *bulk_query_out; + int bulk_query_len; + size_t num_counters; + bool bulk_query_alloc_failed; + unsigned long next_bulk_query_alloc; + struct mlx5_fc_pool fc_pool; +}; + static void mlx5_fc_pool_init(struct mlx5_fc_pool *fc_pool, struct mlx5_core_dev *dev); static void mlx5_fc_pool_cleanup(struct mlx5_fc_pool *fc_pool); static struct mlx5_fc *mlx5_fc_pool_acquire_counter(struct mlx5_fc_pool *fc_pool); @@ -109,7 +139,7 @@ static void mlx5_fc_pool_release_counter(struct mlx5_fc_pool *fc_pool, struct ml static struct list_head *mlx5_fc_counters_lookup_next(struct mlx5_core_dev *dev, u32 id) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; unsigned long next_id = (unsigned long)id + 1; struct mlx5_fc *counter; unsigned long tmp; @@ -137,7 +167,7 @@ static void mlx5_fc_stats_insert(struct mlx5_core_dev *dev, static void mlx5_fc_stats_remove(struct mlx5_core_dev *dev, struct mlx5_fc *counter) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; list_del(&counter->list); @@ -178,7 +208,7 @@ static void mlx5_fc_stats_query_counter_range(struct mlx5_core_dev *dev, struct mlx5_fc *first, u32 last_id) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; bool query_more_counters = (first->id <= last_id); int cur_bulk_len = fc_stats->bulk_query_len; u32 *data = fc_stats->bulk_query_out; @@ -225,7 +255,7 @@ static void mlx5_fc_free(struct mlx5_core_dev *dev, struct mlx5_fc *counter) static void mlx5_fc_release(struct mlx5_core_dev *dev, struct mlx5_fc *counter) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; if (counter->bulk) mlx5_fc_pool_release_counter(&fc_stats->fc_pool, counter); @@ -235,7 +265,7 @@ static void mlx5_fc_release(struct mlx5_core_dev *dev, struct mlx5_fc *counter) static void mlx5_fc_stats_bulk_query_size_increase(struct mlx5_core_dev *dev) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; int max_bulk_len = get_max_bulk_query_len(dev); unsigned long now = jiffies; u32 *bulk_query_out_tmp; @@ -270,9 +300,9 @@ static void mlx5_fc_stats_bulk_query_size_increase(struct mlx5_core_dev *dev) static void mlx5_fc_stats_work(struct work_struct *work) { - struct mlx5_core_dev *dev = container_of(work, struct mlx5_core_dev, - priv.fc_stats.work.work); - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = container_of(work, struct mlx5_fc_stats, + work.work); + struct mlx5_core_dev *dev = fc_stats->fc_pool.dev; /* Take dellist first to ensure that counters cannot be deleted before * they are inserted. */ @@ -334,7 +364,7 @@ static struct mlx5_fc *mlx5_fc_single_alloc(struct mlx5_core_dev *dev) static struct mlx5_fc *mlx5_fc_acquire(struct mlx5_core_dev *dev, bool aging) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; struct mlx5_fc *counter; if (aging && MLX5_CAP_GEN(dev, flow_counter_bulk_alloc) != 0) { @@ -349,7 +379,7 @@ static struct mlx5_fc *mlx5_fc_acquire(struct mlx5_core_dev *dev, bool aging) struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) { struct mlx5_fc *counter = mlx5_fc_acquire(dev, aging); - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; int err; if (IS_ERR(counter)) @@ -389,7 +419,7 @@ struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging) { struct mlx5_fc *counter = mlx5_fc_create_ex(dev, aging); - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; if (aging) mod_delayed_work(fc_stats->wq, &fc_stats->work, 0); @@ -405,7 +435,7 @@ EXPORT_SYMBOL(mlx5_fc_id); void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; if (!counter) return; @@ -422,10 +452,14 @@ EXPORT_SYMBOL(mlx5_fc_destroy); int mlx5_init_fc_stats(struct mlx5_core_dev *dev) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats; int init_bulk_len; int init_out_len; + fc_stats = kzalloc(sizeof(*fc_stats), GFP_KERNEL); + if (!fc_stats) + return -ENOMEM; + spin_lock_init(&fc_stats->counters_idr_lock); idr_init(&fc_stats->counters_idr); INIT_LIST_HEAD(&fc_stats->counters); @@ -436,7 +470,7 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev) init_out_len = mlx5_cmd_fc_get_bulk_query_out_len(init_bulk_len); fc_stats->bulk_query_out = kzalloc(init_out_len, GFP_KERNEL); if (!fc_stats->bulk_query_out) - return -ENOMEM; + goto err_bulk; fc_stats->bulk_query_len = init_bulk_len; fc_stats->wq = create_singlethread_workqueue("mlx5_fc"); @@ -447,23 +481,27 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev) INIT_DELAYED_WORK(&fc_stats->work, mlx5_fc_stats_work); mlx5_fc_pool_init(&fc_stats->fc_pool, dev); + dev->priv.fc_stats = fc_stats; + return 0; err_wq_create: kfree(fc_stats->bulk_query_out); +err_bulk: + kfree(fc_stats); return -ENOMEM; } void mlx5_cleanup_fc_stats(struct mlx5_core_dev *dev) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; struct llist_node *tmplist; struct mlx5_fc *counter; struct mlx5_fc *tmp; - cancel_delayed_work_sync(&dev->priv.fc_stats.work); - destroy_workqueue(dev->priv.fc_stats.wq); - dev->priv.fc_stats.wq = NULL; + cancel_delayed_work_sync(&fc_stats->work); + destroy_workqueue(fc_stats->wq); + fc_stats->wq = NULL; tmplist = llist_del_all(&fc_stats->addlist); llist_for_each_entry_safe(counter, tmp, tmplist, addlist) @@ -475,6 +513,7 @@ void mlx5_cleanup_fc_stats(struct mlx5_core_dev *dev) mlx5_fc_pool_cleanup(&fc_stats->fc_pool); idr_destroy(&fc_stats->counters_idr); kfree(fc_stats->bulk_query_out); + kfree(fc_stats); } int mlx5_fc_query(struct mlx5_core_dev *dev, struct mlx5_fc *counter, @@ -518,7 +557,7 @@ void mlx5_fc_queue_stats_work(struct mlx5_core_dev *dev, struct delayed_work *dwork, unsigned long delay) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; queue_delayed_work(fc_stats->wq, dwork, delay); } @@ -526,7 +565,7 @@ void mlx5_fc_queue_stats_work(struct mlx5_core_dev *dev, void mlx5_fc_update_sampling_interval(struct mlx5_core_dev *dev, unsigned long interval) { - struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats; + struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; fc_stats->sampling_interval = min_t(unsigned long, interval, fc_stats->sampling_interval); diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index e23c692a34c7..fc7e6153b73d 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -474,36 +473,6 @@ struct mlx5_core_sriov { u16 max_ec_vfs; }; -struct mlx5_fc_pool { - struct mlx5_core_dev *dev; - struct mutex pool_lock; /* protects pool lists */ - struct list_head fully_used; - struct list_head partially_used; - struct list_head unused; - int available_fcs; - int used_fcs; - int threshold; -}; - -struct mlx5_fc_stats { - spinlock_t counters_idr_lock; /* protects counters_idr */ - struct idr counters_idr; - struct list_head counters; - struct llist_head addlist; - struct llist_head dellist; - - struct workqueue_struct *wq; - struct delayed_work work; - unsigned long next_query; - unsigned long sampling_interval; /* jiffies */ - u32 *bulk_query_out; - int bulk_query_len; - size_t num_counters; - bool bulk_query_alloc_failed; - unsigned long next_bulk_query_alloc; - struct mlx5_fc_pool fc_pool; -}; - struct mlx5_events; struct mlx5_mpfs; struct mlx5_eswitch; @@ -630,7 +599,7 @@ struct mlx5_priv { struct mlx5_devcom_comp_dev *hca_devcom_comp; struct mlx5_fw_reset *fw_reset; struct mlx5_core_roce roce; - struct mlx5_fc_stats fc_stats; + struct mlx5_fc_stats *fc_stats; struct mlx5_rl_table rl_table; struct mlx5_ft_pool *ft_pool; From patchwork Tue Oct 1 10:37:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13817742 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2086.outbound.protection.outlook.com [40.107.220.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C8C91A08B5 for ; Tue, 1 Oct 2024 10:37:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779067; cv=fail; b=ihpayATHp45zdJWeJVtx+udlB8pgNBmtyGEzwLbNlsApS8bfWJAnign9xtJusl93DRMeEnoU1r1LjBKHavw6jxmICBgZnSUX80rYlSA4qTfjRM8ZjZC2eNECJWYjKLIeURUNhVLZmh9LS1C31nUXm6G6VB/JXPFux+WavkRGcEE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779067; c=relaxed/simple; bh=zNJAjF6vbYmSSRk1USAGGTROR2b9HnW6tIpddi8BBTg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rDgSBBo5yRuVe4R+pnrCy7SB8n/TJK2H1MP9IU+TK24ZAWM0tcPjdc8iQzTrvlSZAW+NaQdD2EhPzhNBkvdz1l1fvaB0jZLgbUwyvRmO7dFJMVcZ4ZK3KnV32qPFKX8CehAx627ZpV3vZ4Idfcajab9sJSgpo4ub9dmTulcxoEs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=DGx7URKj; arc=fail smtp.client-ip=40.107.220.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="DGx7URKj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F1kEtOsa49nMBruoBgmMR80K2G6x8YVLIH7Hr8AGgnYD26p1wte8amS1obj55PO8IFSDBEHPP/cexlPYB50cipgBb96LrSKrtwH4oELdiJVHh7VGMvfMWPNkj35rDDk74jpNGDLyoFH3cNW6RpHcN8ExXa59y2dVqwzTla337Kab6rLEsLCpUFDi1eKbhXm8DHbBhSCQrMmZRdxoSrHsMm3V6k/WBbOLeg2vu3dgr41QTcUfuNbjVeYN4fZwXCXXEnloIfsdH7WdwdjSZfjZWe0/fXBzcY8APDgvaFqHslDI5br53GBpHBjlC4+JlgUtBNp3TH4WZ8J8JEQzzDRFpw== 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=DJs77ZVRAaH5RwUsIzjYHBc5goBqhixG7mpxSQv771A=; b=WMZYQRIbihogt1/9SmRbvbzS0/vHcAk5Ve0s8eRZkSL2L/mExdIqiLhf1B9M8XsyCTfkHmYDRFLRXIGTCsFRuzOcVTrQki/NDdnOFzsE6I2Q/d6oFBM4XMWA5fSeYt8ZWZA4DO4CZaIAZNMEj2NTANUkUuf+0ZHpu+yaMJnw311YRwqXeUEdvCBFq9so1kTKHV222BmrM/UQp49tXetXO5ufvby86aXIl7DcvsI/nNrRukUwEWvC67tYwNLYP7TrjNNse4cvzJjrA4jrE525eEzZuohVrl19axAwMqjGxUJsmSj8G6PY+LguhBgvYVTXmxcTDqXkrvonq13Q6mlQWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=davemloft.net 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=DJs77ZVRAaH5RwUsIzjYHBc5goBqhixG7mpxSQv771A=; b=DGx7URKjuJgFNuA7rLkQiw/dgEhlBouhi6E3OQveDo2z9/MRdAmgfxViMNKd1lqt7TorGjzcDhKnAMw+pDi5nwGr74UQkAUfGBR5wBUvOgZ8QnOzgOhVHQvsaeAVw/anYyPSQV+ZvPLzNfoo2CWSkEzQIf+PIg6bDwTg54xMWTv3hemmv/wixTNMGkpdADYQOQRNeCD6vJZDbjVhziDFlotgC253u7GOx/hZiOKZw85Y5xODiU3aQih6VLNlQI31sVTcILUAUVUljshfY0UttfMJpJDSGHGjQiih6jy5lNfMSkqq8erJm2KCntDWyUw924cusA5QiINs3Bn3RiuBsg== Received: from CH0PR07CA0019.namprd07.prod.outlook.com (2603:10b6:610:32::24) by SN7PR12MB7372.namprd12.prod.outlook.com (2603:10b6:806:29b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Tue, 1 Oct 2024 10:37:43 +0000 Received: from CH2PEPF0000009D.namprd02.prod.outlook.com (2603:10b6:610:32:cafe::ec) by CH0PR07CA0019.outlook.office365.com (2603:10b6:610:32::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Tue, 1 Oct 2024 10:37:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CH2PEPF0000009D.mail.protection.outlook.com (10.167.244.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 10:37:42 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:42 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:41 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 1 Oct 2024 03:37:39 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Simon Horman , Cosmin Ratiu , Tariq Toukan Subject: [PATCH net-next V2 2/6] net/mlx5: hw counters: Use kvmalloc for bulk query buffer Date: Tue, 1 Oct 2024 13:37:05 +0300 Message-ID: <20241001103709.58127-3-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241001103709.58127-1-tariqt@nvidia.com> References: <20241001103709.58127-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009D:EE_|SN7PR12MB7372:EE_ X-MS-Office365-Filtering-Correlation-Id: 364a05ac-fe95-4d4d-2f51-08dce20514af X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: bua8mVJtsyeRwzxc1bLI6gbbB4d8I0S+Ptmqj0EillOczuhHHKmVMSyksQhtOj6Vkp8MiFUV6CqGAjRMJVdExIAcPQUm7RGR7TwfsTNslNPbX5VB8Qoy2SgfIpJ++9rxlcTzYR+cZTsRGv6hAmd9CUyNsG0cypg7Ad/+JLxDpa+pAtXkhRXDAwegm7NOMO6PuyuOqXZETm1Qbyi+vsLNuW2GjmaL5ooy41+Md60fRopuaFtcbgT1zK5Pqs8SuBpmyckUm1mhtJ0wJGT+uJAc7XZIbvwgO02M7LgyAYW2RTGkbe8l86pwajwA6aCKxYWOxCejn0nBBuKtWqsxw3bv9SVE9+UeHabvz9bzCw58ldpwGGoByjF2V/ZZNVG63zh0P8Kk+Go/8aNHyv46ADNzE5tk1bMRl6Koy3GjIOYI3524vVsYNm9mAA9jqIE+wlM5Auu0XJqrC+xAIjtLxCs2Jk6c0dUswJK04TYkunVeIlLVDJ48hNfEYH2RkUD9MstIxsKEzUxWtY7EsKJsNNeCEWIy8GMMUF8mcK1zWsoFRZwMFl9060ZY3Hus6cP7Iq0YkE0u4kof0PxUX6CgWWYM6pgcuznQBtUPdhdwXcPUt5q3tP4Ak9F5xDKrJ+ZDjbVTDcIgTtQYXYUFzmBBpZnS8IDEz9aYoqOtmf/NE7jLDE1f0b2ibhzh7DIqMGj2KEaM/jdti3UbkL+Gvo/ERw5J44IGcKVhYmTKGQR4I4vP0SkCK+DFubhzf55FfAIbA5h84xTKkjMtjU0s2Ao8vJqJZm8cSzUOQ0TIN1NnH2AmlHRTeeGA/6TbkY4R61VR96bPkDsGYP2Bx1YcIZq14+2I4PhIlzqfLIpL+Cw+J6zTSPFtaYABMXPrz7sLYvXPcl6DwXo1rM7C8uRAUJpXGRfDau3z2ihohm0w1E/NHcp3dll+8I0OWBimVdbMzsdBx0dbbbEBf2uS3MXSy3OMLRTT5Ah6ACUDStWquLtlUN64jp04T/an/6ptS7eiILgrvlpqto6kl6kc/FnQ6koH2H5tSkZeECbaZySUtg00jGSLsnY8XI+hj8rM0rwEJ9hlhIhNU5gAOkkKsJXeZ1amVJnaOMVITZp+KvdusMNIuA531PJgvh3fBMB4lux3UpBX37+0rT8APPsPgOjIZKTq3q3i6uEWSPt5uREO5DxlP/HkiU7piSS3vt9FIpEiUxjFxYNcWC2bvG/rdAWv/tkPi8IOXKJrSl7LrBWieRjw6SsVW6CZg3h5qRMrlh2PmHqtQuECJ+U+++8+zx0meUGpiu2H/TxbjHzEgAI2H4/5346iELD+UVe7SdyEjzo0/K1jqyZbcXTgpIRWXscSzATW89N94T8XIkEtgrCcJIlmwMCVUYw0D8jg+vQ3KkQwQQEKLhd2jRtVf994Obr53Cjy5VlDPGfvnxAwKew4O3NnDP/djz/hiIS69GhX9Era0T0vzJRr X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 10:37:42.8256 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 364a05ac-fe95-4d4d-2f51-08dce20514af X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7372 X-Patchwork-Delegate: kuba@kernel.org From: Cosmin Ratiu The bulk query buffer starts out small (see [1]) and as soon as the number of counters goes past the initial threshold grows to max size (32K entries, 512KB) with a retry scheme. This commit switches to using kvmalloc for the buffer, which has a near zero likelihood of failing, and thus the explicit retry scheme becomes superfluous and is taken out. On the low chance the allocation fails, it will still be retried every sampling_interval, when the wq task runs. [1] commit b247f32aecad ("net/mlx5: Dynamically resize flow counters query buffer") Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- .../ethernet/mellanox/mlx5/core/fs_counters.c | 59 +++++++------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c index 7d6174d0f260..9892895da9ee 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c @@ -38,7 +38,6 @@ #include "fs_cmd.h" #define MLX5_FC_STATS_PERIOD msecs_to_jiffies(1000) -#define MLX5_FC_BULK_QUERY_ALLOC_PERIOD msecs_to_jiffies(180 * 1000) /* Max number of counters to query in bulk read is 32K */ #define MLX5_SW_MAX_COUNTERS_BULK BIT(15) #define MLX5_INIT_COUNTERS_BULK 8 @@ -263,39 +262,28 @@ static void mlx5_fc_release(struct mlx5_core_dev *dev, struct mlx5_fc *counter) mlx5_fc_free(dev, counter); } -static void mlx5_fc_stats_bulk_query_size_increase(struct mlx5_core_dev *dev) +static void mlx5_fc_stats_bulk_query_buf_realloc(struct mlx5_core_dev *dev, + int bulk_query_len) { struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; - int max_bulk_len = get_max_bulk_query_len(dev); - unsigned long now = jiffies; u32 *bulk_query_out_tmp; - int max_out_len; - - if (fc_stats->bulk_query_alloc_failed && - time_before(now, fc_stats->next_bulk_query_alloc)) - return; + int out_len; - max_out_len = mlx5_cmd_fc_get_bulk_query_out_len(max_bulk_len); - bulk_query_out_tmp = kzalloc(max_out_len, GFP_KERNEL); + out_len = mlx5_cmd_fc_get_bulk_query_out_len(bulk_query_len); + bulk_query_out_tmp = kvzalloc(out_len, GFP_KERNEL); if (!bulk_query_out_tmp) { mlx5_core_warn_once(dev, - "Can't increase flow counters bulk query buffer size, insufficient memory, bulk_size(%d)\n", - max_bulk_len); - fc_stats->bulk_query_alloc_failed = true; - fc_stats->next_bulk_query_alloc = - now + MLX5_FC_BULK_QUERY_ALLOC_PERIOD; + "Can't increase flow counters bulk query buffer size, alloc failed, bulk_query_len(%d)\n", + bulk_query_len); return; } - kfree(fc_stats->bulk_query_out); + kvfree(fc_stats->bulk_query_out); fc_stats->bulk_query_out = bulk_query_out_tmp; - fc_stats->bulk_query_len = max_bulk_len; - if (fc_stats->bulk_query_alloc_failed) { - mlx5_core_info(dev, - "Flow counters bulk query buffer size increased, bulk_size(%d)\n", - max_bulk_len); - fc_stats->bulk_query_alloc_failed = false; - } + fc_stats->bulk_query_len = bulk_query_len; + mlx5_core_info(dev, + "Flow counters bulk query buffer size increased, bulk_query_len(%d)\n", + bulk_query_len); } static void mlx5_fc_stats_work(struct work_struct *work) @@ -327,13 +315,14 @@ static void mlx5_fc_stats_work(struct work_struct *work) fc_stats->num_counters--; } - if (fc_stats->bulk_query_len < get_max_bulk_query_len(dev) && - fc_stats->num_counters > get_init_bulk_query_len(dev)) - mlx5_fc_stats_bulk_query_size_increase(dev); - if (time_before(now, fc_stats->next_query) || list_empty(&fc_stats->counters)) return; + + if (fc_stats->bulk_query_len < get_max_bulk_query_len(dev) && + fc_stats->num_counters > get_init_bulk_query_len(dev)) + mlx5_fc_stats_bulk_query_buf_realloc(dev, get_max_bulk_query_len(dev)); + last = list_last_entry(&fc_stats->counters, struct mlx5_fc, list); counter = list_first_entry(&fc_stats->counters, struct mlx5_fc, @@ -453,12 +442,11 @@ EXPORT_SYMBOL(mlx5_fc_destroy); int mlx5_init_fc_stats(struct mlx5_core_dev *dev) { struct mlx5_fc_stats *fc_stats; - int init_bulk_len; - int init_out_len; fc_stats = kzalloc(sizeof(*fc_stats), GFP_KERNEL); if (!fc_stats) return -ENOMEM; + dev->priv.fc_stats = fc_stats; spin_lock_init(&fc_stats->counters_idr_lock); idr_init(&fc_stats->counters_idr); @@ -466,12 +454,10 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev) init_llist_head(&fc_stats->addlist); init_llist_head(&fc_stats->dellist); - init_bulk_len = get_init_bulk_query_len(dev); - init_out_len = mlx5_cmd_fc_get_bulk_query_out_len(init_bulk_len); - fc_stats->bulk_query_out = kzalloc(init_out_len, GFP_KERNEL); + /* Allocate initial (small) bulk query buffer. */ + mlx5_fc_stats_bulk_query_buf_realloc(dev, get_init_bulk_query_len(dev)); if (!fc_stats->bulk_query_out) goto err_bulk; - fc_stats->bulk_query_len = init_bulk_len; fc_stats->wq = create_singlethread_workqueue("mlx5_fc"); if (!fc_stats->wq) @@ -481,12 +467,11 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev) INIT_DELAYED_WORK(&fc_stats->work, mlx5_fc_stats_work); mlx5_fc_pool_init(&fc_stats->fc_pool, dev); - dev->priv.fc_stats = fc_stats; return 0; err_wq_create: - kfree(fc_stats->bulk_query_out); + kvfree(fc_stats->bulk_query_out); err_bulk: kfree(fc_stats); return -ENOMEM; @@ -512,7 +497,7 @@ void mlx5_cleanup_fc_stats(struct mlx5_core_dev *dev) mlx5_fc_pool_cleanup(&fc_stats->fc_pool); idr_destroy(&fc_stats->counters_idr); - kfree(fc_stats->bulk_query_out); + kvfree(fc_stats->bulk_query_out); kfree(fc_stats); } From patchwork Tue Oct 1 10:37:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13817744 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2074.outbound.protection.outlook.com [40.107.95.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5F8B19CC0F for ; Tue, 1 Oct 2024 10:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779083; cv=fail; b=lElt/4AgtnInjzteg1T2h5ghRe3z9YWkUvikmnIY92q7pCzIb5sKL8kyva/MDzuV3cvdBNzSzphRp6d7S/WjCLEg0Tfi4lLjgvGg9kE1rCQWKaM0TaUnc6dmNEs4wtgZmXEYBCtFWJgthu0dQd1nmWN2IZaUS1avUvftfw7rV/g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779083; c=relaxed/simple; bh=MdJliMSBFa1EqMvO1S60iXF+vQW0fvBEJ8W6Q2VWv8c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ttK+X1T9k0HyqL5+fjb8GIcJ0YrEsE+uhpDUihskO5uktjhWxcVx4Yoy5ib6XXKidyDO2Ywx6YqzFV5rKNfz+HvwZIsHgpyz7fkaiT5ocf8nPEF1PxB2pCiislh6z6kAepue0zdzp2HZirsomy5Z1iKPs2h7LonJaazad9YbBdg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=nxIneoYn; arc=fail smtp.client-ip=40.107.95.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="nxIneoYn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DwVjsqMqVUy2iYq6yM7+zHmOV7PiYeIz2KDGjCuqDgzLTi6Fulxky8u6mhoEYtW0UoUm1Xnf29bJ/uRLLIn5djnGbrUtzRJVEkZS9Wmd18qe2Bv/iIAt8JpbfCoovLWypfF7+yx8Rg7j8W0sLFKqYOdcw3P7af5DSld/PFpDhBQ+VrEEbFdNcqvRuZPlB6Lth/s/wAHRYE1v4Ull1lecS8JduVVIJsm+bt+vUcG4VPxowiJchDc0xwiPtCmfilpScZq81+Pm8llbnAPXNhjlzPevxng2ZHzAMwSm+zPgtb4FyRAp6wRC8zO95Ttt/6addlxlM2fgPs6o58mNzhmOdw== 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=4xd+sSglU+WvtxNUA/9fYIcr4xCYH4R97W7jHquO9ss=; b=x/FMy+qPUvKeiO4olDRe+584zCTaUmOMbDX9f3MWuVxytNG74hp+P3vyPpYNH5J/n4+SfplTRNuINoG4NbL6O+5sC1uy+6ApCowcxEZa9MKqp4P1uToqeCWsbbF8S4dh4X4X3xHqk4ARX3DQm4QzGD5RFB/FG6ZhsiuzgeMsRhlSGQUp6Ek+5k4b6+JBi5M7iMbW6Fk0SjhmXDuBlhicarEyeTSAp0K+C4cSaR0rbwRsC0SA2h7XX1czlTb5Yi8/8w5B6scqVqjioeCdrwJeYtAj5uhK7fTXF4DRR5NOzybrWbMgBV6nmMakHsSiQtBxaLM8DJesVvA4XFuwFRREQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net 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=4xd+sSglU+WvtxNUA/9fYIcr4xCYH4R97W7jHquO9ss=; b=nxIneoYnZuEsJ+50LTcTjAaIgHtqRZaDHEEewXD+dk6pBT8cKEKPx2cMBI2KUxIg4HxnRgFAnJjnCWzJZxG7S2DkhiXy9sFBKPOy2aA1POUDYy4fu1JTDdCBQLb97FgBYBCpfW1jAX8sLeDawPNqlg467hGIA5aQlqTyQXO7iCUjJ/m02FEf5ZS0PmtbQwQzUiw23PiCAQiIlDqIzgNcPX528dSoyheIIp8qc+lRROSGrHk5YAW7GV/QNSnnKMm7vEHrIW9mc27fAqoVhXsJ5azfd3Y/yoiaHaPH6Z80CdE3gr0lPJnCpoFdwc/SM32pSJSwe1kVbyIlFmUi7XxSxQ== Received: from SJ0PR03CA0073.namprd03.prod.outlook.com (2603:10b6:a03:331::18) by MN0PR12MB6222.namprd12.prod.outlook.com (2603:10b6:208:3c2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Tue, 1 Oct 2024 10:37:56 +0000 Received: from SJ1PEPF000023CF.namprd02.prod.outlook.com (2603:10b6:a03:331:cafe::7f) by SJ0PR03CA0073.outlook.office365.com (2603:10b6:a03:331::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Tue, 1 Oct 2024 10:37:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SJ1PEPF000023CF.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 10:37:56 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:45 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:44 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 1 Oct 2024 03:37:42 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Simon Horman , Cosmin Ratiu , Tariq Toukan Subject: [PATCH net-next V2 3/6] net/mlx5: hw counters: Replace IDR+lists with xarray Date: Tue, 1 Oct 2024 13:37:06 +0300 Message-ID: <20241001103709.58127-4-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241001103709.58127-1-tariqt@nvidia.com> References: <20241001103709.58127-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023CF:EE_|MN0PR12MB6222:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b4a7496-58b7-4123-50d6-08dce2051cda X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: 3OzE8PBWiU6yvlVS2sdnIwHTYWSt+XlLptCrZvcNBxrFwgqo2nMSKQQ/ozqu0YIX5ey4gruELGjU2BmK0ItY9RkOkp8zzBLENDZRCvNr5e1JrwV+XmzUiiv5VeMxeQRzduLm5ODpQ2kccj09hcTMjQezXNi8iQXLCS/3M7ZQBYP87Zpz7+vwbDLb3hWVyrIM6IeYB1orpmctKaAsNEYGlle6/aWqBnh9F8G9uqeVhTAAJGLn6Youf6Fxt2sl6hk+/n2uuYa5pakhaRiZOsPJvuf6V/OGyB6cR4bSl1qJEZxFUXw3w9H1KzYFkallzHxaD+THPiJETQY9wW/TkiJn68KnlXfKS6jdwdd2oJiakCCIxV3iNzp5N+qoU4auho+rbuGRtMp7xYRauPw+ocO1dnZE9M4WnCdx5Dy9Qu4DVBTfpudDjRxIIXU59hLuJp+KsTAC04yLk9A3mJsIGRIRsn+fhPLWvsWtPaKs1fJ6sHopNIaw/ZGh6JXII7TpaxyruwpHS/hU8HiA+AFu0vb1cx7SvtLleNzDYGZlB4V5OYEShGp69L6XYptw2pn3UDtmNq1seGpPviHRL9z5AMEllGkH//jATFjfCbfa1lh/EgxjJZN4otJSfO7c8Q0IUHwSeixihlVSPlci8P8QQHbQKLvi/p51Zj2e49Q+ravnHtTqOT17H9Ai2H+xM17C0Ix19rOPuCpYwwt8qQAYG5nX6NLUXyybqO+ZzKb7h7XdBMcA5j+fxCSl8G933NAdNn6WVfAuvj+cB5+1lgZia2ddzzjBQnX0brfb3GuoZ+UCLas79uGJNSk/tn6LihLuX8ET9CvbzDeyZXtw4XVL1VGxQd4gD2tDJSY74lzQLg89Yvi5+kvzmW+J7R3wUAJ7gh6cdX1lRqxbABcw97ArCGosTzBOSbHHY6/fCRNXYHgs9gSB5OcBNU5j+mPpmchVpylrDYM12wzrrupf8hWynjk4IZPd4stggxnWTLEedVJSO222X0/MAiK3Gpu/F35TVvd8IAgJd8upJM7GVvCKbSr0yDKkyg7dx4gJyc6wbKekpyCp2qXRD6GjaZbja4EWtUUbrNfJhD5zO7G4ACc5RIZgft/sBmD90M1opN2mCfcfrwQKs2STgsJn46tFVHdZM1YtGYp9eRuz//rLKOSg9pqzUHY2iFhbza55Rr3SZhx+LNwTmZW9pRDTOLW//Sz674bUqaTmFpVfCj4qXthkTRAz3Je3NgPOoZoR72hGOtmT7b/xhCzDe4QeCHQAdP9VKKMwH6VSh3Q2UTfg+MgQukZ5dhpLqPEEbpYDqaX242z+h0+lieqHoC1FHyc8zZgM18ygAna47IbdNeG8BaT3iyC1ExAPA+VGl53nOEvzgqGuJbU= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 10:37:56.6395 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b4a7496-58b7-4123-50d6-08dce2051cda X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF000023CF.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6222 X-Patchwork-Delegate: kuba@kernel.org From: Cosmin Ratiu Previously, managing counters was a complicated affair involving an IDR, a sorted double linked list, two single linked lists and a complex dance between a non-periodic wq task and users adding/deleting counters. Adding was done by inserting new counters into the IDR and into a single linked list, leaving the wq to process the list and actually add the counters into the double linked list, maintained sorted with the IDR. Deleting involved adding the counter into another single linked list, leaving the wq to actually unlink the counter from the other structures and release it. Dumping the counters is done with the bulk query API, which relies on the counter list being sorted and unmutable during querying to efficiently retrieve cached counter values. Finally, the IDR data struct is deprecated. This commit replaces all of that with an xarray. Adding is now done directly, by using xa_lock. Deleting is also done directly, under the xa_lock. Querying is done from a periodic task running every sampling_interval (default 1s) and uses the bulk query API for efficiency. It works by iterating over the xarray: - when a new bulk needs to be started, the bulk information is computed under the xa_lock. - the xa iteration state is saved and the xa_lock dropped. - the HW is queried for bulk counter values. - the xa_lock is reacquired. - counter caches with ids covered by the bulk response are updated. Querying always requests the max bulk length, for simplicity. Counters could be added/deleted while the HW is queried. This is safe, as the HW API simply returns unknown values for counters not in HW, but those values won't be accessed. Only counters present in xarray before bulk query will actually read queried cache values. This cuts down the size of mlx5_fc by 4 pointers (88->56 bytes), which amounts to ~3MB / 100K counters. But more importantly, this solves the wq spinlock congestion issue seen happening on high-rate counter insertion+deletion. Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- .../ethernet/mellanox/mlx5/core/fs_counters.c | 276 ++++++------------ 1 file changed, 82 insertions(+), 194 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c index 9892895da9ee..05d9351ff577 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c @@ -32,7 +32,6 @@ #include #include -#include #include "mlx5_core.h" #include "fs_core.h" #include "fs_cmd.h" @@ -51,21 +50,13 @@ struct mlx5_fc_cache { }; struct mlx5_fc { - struct list_head list; - struct llist_node addlist; - struct llist_node dellist; - - /* last{packets,bytes} members are used when calculating the delta since - * last reading - */ - u64 lastpackets; - u64 lastbytes; - - struct mlx5_fc_bulk *bulk; u32 id; bool aging; - + struct mlx5_fc_bulk *bulk; struct mlx5_fc_cache cache ____cacheline_aligned_in_smp; + /* last{packets,bytes} are used for calculating deltas since last reading. */ + u64 lastpackets; + u64 lastbytes; }; struct mlx5_fc_pool { @@ -80,19 +71,14 @@ struct mlx5_fc_pool { }; struct mlx5_fc_stats { - spinlock_t counters_idr_lock; /* protects counters_idr */ - struct idr counters_idr; - struct list_head counters; - struct llist_head addlist; - struct llist_head dellist; + struct xarray counters; struct workqueue_struct *wq; struct delayed_work work; - unsigned long next_query; unsigned long sampling_interval; /* jiffies */ u32 *bulk_query_out; int bulk_query_len; - size_t num_counters; + size_t num_counters; /* Also protected by xarray->xa_lock. */ bool bulk_query_alloc_failed; unsigned long next_bulk_query_alloc; struct mlx5_fc_pool fc_pool; @@ -103,78 +89,6 @@ static void mlx5_fc_pool_cleanup(struct mlx5_fc_pool *fc_pool); static struct mlx5_fc *mlx5_fc_pool_acquire_counter(struct mlx5_fc_pool *fc_pool); static void mlx5_fc_pool_release_counter(struct mlx5_fc_pool *fc_pool, struct mlx5_fc *fc); -/* locking scheme: - * - * It is the responsibility of the user to prevent concurrent calls or bad - * ordering to mlx5_fc_create(), mlx5_fc_destroy() and accessing a reference - * to struct mlx5_fc. - * e.g en_tc.c is protected by RTNL lock of its caller, and will never call a - * dump (access to struct mlx5_fc) after a counter is destroyed. - * - * access to counter list: - * - create (user context) - * - mlx5_fc_create() only adds to an addlist to be used by - * mlx5_fc_stats_work(). addlist is a lockless single linked list - * that doesn't require any additional synchronization when adding single - * node. - * - spawn thread to do the actual destroy - * - * - destroy (user context) - * - add a counter to lockless dellist - * - spawn thread to do the actual del - * - * - dump (user context) - * user should not call dump after destroy - * - * - query (single thread workqueue context) - * destroy/dump - no conflict (see destroy) - * query/dump - packets and bytes might be inconsistent (since update is not - * atomic) - * query/create - no conflict (see create) - * since every create/destroy spawn the work, only after necessary time has - * elapsed, the thread will actually query the hardware. - */ - -static struct list_head *mlx5_fc_counters_lookup_next(struct mlx5_core_dev *dev, - u32 id) -{ - struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; - unsigned long next_id = (unsigned long)id + 1; - struct mlx5_fc *counter; - unsigned long tmp; - - rcu_read_lock(); - /* skip counters that are in idr, but not yet in counters list */ - idr_for_each_entry_continue_ul(&fc_stats->counters_idr, - counter, tmp, next_id) { - if (!list_empty(&counter->list)) - break; - } - rcu_read_unlock(); - - return counter ? &counter->list : &fc_stats->counters; -} - -static void mlx5_fc_stats_insert(struct mlx5_core_dev *dev, - struct mlx5_fc *counter) -{ - struct list_head *next = mlx5_fc_counters_lookup_next(dev, counter->id); - - list_add_tail(&counter->list, next); -} - -static void mlx5_fc_stats_remove(struct mlx5_core_dev *dev, - struct mlx5_fc *counter) -{ - struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; - - list_del(&counter->list); - - spin_lock(&fc_stats->counters_idr_lock); - WARN_ON(!idr_remove(&fc_stats->counters_idr, counter->id)); - spin_unlock(&fc_stats->counters_idr_lock); -} - static int get_init_bulk_query_len(struct mlx5_core_dev *dev) { return min_t(int, MLX5_INIT_COUNTERS_BULK, @@ -203,47 +117,64 @@ static void update_counter_cache(int index, u32 *bulk_raw_data, cache->lastuse = jiffies; } -static void mlx5_fc_stats_query_counter_range(struct mlx5_core_dev *dev, - struct mlx5_fc *first, - u32 last_id) +/* Synchronization notes + * + * Access to counter array: + * - create - mlx5_fc_create() (user context) + * - inserts the counter into the xarray. + * + * - destroy - mlx5_fc_destroy() (user context) + * - erases the counter from the xarray and releases it. + * + * - query mlx5_fc_query(), mlx5_fc_query_cached{,_raw}() (user context) + * - user should not access a counter after destroy. + * + * - bulk query (single thread workqueue context) + * - create: query relies on 'lastuse' to avoid updating counters added + * around the same time as the current bulk cmd. + * - destroy: destroyed counters will not be accessed, even if they are + * destroyed during a bulk query command. + */ +static void mlx5_fc_stats_query_all_counters(struct mlx5_core_dev *dev) { struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; - bool query_more_counters = (first->id <= last_id); - int cur_bulk_len = fc_stats->bulk_query_len; + u32 bulk_len = fc_stats->bulk_query_len; + XA_STATE(xas, &fc_stats->counters, 0); u32 *data = fc_stats->bulk_query_out; - struct mlx5_fc *counter = first; + struct mlx5_fc *counter; + u32 last_bulk_id = 0; + u64 bulk_query_time; u32 bulk_base_id; - int bulk_len; int err; - while (query_more_counters) { - /* first id must be aligned to 4 when using bulk query */ - bulk_base_id = counter->id & ~0x3; - - /* number of counters to query inc. the last counter */ - bulk_len = min_t(int, cur_bulk_len, - ALIGN(last_id - bulk_base_id + 1, 4)); - - err = mlx5_cmd_fc_bulk_query(dev, bulk_base_id, bulk_len, - data); - if (err) { - mlx5_core_err(dev, "Error doing bulk query: %d\n", err); - return; - } - query_more_counters = false; - - list_for_each_entry_from(counter, &fc_stats->counters, list) { - int counter_index = counter->id - bulk_base_id; - struct mlx5_fc_cache *cache = &counter->cache; - - if (counter->id >= bulk_base_id + bulk_len) { - query_more_counters = true; - break; + xas_lock(&xas); + xas_for_each(&xas, counter, U32_MAX) { + if (xas_retry(&xas, counter)) + continue; + if (unlikely(counter->id >= last_bulk_id)) { + /* Start new bulk query. */ + /* First id must be aligned to 4 when using bulk query. */ + bulk_base_id = counter->id & ~0x3; + last_bulk_id = bulk_base_id + bulk_len; + /* The lock is released while querying the hw and reacquired after. */ + xas_unlock(&xas); + /* The same id needs to be processed again in the next loop iteration. */ + xas_reset(&xas); + bulk_query_time = jiffies; + err = mlx5_cmd_fc_bulk_query(dev, bulk_base_id, bulk_len, data); + if (err) { + mlx5_core_err(dev, "Error doing bulk query: %d\n", err); + return; } - - update_counter_cache(counter_index, data, cache); + xas_lock(&xas); + continue; } + /* Do not update counters added after bulk query was started. */ + if (time_after64(bulk_query_time, counter->cache.lastuse)) + update_counter_cache(counter->id - bulk_base_id, data, + &counter->cache); } + xas_unlock(&xas); } static void mlx5_fc_free(struct mlx5_core_dev *dev, struct mlx5_fc *counter) @@ -291,46 +222,19 @@ static void mlx5_fc_stats_work(struct work_struct *work) struct mlx5_fc_stats *fc_stats = container_of(work, struct mlx5_fc_stats, work.work); struct mlx5_core_dev *dev = fc_stats->fc_pool.dev; - /* Take dellist first to ensure that counters cannot be deleted before - * they are inserted. - */ - struct llist_node *dellist = llist_del_all(&fc_stats->dellist); - struct llist_node *addlist = llist_del_all(&fc_stats->addlist); - struct mlx5_fc *counter = NULL, *last = NULL, *tmp; - unsigned long now = jiffies; - - if (addlist || !list_empty(&fc_stats->counters)) - queue_delayed_work(fc_stats->wq, &fc_stats->work, - fc_stats->sampling_interval); - - llist_for_each_entry(counter, addlist, addlist) { - mlx5_fc_stats_insert(dev, counter); - fc_stats->num_counters++; - } + int num_counters; - llist_for_each_entry_safe(counter, tmp, dellist, dellist) { - mlx5_fc_stats_remove(dev, counter); - - mlx5_fc_release(dev, counter); - fc_stats->num_counters--; - } - - if (time_before(now, fc_stats->next_query) || - list_empty(&fc_stats->counters)) - return; + queue_delayed_work(fc_stats->wq, &fc_stats->work, fc_stats->sampling_interval); + /* num_counters is only needed for determining whether to increase the buffer. */ + xa_lock(&fc_stats->counters); + num_counters = fc_stats->num_counters; + xa_unlock(&fc_stats->counters); if (fc_stats->bulk_query_len < get_max_bulk_query_len(dev) && - fc_stats->num_counters > get_init_bulk_query_len(dev)) + num_counters > get_init_bulk_query_len(dev)) mlx5_fc_stats_bulk_query_buf_realloc(dev, get_max_bulk_query_len(dev)); - last = list_last_entry(&fc_stats->counters, struct mlx5_fc, list); - - counter = list_first_entry(&fc_stats->counters, struct mlx5_fc, - list); - if (counter) - mlx5_fc_stats_query_counter_range(dev, counter, last->id); - - fc_stats->next_query = now + fc_stats->sampling_interval; + mlx5_fc_stats_query_all_counters(dev); } static struct mlx5_fc *mlx5_fc_single_alloc(struct mlx5_core_dev *dev) @@ -374,7 +278,6 @@ struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) if (IS_ERR(counter)) return counter; - INIT_LIST_HEAD(&counter->list); counter->aging = aging; if (aging) { @@ -384,18 +287,15 @@ struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) counter->lastbytes = counter->cache.bytes; counter->lastpackets = counter->cache.packets; - idr_preload(GFP_KERNEL); - spin_lock(&fc_stats->counters_idr_lock); + xa_lock(&fc_stats->counters); - err = idr_alloc_u32(&fc_stats->counters_idr, counter, &id, id, - GFP_NOWAIT); - - spin_unlock(&fc_stats->counters_idr_lock); - idr_preload_end(); - if (err) + err = xa_err(__xa_store(&fc_stats->counters, id, counter, GFP_KERNEL)); + if (err != 0) { + xa_unlock(&fc_stats->counters); goto err_out_alloc; - - llist_add(&counter->addlist, &fc_stats->addlist); + } + fc_stats->num_counters++; + xa_unlock(&fc_stats->counters); } return counter; @@ -407,12 +307,7 @@ struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging) { - struct mlx5_fc *counter = mlx5_fc_create_ex(dev, aging); - struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; - - if (aging) - mod_delayed_work(fc_stats->wq, &fc_stats->work, 0); - return counter; + return mlx5_fc_create_ex(dev, aging); } EXPORT_SYMBOL(mlx5_fc_create); @@ -430,11 +325,11 @@ void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter) return; if (counter->aging) { - llist_add(&counter->dellist, &fc_stats->dellist); - mod_delayed_work(fc_stats->wq, &fc_stats->work, 0); - return; + xa_lock(&fc_stats->counters); + fc_stats->num_counters--; + __xa_erase(&fc_stats->counters, counter->id); + xa_unlock(&fc_stats->counters); } - mlx5_fc_release(dev, counter); } EXPORT_SYMBOL(mlx5_fc_destroy); @@ -448,11 +343,7 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev) return -ENOMEM; dev->priv.fc_stats = fc_stats; - spin_lock_init(&fc_stats->counters_idr_lock); - idr_init(&fc_stats->counters_idr); - INIT_LIST_HEAD(&fc_stats->counters); - init_llist_head(&fc_stats->addlist); - init_llist_head(&fc_stats->dellist); + xa_init(&fc_stats->counters); /* Allocate initial (small) bulk query buffer. */ mlx5_fc_stats_bulk_query_buf_realloc(dev, get_init_bulk_query_len(dev)); @@ -467,7 +358,7 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev) INIT_DELAYED_WORK(&fc_stats->work, mlx5_fc_stats_work); mlx5_fc_pool_init(&fc_stats->fc_pool, dev); - + queue_delayed_work(fc_stats->wq, &fc_stats->work, MLX5_FC_STATS_PERIOD); return 0; err_wq_create: @@ -480,23 +371,20 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev) void mlx5_cleanup_fc_stats(struct mlx5_core_dev *dev) { struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; - struct llist_node *tmplist; struct mlx5_fc *counter; - struct mlx5_fc *tmp; + unsigned long id; cancel_delayed_work_sync(&fc_stats->work); destroy_workqueue(fc_stats->wq); fc_stats->wq = NULL; - tmplist = llist_del_all(&fc_stats->addlist); - llist_for_each_entry_safe(counter, tmp, tmplist, addlist) - mlx5_fc_release(dev, counter); - - list_for_each_entry_safe(counter, tmp, &fc_stats->counters, list) + xa_for_each(&fc_stats->counters, id, counter) { + xa_erase(&fc_stats->counters, id); mlx5_fc_release(dev, counter); + } + xa_destroy(&fc_stats->counters); mlx5_fc_pool_cleanup(&fc_stats->fc_pool); - idr_destroy(&fc_stats->counters_idr); kvfree(fc_stats->bulk_query_out); kfree(fc_stats); } From patchwork Tue Oct 1 10:37:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13817746 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2055.outbound.protection.outlook.com [40.107.244.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96F9A1A0BDE for ; Tue, 1 Oct 2024 10:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779087; cv=fail; b=UKHQTFrMDn4vh6q4l2Pm6Q6Cj+eZ1zaeP49B34KuyFUL40wye/rU0519liwhYRC6Y5EDtbVfnIth1Q48c07G3MBIGKkcCj5x+h4gtK46AQKXuYAAflRIOFZ4W2AkWADYGphBlTCMgLTK8fl28f1URPdA6pCCAqrZczAiWqQyN9I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779087; c=relaxed/simple; bh=5n3sZH2bRntkMmZIJLXG0+s33H09Q+wSr8cLPAA1sAQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KHW33/9Hkt5gMn1zIzN6nfjtkNqsmI+k1RgADfvA9Nk4n9GjBKLL00Bc0nZI60b4qGoPXMqR2PsYm7gGc1J8ikTHqWQXykBCOrqDvUmNHdwsIUE3LpD+jDqJsc8e5f6szxP8Lg5jurxYlVgmBSjiVXyNREg2XIvqJqayPtBad/o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=aeq/VCNp; arc=fail smtp.client-ip=40.107.244.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="aeq/VCNp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cotk6dmcml7Q2tK2q8wn9m8M1VntEdb53rgjoxlFn/Uu2EM0RALdupW6lciYEpKKNHAuEtLZ2DtGT624GT7vh+zMwjK6ba2agzrkmrw9x7WwIbUiyWhiulGKBRXpFU2tr6CVThxPXfNkym7njOGTvQyWAzvFL+Vtz/QubFFdUm+X9SHXwVZ3lyUqta+/T1HK9Sd+2r1y4cgkg6NI7/3wRSuAYG4aewty6qwyyGqYylXASR+7LDXZhQEGgVMntmkZNIxRKEme9UZWCUHIOu52NxLJsmeDHsy8QT/qO9TBnevSNQrGKJ08v8MIN0waTMUWaI6Wfla9lpX7LwmQ49PWlA== 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=cWeXu8oB5hWGn88YtOrb9nDr5pwy8kUIM1NvQU0vqcg=; b=JmL0iAsRFeu8l8Y+vgSt6HyZNl5vOz//wfDubWmbXDw0kMHm2FAG6cxzNIfXixwpQdigCdyN7UcLWbjF4cx3qIhf+lmJqp+5nt/5ETnX2hwkofvQkV5iJz5wc6UGilOk4OuhYw245TQim0W+d3WL4zZ1VO/qkOEXGUbq124Q8/xxfXaSaj0Jz4uNsopQGuuYI2V3Kr5xlPBx9VIH0Nbf7LLv7Fh3ObB1S7VDE34SunpI/X5uKuVYenbIxnhyBpDMCv/y7ddInPPump4DibYV+JZPGYrXgCb7ygjPNFKCtcglPudPIkyzOoe6BUZOgW/kFMEzEE8XVIIWn2SOdnMHhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net 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=cWeXu8oB5hWGn88YtOrb9nDr5pwy8kUIM1NvQU0vqcg=; b=aeq/VCNp78fqoTaEo2VGiutMCP0k7cLf2Djf8Iku9i5LOAvQUpXlpdoJczSh7FOREAFnZDNn4qXLn3umZ160qwtsB9VoVVXynlUZDL+EpCSaornC1DHsZSiMCOzjC8Mfau7VjLf+jI4zNtsuFMWei9GkFrc2aHoMf9F6KuXf5FoK2XXDsXUZfwpA81VRdS4xIDxuDNAqDAtL7RJj8H49dkYItFINGtX/t04LMjVWgNHEYkAOOENs9NBET9P+x28qFodeiXX7mehr/9m667SmzxKXO3Aa9zcyGaTKqwM+GxKMcn0w1ptNo7uaZtOw4+xqHAF+ugAFopcpZNq1MVwwPA== Received: from SJ0PR13CA0100.namprd13.prod.outlook.com (2603:10b6:a03:2c5::15) by CY8PR12MB8340.namprd12.prod.outlook.com (2603:10b6:930:7a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Tue, 1 Oct 2024 10:38:00 +0000 Received: from SJ1PEPF000023CD.namprd02.prod.outlook.com (2603:10b6:a03:2c5:cafe::a6) by SJ0PR13CA0100.outlook.office365.com (2603:10b6:a03:2c5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15 via Frontend Transport; Tue, 1 Oct 2024 10:38:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SJ1PEPF000023CD.mail.protection.outlook.com (10.167.244.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 10:37:59 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:48 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:47 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 1 Oct 2024 03:37:45 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Simon Horman , Cosmin Ratiu , Tariq Toukan Subject: [PATCH net-next V2 4/6] net/mlx5: hw counters: Drop unneeded cacheline alignment Date: Tue, 1 Oct 2024 13:37:07 +0300 Message-ID: <20241001103709.58127-5-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241001103709.58127-1-tariqt@nvidia.com> References: <20241001103709.58127-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023CD:EE_|CY8PR12MB8340:EE_ X-MS-Office365-Filtering-Correlation-Id: ddd714c3-876f-4aa8-b411-08dce2051ebf 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: Xfq4B/mWERVJJorl1InEbLJGRKdmC1k9H6FtuaeSdDPqDOhg8Z5s2hLRAOG42298CGIrrtujB2K4c1f1JwA3xGP6yW546drE2XJn3hm9NdZ8+91kFodU7MTmOv67yTtEDG4wMkkPWJmbf9+JaQBPNgZ8AX5n9s3kOzvG2fCPHxh5I1E1lARzwrhNYKdtyP96r62TDqQLQ/cVjrhgIGXgyQMPvr+BVz+XJz/fge/0pDVd9rhkCviJZlmCPzvQSePuAsvWUS6zfB1Nzm7ULi9qVd6j4N73qU4CmC0WOt+CxCY86/hWej4sujGFbmEpgROGCzKO6HDX9MsyK3gJxGg1ijx5GtbAM0Su9NGr6FUO6Dmk9aGa87kZjwsDb5A4YNI5mhz05q+pGLL0tKlpH8GYh3M78Q8in8aHmMZk9EbKSoxEBpdpGcIi6k7Ku6x8wNAHJhAe8830Xi4k8RRCk9cCfFtI5qFhX3OCemqTMPryXocfByyQmA/jXC07+y+3yrlPqNwa46yRcRXw696w3s3Hmn6r0zfMtfkDrHpWZPkRSjDQdFbHgCFelMY3tbaAbj98vGgF1V59DrYjwj8AdT46frFdEXHJ3VZcCplQ1bk/gUnPCHipmdNB2D8nRFYbkea/4WXMOAYZEyaG57pWFwNnHbfNfebL/h0VWJnXLvh5lrcwZYXo/0zyHwoBT4LAupejzdXWrvVEu01IndW0ASQstvlUkG1WyZ7w7jsZBPAQqc/vCzWgdqSr7l3dfBsKlB/59KJF9JQXgpR+foUf/PwVIwi1KcY4xy6OOXi0zYrWP/LZyeseaI1irK8/q+9zRvLnnLoYKEjWyhhbdHIrGBx6IuEYqZEfXslgPnBFTlmcShND7QtrYDODVPrUMSrg2aseyuvRdAjc2zU/vppK9RyP7IVdTXFmbJjpkzY0XNEy2vehVdso6eGv9+616709VxaCDS38L3LGjRGUFvidCkpA2ptp+Af4UcFAKpSDY6imLcFpUAohpbKR4dXkt6RPbcbY4jhd1C0bBrU5+uglayVx6Z5vW4D2ln7QnU0K/lgXLvrvEOh8VddCsoTM0u2nroEVMRpRRKPfTB3Xh8Tr4ANUSs+RJkDvUHw97VmK7JcNmHCnCd2wf1qR0petWrpfR2s+RMmJQAP7GdRRGizheu3ZaUw87M9OM6eOqhMh75Vjkl7RGJN3IuhmJJ4gkbaYlFIvkQ4dZKRx3MzcuCVcLXpQY3Kj8xwJMCecyIvomtzdvJbWyFSPbf/LJgeg3sMqUHHFTNkfLjCCs92xSLfLXviF1S3QhZlaEFv9372zgtFZF99TZWx3o9IF0fE1kOjkeT+CEuL317aNma+eGM3YhqCBJfen8i+aCnChSlmd1M2Ztvjlp8RoyVEzUFumEswooYJLxg9J75eSEN9j13mCppXcrimmWlC3gEwBOdEQ3Flp3daKOjg7ZqmhwPLG50FUpWA6 X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 10:37:59.8205 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ddd714c3-876f-4aa8-b411-08dce2051ebf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF000023CD.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8340 X-Patchwork-Delegate: kuba@kernel.org From: Cosmin Ratiu The mlx5_fc struct has a cache for values queried from hw, which is cacheline aligned. On x86_64, this results in: struct mlx5_fc { u32 id; /* 0 4 */ bool aging; /* 4 1 */ /* XXX 3 bytes hole, try to pack */ struct mlx5_fc_bulk * bulk; /* 8 8 */ /* XXX 48 bytes hole, try to pack */ /* --- cacheline 1 boundary (64 bytes) --- */ struct mlx5_fc_cache cache __attribute__((__aligned__(64))); /* 64 24 */ u64 lastpackets; /* 88 8 */ u64 lastbytes; /* 96 8 */ /* size: 128, cachelines: 2, members: 6 */ /* sum members: 53, holes: 2, sum holes: 51 */ /* padding: 24 */ /* forced aligns: 1, forced holes: 1, sum forced holes: 48 */ } __attribute__((__aligned__(64))); (output from pahole). ...So a 48+24=72 byte waste. As far as I can determine, this serves no purpose other than maybe making sure that the values in the cache do not span two cachelines in the worst case scenario, but that's not a valid enough reason to waste 72 bytes per counter, especially since this code is not performance-critical. There could potentially be hundreds of thousands of counters (e.g. for connection-tracking), so this quickly adds up to multiple MB wasted. This commit removes the alignment, resulting in: struct mlx5_fc { [...] /* size: 56, cachelines: 1, members: 6 */ /* sum members: 53, holes: 1, sum holes: 3 */ /* last cacheline: 56 bytes */ }; Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c index 05d9351ff577..ef13941e55c2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c @@ -53,7 +53,7 @@ struct mlx5_fc { u32 id; bool aging; struct mlx5_fc_bulk *bulk; - struct mlx5_fc_cache cache ____cacheline_aligned_in_smp; + struct mlx5_fc_cache cache; /* last{packets,bytes} are used for calculating deltas since last reading. */ u64 lastpackets; u64 lastbytes; From patchwork Tue Oct 1 10:37:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13817747 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2084.outbound.protection.outlook.com [40.107.100.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8B721A2653 for ; Tue, 1 Oct 2024 10:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779087; cv=fail; b=S49FpGZHAIZmgA294qIp6wH2rXr4ycAU+usyaj7vvrV5cPRlNzYeu3h8PyQK1BE4y21I8Iuas6HquTfO1ljWEq3swyqki3cmp4kMmDs8JfDGOabBRS8/eUdmYMptM4Zf4nMlKnsfjnuns9Erc3v0azh79IpcW3hOdwpAfaXvZ34= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779087; c=relaxed/simple; bh=2jypo7DGpI8g0wA9U8X8BmO5SBEhWXsYOAXjBc5/h3Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cUCPJWd8M6TGxex9DXtdiIUAWEW6/5ocpA3ueXlbk0tHGeVm7ggVsUevFM7v+H4MCfVqPkbdDLDUvp8hf1LEKzzTDuQ1RI3FfnauOZ9SJkFFWrGLylrEBCRElZPyYxeMdlHOrrIuGmZUKl8jjxRV/OQCSQIHWLv4+3DOyhNPzlk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=bmUPWHTk; arc=fail smtp.client-ip=40.107.100.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="bmUPWHTk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ujfzK14tr07HfuxUbw+jhz6oLH70UZeWmrnWsU8YN56kbZbMjMeEdvJ6YGx8bBtq4jXZvDUSi9SNTEKR/Vg/Gwjiysd8yaz87gHFl5JABWmwXlEQg1pUFqOUYchY1J60+gCPFJa4E7t8QfWm+jMgVjRlfljyXzWtUPKqikiO5tzo5jP9P9EiVHRGPG8UKVP8dVYdUdfeP4VLmfoNXoivJzDb4txL+e9uCViYp7rf9pdo3a6lWjFEjwi8Ihv1dzxAzK7ptOTsb7lkwhpqZOR6y+P544EnXVV1HyHe7VKFtcWcXBMbLB3nFKSQGa9FuVubNtp/2o+vsjDqV5KeLn5biQ== 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=lRX3CrtQll6TLsWQLDqiZ188Kb1dwWlFcTPrC/ac9uI=; b=xM1SJMi1KI6vbj4iMf9kwjzjtqzqFgIBSjEViiHfW8htISP1Y+ruHzVTLNyZ8fzNRJCuGFgjWDvxFWVZaw53pGtc8sJImKdGr9HeWrmjSXVaiUIbcz2Dd9AH2eLVTXujOtLyak9hiSAO591YLz2p3zfn659rzOG/fqDYeA8+gByhyw8vtY7VnilX3N0TnZnmxsZDymxJ3toZKxnEL3wA96t2HPAu/2EDJkShtYZ0QnJwbPWkM/xSt7hYZc2/yD7jL2rOogXFvNyamrfiuVpm8SOeyt1aowGh7+cM0ZlEcCVMTZhFnI4A98anYem5S/cVLJOd/N22eSYItygiZecrEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net 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=lRX3CrtQll6TLsWQLDqiZ188Kb1dwWlFcTPrC/ac9uI=; b=bmUPWHTkNGd7CbR2aMKj58N6I+Iz+JgpIOLMuzE8k6gUPNI/ywXNgoVqYz8KB3VyY7C2tr9Ng6fmLX0iYN5kGJhUmzJyw9GNhV3EaDd8NzudIfewtn8DDNnqWECsVES4/hgNwak/y7CN0Bzko5FrDlzN8CrnK0W/1W/BFA3zwjVWpLpAFjxFJRD4itrV3a5i7ndYNrN8r/1Es7/6mQmFsAIVzrYk38mCQiaf6K/TiBkveVPvlIB0jbEOKIoxPX9tXiaf6WOpVNsKVj2RYG4W3/Vbe9Qu/W3jPCJTuHimJBsNez6lZvQbJMTa+8QjBrttV0r0mdTV1RDO6fKuOycoPg== Received: from SJ0PR13CA0099.namprd13.prod.outlook.com (2603:10b6:a03:2c5::14) by MW4PR12MB7264.namprd12.prod.outlook.com (2603:10b6:303:22e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15; Tue, 1 Oct 2024 10:38:01 +0000 Received: from SJ1PEPF000023CD.namprd02.prod.outlook.com (2603:10b6:a03:2c5:cafe::61) by SJ0PR13CA0099.outlook.office365.com (2603:10b6:a03:2c5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15 via Frontend Transport; Tue, 1 Oct 2024 10:38:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SJ1PEPF000023CD.mail.protection.outlook.com (10.167.244.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 10:38:01 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:51 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:51 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 1 Oct 2024 03:37:48 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Simon Horman , Cosmin Ratiu , Tariq Toukan Subject: [PATCH net-next V2 5/6] net/mlx5: hw counters: Don't maintain a counter count Date: Tue, 1 Oct 2024 13:37:08 +0300 Message-ID: <20241001103709.58127-6-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241001103709.58127-1-tariqt@nvidia.com> References: <20241001103709.58127-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023CD:EE_|MW4PR12MB7264:EE_ X-MS-Office365-Filtering-Correlation-Id: 327a934f-0338-47b4-ce32-08dce2051fdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: nVofaiySbFObn85frBroEa90ZzhTTPIi1F+Ca/d25sIpGtccIL3LWz8bm8RjPyyfpxMOiMFq6asfasHxHtT2FUifOqbF5OtZk+toYX/bVL+MtJ925W50PECMmuO4Om+YqusMOrNc/USifS1Netz1flkQB4O5tDRu+OL8RnmJ/yPqB3gCtdTZ9QdF1aOjNXyRny8+m3clqMZqs8SwkcW0RW8SaAYYplyLnsKwXGNLR8To8SZfBVhVoa1MTMIhQ3y4l3oBQocs4SN9P/W0fsgSTuXb73vBQK7gbISI7DVyTOfjWiJ/IfkmHzVNjf3RE18CMNcVPqODcDFTsLB3ftmquwjhqT2xuGwKw8WbDkfmA0/3HXrshr6HvP2eaeTs6YWqo6szfPQucoyqbXe6XrNLAcXRpyHMkEJ9R5AEzrgPfmSU93sYAyFK1sfDh2pJHPmDrFrVYHngligtziF3BmlENd6f18yWtFH3GAuk32Fintk9kfQ/HAGIH84RfaZc5iMSXoADF0F1R+OU9k3vmc7wcf9DCa2M6lSLUuAnO39M7IPRLFcbxV7cKf18Tj3fM5smIsRne1ZEmG6uxaFJ1+g9hstNtc1zr5BLxH5tx0HkVlg5LXl/ZrcX7XpFilC3cvGIaU+ybYsgVAJiwtFfkvDzU4Io015Se51JXlUu2DWt+gZt+zJEWm0av1hgOwa5tGZ9/LSnoHHrHtuync9rhqIeUntW8o8gkk7Bq/6oCUdXMCN38gn1g2amUhXu2L5jxA7J2I6+/uC7IJNmOEgvXU6AOa8bag8slvip4ALMW0k+666jY6gaLB87kLz7LE8RWld84lpWq/06wrugw4WZn3Q9wCpG6Fu4WbxQkR4uA5e6AmFC/XblomnfatGAV7kPHLFB8cF1vpaBgDdE+j7MzRAOr8x2qevnbXBC8hhBy8oanzhTCGi+qkJK+1BcKhZrpmIgdH7nJMqkUwrCFeqzHOlNg3TVSlnmmzAXwVwIoyInWHuRuy9FquZT/PQq+2SUjwTlKo+2g6iKZwSX19Im7vyWYrSoMpBfAJB5VTdFZnCu3w0mEzVtzsOd/ktCedqJGZm8Pn6ZBDpmu0UeisTZjxWt+QCvExcHSOji5IkUcQgHyGRcH5SSDbAmx4Q04zalYItGdYGC+YAACQ1d1oO9yMRJwnWdc1R9CrNyy71/rOOsgPaUWtNtlMQSUKIrGsX1to78Vl/+3IIBgIZ6jb0Q9/uQz29lax+4ntweB9YVhBDdNfDlayEvCFbUuzHMQcpekEfZedKU5S03c5vn1W9DLzy70NglCQq53sJwA6B9pjhtu4zyZSS6odkY2ujuOlJkewK/idBTwV9bgdHmQDTZp1NTelxJGeHzWKUey26li5VJjX0tZrknS7bVsrR1m3GIJA7b2Sz+YE7xbnNmc0QiMOvcpg8WPALiL0WpZE3w2mImqN4rrjMo6PdBPM7VtENEWdRp X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 10:38:01.6799 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 327a934f-0338-47b4-ce32-08dce2051fdd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF000023CD.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7264 X-Patchwork-Delegate: kuba@kernel.org From: Cosmin Ratiu num_counters is only used for deciding whether to grow the bulk query buffer, which is done once more counters than a small initial threshold are present. After that, maintaining num_counters serves no purpose. This commit replaces that with an actual xarray traversal to count the counters. This appears expensive at first sight, but is only done when the number of counters is less than the initial threshold (8) and only once every sampling interval. Once the number of counters goes above the threshold, the bulk query buffer is grown to max size and the xarray traversal is never done again. Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- .../ethernet/mellanox/mlx5/core/fs_counters.c | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c index ef13941e55c2..0b80c33cba5f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c @@ -78,7 +78,6 @@ struct mlx5_fc_stats { unsigned long sampling_interval; /* jiffies */ u32 *bulk_query_out; int bulk_query_len; - size_t num_counters; /* Also protected by xarray->xa_lock. */ bool bulk_query_alloc_failed; unsigned long next_bulk_query_alloc; struct mlx5_fc_pool fc_pool; @@ -217,21 +216,28 @@ static void mlx5_fc_stats_bulk_query_buf_realloc(struct mlx5_core_dev *dev, bulk_query_len); } +static int mlx5_fc_num_counters(struct mlx5_fc_stats *fc_stats) +{ + struct mlx5_fc *counter; + int num_counters = 0; + unsigned long id; + + xa_for_each(&fc_stats->counters, id, counter) + num_counters++; + return num_counters; +} + static void mlx5_fc_stats_work(struct work_struct *work) { struct mlx5_fc_stats *fc_stats = container_of(work, struct mlx5_fc_stats, work.work); struct mlx5_core_dev *dev = fc_stats->fc_pool.dev; - int num_counters; queue_delayed_work(fc_stats->wq, &fc_stats->work, fc_stats->sampling_interval); - /* num_counters is only needed for determining whether to increase the buffer. */ - xa_lock(&fc_stats->counters); - num_counters = fc_stats->num_counters; - xa_unlock(&fc_stats->counters); - if (fc_stats->bulk_query_len < get_max_bulk_query_len(dev) && - num_counters > get_init_bulk_query_len(dev)) + /* Grow the bulk query buffer to max if not maxed and enough counters are present. */ + if (unlikely(fc_stats->bulk_query_len < get_max_bulk_query_len(dev) && + mlx5_fc_num_counters(fc_stats) > get_init_bulk_query_len(dev))) mlx5_fc_stats_bulk_query_buf_realloc(dev, get_max_bulk_query_len(dev)); mlx5_fc_stats_query_all_counters(dev); @@ -287,15 +293,9 @@ struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) counter->lastbytes = counter->cache.bytes; counter->lastpackets = counter->cache.packets; - xa_lock(&fc_stats->counters); - - err = xa_err(__xa_store(&fc_stats->counters, id, counter, GFP_KERNEL)); - if (err != 0) { - xa_unlock(&fc_stats->counters); + err = xa_err(xa_store(&fc_stats->counters, id, counter, GFP_KERNEL)); + if (err != 0) goto err_out_alloc; - } - fc_stats->num_counters++; - xa_unlock(&fc_stats->counters); } return counter; @@ -324,12 +324,8 @@ void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter) if (!counter) return; - if (counter->aging) { - xa_lock(&fc_stats->counters); - fc_stats->num_counters--; - __xa_erase(&fc_stats->counters, counter->id); - xa_unlock(&fc_stats->counters); - } + if (counter->aging) + xa_erase(&fc_stats->counters, counter->id); mlx5_fc_release(dev, counter); } EXPORT_SYMBOL(mlx5_fc_destroy); From patchwork Tue Oct 1 10:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13817745 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2048.outbound.protection.outlook.com [40.107.100.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9CA719CC08 for ; Tue, 1 Oct 2024 10:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779084; cv=fail; b=rj6bjQnSAuxWZFmdw88qQ+Fkxg+VTOmFzN17nuiErXUsWcIGVAsgXqK0iCl5PgzkqSf979SGUR8pMB8rhpn1td3Kprrs8GjpojdKH5gwYGqK3COLNdAmHNFvDoMrN5pmcWsSOX965zbabLO9rmnIqLilNfCktUsnjUtDTHrAvKI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727779084; c=relaxed/simple; bh=TKY/buyhaJrAkZOWl86+E3prr3fKHqCHcaSMpsRrSvQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j2XpDjLEMzKT7JOWdsn8Hl4EHyfa5fTyirJUPIucmLo27USdftyaxkaXKIRCF7mWMoxz2nSL7t6z4KId/zYukWQTGgp4RqAXN8+TrbT4bincQuVEI68qcuxHodbE8uuR8gr/EOpoV0CvBqrxEGT050aDg6cqw6o/W8DXLk85E60= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=BvAMYSF/; arc=fail smtp.client-ip=40.107.100.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="BvAMYSF/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ErGbZW6zgRdVkVtHarWm4c38rQfv9XB90g7+Gl18lt7kTmHCV36DkiOahsHUkvuXZAyK5p0+zcfJrrPqKou6wYOVC5N/KbaMK8iFhtY2TCHuJEECA/8Mx0fVbrjTiH0ol0e9FL+5tHaLqlmyN5i9ya3bg4H5k6t/Ovk7Uynd322Qoo7sunUGc7Ip2P/grBM5wVm5k2JEr/RMCafAjPKUtSHMiS2ftzWOGBJDWRNt7ceGmNwoKvaG/hV0N6g2602hOilTWMBRweANApvWKXEn5arVElptmhw9O79uZKCWH1DZ0CmID1awOW6lEThgOE8oQaimaWik+iRxZ+PBOitGnA== 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=+jH3QfNSYs8bgAa+N9PUNOrQQ8fgi8985NoRHonJlGA=; b=jrhZQqWIJwUFvYST64bGjcIXxXMZRUNtPBtG+HTIwMgtpP6vHjNcWYJKf/Gbs1BWhNNeunoItSAzg4MiCglhI2NQN+OO1YmluV/eG8+b5H11kx8DIGZysDyr36dGmQi64Fht5CxRMDdctSRwH8+Kz+91fN99KW7axSHP/IiAHDiHHfI3mmOxKTyKOxMceJPMNMSSXMym47nhyM2mV65e9b7SLJxBD0VFhJ1gS3h5mptLC17QaaRxTibXCnQvOs7rYKfBr5zzfRP/PcRdVu7CvN+03fPDy6F+/rCGVotqVdbO3sBYmCu3qk+fAFQ6SWUZHL2+B+LMppQzp3zDeJwknA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=davemloft.net 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=+jH3QfNSYs8bgAa+N9PUNOrQQ8fgi8985NoRHonJlGA=; b=BvAMYSF/E4CR2GdxA7CfpROS5OPnzmdZjLNC5MoMDMKjrBjlSlpPq2Rb5DQsCiXNQjC1gj0HUkQfWxvASv4g1913/FcfAFSkI55KCOKujnBMRh26zqMSiX6s+vkXyYSx2Xj2L+rNcRGevLf8TzRXAibrFwZxsMDORYlNcB4Kh/Gqmv6EhTO+wAFviPIJlVGffWkTgAowKduGl5FxOpeTugpE9CmFJEQLzJ+/+pqN9olecZCI5aAZrsCdDGRQQarp3aWXAm1AeOjJY3buIOXe4HVs8oGrnoZXfKBFIeXdGi5wNDUqIMTODmr5hl+Xnv5wToHvrnhAXkZJOFUtL6OHhw== Received: from CH0PR03CA0395.namprd03.prod.outlook.com (2603:10b6:610:11b::12) by PH0PR12MB7960.namprd12.prod.outlook.com (2603:10b6:510:287::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.25; Tue, 1 Oct 2024 10:37:58 +0000 Received: from CH2PEPF0000009F.namprd02.prod.outlook.com (2603:10b6:610:11b:cafe::a9) by CH0PR03CA0395.outlook.office365.com (2603:10b6:610:11b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15 via Frontend Transport; Tue, 1 Oct 2024 10:37:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CH2PEPF0000009F.mail.protection.outlook.com (10.167.244.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 10:37:57 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:54 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 1 Oct 2024 03:37:54 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 1 Oct 2024 03:37:51 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Simon Horman , Cosmin Ratiu , Tariq Toukan Subject: [PATCH net-next V2 6/6] net/mlx5: hw counters: Remove mlx5_fc_create_ex Date: Tue, 1 Oct 2024 13:37:09 +0300 Message-ID: <20241001103709.58127-7-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241001103709.58127-1-tariqt@nvidia.com> References: <20241001103709.58127-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009F:EE_|PH0PR12MB7960:EE_ X-MS-Office365-Filtering-Correlation-Id: 2fe36fe5-5854-4cd0-0727-08dce2051d58 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: hvXAJ8mdD3pQshEETlHcYz6vrvZFGqtPWlZN89feiLgQHS8b6bCuj8YGZcMi2HWTWvoP69v6GHcxeOlPJCAUNHm5Lan2vtw34Tg74Tb1htA411tFk56+4cPo9vgEArGNVBTJTEEQJh2L7UcMBTYqgTjjpClCgHRN/CliRNEaZOIgA2wLdj8iO3aNMT76+0Jk1aBsG4Ta4I63zhXqpUfgE1/t8KW4l3PDsvqkdeGvO5A9MuXH69TqMVHhWtR9Do9v5qBckfxXFvjoxANSlxZHhyKkYyLUepJRtq6+PinuxsOhFVtd9tm7rmeAap88IMDf6XE2H8sk+2zUVy3zp+Ka01wW9bPIVFGWBOtbhnt0ZM1Bo6fTyj51dZNYBytv6AfgC5BWeGJY0NXAJ6YtQLyRN3yUOtzIZfAGinxJP6d/6MEyvCkz9Dr5Rfrk3CCEnwXV/AiBoL4mrxIcxzBxXY4eYcnfsn5AUIVtI5ruH/IYmKZdUlt/YsOhHL1lW96K/D2n2Ix2w38jX6Y5g8Q5XdcmdMLz3/IgxpscTq+1+pupp/vv37gBWprESvG5rPZ6aYL8xuAl+/hWnOoG4iKD3e3WGTga7g44q9b66ITvAvKRDpjmLTexuEw46ObJ/2ze27uMumuzERlxrRooWD0S53EzI0C2AtGWJHkdvPZq7xOIgKL2Nq+XxihEyH7TfxqTYa/HqS/ivgnRgai+nfFVbkNHPbOefRHfpCHd/DguWkCPoAbY5A4vupsjtulWMSOx2UJzxMTGHE5ndfYSgeR+CcehzPLwC/QarPp9hOTBdM1qv3JpiidP7PicMQacbxhJt4TwttQY4ZDLcnZAc5hKvDx/w2LzNSkIwo76j3GOmUl1OoO+xbO1n7vNY6JK3TpeLLQDfi/eJEAP3akIAeEX5m1OwR2JaK041koGPJNgdKv7SJn5f6+eExCpbSSRACnwOX+eJxVjOm2j7//9blgb7ASHXIybbraMT82n77sKLQ9CNwTbAgM5I/F7FiqzSdmr8n4sBvjuzuCWP/bbjnEl3aV8IdVxPE1/5yPXIiRCi3Ou7JN4/4+uA05tbEp9Y2Y24xCj3743L/CGVunxxlbCrtizM+FHgOhPlcz+MTdqXoWfaZzQ8cpmVpishQSopRYwhOqpegh5QLK574xRCWlH6u+IXNxRYgjicUvPKaI0cNdH4Sb3+Cv46smBRZMSrBC4Emr48uRZDqySIiK4XBQyJa86b73L8gkKGkvkGc3yTcXDsBqTBt7zZsmIVyjpYqEhvq/Amd0yeij2LjLhTLj2TgSCB3pKEQHexMNlsxS2gGm1fj2dfuUtBmSvLoG+qY/ROhUzkwpg8UveFI3GpGr7/GIrEIB1D97GTECa+I53dcst0RU5rxKSlD6ZRBWxTDvnb3f2 X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 10:37:57.3227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2fe36fe5-5854-4cd0-0727-08dce2051d58 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7960 X-Patchwork-Delegate: kuba@kernel.org From: Cosmin Ratiu It no longer serves any purpose and is identical to mlx5_fc_create upon which it was originally based of. Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c | 7 +------ include/linux/mlx5/fs.h | 3 --- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c index dcfccaaa8d91..4877a9d86807 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c @@ -1026,7 +1026,7 @@ mlx5_tc_ct_counter_create(struct mlx5_tc_ct_priv *ct_priv) return ERR_PTR(-ENOMEM); counter->is_shared = false; - counter->counter = mlx5_fc_create_ex(ct_priv->dev, true); + counter->counter = mlx5_fc_create(ct_priv->dev, true); if (IS_ERR(counter->counter)) { ct_dbg("Failed to create counter for ct entry"); ret = PTR_ERR(counter->counter); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c index 0b80c33cba5f..62d0c689796b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c @@ -275,7 +275,7 @@ static struct mlx5_fc *mlx5_fc_acquire(struct mlx5_core_dev *dev, bool aging) return mlx5_fc_single_alloc(dev); } -struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) +struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging) { struct mlx5_fc *counter = mlx5_fc_acquire(dev, aging); struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats; @@ -304,11 +304,6 @@ struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging) mlx5_fc_release(dev, counter); return ERR_PTR(err); } - -struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging) -{ - return mlx5_fc_create_ex(dev, aging); -} EXPORT_SYMBOL(mlx5_fc_create); u32 mlx5_fc_id(struct mlx5_fc *counter) diff --git a/include/linux/mlx5/fs.h b/include/linux/mlx5/fs.h index b744e554f014..438db888bde0 100644 --- a/include/linux/mlx5/fs.h +++ b/include/linux/mlx5/fs.h @@ -298,9 +298,6 @@ int mlx5_modify_rule_destination(struct mlx5_flow_handle *handler, struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging); -/* As mlx5_fc_create() but doesn't queue stats refresh thread. */ -struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging); - void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter); u64 mlx5_fc_query_lastuse(struct mlx5_fc *counter); void mlx5_fc_query_cached(struct mlx5_fc *counter,