From patchwork Fri Aug 16 09:01:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765792 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2056.outbound.protection.outlook.com [40.107.95.56]) (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 91816146000; Fri, 16 Aug 2024 09:02:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798975; cv=fail; b=HN8TVVXAaUKZTx6hKzozmlWN56MGRNdnzmRG6Mlm2YaTAHhVpy0iQ0b+ykPi70MIu7iwOVHCg2Z5VKUMhogYZx0bolm0x8ztdnaZaLjkv/Dh8lK41uB/UGiG7RPckYxCKUDos6VpMmFmU/8/nBeKPCRV9zieDBZGGXFbp8NXGNk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798975; c=relaxed/simple; bh=1IZTLS6EWIllixTdyxPdXYqBRm1eXn4pXBNiyA/ISqo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hu0mPkFTNBOlz0rZTGWAhlTvRcnX21XE4R6+c3Bp+6hDKqz9ZEshTiGhYYa1UgAkdugIU6F+SoapjKb8STCrSQvyCAP+4wAGSMdqmjz8cd2eFxm5xZ0ukDB6aWdESpEBoStvBXA3TvJvLlMGeatLTugJeXqu6xnORCpCgnZK/1Q= 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=KtPVMRf+; arc=fail smtp.client-ip=40.107.95.56 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="KtPVMRf+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WU01ZR4pCln/ydfa9IRsP2V92AyPZdRAxuEZXy0lOmb67O7L/JHfODFDG9wiBbdpICoKYhtLHvWAz8HmKoEKnhf3wPQW8S9Wl2cez6fAarbpoPxRxmrfohJRf/uOlyZFM5Fk0h9dL6f/8Vny2pW32C7xOrc0l21DlDtMEfQy4l7gqtk9EO/ISNzWfwvDK0RsCShYxkcZhkpGKIDUx7bGbDXue8Ndmb03ZHztx69213jYoUF9Va+r8gDYVOPUR8EM4dGKieVEp8S3V7Yo3pMcARMsNNR2Z9zBjv9kfPNlr55BE/fCaf6BxBY073lB+DZ43S4E8QpTkdCcPJv16IsNbw== 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=VIAJplQdvJEqiwsRH2lFpllSxV45XeFNw1hDiZBrKFE=; b=C1vlCiyMnZthPocRR4Q7Rk2pXncu0O5IfJckXnDoXLY2n6uSXhmsWa9UxzZiR9Z45tihki4yjccJ8EO++lVe+TVtCG4I6j71mxUeP49MMWrZawhQK8BDYirobVJm7Q1ZyghjiJsofEgmY161huVJMY/KZMDQRjVcGzD2bDgzX118/Bd3wNwSU2SX47bGphLXr73JIX9bfC1Ejj0Q+izRUIy/TujUVL4G/nQzthOm1IIhdG4nBvSl+nayBcH7LCzHgjieM0oX4/rAJQVm5fzIDzaO8YGI+EUHnyO47rF5Hn/+reC/H9h/1+N0vrPaTpvwBZ01qCSTj4OCFa8JdU1bkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.com 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=VIAJplQdvJEqiwsRH2lFpllSxV45XeFNw1hDiZBrKFE=; b=KtPVMRf+GPcYOA+omu0HFSuWiBaZCKLjwrVCnTgN52GmkCHQct3zl8+dq+kqyXSIH1VvCE5jhGQjYhxAW/5CCgb8dB+E3phAKKmvl8c4p5Z4tNhheVbodRExIpx3O35BdB6wJKm+Gfgdh2bm6ABZkxiK7P84syFNWydoZreMuTKb5T6ngLr2bW5BsdsszwZairNMVwE1CsUvjZGjGR5NAKqN/XSXzWD2bz8rGJHY82Vr5vpwCtvBdY80r77v3Os9urb2cRh+XiOEajd2MA5NXzHamMkhF9M3fmW067/LjgS7tDxHWmiUxbw+uXqFykmYlDLjqVUIMMUrh9UT9o7ROg== Received: from BN9PR03CA0701.namprd03.prod.outlook.com (2603:10b6:408:ef::16) by MW6PR12MB8900.namprd12.prod.outlook.com (2603:10b6:303:244::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:02:50 +0000 Received: from BN1PEPF00004688.namprd05.prod.outlook.com (2603:10b6:408:ef:cafe::af) by BN9PR03CA0701.outlook.office365.com (2603:10b6:408:ef::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.33 via Frontend Transport; Fri, 16 Aug 2024 09:02:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN1PEPF00004688.mail.protection.outlook.com (10.167.243.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:50 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 16 Aug 2024 02:02:37 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 16 Aug 2024 02:02:36 -0700 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:33 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 06/10] vdpa/mlx5: Parallelize device suspend Date: Fri, 16 Aug 2024 12:01:55 +0300 Message-ID: <20240816090159.1967650-7-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-1-dtatulea@nvidia.com> Precedence: bulk X-Mailing-List: kvm@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: BN1PEPF00004688:EE_|MW6PR12MB8900:EE_ X-MS-Office365-Filtering-Correlation-Id: 1aece55c-94fd-42ab-a74a-08dcbdd23494 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?JM5qZ9Fi9fd4ljAR8GzZFI82Cfg5oOu?= =?utf-8?q?ovHrH7SLgpKN5ENZKrsJtzBlk+vuc9NYGnnNPbwqNCtGjC8IBMO8jpC4m6SG8wnT8?= =?utf-8?q?jItrUm+cFuccr6VmRAh8niOxJ525w012mtpeqPwcLIbWQjIisa6Ej2JHhkKbwNGhw?= =?utf-8?q?nPyCkwKmvV4wwJzdAB6Voeiix/gUEMYbt7uBGzibF5DPVUgMHUwmSHqOoIJ31+EX4?= =?utf-8?q?YosNJ/Z9OfW76lAxklp4oN3PUN6TgBhltcSk7lHhiktwUUvzQ37e+McOsZlUXoE/8?= =?utf-8?q?neworWU/S1wri6L+jLVezf/Ue7ZPRIj9gOP80Apn7JAib4QWZHSuP2DqowmDZohnW?= =?utf-8?q?qz+zd6zqUd14F+3UifedNT5Vg5FI8mi9d4VEToOUsQm5SV02cVus7upAAa0KP3PzH?= =?utf-8?q?mT08J0ctiAWcgjFlppTI3wF6qJZX9vQds2wL52BhiHqhtUX5EhsZwWPCeHnK2jRGJ?= =?utf-8?q?Qz+wMu2qpG3l/OqipLghK2Rp6N9bWoNoDYrLTO6LEJjivMehyC48hWAG9D0ft3Y+W?= =?utf-8?q?cSF9rL5AdtjuUfDyGWdd77aEefKCTcvV3pDXua9GiBQPfGtwSI6BnQ3e4Et2F1qOQ?= =?utf-8?q?hcHlhm1a+jWGZNO/plJjD0i5Qov6lOj08atlp/zHgxS8Buillzkh2PRa1KluWERrx?= =?utf-8?q?RjNt8999US4EcDw17ovtYrYyGiIBAhtYB4vbxv3hGPRxmaGxzsyYmqLjUtqWh5TLM?= =?utf-8?q?cwIKj+gw5Hh9IR8uHyIt2D06rxuj++JLZSd0OWL6FQBbCs/QeAwTPjqgGJXlbcB5q?= =?utf-8?q?qw2X9qlK0hqYESqctLCDPbeTCZlL70AxY0MNI2iuq7P4OsNJONJmx756YyiuaVobT?= =?utf-8?q?ymiLwnOpmPknEgVW47uRP9fxpMX7h8pudPqhL6DIOMbv+GMOJpANclleQLLtnlQz8?= =?utf-8?q?EmWkjSl3GH+jVQIV/HmGcilKqAFeCyglkPXhdx3JM0bSyHG8MohHbi90ZtUNy5YLV?= =?utf-8?q?iixD8J2KxttCPn9/DIB1+NuCyw/normh9K89oRoAQ0LTja9FEpYYCfNIvUF2E2bus?= =?utf-8?q?xI4O8ZWlKlHl7J0H+T8lfRONns7+2d3DSTV92H2ktKJ9w3g+wVS65BTD2NHxDHnO2?= =?utf-8?q?Hv9qCmCt1TAbtFzcEkp6PSPzhbGOJpBtVa9lYIxJJ1QK0+anwSTjpOViBdq5m4aGR?= =?utf-8?q?S3bzgA+rdUf2LNsjBc5/NW0vuU7sVKfdPnzJNWp/qsVy6xXE31RVVK8af8UojMQqC?= =?utf-8?q?PetPJtrBjX7VIrPC/dgqLfQneFiQz0DagGD9Kp2+7efTVuFqxpBSxUBVydcdCEeM2?= =?utf-8?q?gSUsgdY2ZSZhWPDjlYJ9ldV3T30HX2dX4yOgncTMeIqmnUZOQf/mj0xtzY7KqQcps?= =?utf-8?q?k2KkHXgwnP2OklBdkkhWHwbAl/r9brc2PGC5rRM1HCJy4CpDE4/17PukMLXVklgRv?= =?utf-8?q?AHOm2RMO056?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:50.0206 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1aece55c-94fd-42ab-a74a-08dcbdd23494 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004688.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8900 Currently device suspend works on vqs serially. Building up on previous changes that converted vq operations to the async api, this patch parallelizes the device suspend: 1) Suspend all active vqs parallel. 2) Query suspended vqs in parallel. For 1 vDPA device x 32 VQs (16 VQPs) attached to a large VM (256 GB RAM, 32 CPUs x 2 threads per core), the device suspend time is reduced from ~37 ms to ~13 ms. A later patch will remove the link unregister operation which will make it even faster. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio PĂ©rez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 56 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 9be7a88d71a7..5fba16c80dbb 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1630,49 +1630,51 @@ static int modify_virtqueues(struct mlx5_vdpa_net *ndev, int start_vq, int num_v return err; } -static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) +static int suspend_vqs(struct mlx5_vdpa_net *ndev, int start_vq, int num_vqs) { - struct mlx5_virtq_attr attr; + struct mlx5_vdpa_virtqueue *mvq; + struct mlx5_virtq_attr *attrs; + int vq_idx, i; int err; + if (start_vq >= ndev->cur_num_vqs) + return -EINVAL; + + mvq = &ndev->vqs[start_vq]; if (!mvq->initialized) return 0; if (mvq->fw_state != MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY) return 0; - err = modify_virtqueues(ndev, mvq->index, 1, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND); - if (err) { - mlx5_vdpa_err(&ndev->mvdev, "modify to suspend failed, err: %d\n", err); - return err; - } - - err = query_virtqueues(ndev, mvq->index, 1, &attr); - if (err) { - mlx5_vdpa_err(&ndev->mvdev, "failed to query virtqueue, err: %d\n", err); + err = modify_virtqueues(ndev, start_vq, num_vqs, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND); + if (err) return err; - } - - mvq->avail_idx = attr.available_index; - mvq->used_idx = attr.used_index; - - return 0; -} -static int suspend_vqs(struct mlx5_vdpa_net *ndev) -{ - int err = 0; - int i; + attrs = kcalloc(num_vqs, sizeof(struct mlx5_virtq_attr), GFP_KERNEL); + if (!attrs) + return -ENOMEM; - for (i = 0; i < ndev->cur_num_vqs; i++) { - int local_err = suspend_vq(ndev, &ndev->vqs[i]); + err = query_virtqueues(ndev, start_vq, num_vqs, attrs); + if (err) + goto done; - err = local_err ? local_err : err; + for (i = 0, vq_idx = start_vq; i < num_vqs; i++, vq_idx++) { + mvq = &ndev->vqs[vq_idx]; + mvq->avail_idx = attrs[i].available_index; + mvq->used_idx = attrs[i].used_index; } +done: + kfree(attrs); return err; } +static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) +{ + return suspend_vqs(ndev, mvq->index, 1); +} + static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) { int err; @@ -3053,7 +3055,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, bool teardown = !is_resumable(ndev); int err; - suspend_vqs(ndev); + suspend_vqs(ndev, 0, ndev->cur_num_vqs); if (teardown) { err = save_channels_info(ndev); if (err) @@ -3606,7 +3608,7 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev) down_write(&ndev->reslock); unregister_link_notifier(ndev); - err = suspend_vqs(ndev); + err = suspend_vqs(ndev, 0, ndev->cur_num_vqs); mlx5_vdpa_cvq_suspend(mvdev); mvdev->suspended = true; up_write(&ndev->reslock);