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 CAE99A0C53; Wed, 3 Nov 2021 12:05:55 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2F9B7426EF; Wed, 3 Nov 2021 12:05:08 +0100 (CET) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2048.outbound.protection.outlook.com [40.107.92.48]) by mails.dpdk.org (Postfix) with ESMTP id 90492411FE for ; Wed, 3 Nov 2021 12:05:01 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UtL8fdV17xg2evLsk9oDRUf9RAjp/HieWkWfQiYVza0EwF0t32uBfafESKiphFR/K1PiTIcswHzbf3Q6MVyfWoauDtfCFcob/WMMpllzbf+/m5ZTu2NbGwYLyeccO5tiqstcfz4zWsjwr2Mh89AFyapQU6eQRWq87+LFqQNasW0T4qHtdB3uzMV2n/O2H+cvx0woQmlqBzHpFv1Ly3VsLo1uccmWqRmcLbGJOeFi5VSWFLPHzEIy16JK/eCiQx6qU7kAfxKSmyn7pvgZn7KUlI/sTpkRczim1+KijQm5k1kydAt5td4mVTRvbYpcSl1d6z/auYwtp7ncGfwtOm4Dwg== 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=DS53plPGzrKvtF0AVYWN6sVmOSmCEE6GPfg0svPYcJA=; b=LpCxZUL/3TM7VRrf75H4J71dVfY6HQnUC866eDooNTlqdbT9lXUbT5KK6WLnvYE0i58yxfSvx0hy8nx2LjIjliw+7UFvX3s7dPm1s+Jl22Y7pT2/pX7BO3FtvehiOA18N25qy3fx8/YH5QbaXWDpvQTc98w3EpyJ+OKEJm7kPBkUm6zFScJLMt0vJ5/IASVxccdr9P4XjkHZEj6nBFQPzRgWCeW1gMSRFR0PJWgQnraEhmexujJUfFtp+gKy5zDspIrN8gfQZB1fxiebpUxaXKLYX0nvgG9hUP36fJfDhCFZ0rNb4T/KbPDw0PdcjvejseVBpphBLWdt/th0jyPcYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine 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=DS53plPGzrKvtF0AVYWN6sVmOSmCEE6GPfg0svPYcJA=; b=IYPXyia1OLn/PunAhtrhDPFHAz71tNhQ2gsYCRlJjzFnUa5IxLTsGaDCxIDuv6YEYqGqIXPGIf+Mm3duHVGao4oOwU4AOjAJZ6JZVpk6fXjb1P3V3sMqJoRxpKe/8N4IY5cEES1MPchbZ9YMoziTih4uZ7Ra9XqaIUsuFedDXs3luzTYhEChQ/6hTOtwJ98MNnm4te0H6sTRTOnV0xOw+rZThZyb6KH8zZEKvn4MdzuPxpa0H3RDYQZddy4Djb+gLoqlQrBi0JcvFqpXKWgv/dv5vF5aMxGScAaH5rmJ8ExRaLlRmaB3jQOVKRD7JvvtXRops1jTjWJT42XbO8R3zw== Received: from DM6PR03CA0079.namprd03.prod.outlook.com (2603:10b6:5:333::12) by BYAPR12MB3400.namprd12.prod.outlook.com (2603:10b6:a03:da::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11; Wed, 3 Nov 2021 11:04:58 +0000 Received: from DM6NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::15) by DM6PR03CA0079.outlook.office365.com (2603:10b6:5:333::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15 via Frontend Transport; Wed, 3 Nov 2021 11:04:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT064.mail.protection.outlook.com (10.13.172.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4669.10 via Frontend Transport; Wed, 3 Nov 2021 11:04:58 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 3 Nov 2021 11:04:55 +0000 From: To: CC: Elena Agostini Date: Wed, 3 Nov 2021 19:15:52 +0000 Message-ID: <20211103191554.16449-8-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211103191554.16449-1-eagostini@nvidia.com> References: <20210602203531.2288645-1-thomas@monjalon.net> <20211103191554.16449-1-eagostini@nvidia.com> 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 HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 005d064d-9309-4193-2477-08d99eb9c677 X-MS-TrafficTypeDiagnostic: BYAPR12MB3400: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:117; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JZL/eTMs/NsDwVxC7Y2WdrzpXVKfwpOmiEDMgxpXRC4poTS482oUg4MNf3YIqRsIGia1KRvZeDiqm5dPwmfVlLQR8nR7mhpgjMQatJG5cL0co7RBcNrOHdRIPY0nKiyCVHFtlCKZiaTQUiAvu3HrvDMaYjGRoCSJn12NCP345PqpREZccLjncTQ5oi3LtOf5nfIqKCRMml4nDF/0V7g2aTICbfko5w52yzFCbMIF16Knnu9bxoL5HYvApD1zF3krcEIp7xGCkduSLVRwmRgJnD5Gyhv/SVr8ZWttEd6QVt+Tkuu76mqg24KdGZHrwW5DkexXhpO6X1nD713NeX/f/z/VbY/k3e2Jm2qGNBFfRHR+RRNA3756xmykEqWvtfe0QFdbPMsOxqJguCJ/vUcyFdafepanuMVdzEa+unHwXmMdfSMvhd9K7gyNyz5OT9mNz3r4md5Ny+yPq6ljUqLWdeyrt03ufqm05dUvO9Dfz4hmBsx4eKKbXrTbai0sDKbNzOTIUbtREQG/kFhqPQK5kbD2nvx+00HWxbFfEd9a3ucUch2t5Jz7GUfeBkS0ok8ztj5Yz3Ry8Ifz2tn5aKVd7jGsHn6EGWhaukuqf6y2tC/RAjX4npJL1KnU6LEvHFcJ3MqXcOm9u2u/zsFlK/4IAAQ7M4mcWhtShQ4ZfyqgmE6BaLC5ZzVuxqbacJwk/NAt9fSB7zwg0FSxDMZ7vwkZPw== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(186003)(16526019)(70586007)(8676002)(4326008)(7636003)(26005)(70206006)(55016002)(6286002)(107886003)(36906005)(316002)(356005)(6666004)(83380400001)(36860700001)(82310400003)(426003)(36756003)(336012)(30864003)(1076003)(47076005)(8936002)(508600001)(7696005)(86362001)(2616005)(5660300002)(6916009)(2876002)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2021 11:04:58.4281 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 005d064d-9309-4193-2477-08d99eb9c677 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3400 Subject: [dpdk-dev] [PATCH v4 7/9] gpudev: add communication flag 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 Sender: "dev" From: Elena Agostini In heterogeneous computing system, processing is not only in the CPU. Some tasks can be delegated to devices working in parallel. When mixing network activity with task processing there may be the need to put in communication the CPU with the device in order to synchronize operations. The purpose of this flag is to allow the CPU and the GPU to exchange ACKs. A possible use-case is described below. CPU: - Trigger some task on the GPU - Prepare some data - Signal to the GPU the data is ready updating the communication flag GPU: - Do some pre-processing - Wait for more data from the CPU polling on the communication flag - Consume the data prepared by the CPU Signed-off-by: Elena Agostini --- app/test-gpudev/main.c | 66 +++++++++++++++ doc/guides/prog_guide/gpudev.rst | 13 +++ doc/guides/rel_notes/release_21_11.rst | 1 + lib/gpudev/gpudev.c | 94 +++++++++++++++++++++ lib/gpudev/rte_gpudev.h | 108 +++++++++++++++++++++++++ lib/gpudev/version.map | 4 + 6 files changed, 286 insertions(+) diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c index 98c02a3ee0..22f5c950b2 100644 --- a/app/test-gpudev/main.c +++ b/app/test-gpudev/main.c @@ -166,6 +166,67 @@ register_cpu_memory(uint16_t gpu_id) return 0; } +static int +create_update_comm_flag(uint16_t gpu_id) +{ + struct rte_gpu_comm_flag devflag; + int ret = 0; + uint32_t set_val; + uint32_t get_val; + + printf("\n=======> TEST: Communication flag\n"); + + ret = rte_gpu_comm_create_flag(gpu_id, &devflag, RTE_GPU_COMM_FLAG_CPU); + if(ret < 0) + { + fprintf(stderr, "rte_gpu_comm_create_flag returned error %d\n", ret); + return -1; + } + + set_val = 25; + ret = rte_gpu_comm_set_flag(&devflag, set_val); + if(ret < 0) + { + fprintf(stderr, "rte_gpu_comm_set_flag returned error %d\n", ret); + return -1; + } + + ret = rte_gpu_comm_get_flag_value(&devflag, &get_val); + if(ret < 0) + { + fprintf(stderr, "rte_gpu_comm_get_flag_value returned error %d\n", ret); + return -1; + } + + printf("Communication flag value at 0x%p was set to %d and current value is %d\n", devflag.ptr, set_val, get_val); + + set_val = 38; + ret = rte_gpu_comm_set_flag(&devflag, set_val); + if(ret < 0) + { + fprintf(stderr, "rte_gpu_comm_set_flag returned error %d\n", ret); + return -1; + } + + ret = rte_gpu_comm_get_flag_value(&devflag, &get_val); + if(ret < 0) + { + fprintf(stderr, "rte_gpu_comm_get_flag_value returned error %d\n", ret); + return -1; + } + + printf("Communication flag value at 0x%p was set to %d and current value is %d\n", devflag.ptr, set_val, get_val); + + ret = rte_gpu_comm_destroy_flag(&devflag); + if(ret < 0) + { + fprintf(stderr, "rte_gpu_comm_destroy_flags returned error %d\n", ret); + return -1; + } + + return 0; +} + int main(int argc, char **argv) { @@ -217,6 +278,11 @@ main(int argc, char **argv) alloc_gpu_memory(gpu_id); register_cpu_memory(gpu_id); + /** + * Communication items test + */ + create_update_comm_flag(gpu_id); + /* clean up the EAL */ rte_eal_cleanup(); printf("Bye...\n"); diff --git a/doc/guides/prog_guide/gpudev.rst b/doc/guides/prog_guide/gpudev.rst index eb5f0af817..e0db627aed 100644 --- a/doc/guides/prog_guide/gpudev.rst +++ b/doc/guides/prog_guide/gpudev.rst @@ -32,6 +32,10 @@ This library provides a number of features: - Interoperability with device-specific library through generic handlers. - Allocate and free memory on the device. - Register CPU memory to make it visible from the device. +- Communication between the CPU and the device. + +The whole CPU - GPU communication is implemented +using CPU memory visible from the GPU. API Overview @@ -73,3 +77,12 @@ Some GPU drivers may need, under certain conditions, to enforce the coherency of external devices writes (e.g. NIC receiving packets) into the GPU memory. gpudev abstracts and exposes this capability. + +Communication Flag +~~~~~~~~~~~~~~~~~~ + +Considering an application with some GPU task +that's waiting to receive a signal from the CPU +to move forward with the execution. +The communication flag allocates a CPU memory GPU-visible ``uint32_t`` flag +that can be used by the CPU to communicate with a GPU task. diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index f70680dad3..16d10bb14c 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -95,6 +95,7 @@ New Features * Device information * Memory management + * Communication flag * **Added new RSS offload types for IPv4/L4 checksum in RSS flow.** diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c index cefefd737a..827e29d8f6 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -643,3 +643,97 @@ rte_gpu_mbw(int16_t dev_id) } return GPU_DRV_RET(dev->ops.mbw(dev)); } + +int +rte_gpu_comm_create_flag(uint16_t dev_id, struct rte_gpu_comm_flag *devflag, + enum rte_gpu_comm_flag_type mtype) +{ + size_t flag_size; + int ret; + + if (devflag == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } + if (mtype != RTE_GPU_COMM_FLAG_CPU) { + rte_errno = EINVAL; + return -rte_errno; + } + + flag_size = sizeof(uint32_t); + + devflag->ptr = rte_zmalloc(NULL, flag_size, 0); + if (devflag->ptr == NULL) { + rte_errno = ENOMEM; + return -rte_errno; + } + + ret = rte_gpu_register(dev_id, flag_size, devflag->ptr); + if(ret < 0) + { + rte_errno = ENOMEM; + return -rte_errno; + } + + devflag->mtype = mtype; + devflag->dev_id = dev_id; + + return 0; +} + +int +rte_gpu_comm_destroy_flag(struct rte_gpu_comm_flag *devflag) +{ + int ret; + + if (devflag == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } + + ret = rte_gpu_unregister(devflag->dev_id, devflag->ptr); + if(ret < 0) + { + rte_errno = EINVAL; + return -1; + } + + rte_free(devflag->ptr); + + return 0; +} + +int +rte_gpu_comm_set_flag(struct rte_gpu_comm_flag *devflag, uint32_t val) +{ + if (devflag == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } + + if (devflag->mtype != RTE_GPU_COMM_FLAG_CPU) { + rte_errno = EINVAL; + return -rte_errno; + } + + RTE_GPU_VOLATILE(*devflag->ptr) = val; + + return 0; +} + +int +rte_gpu_comm_get_flag_value(struct rte_gpu_comm_flag *devflag, uint32_t *val) +{ + if (devflag == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } + if (devflag->mtype != RTE_GPU_COMM_FLAG_CPU) { + rte_errno = EINVAL; + return -rte_errno; + } + + *val = RTE_GPU_VOLATILE(*devflag->ptr); + + return 0; +} diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h index e790b3e2b7..4a10a8bcf5 100644 --- a/lib/gpudev/rte_gpudev.h +++ b/lib/gpudev/rte_gpudev.h @@ -38,6 +38,9 @@ extern "C" { /** Catch-all callback data. */ #define RTE_GPU_CALLBACK_ANY_DATA ((void *)-1) +/** Access variable as volatile. */ +#define RTE_GPU_VOLATILE(x) (*(volatile typeof(x)*)&(x)) + /** Store device info. */ struct rte_gpu_info { /** Unique identifier name. */ @@ -68,6 +71,22 @@ enum rte_gpu_event { typedef void (rte_gpu_callback_t)(int16_t dev_id, enum rte_gpu_event event, void *user_data); +/** Memory where communication flag is allocated. */ +enum rte_gpu_comm_flag_type { + /** Allocate flag on CPU memory visible from device. */ + RTE_GPU_COMM_FLAG_CPU = 0, +}; + +/** Communication flag to coordinate CPU with the device. */ +struct rte_gpu_comm_flag { + /** Device that will use the device flag. */ + uint16_t dev_id; + /** Pointer to flag memory area. */ + uint32_t *ptr; + /** Type of memory used to allocate the flag. */ + enum rte_gpu_comm_flag_type mtype; +}; + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. @@ -405,6 +424,95 @@ int rte_gpu_unregister(int16_t dev_id, void *ptr); __rte_experimental int rte_gpu_mbw(int16_t dev_id); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Create a communication flag that can be shared + * between CPU threads and device workload to exchange some status info + * (e.g. work is done, processing can start, etc..). + * + * @param dev_id + * Reference device ID. + * @param devflag + * Pointer to the memory area of the devflag structure. + * @param mtype + * Type of memory to allocate the communication flag. + * + * @return + * 0 on success, -rte_errno otherwise: + * - ENODEV if invalid dev_id + * - EINVAL if invalid inputs + * - ENOTSUP if operation not supported by the driver + * - ENOMEM if out of space + * - EPERM if driver error + */ +__rte_experimental +int rte_gpu_comm_create_flag(uint16_t dev_id, + struct rte_gpu_comm_flag *devflag, + enum rte_gpu_comm_flag_type mtype); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Deallocate a communication flag. + * + * @param devflag + * Pointer to the memory area of the devflag structure. + * + * @return + * 0 on success, -rte_errno otherwise: + * - ENODEV if invalid dev_id + * - EINVAL if NULL devflag + * - ENOTSUP if operation not supported by the driver + * - EPERM if driver error + */ +__rte_experimental +int rte_gpu_comm_destroy_flag(struct rte_gpu_comm_flag *devflag); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Set the value of a communication flag as the input value. + * Flag memory area is treated as volatile. + * The flag must have been allocated with RTE_GPU_COMM_FLAG_CPU. + * + * @param devflag + * Pointer to the memory area of the devflag structure. + * @param val + * Value to set in the flag. + * + * @return + * 0 on success, -rte_errno otherwise: + * - EINVAL if invalid input params + */ +__rte_experimental +int rte_gpu_comm_set_flag(struct rte_gpu_comm_flag *devflag, + uint32_t val); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Get the value of the communication flag. + * Flag memory area is treated as volatile. + * The flag must have been allocated with RTE_GPU_COMM_FLAG_CPU. + * + * @param devflag + * Pointer to the memory area of the devflag structure. + * @param val + * Flag output value. + * + * @return + * 0 on success, -rte_errno otherwise: + * - EINVAL if invalid input params + */ +__rte_experimental +int rte_gpu_comm_get_flag_value(struct rte_gpu_comm_flag *devflag, + uint32_t *val); + #ifdef __cplusplus } #endif diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map index d72d470d8e..2fc039373a 100644 --- a/lib/gpudev/version.map +++ b/lib/gpudev/version.map @@ -6,6 +6,10 @@ EXPERIMENTAL { rte_gpu_callback_register; rte_gpu_callback_unregister; rte_gpu_close; + rte_gpu_comm_create_flag; + rte_gpu_comm_destroy_flag; + rte_gpu_comm_get_flag_value; + rte_gpu_comm_set_flag; rte_gpu_count_avail; rte_gpu_find_next; rte_gpu_free; -- 2.17.1