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 32248A034D; Mon, 3 Jan 2022 19:24:31 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F155B40042; Mon, 3 Jan 2022 19:24:30 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2065.outbound.protection.outlook.com [40.107.220.65]) by mails.dpdk.org (Postfix) with ESMTP id 45EF54003C for ; Mon, 3 Jan 2022 19:24:29 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kz9VxFlL+N7m3ex64dK3zABL6M8AUy/lGO+wEV10rekkUPKJEdUQ4yPqek5Gr+Y+5VYhzNgE3eJPJ7nSRHsL5sxhwYDw/HxWQcIf/5Glyv5O33TZX4xuvA3SqZnb+bHHXjGSFiUvyhgQfuLqHxFWBjtMwUe7Hml+ACJe4OOlk7QDkNEn0Gu05ijafBzw61y0bsNz0H/y0nqjm+ipDpF3Qp4bwnwGrhJSkUyM/iGr8kCbwirP1LcoXY64ZRFyw2xP8xojQ4eH6BXG/qLUudkcFNbCUy7PNscEcLnTHbK04OYrQHKtX1kWjQkm+ZlYRh5fz9IJKy8dBh12/DPXto0eIw== 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=fdX8Sk+yea59MOFvj88NQELy2UTLyhonaxqEpnWas30=; b=nd0wM5VIzDa4apKDHBbODbcBpgKzMN1C+MSIi62cf4yO0pMpWUg3gVpP8xA6OA/qqLu7/2HRQz2GRBTWhEP/yt/Qc1l8FDB81AeRZLAB32gjRsyiOQHCYNejkIp5SR9r3BCjTM0AgwxA6hko7TMQYl7fkS4XaITQw0BXn9GRfZMJgDupLBmmEESdogptm+LC7/UadAjROc9jG6/9SWKeqlNKbQyQ/5uX1x793tPGLC2FPyT76zYA2iJEEBDxfYBQ9FtQr2zx/EkUqMaZp6SvFa7uNgLZKH79LqMAHJ8YUo4v8EaedaqjvGe4HC0RHWS8cyvt8QZhLwDeffRffd7biw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) 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=fdX8Sk+yea59MOFvj88NQELy2UTLyhonaxqEpnWas30=; b=CGY8yr1U+3N19XRWTwRn/oWWuqjuNCzdMPxXbRY5rM3AlH/9rcuodooxA8u7i/ZS/N6DikvMmdVqEHgJRvyt4cDDeALH90O5nOkvTyBBJAEeb6fNem3vHlJVAVo9UypXQdyuvHtB4j68+75QDWMgdYvT5z6YQbPsZRQD0aoREI4yZj8Lew4MUflxG1y1LisPNeecjsQ+dneY9IUAdvJgfQru5K53m1oMSDpUY+jmPhfJ4PmUk6kT9/UdRf1/uQsGXk6QxPez4y/c9lOD9JMDyrHoseLkwQSqMCobpR03uA2GWuNWIDFTlNTXGlxPzAZoSnDVj/8aXNBTte+MFTpjTg== Received: from BN8PR04CA0032.namprd04.prod.outlook.com (2603:10b6:408:70::45) by DM6PR12MB2795.namprd12.prod.outlook.com (2603:10b6:5:41::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.13; Mon, 3 Jan 2022 18:24:27 +0000 Received: from BN8NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:408:70:cafe::cc) by BN8PR04CA0032.outlook.office365.com (2603:10b6:408:70::45) 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:24:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT060.mail.protection.outlook.com (10.13.177.211) 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:24:26 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 3 Jan 2022 18:24:26 +0000 Received: from nvidia.com (172.20.187.5) 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:24:25 -0800 From: To: CC: Elena Agostini Subject: [PATCH v1] gpudev: pin GPU memory Date: Tue, 4 Jan 2022 02:34:08 +0000 Message-ID: <20220104023408.13379-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.5] 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: b86e773c-164c-4d44-806d-08d9cee6468e X-MS-TrafficTypeDiagnostic: DM6PR12MB2795: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: LEIbnj9BV3fro8lQg/g1YJ5SiIA/5Cz0rJVlnTgnO02cEJOhuVAXV80MwAUMs4VnwGXMd7uT2sok7bIcyw4D/8L+PpnQXbcMHRU9PhGrG2Wf8GqVm2cs6hcMFpx1ajMXXwZ574HnAFIoKJGiMn4ZNhEsdaHuZ3ZY3smwG4pvPkyzpDL6CVh+KUlw1+sgQX3S5b41hibirfzAw1ebSjo97W87iwBcgkKVFIPM/2fP6srIrQGhZQCtzdetN4k7n6iBGglkUeF5XxGJAcGMffd5X+6px4rgKq/ucaVjYuUCW/kk9YhmG03EtdouppfV3iZUngxeWr/nyQUp6+ibhqmUsmAk2ISs8Uk+ripruOPJBQMDMmaEcm4+jxjYFtqsThE+BDRcMzBHQQIFYIQqKW/UERT/MThmTApYAChLVIqEfUGIcQAyabMWFqn4HDZpEDKEtA5Dgk8Yf67t3iTi4r7aYTHXa0I0YVJN2582zQuYCxdil8RNdmsglPoO9AQkOa2PLK/8n1i9JoDxNHCGosQuFLryzDKK4N/8FdYsbrLSklskbnP2BvUwyq84T1Bw95YAvhMVKTo/KQmPX6/cY3mKxuNFL7BEq7u8zzo9IskRkOeJi4+J4RZY2ccrPcg8XkCz4/avVqSLvN2liWFduZQNQHYCM1uatqDqryE++CaKu8ejuBLVuD84hOOnWGyLqegcqYNKsN3FeCO6hFSKiX3ipTiAEFfcgwaTRFtJ6VMRwe+j/Z8B2Hve/lu/+h5jjnhYhguZ1aquWIOBeREz6JfnzNCN2iLyVqIJShMHRDhK8Sc= X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(40470700002)(36840700001)(46966006)(6666004)(1076003)(7696005)(83380400001)(336012)(36860700001)(70206006)(426003)(8676002)(8936002)(316002)(5660300002)(47076005)(36756003)(6286002)(81166007)(186003)(4326008)(16526019)(26005)(508600001)(356005)(107886003)(55016003)(82310400004)(86362001)(2906002)(2876002)(70586007)(2616005)(40460700001)(6916009)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2022 18:24:26.9461 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b86e773c-164c-4d44-806d-08d9cee6468e 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.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2795 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..a616941926 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