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 2C963A034D; Mon, 3 Jan 2022 19:29:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E30B040042; Mon, 3 Jan 2022 19:29:40 +0100 (CET) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2068.outbound.protection.outlook.com [40.107.101.68]) by mails.dpdk.org (Postfix) with ESMTP id 160D84003C for ; Mon, 3 Jan 2022 19:29:40 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W6kGekkI0xL+PEH5nooTbUtDPObYoE+vAgk83kv0nD/Ddu3AgVgiWUBk6ITnOvcn006eWgwgh+1LwHi0eWbKb156o7qws/lGYVHBI4irLIVpVU6Edobg0h8SqrUjb8ZYQxmkAmb6Z6ocYeb8Hl2NFrlppXZNT82w56g8IDO4tOl6mW4g16JoxkySquX2k7M+ZMr6sXLtfgaOdYSLNAoPrsyIZ2wcToUALZaLW5iii302h+DoSvU4tXju3aaHbHqWaJdpIw1hSDbuvAzHaO82LyMfQ0VKRHv+u+7KAgZncx4NMvLhLrcDqjzcNcvZ++w26iHGVF8/38Z/DdnNBLCGXQ== 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=1I7bbJBUHfbkz49nDILaI2CWQz6uYo+22tb4B43xjlk=; b=ne20ue2+Ldq9u8XPBF1QaaBaewfidQcO7UI82HzUq0Dt1CVEwKVgZ7AWQvM9AkJ4k39Xz4+iHUtkFdimxSs7/KFJjT37kNRGA1dXI7MSRvoJhpxyLXObqVLluttPKUHyhG/9U/XkTwIOcn4AxYI1ZhyXEYSLND0ZZ3rvGEio78o30tm0Gzb9daJzW5PGJ8U4kGaA9F6RmsEsOkBwoK2xf8eiYkCYMPFaxlYcahdumUPVHNa9X24bC2RI+iYmRyGyL0m13kVsOvGNZ1Nu9PAluEOd7G9qAae9r67ly9o3MJrTEffPHu1fg+5pPhYR3gx4122/jzgutF4xLQ4jjUvsYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=1I7bbJBUHfbkz49nDILaI2CWQz6uYo+22tb4B43xjlk=; b=S6042/VG0VhgAe4zahBMSh5/YO3kS5SaAuHv1Iqj7tF9E+AJ7NHfmTkfn5O2JWD028Dkp+Jht3epA0xjASxRW4NO4Bk9ReD2rVSKph08DF3GYqCVZ8ME/WOrKsDd2rrkEapALCE9VEWTtI4bnsRDY1w/cMjkv9z2aOiuVc9VahLY8CTlqtzrxSeCPo5qjpvZWWuJ9ne2+NfQxi2Rbj1AWr//T6yS5cOem2pWSTzc2rMfkIeiTEySemQbb520J4BaOHSIgLGAVHh2xKmz9SSHyW/chH1L23of/BsgfVX7LGDgzD/ftU3clu5GTEZfE9uGA6wAz3S8F2AhsRI5SdxnXQ== Received: from DM6PR01CA0030.prod.exchangelabs.com (2603:10b6:5:296::35) by PH0PR12MB5481.namprd12.prod.outlook.com (2603:10b6:510:d4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.15; Mon, 3 Jan 2022 18:29:36 +0000 Received: from DM6NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:5:296:cafe::14) by DM6PR01CA0030.outlook.office365.com (2603:10b6:5:296::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.14 via Frontend Transport; Mon, 3 Jan 2022 18:29:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT023.mail.protection.outlook.com (10.13.173.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4844.14 via Frontend Transport; Mon, 3 Jan 2022 18:29:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 3 Jan 2022 18:29:35 +0000 Received: from nvidia.com (172.20.187.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.986.9; Mon, 3 Jan 2022 10:29:35 -0800 From: To: CC: Elena Agostini Subject: [PATCH v2] gpudev: pin GPU memory Date: Tue, 4 Jan 2022 02:39:25 +0000 Message-ID: <20220104023925.14257-1-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: abe6f98f-aa8e-45b4-4174-08d9cee6ff0c X-MS-TrafficTypeDiagnostic: PH0PR12MB5481:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:267; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XpoUi19pLU322fbwRAld7NBgq/jN4RBj6fTdrrQuq2U5LB1p0LPVbs3deK6HCCXO8UqTHiYva+ufFtKngqHz78x5aZyazKtvNzkKBJq4FHDmdPtwIvDCLAM0eiCKlGriHGExcqZn4oaTtPZ11U1nKL0Myy4UH0JiGVu5flIyrDmhcIN7Hs9APFGNsf3VQnEKJGzHmXcR4+NrAvaNnjzlYM31liY6j5h1OECq9D2uXs9aDdibOdjYG0wvB6I1/5IQN8z3dayWHa7nlJKm/vQQgBM016opbnubrMM4eNY6XhP9Pt8yN5sxQQaQKsMxKgtKTJuPcz8p9imisBj+HV/yUt1yJGWb/W1hd+vl76MJzb4mPWN1w14vrq4BFlePcly9LDb2y89l3VT4gpJiWG7HLHA+1VoFDlG3RobYMnp5ah9rPtImEgovxNqMW9lPKCYCpqWPUqECxjZnuiPJ/llMaLll+XYJd6huf31y8PhqwvLOAkPUVImYjv6JNghFkB/a5Vh81TWPXnYt3aLM+/BvyMXxLGsulbv6HqtWFOp2YKk60KO5xm88XsYQDk8GIKaLs9PTjxQN6aovuWgerEAQQUb6v4qTKZ3bk3IEKdKn6YpZQcR3UqXFUQZIoAf/FfbOXdbHn6bRSSdFL8olJn5Qz+W5lbwn4TRyL5LzRv1tSuikosWNKyoUk2QfRmliSTxTZ7lhTaxuMMpnzI2V4yO6nRkAZCiQpSDzBVGKFyOgmTtoGz9eWSZoR7/NQtLGnyOuzqB4UzXQT52T0iV7acr/Xz23h0gJc4uCI9ByQVdWECI= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(40470700002)(55016003)(82310400004)(7696005)(2616005)(70586007)(2906002)(508600001)(26005)(426003)(83380400001)(86362001)(1076003)(36756003)(186003)(40460700001)(356005)(8676002)(4326008)(5660300002)(16526019)(70206006)(6916009)(107886003)(81166007)(6286002)(47076005)(8936002)(36860700001)(336012)(6666004)(2876002)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2022 18:29:36.5335 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: abe6f98f-aa8e-45b4-4174-08d9cee6ff0c 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.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5481 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: Elena Agostini Enable the possibility to make a GPU memory area accessible from the CPU. GPU memory has to be allocated via rte_gpu_mem_alloc(). This patch allows the gpudev library to pin, through the GPU driver, a chunk of GPU memory and to return a memory pointer usable by the CPU to access the GPU memory area. Signed-off-by: Elena Agostini --- lib/gpudev/gpudev.c | 47 +++++++++++++++++++++++++++++++++++ lib/gpudev/gpudev_driver.h | 6 +++++ lib/gpudev/rte_gpudev.h | 50 ++++++++++++++++++++++++++++++++++++++ lib/gpudev/version.map | 2 ++ 4 files changed, 105 insertions(+) diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c index 9ae36dbae9..ca627e44b3 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -634,6 +634,53 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr) return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr)); } +int +rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr) +{ + struct rte_gpu *dev; + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "pin mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return -rte_errno; + } + + if (dev->ops.mem_pin == NULL) { + GPU_LOG(ERR, "mem pinning not supported"); + rte_errno = ENOTSUP; + return -rte_errno; + } + + if (ptr == NULL || size == 0) /* dry-run */ + return 0; + + return GPU_DRV_RET(dev->ops.mem_pin(dev, size, ptr)); +} + +int +rte_gpu_mem_unpin(int16_t dev_id, void *ptr) +{ + struct rte_gpu *dev; + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "unpin mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return -rte_errno; + } + + if (dev->ops.mem_unpin == NULL) { + rte_errno = ENOTSUP; + return -rte_errno; + } + + if (ptr == NULL) /* dry-run */ + return 0; + + return GPU_DRV_RET(dev->ops.mem_unpin(dev, ptr)); +} + int rte_gpu_wmb(int16_t dev_id) { diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h index cb7b101f2f..13dd8dac43 100644 --- a/lib/gpudev/gpudev_driver.h +++ b/lib/gpudev/gpudev_driver.h @@ -31,6 +31,8 @@ typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr); typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr); typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr); typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr); +typedef int (rte_gpu_mem_pin_t)(struct rte_gpu *dev, size_t size, void *ptr); +typedef int (rte_gpu_mem_unpin_t)(struct rte_gpu *dev, void *ptr); typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev); struct rte_gpu_ops { @@ -46,6 +48,10 @@ struct rte_gpu_ops { rte_gpu_mem_register_t *mem_register; /* Unregister CPU memory from device. */ rte_gpu_mem_unregister_t *mem_unregister; + /* Pin GPU memory. */ + rte_gpu_mem_pin_t *mem_pin; + /* Unpin GPU memory. */ + rte_gpu_mem_unpin_t *mem_unpin; /* Enforce GPU write memory barrier. */ rte_gpu_wmb_t *wmb; }; diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h index fa3f3aad4f..0a9033c6e0 100644 --- a/lib/gpudev/rte_gpudev.h +++ b/lib/gpudev/rte_gpudev.h @@ -447,6 +447,56 @@ int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr); __rte_experimental int rte_gpu_mem_unregister(int16_t dev_id, void *ptr); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Pin a chunk of GPU memory to make it accessible from the CPU + * using the memory pointer returned by the function. + * GPU memory has to be allocated via rte_gpu_mem_alloc(). + * + * @param dev_id + * Device ID requiring pinned memory. + * @param size + * Number of bytes to pin. + * Requesting 0 will do nothing. + * @param ptr + * Pointer to the GPU memory area to be pinned. + * NULL is a no-op accepted value. + + * @return + * A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set: + * - ENODEV if invalid dev_id + * - EINVAL if reserved flags + * - ENOTSUP if operation not supported by the driver + * - E2BIG if size is higher than limit + * - ENOMEM if out of space + * - EPERM if driver error + */ +__rte_experimental +int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Unpin a chunk of GPU memory previously pinned with rte_gpu_mem_pin() + * + * @param dev_id + * Reference device ID. + * @param ptr + * Pointer to the memory area to be unpinned. + * NULL is a no-op accepted value. + * + * @return + * 0 on success, -rte_errno otherwise: + * - ENODEV if invalid dev_id + * - ENOTSUP if operation not supported by the driver + * - EPERM if driver error + */ +__rte_experimental +int rte_gpu_mem_unpin(int16_t dev_id, void *ptr); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map index 2e414c65cc..8fb0f4623b 100644 --- a/lib/gpudev/version.map +++ b/lib/gpudev/version.map @@ -21,7 +21,9 @@ EXPERIMENTAL { rte_gpu_is_valid; rte_gpu_mem_alloc; rte_gpu_mem_free; + rte_gpu_mem_pin; rte_gpu_mem_register; + rte_gpu_mem_unpin; rte_gpu_mem_unregister; rte_gpu_wmb; }; -- 2.17.1