From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1D515A0543; Mon, 6 Jun 2022 13:22:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A350142B73; Mon, 6 Jun 2022 13:22:02 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2044.outbound.protection.outlook.com [40.107.236.44]) by mails.dpdk.org (Postfix) with ESMTP id DC7C5415D7 for ; Mon, 6 Jun 2022 13:22:01 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XlP9sch97hwPVTGRCmxDjtw5oqKkH1bpi/32Gva4Ie+C6CM6TasULMuqDV4v0W0jOxTnf3dAEY0atauEZHU6Hfc8cH8lz6mWcf2w/5ObcvFNNArRurpax2Ei5P6QJVEdkv0NqXYZiJsbx4sKDT78LL7kq2YAYKe1R/XlrkrV3BdLWqGV+3WfuAiv8DEoMARaxKrouhcP26AfHss0KuQfFN/15AyK5nr2QNYPAo76M5LyMqeV3yUEGoWrSgTolLaVLJ082r5HvLpfid9NtKG094eOc9xf7PYrPeFWdDxMUVxNBOyVwlTXBe+BNnLQ3Dq+hGU3M8WhPsj/Qem8PzPJ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=pWgUAQGnUueLXIS/QHxVt3prfe0vowEE1RTBi6rBqKY=; b=iOIwZ3l9RvA0MIr5DVLZhSPlQvK8X3im4pQv+hit9wInz3MX/iHC/omgqoytDM/zLEUWkytPyZabBDdZ+L5AK3UZ4Xf6OAzLgpTtIk+sOot5iV+Xlv/dL9RCAindN/m0ZEdfFVVwWJQ1v3LIEasdLCXDIVO0PvSQZl+CLcBozTWT1ZgsERgWlRdTshEhVWuJ9+shbMZAHBJG6CdUt4UfGXPfDB98Wj+hW3j4Cyyj8+sdamsvi2qLn/wdv6Xgtq28007y+WsfdCg4hLisSAE3Ty1DVP35hpI5KD79ZiteCECLpB+Bmwl7PwKTpyIyq5fEc53Q1PFimv3Iswg2OeVR9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=monjalon.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 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=pWgUAQGnUueLXIS/QHxVt3prfe0vowEE1RTBi6rBqKY=; b=YzgYj7iVK/Tr65uUcKxR3dw3rvcjOXGj6pkipMtEr+HiGGFQ7ZhELcaiwgv1MOapw0ChF5n6anqSwnWFPbShzET/hmw1JfzoMnuCIUj4siCheINEMiBSIStog37ZMWoKtSSgoTHEZKztjwF1jrtLWruRK9doUZgA2cqfichH3JdhXJ+2hERCd6KCUwxaBnbE+/5uirD0ah6LmgoQxPIgqecnkuY6hbnjgPW4A7D17DkiuORxdPJXI18L4C6czlBA6OyC3fY44Tis5eb2wTbnLsrdyD36+rxzQ+A8A+G+PZi5gBVFZeR4c8qpm0hbaUOJtepmNd5SsEmn8IzkTYmcYw== Received: from BN8PR07CA0014.namprd07.prod.outlook.com (2603:10b6:408:ac::27) by DM6PR12MB4154.namprd12.prod.outlook.com (2603:10b6:5:21d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Mon, 6 Jun 2022 11:22:00 +0000 Received: from BN8NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ac:cafe::cf) by BN8PR07CA0014.outlook.office365.com (2603:10b6:408:ac::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.18 via Frontend Transport; Mon, 6 Jun 2022 11:22:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by BN8NAM11FT019.mail.protection.outlook.com (10.13.176.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5314.12 via Frontend Transport; Mon, 6 Jun 2022 11:21:59 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Mon, 6 Jun 2022 11:21:57 +0000 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 6 Jun 2022 04:21:54 -0700 From: Li Zhang To: , , , CC: , , , , Yajun Wu Subject: [PATCH v1 04/17] vdpa/mlx5: support pre create virtq resource Date: Mon, 6 Jun 2022 14:20:44 +0300 Message-ID: <20220606112109.208873-8-lizh@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220606112109.208873-1-lizh@nvidia.com> References: <20220408075606.33056-1-lizh@nvidia.com> <20220606112109.208873-1-lizh@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 233cd452-e0c4-4e96-8d90-08da47aec622 X-MS-TrafficTypeDiagnostic: DM6PR12MB4154:EE_ X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xQb+mGLFRFyoSu31E3YEdddfuF8yvDwYpMGUcnyV3+lpUDOhNd/xRjHc5jjVeDoem+Mt/UmgIN7Pkgzi6Vroxq0mMu7TKCzGb4h0ebs7JmJ/JwAmOQYVJc2UxOPun8c1hkKYBxDcDnzBXXEflWLUF/488UusIhJZYurhWQ2u+HJz/nw7akh9CutGXDV648lspSuMOeH/lzpWAa9Gb5IeB0cEh6JIkJObeFCwEMeK1n+0zuA25ddWgNXCM3xR0o0L9gMgLGdMEVpih8FxbyAt/qXmK6EyDsJHtC5SaMwN60gw67Du4Y9HbALoKVTmdWKMeRNX8pNBKZPwc2CZgL6snDqQ4Vb2TnfczwcAHoGFKZ7wudXguTNZ+m08EvUlmBs51+H87q2WyYioTP06/G84VV23qk0PGYWuKdvbKk2Wj5NuhI+hdjxhiKLj1h5vVuzSn5MLmQ5DFAa/H2lN2fEQYopVB1bxe6D54xFHMxo0w5eloiggdd8lAJS57IzCyrNfl9XgiGl84Mi4/qB/mXGKo2bW5lesrHCxWiswcocPxr5m/QLYT7VNtUOVsVL1RGpbzjRTbb+rHtkQs06ZqDGeyOKcyUWPro/l3hFxAvk/pIIuk7hM998FVq2DrzahN271GxX1MsOfhe7TDeOQpyccZhLbpOeufglITSzuTRYDLJgcoaTKTaV/weaye4Xm/U+N2kOCOBJnJiLG488eJHcL8A== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(356005)(55016003)(26005)(6666004)(2906002)(6636002)(47076005)(40460700003)(81166007)(6286002)(54906003)(316002)(36756003)(86362001)(36860700001)(83380400001)(426003)(7696005)(2616005)(4326008)(110136005)(8676002)(107886003)(1076003)(70586007)(70206006)(186003)(5660300002)(16526019)(508600001)(336012)(8936002)(82310400005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2022 11:21:59.8662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 233cd452-e0c4-4e96-8d90-08da47aec622 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4154 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Yajun Wu The motivation of this change is to reduce vDPA device queue creation time by create some queue resource in vDPA device probe stage. In VM live migration scenario, this can reduce 0.8ms for each queue creation, thus reduce LM network downtime. To create queue resource(umem/counter) in advance, we need to know virtio queue depth and max number of queue VM will use. Introduce two new devargs: queues(max queue pair number) and queue_size (queue depth). Two args must be both provided, if only one argument provided, the argument will be ignored and no pre-creation. The queues and queue_size must also be identical to vhost configuration driver later receive. Otherwise either the pre-create resource is wasted or missing or the resource need destroy and recreate(in case queue_size mismatch). Pre-create umem/counter will keep alive until vDPA device removal. Signed-off-by: Yajun Wu --- doc/guides/vdpadevs/mlx5.rst | 14 +++++++ drivers/vdpa/mlx5/mlx5_vdpa.c | 75 ++++++++++++++++++++++++++++++++++- drivers/vdpa/mlx5/mlx5_vdpa.h | 2 + 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/doc/guides/vdpadevs/mlx5.rst b/doc/guides/vdpadevs/mlx5.rst index 3ded142311..0ad77bf535 100644 --- a/doc/guides/vdpadevs/mlx5.rst +++ b/doc/guides/vdpadevs/mlx5.rst @@ -101,6 +101,20 @@ for an additional list of options shared with other mlx5 drivers. - 0, HW default. +- ``queue_size`` parameter [int] + + - 1 - 1024, Virio Queue depth for pre-creating queue resource to speed up + first time queue creation. Set it together with queues devarg. + + - 0, default value, no pre-create virtq resource. + +- ``queues`` parameter [int] + + - 1 - 128, Max number of virio queue pair(including 1 rx queue and 1 tx queue) + for pre-create queue resource to speed up first time queue creation. Set it + together with queue_size devarg. + + - 0, default value, no pre-create virtq resource. Error handling ^^^^^^^^^^^^^^ diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index ee71339b78..faf833ee2f 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -244,7 +244,9 @@ mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv) static void mlx5_vdpa_dev_cache_clean(struct mlx5_vdpa_priv *priv) { - mlx5_vdpa_virtqs_cleanup(priv); + /* Clean pre-created resource in dev removal only. */ + if (!priv->queues) + mlx5_vdpa_virtqs_cleanup(priv); mlx5_vdpa_mem_dereg(priv); } @@ -494,6 +496,12 @@ mlx5_vdpa_args_check_handler(const char *key, const char *val, void *opaque) priv->hw_max_latency_us = (uint32_t)tmp; } else if (strcmp(key, "hw_max_pending_comp") == 0) { priv->hw_max_pending_comp = (uint32_t)tmp; + } else if (strcmp(key, "queue_size") == 0) { + priv->queue_size = (uint16_t)tmp; + } else if (strcmp(key, "queues") == 0) { + priv->queues = (uint16_t)tmp; + } else { + DRV_LOG(WARNING, "Invalid key %s.", key); } return 0; } @@ -524,9 +532,68 @@ mlx5_vdpa_config_get(struct mlx5_kvargs_ctrl *mkvlist, if (!priv->event_us && priv->event_mode == MLX5_VDPA_EVENT_MODE_DYNAMIC_TIMER) priv->event_us = MLX5_VDPA_DEFAULT_TIMER_STEP_US; + if ((priv->queue_size && !priv->queues) || + (!priv->queue_size && priv->queues)) { + priv->queue_size = 0; + priv->queues = 0; + DRV_LOG(WARNING, "Please provide both queue_size and queues."); + } DRV_LOG(DEBUG, "event mode is %d.", priv->event_mode); DRV_LOG(DEBUG, "event_us is %u us.", priv->event_us); DRV_LOG(DEBUG, "no traffic max is %u.", priv->no_traffic_max); + DRV_LOG(DEBUG, "queues is %u, queue_size is %u.", priv->queues, + priv->queue_size); +} + +static int +mlx5_vdpa_virtq_resource_prepare(struct mlx5_vdpa_priv *priv) +{ + uint32_t index; + uint32_t i; + + if (!priv->queues) + return 0; + for (index = 0; index < (priv->queues * 2); ++index) { + struct mlx5_vdpa_virtq *virtq = &priv->virtqs[index]; + + if (priv->caps.queue_counters_valid) { + if (!virtq->counters) + virtq->counters = + mlx5_devx_cmd_create_virtio_q_counters + (priv->cdev->ctx); + if (!virtq->counters) { + DRV_LOG(ERR, "Failed to create virtq couners for virtq" + " %d.", index); + return -1; + } + } + for (i = 0; i < RTE_DIM(virtq->umems); ++i) { + uint32_t size; + void *buf; + struct mlx5dv_devx_umem *obj; + + size = priv->caps.umems[i].a * priv->queue_size + + priv->caps.umems[i].b; + buf = rte_zmalloc(__func__, size, 4096); + if (buf == NULL) { + DRV_LOG(ERR, "Cannot allocate umem %d memory for virtq" + " %u.", i, index); + return -1; + } + obj = mlx5_glue->devx_umem_reg(priv->cdev->ctx, buf, + size, IBV_ACCESS_LOCAL_WRITE); + if (obj == NULL) { + rte_free(buf); + DRV_LOG(ERR, "Failed to register umem %d for virtq %u.", + i, index); + return -1; + } + virtq->umems[i].size = size; + virtq->umems[i].buf = buf; + virtq->umems[i].obj = obj; + } + } + return 0; } static int @@ -604,6 +671,8 @@ mlx5_vdpa_create_dev_resources(struct mlx5_vdpa_priv *priv) return -rte_errno; if (mlx5_vdpa_event_qp_global_prepare(priv)) return -rte_errno; + if (mlx5_vdpa_virtq_resource_prepare(priv)) + return -rte_errno; return 0; } @@ -638,6 +707,7 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *cdev, priv->num_lag_ports = 1; pthread_mutex_init(&priv->vq_config_lock, NULL); priv->cdev = cdev; + mlx5_vdpa_config_get(mkvlist, priv); if (mlx5_vdpa_create_dev_resources(priv)) goto error; priv->vdev = rte_vdpa_register_device(cdev->dev, &mlx5_vdpa_ops); @@ -646,7 +716,6 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *cdev, rte_errno = rte_errno ? rte_errno : EINVAL; goto error; } - mlx5_vdpa_config_get(mkvlist, priv); SLIST_INIT(&priv->mr_list); pthread_mutex_lock(&priv_list_lock); TAILQ_INSERT_TAIL(&priv_list, priv, next); @@ -684,6 +753,8 @@ mlx5_vdpa_release_dev_resources(struct mlx5_vdpa_priv *priv) { uint32_t i; + if (priv->queues) + mlx5_vdpa_virtqs_cleanup(priv); mlx5_vdpa_dev_cache_clean(priv); for (i = 0; i < priv->caps.max_num_virtio_queues; i++) { if (!priv->virtqs[i].counters) diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index e7f3319f89..f6719a3c60 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -135,6 +135,8 @@ struct mlx5_vdpa_priv { uint8_t hw_latency_mode; /* Hardware CQ moderation mode. */ uint16_t hw_max_latency_us; /* Hardware CQ moderation period in usec. */ uint16_t hw_max_pending_comp; /* Hardware CQ moderation counter. */ + uint16_t queue_size; /* virtq depth for pre-creating virtq resource */ + uint16_t queues; /* Max virtq pair for pre-creating virtq resource */ struct rte_vdpa_device *vdev; /* vDPA device. */ struct mlx5_common_device *cdev; /* Backend mlx5 device. */ int vid; /* vhost device id. */ -- 2.31.1