From patchwork Tue Jan 4 01:47:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Agostini X-Patchwork-Id: 105592 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9E2CFA034D; Mon, 3 Jan 2022 18:37:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 048CA410E0; Mon, 3 Jan 2022 18:37:37 +0100 (CET) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2058.outbound.protection.outlook.com [40.107.92.58]) by mails.dpdk.org (Postfix) with ESMTP id B5AAE40042 for ; Mon, 3 Jan 2022 18:37:34 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hTtuigp6vk2xxcCHNzr5FT98+h+czD6Szt/Uhv/9ZiI4qWuVs+VF/1mCB8UlsooV9DUgy4zDgA6yQUkDZm7ScaoMJh4bfZ37vsDqp5zpsYT79O47Vy+YMxqKwDiERlrvJ2JR4BA9fvKAt/ZO70YYb7kee1pwjUO2Yma/Sw9szzl00XCZ9Op4gybBioXt9/E3nlL/PsLJZazEl9eQ4edXDSCr359pp6Ad7tEyu0K+cJItaexJ0DRWg+39eCf9WQpvY02qyFGBAIskriju6ALR22VrYMltnc7FB0M3sEHtY2VW5VZS7T4cVgbME7zTNKkVSm0qeg0X97N/GYTlnRO+Dg== 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=iMKfkRTPISRq5l34il6PHGJq6baX1p9oxit7OOtZeog=; b=GqexSQpaHIbDxY/2YXs0K0UN/K27XLG8cTvApXgUexRHM0uV2Xw8wqduIl3O/a0166t6BzrFIWxOAUH8S47JhTwJqUTwJcZXYD5tbitPNSyBQGBuVcf0Gy+Qf7YlhXBxD9puntv4PJMANHBTohAXhBT4phKEOnvqVQfQYKY2OTEG5kHING/ZBgyxIJqY1I2sq7w8UaTarFaqYp3jvhLQtDjg3zZHIE2juxsPwg2AseicNvrdhGw3E8GC4eyYmzvTp23lneGJlKv8Zme6kf7wTXf0uFQ0CgDiEOk5osEPnuVCgR02HiqSECceF0V17z6cfGeUo/wriBmn8rYf/NBh3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) 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=iMKfkRTPISRq5l34il6PHGJq6baX1p9oxit7OOtZeog=; b=X+tYWIzDjJmJL1gc8bWo8D2Qy3kDB3iCloal37uw9ygUK+Jn0T2/OGlDiijoWlkxLmpYsT24UuDgCZNgcF5OgJgIMfGtu6OACbjOvaurOaOZWCe1HDK6OWoUk/FCV7OjIRXO+FvHzg8j1OIhGYFn+IpJ4ftKgWPZ2B3fW/smk/3k9FtfN/BGkO/3JKMIyQOgUXkkiBriHyvyrHubDmfz8vVyt5JBSZw/LiyuvWud/PMgdkaFHhpI035eYaMOsa1dpYDuunKqhJtua8TQEcago2QkkNRYY09LWqhFBMu3umxw0ngs2BXxhTAsGaRHgb+rxTmTATg3zHStJYY8YkUxQA== Received: from MW4PR04CA0149.namprd04.prod.outlook.com (2603:10b6:303:84::34) by DM6PR12MB3674.namprd12.prod.outlook.com (2603:10b6:5:1c4::29) 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 17:37:33 +0000 Received: from CO1NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:303:84:cafe::82) by MW4PR04CA0149.outlook.office365.com (2603:10b6:303:84::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.15 via Frontend Transport; Mon, 3 Jan 2022 17:37:33 +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; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT065.mail.protection.outlook.com (10.13.174.62) 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 17:37:32 +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.18; Mon, 3 Jan 2022 17:37:32 +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 09:37:31 -0800 From: To: CC: Elena Agostini Subject: [PATCH v1 1/3] gpudev: mem alloc aligned memory Date: Tue, 4 Jan 2022 01:47:19 +0000 Message-ID: <20220104014721.1799-2-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220104014721.1799-1-eagostini@nvidia.com> References: <20220104014721.1799-1-eagostini@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9e1bdfed-6d66-4980-7dc8-08d9cedfb911 X-MS-TrafficTypeDiagnostic: DM6PR12MB3674:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a2lRiFi3mv7VG0OEzC+Ko1UArYdbN9uYFugkB8g/Mve6onCGBDB2oTE4pg9QT+Xqv9yxs9YXNO7DdnJiStBs29ZwQPHFg8KGz41cnyIwdeGt/nbg+APXzXS0+BRS7V96p/L/UQsoYIOJdc8XAEesxXhU4aMGUAdbfgXBpdP6WIikz8kU7uesv/swHDWz2xg/Cq8tULlmZAb2d9xvNKmBpGvp2pauqT9kT2XWAgttxtSgGlSaqNLpgT5vwHVSD2ynd5W0yOYnncxAqKCS5Tu4rL04Gi4CBv9R5kt3XUXEoIYQgxYf/0EpFNb30vafGQ/TaTnQfZ+/jlrsXmvE4SmtGerMFBy3iBuKEZbJ8erjXLNw+nXrlUvKaZbCuf9W62x7tGPntNG+2oofo5ZEGeB4enqYSM0xL6kaboSDiTyXwNvYk+2OjwRF0FB3izEKoVq7wqFjWj2TKucmWin07Q+Xux9VXW1QVPT0gDaj1MLh39nqKTU85CZ9Jz64MUaI7RDc+lNd/EUEvxVv+RRVVW7acKbNSHYkWUisB4KLG2V7LUeXbSPRO5guEWVLEVt8oMlVrcc9PMKLSQ6HVlWJn51nMTjCAmJjevtay+6WN6d2JuM6QKNKOssqGiFZdoq3rhnEZYZZ7jOWH852mzvDp3Sfs3/VJ5YspZPUe/02N5UfPhWl2hl/PedYZYPyQ6ezdVW9eGDpZinJVc0ZuowfBN4W9dc3lCT1VXZ/9irAXBIqO2qk+eRvVCwxjYfhRtt3lVBoJbmPJZh1/8EPu7Fnu3ud86vu1gOYyIgNLA2IovlJ1bI= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(46966006)(40470700002)(36840700001)(356005)(86362001)(2616005)(6286002)(40460700001)(508600001)(7696005)(316002)(336012)(16526019)(36756003)(26005)(6666004)(186003)(36860700001)(5660300002)(8676002)(70206006)(2906002)(70586007)(2876002)(83380400001)(426003)(107886003)(47076005)(4326008)(55016003)(81166007)(6916009)(8936002)(1076003)(82310400004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2022 17:37:32.6502 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e1bdfed-6d66-4980-7dc8-08d9cedfb911 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: CO1NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3674 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 Similarly to rte_malloc, rte_gpu_mem_alloc accept as input the memory alignment size. GPU driver should return GPU memory address aligned with the input value. Signed-off-by: Elena Agostini --- lib/gpudev/gpudev.c | 10 ++++++++-- lib/gpudev/gpudev_driver.h | 2 +- lib/gpudev/rte_gpudev.h | 10 +++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c index 9ae36dbae9..dc8c3baefa 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -527,7 +527,7 @@ rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info) } void * -rte_gpu_mem_alloc(int16_t dev_id, size_t size) +rte_gpu_mem_alloc(int16_t dev_id, size_t size, unsigned int align) { struct rte_gpu *dev; void *ptr; @@ -549,7 +549,13 @@ rte_gpu_mem_alloc(int16_t dev_id, size_t size) if (size == 0) /* dry-run */ return NULL; - ret = dev->ops.mem_alloc(dev, size, &ptr); + if (align && !rte_is_power_of_2(align)) { + GPU_LOG(ERR, "requested alignment is not a power of two %u", align); + rte_errno = EINVAL; + return NULL; + } + + ret = dev->ops.mem_alloc(dev, size, &ptr, align); switch (ret) { case 0: diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h index cb7b101f2f..d06f465194 100644 --- a/lib/gpudev/gpudev_driver.h +++ b/lib/gpudev/gpudev_driver.h @@ -27,7 +27,7 @@ enum rte_gpu_state { struct rte_gpu; typedef int (rte_gpu_close_t)(struct rte_gpu *dev); typedef int (rte_gpu_info_get_t)(struct rte_gpu *dev, struct rte_gpu_info *info); -typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr); +typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr, unsigned int align); 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); diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h index fa3f3aad4f..9e2e2c5dce 100644 --- a/lib/gpudev/rte_gpudev.h +++ b/lib/gpudev/rte_gpudev.h @@ -364,18 +364,22 @@ int rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info); * @param size * Number of bytes to allocate. * Requesting 0 will do nothing. - * + * @param align + * If 0, the return is a pointer that is suitably aligned for any kind of + * variable (in the same manner as malloc()). + * Otherwise, the return is a pointer that is a multiple of *align*. In + * this case, it must obviously be a power of two. * @return * A pointer to the allocated memory, otherwise NULL and rte_errno is set: * - ENODEV if invalid dev_id - * - EINVAL if reserved flags + * - EINVAL if align is not a power of two * - 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 -void *rte_gpu_mem_alloc(int16_t dev_id, size_t size) +void *rte_gpu_mem_alloc(int16_t dev_id, size_t size, unsigned int align) __rte_alloc_size(2); /**