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 D90F3A0C4D; Mon, 8 Nov 2021 11:48:08 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8838C4115C; Mon, 8 Nov 2021 11:47:15 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2073.outbound.protection.outlook.com [40.107.93.73]) by mails.dpdk.org (Postfix) with ESMTP id AFEA541135 for ; Mon, 8 Nov 2021 11:47:11 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cwSnEzZthhwIAjpCJ6d7c3Kw3tjZzoMjLP7ILRvrKp0nNPgGPfw7XFUwCtt/PNXrwVk31amL51XOWPmwhfwl/T6UuQ29Yne4E6ojJaCr2YXlrsW+SOsylbHWtl5vIXt9ZeRjKSy3Ip+IF3ml0M7AW4AjkFQHEb6f8cp/AWvYaoBM2mKiDOSwHrZyYLcy192sY9ioDII2iLJJFdPl9TBV26uq/SYxIDHwHA1/E5VO9qzazD1qQP0OslHYe0Cnbbop4bx8On8vfjgBwftC7WV1M3u8MLD+Eam/n8/m6q6ivtEwHDKbn7NRJzKTFGDPToXzEB0ivHfLkxX6Y5/nBZUtKg== 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=VX5zpehkghcafleHeX83G1br/+w3dEjZdifrsXb2y5s=; b=CncCEOXRlBRaDpgCxymV9bK6KCNmRLX55L0LfJJnLVMlW0DFlY9PHSjzJ3Z2IvyDTvHvBxbRT+dCKzX2RKh3k7XB/VLVhjIMkDkaiLpgriDUHrGfacrxjUEuNil+aPfFneN8oZ/8i6LxRSXAf/Dd4n4xyCirZ/mYU6Ld5V101R3ZErfVNofB6HCVWc9eATSH6TdrL8kegMZfiCcN//2JmOahA9X9DdGaxZaxX+ljgI3G3y5eGa7arOzno8S/quZgLGUAgsppew9SnJ9CrDRhdaDVVHPaGvR8i6LYT8Wwv1UGf+BKnuh6jKpPUSKNidFLYf75VY02nk2dbXKtDMRycQ== 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=VX5zpehkghcafleHeX83G1br/+w3dEjZdifrsXb2y5s=; b=I3r1mtYYFa+zWGlbrK/teMxsaT8N4KdgQH38VPsO9YOnFWRLoR9/NbGCFgau8XRyC69pj9qJ6QR7f+Q1cWKUnL2Utpi9MBE5ZgHtRJK/KNSWEhlHN3mz++MJAqrzKxtfLlNJ0FXjY+UARhTeZuIL40KNhi2x5dN445NvXAqkYjM9f7tNWe/7XLb6UF60/0XYFRqcXHDE9sXRR1iuJIkB0RPBH8BBZS8etFobTcNkL8RfBV15BRd4sVxNZGJ77nNoaIUInp2kAR0tw2/F1aIk8wGE2mxvF0CxzM7RMAp4+v8/Fp2cjkeNIhDP1uLorN8XseUFF3qe73Pw9bu/8pnblg== Received: from MW2PR16CA0037.namprd16.prod.outlook.com (2603:10b6:907:1::14) by BY5PR12MB4243.namprd12.prod.outlook.com (2603:10b6:a03:20f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.10; Mon, 8 Nov 2021 10:47:10 +0000 Received: from CO1NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:907:1:cafe::4f) by MW2PR16CA0037.outlook.office365.com (2603:10b6:907:1::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Mon, 8 Nov 2021 10:47:10 +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 CO1NAM11FT064.mail.protection.outlook.com (10.13.175.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4669.10 via Frontend Transport; Mon, 8 Nov 2021 10:47:09 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 8 Nov 2021 10:47:02 +0000 From: To: CC: Elena Agostini Date: Mon, 8 Nov 2021 18:58:04 +0000 Message-ID: <20211108185805.3887-9-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211108185805.3887-1-eagostini@nvidia.com> References: <20210602203531.2288645-1-thomas@monjalon.net> <20211108185805.3887-1-eagostini@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74bba9df-e19d-4e42-4752-08d9a2a51d72 X-MS-TrafficTypeDiagnostic: BY5PR12MB4243: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:962; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nFtp4+7ArNY+I+5f/BjaEUiksqnoPjAqso6FukTpF5n7OJXMlKe+GYShzkXmFzHJRmrTKU2FbThsYAZkIrnI1WPYCqCUwFcKbvlQtKxyrn9FKvWZJ1R7PVYNt9du/DpbgmcH4Cz9Efv+FEBqw15OL91ypZ0IHpbtZhaEETyhICdw3GuTGQuDZlu0VlkCONx9/YjsjWZ3FknU6IAK8p8Vn8FC+TZlg+1CFtJpD1PsDpu8a4ZBJE7pJEgnu5EIyfibSoukqdE8duZpXrz8nWJx2gVnf06ndwC8AXgAezn2dMwiWgWM5HKGPqlRGjsyaHWT9qmHnMoKRkm7yKh/YM1f4vsciJ7Arw5hDcHtuNqM3EwW0t/C0hP6D7vXa44jrf3oI8rhAG1lR5t8eADRQAO9t1homobVWoYOHfWSTaONUBaq6vd54zGQZ8IcukOS/+f2wehyj/qECaD3w9v+Qiebz3AZaP6GdokDG0jhRISRACaELCS9TCJNLfAUysNuHaf78aT9WyBrvh14IEVor984cPrCuhqUdbpHR5Zb4b6ELZArTgFAnkPD6ByACeCh3nlF/KNsnLz+m7iYbK+pcI6vp6ujY0FOn06iMFf6e/6PQUr0DT6qGBPKfHQxtlDtRLCMTVuuyG3TaLxdh2H30JXCBQwF7lCjzViJldcnWrvgKJeYZ5UxvnC3WKuiTev61qcPQ75xrZoROw7K3pBeM9STeQ== 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)(46966006)(36840700001)(7636003)(356005)(82310400003)(7696005)(26005)(426003)(4326008)(83380400001)(16526019)(2616005)(336012)(508600001)(6286002)(186003)(316002)(8936002)(2906002)(86362001)(36860700001)(70586007)(70206006)(36756003)(2876002)(30864003)(1076003)(8676002)(5660300002)(55016002)(107886003)(6916009)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2021 10:47:09.5968 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74bba9df-e19d-4e42-4752-08d9a2a51d72 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: CO1NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4243 Subject: [dpdk-dev] [PATCH v5 8/9] gpudev: add communication list 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. An example could be a receive-and-process application where CPU is responsible for receiving packets in multiple mbufs and the GPU is responsible for processing the content of those packets. The purpose of this list is to provide a buffer in CPU memory visible from the GPU that can be treated as a circular buffer to let the CPU provide fondamental info of received packets to the GPU. A possible use-case is described below. CPU: - Trigger some task on the GPU - in a loop: - receive a number of packets - provide packets info to the GPU GPU: - Do some pre-processing - Wait to receive a new set of packet to be processed Layout of a communication list would be: ------- | 0 | => pkt_list | status | | #pkts | ------- | 1 | => pkt_list | status | | #pkts | ------- | 2 | => pkt_list | status | | #pkts | ------- | .... | => pkt_list ------- Signed-off-by: Elena Agostini --- app/test-gpudev/main.c | 95 ++++++++++++++ doc/guides/prog_guide/gpudev.rst | 16 +++ doc/guides/rel_notes/release_21_11.rst | 2 +- lib/gpudev/gpudev.c | 164 +++++++++++++++++++++++++ lib/gpudev/meson.build | 2 + lib/gpudev/rte_gpudev.h | 129 +++++++++++++++++++ lib/gpudev/version.map | 4 + 7 files changed, 411 insertions(+), 1 deletion(-) diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c index 516a01b927..111ed6d415 100644 --- a/app/test-gpudev/main.c +++ b/app/test-gpudev/main.c @@ -209,6 +209,100 @@ create_update_comm_flag(uint16_t gpu_id) return 0; } +static int +simulate_gpu_task(struct rte_gpu_comm_list *comm_list_item, int num_pkts) +{ + int idx; + + if (comm_list_item == NULL) + return -1; + + for (idx = 0; idx < num_pkts; idx++) { + /** + * consume(comm_list_item->pkt_list[idx].addr); + */ + } + comm_list_item->status = RTE_GPU_COMM_LIST_DONE; + + return 0; +} + +static int +create_update_comm_list(uint16_t gpu_id) +{ + int ret = 0; + int i = 0; + struct rte_gpu_comm_list *comm_list; + uint32_t num_comm_items = 1024; + struct rte_mbuf *mbufs[10]; + + printf("\n=======> TEST: Communication list\n"); + + comm_list = rte_gpu_comm_create_list(gpu_id, num_comm_items); + if (comm_list == NULL) { + fprintf(stderr, "rte_gpu_comm_create_list returned error %d\n", ret); + return -1; + } + + /** + * Simulate DPDK receive functions like rte_eth_rx_burst() + */ + for (i = 0; i < 10; i++) { + mbufs[i] = rte_zmalloc(NULL, sizeof(struct rte_mbuf), 0); + if (mbufs[i] == NULL) { + fprintf(stderr, "Failed to allocate fake mbufs in CPU memory.\n"); + return -1; + } + + memset(mbufs[i], 0, sizeof(struct rte_mbuf)); + } + + /** + * Populate just the first item of the list + */ + ret = rte_gpu_comm_populate_list_pkts(&(comm_list[0]), mbufs, 10); + if (ret < 0) { + fprintf(stderr, "rte_gpu_comm_populate_list_pkts returned error %d\n", ret); + return -1; + } + + ret = rte_gpu_comm_cleanup_list(&(comm_list[0])); + if (ret == 0) { + fprintf(stderr, "rte_gpu_comm_cleanup_list erroneusly cleaned the list even if packets have not beeing consumed yet\n"); + return -1; + } else { + fprintf(stderr, "rte_gpu_comm_cleanup_list correctly didn't clean up the packets because they have not beeing consumed yet\n"); + } + + /** + * Simulate a GPU tasks going through the packet list to consume + * mbufs packets and release them + */ + simulate_gpu_task(&(comm_list[0]), 10); + + /** + * Packets have been consumed, now the communication item + * and the related mbufs can be all released + */ + ret = rte_gpu_comm_cleanup_list(&(comm_list[0])); + if (ret < 0) { + fprintf(stderr, "rte_gpu_comm_cleanup_list returned error %d\n", ret); + return -1; + } + + ret = rte_gpu_comm_destroy_list(comm_list, num_comm_items); + if (ret < 0) { + fprintf(stderr, "rte_gpu_comm_destroy_list returned error %d\n", ret); + return -1; + } + + for (i = 0; i < 10; i++) + rte_free(mbufs[i]); + + printf("\nCommunication list test passed!\n"); + return 0; +} + int main(int argc, char **argv) { @@ -263,6 +357,7 @@ main(int argc, char **argv) * Communication items test */ create_update_comm_flag(gpu_id); + create_update_comm_list(gpu_id); /* clean up the EAL */ rte_eal_cleanup(); diff --git a/doc/guides/prog_guide/gpudev.rst b/doc/guides/prog_guide/gpudev.rst index e0db627aed..cbaec5a1e4 100644 --- a/doc/guides/prog_guide/gpudev.rst +++ b/doc/guides/prog_guide/gpudev.rst @@ -86,3 +86,19 @@ 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. + +Communication list +~~~~~~~~~~~~~~~~~~ + +By default, DPDK pulls free mbufs from a mempool to receive packets. +Best practice, expecially in a multithreaded application, +is to no make any assumption on which mbufs will be used +to receive the next bursts of packets. +Considering an application with a GPU memory mempool +attached to a receive queue having some task waiting on the GPU +to receive a new burst of packets to be processed, +there is the need to communicate from the CPU +the list of mbuf payload addresses where received packet have been stored. +The ``rte_gpu_comm_*()`` functions are responsible to create a list of packets +that can be populated with receive mbuf payload addresses +and communicated to the task running on the GPU. diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index 78b29d9a25..23d8591f40 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -105,7 +105,7 @@ New Features * Device information * Memory management - * Communication flag + * Communication flag & list * **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 f887f3dd93..88148eb704 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -735,3 +735,167 @@ rte_gpu_comm_get_flag_value(struct rte_gpu_comm_flag *devflag, uint32_t *val) return 0; } + +struct rte_gpu_comm_list * +rte_gpu_comm_create_list(uint16_t dev_id, + uint32_t num_comm_items) +{ + struct rte_gpu_comm_list *comm_list; + uint32_t idx_l; + int ret; + struct rte_gpu *dev; + + if (num_comm_items == 0) { + rte_errno = EINVAL; + return NULL; + } + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "memory barrier for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return NULL; + } + + comm_list = rte_zmalloc(NULL, sizeof(struct rte_gpu_comm_list) * num_comm_items, 0); + if (comm_list == NULL) { + rte_errno = ENOMEM; + return NULL; + } + + ret = rte_gpu_register(dev_id, sizeof(struct rte_gpu_comm_list) * num_comm_items, comm_list); + if (ret < 0) { + rte_errno = ENOMEM; + return NULL; + } + + for (idx_l = 0; idx_l < num_comm_items; idx_l++) { + comm_list[idx_l].pkt_list = rte_zmalloc(NULL, sizeof(struct rte_gpu_comm_pkt) * RTE_GPU_COMM_LIST_PKTS_MAX, 0); + if (comm_list[idx_l].pkt_list == NULL) { + rte_errno = ENOMEM; + return NULL; + } + + ret = rte_gpu_register(dev_id, sizeof(struct rte_gpu_comm_pkt) * RTE_GPU_COMM_LIST_PKTS_MAX, comm_list[idx_l].pkt_list); + if (ret < 0) { + rte_errno = ENOMEM; + return NULL; + } + + RTE_GPU_VOLATILE(comm_list[idx_l].status) = RTE_GPU_COMM_LIST_FREE; + comm_list[idx_l].num_pkts = 0; + comm_list[idx_l].dev_id = dev_id; + + comm_list[idx_l].mbufs = rte_zmalloc(NULL, sizeof(struct rte_mbuf *) * RTE_GPU_COMM_LIST_PKTS_MAX, 0); + if (comm_list[idx_l].mbufs == NULL) { + rte_errno = ENOMEM; + return NULL; + } + } + + return comm_list; +} + +int +rte_gpu_comm_destroy_list(struct rte_gpu_comm_list *comm_list, + uint32_t num_comm_items) +{ + uint32_t idx_l; + int ret; + uint16_t dev_id; + + if (comm_list == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } + + dev_id = comm_list[0].dev_id; + + for (idx_l = 0; idx_l < num_comm_items; idx_l++) { + ret = rte_gpu_unregister(dev_id, comm_list[idx_l].pkt_list); + if (ret < 0) { + rte_errno = EINVAL; + return -1; + } + + rte_free(comm_list[idx_l].pkt_list); + rte_free(comm_list[idx_l].mbufs); + } + + ret = rte_gpu_unregister(dev_id, comm_list); + if (ret < 0) { + rte_errno = EINVAL; + return -1; + } + + rte_free(comm_list); + + return 0; +} + +int +rte_gpu_comm_populate_list_pkts(struct rte_gpu_comm_list *comm_list_item, + struct rte_mbuf **mbufs, uint32_t num_mbufs) +{ + uint32_t idx; + + if (comm_list_item == NULL || comm_list_item->pkt_list == NULL || + mbufs == NULL || num_mbufs > RTE_GPU_COMM_LIST_PKTS_MAX) { + rte_errno = EINVAL; + return -rte_errno; + } + + for (idx = 0; idx < num_mbufs; idx++) { + /* support only unchained mbufs */ + if (unlikely((mbufs[idx]->nb_segs > 1) || + (mbufs[idx]->next != NULL) || + (mbufs[idx]->data_len != mbufs[idx]->pkt_len))) { + rte_errno = ENOTSUP; + return -rte_errno; + } + comm_list_item->pkt_list[idx].addr = + rte_pktmbuf_mtod_offset(mbufs[idx], uintptr_t, 0); + comm_list_item->pkt_list[idx].size = mbufs[idx]->pkt_len; + comm_list_item->mbufs[idx] = mbufs[idx]; + } + + RTE_GPU_VOLATILE(comm_list_item->num_pkts) = num_mbufs; + rte_gpu_mbw(comm_list_item->dev_id); + RTE_GPU_VOLATILE(comm_list_item->status) = RTE_GPU_COMM_LIST_READY; + rte_gpu_mbw(comm_list_item->dev_id); + + return 0; +} + +int +rte_gpu_comm_cleanup_list(struct rte_gpu_comm_list *comm_list_item) +{ + uint32_t idx = 0; + + if (comm_list_item == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } + + if (RTE_GPU_VOLATILE(comm_list_item->status) == + RTE_GPU_COMM_LIST_READY) { + GPU_LOG(ERR, "packet list is still in progress"); + rte_errno = EINVAL; + return -rte_errno; + } + + for (idx = 0; idx < RTE_GPU_COMM_LIST_PKTS_MAX; idx++) { + if (comm_list_item->pkt_list[idx].addr == 0) + break; + + comm_list_item->pkt_list[idx].addr = 0; + comm_list_item->pkt_list[idx].size = 0; + comm_list_item->mbufs[idx] = NULL; + } + + RTE_GPU_VOLATILE(comm_list_item->status) = RTE_GPU_COMM_LIST_FREE; + RTE_GPU_VOLATILE(comm_list_item->num_pkts) = 0; + rte_mb(); + + return 0; +} diff --git a/lib/gpudev/meson.build b/lib/gpudev/meson.build index 608154817b..89a118f357 100644 --- a/lib/gpudev/meson.build +++ b/lib/gpudev/meson.build @@ -8,3 +8,5 @@ headers = files( sources = files( 'gpudev.c', ) + +deps += ['mbuf'] diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h index 1466ac164b..3023154be8 100644 --- a/lib/gpudev/rte_gpudev.h +++ b/lib/gpudev/rte_gpudev.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -41,6 +42,9 @@ extern "C" { /** Access variable as volatile. */ #define RTE_GPU_VOLATILE(x) (*(volatile typeof(x) *)&(x)) +/** Max number of packets per communication list. */ +#define RTE_GPU_COMM_LIST_PKTS_MAX 1024 + /** Store device info. */ struct rte_gpu_info { /** Unique identifier name. */ @@ -87,6 +91,43 @@ struct rte_gpu_comm_flag { enum rte_gpu_comm_flag_type mtype; }; +/** List of packets shared among CPU and device. */ +struct rte_gpu_comm_pkt { + /** Address of the packet in memory (e.g. mbuf->buf_addr). */ + uintptr_t addr; + /** Size in byte of the packet. */ + size_t size; +}; + +/** Possible status for the list of packets shared among CPU and device. */ +enum rte_gpu_comm_list_status { + /** Packet list can be filled with new mbufs, no one is using it. */ + RTE_GPU_COMM_LIST_FREE = 0, + /** Packet list has been filled with new mbufs and it's ready to be used .*/ + RTE_GPU_COMM_LIST_READY, + /** Packet list has been processed, it's ready to be freed. */ + RTE_GPU_COMM_LIST_DONE, + /** Some error occurred during packet list processing. */ + RTE_GPU_COMM_LIST_ERROR, +}; + +/** + * Communication list holding a number of lists of packets + * each having a status flag. + */ +struct rte_gpu_comm_list { + /** Device that will use the communication list. */ + uint16_t dev_id; + /** List of mbufs populated by the CPU with a set of mbufs. */ + struct rte_mbuf **mbufs; + /** List of packets populated by the CPU with a set of mbufs info. */ + struct rte_gpu_comm_pkt *pkt_list; + /** Number of packets in the list. */ + uint32_t num_pkts; + /** Status of the list. */ + enum rte_gpu_comm_list_status status; +}; + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. @@ -513,6 +554,94 @@ __rte_experimental int rte_gpu_comm_get_flag_value(struct rte_gpu_comm_flag *devflag, uint32_t *val); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Create a communication list that can be used to share packets + * between CPU and device. + * Each element of the list contains: + * - a packet list of RTE_GPU_COMM_LIST_PKTS_MAX elements + * - number of packets in the list + * - a status flag to communicate if the packet list is FREE, + * READY to be processed, DONE with processing. + * + * The list is allocated in CPU-visible memory. + * At creation time, every list is in FREE state. + * + * @param dev_id + * Reference device ID. + * @param num_comm_items + * Number of items in the communication list. + * + * @return + * A pointer to the allocated list, otherwise NULL and rte_errno is set: + * - EINVAL if invalid input params + */ +__rte_experimental +struct rte_gpu_comm_list *rte_gpu_comm_create_list(uint16_t dev_id, + uint32_t num_comm_items); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Destroy a communication list. + * + * @param comm_list + * Communication list to be destroyed. + * @param num_comm_items + * Number of items in the communication list. + * + * @return + * 0 on success, -rte_errno otherwise: + * - EINVAL if invalid input params + */ +__rte_experimental +int rte_gpu_comm_destroy_list(struct rte_gpu_comm_list *comm_list, + uint32_t num_comm_items); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Populate the packets list of the communication item + * with info from a list of mbufs. + * Status flag of that packet list is set to READY. + * + * @param comm_list_item + * Communication list item to fill. + * @param mbufs + * List of mbufs. + * @param num_mbufs + * Number of mbufs. + * + * @return + * 0 on success, -rte_errno otherwise: + * - EINVAL if invalid input params + * - ENOTSUP if mbufs are chained (multiple segments) + */ +__rte_experimental +int rte_gpu_comm_populate_list_pkts(struct rte_gpu_comm_list *comm_list_item, + struct rte_mbuf **mbufs, uint32_t num_mbufs); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Reset a communication list item to the original state. + * The status flag set to FREE and mbufs are returned to the pool. + * + * @param comm_list_item + * Communication list item to reset. + * + * @return + * 0 on success, -rte_errno otherwise: + * - EINVAL if invalid input params + */ +__rte_experimental +int rte_gpu_comm_cleanup_list(struct rte_gpu_comm_list *comm_list_item); + #ifdef __cplusplus } #endif diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map index 2fc039373a..45a35fa6e4 100644 --- a/lib/gpudev/version.map +++ b/lib/gpudev/version.map @@ -6,9 +6,13 @@ EXPERIMENTAL { rte_gpu_callback_register; rte_gpu_callback_unregister; rte_gpu_close; + rte_gpu_comm_cleanup_list; rte_gpu_comm_create_flag; + rte_gpu_comm_create_list; rte_gpu_comm_destroy_flag; + rte_gpu_comm_destroy_list; rte_gpu_comm_get_flag_value; + rte_gpu_comm_populate_list_pkts; rte_gpu_comm_set_flag; rte_gpu_count_avail; rte_gpu_find_next; -- 2.17.1