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 77883A0C43; Fri, 8 Oct 2021 19:44:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9CA2741144; Fri, 8 Oct 2021 19:43:49 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2053.outbound.protection.outlook.com [40.107.243.53]) by mails.dpdk.org (Postfix) with ESMTP id 4CF184111B for ; Fri, 8 Oct 2021 19:43:48 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kj7+I5xxo5z5vF9nU27z3r0TzgRxFot5/DvLyoCNzAPNeACCTQl6VEKxNtcxfYmyPAes7S97f/NwZSRrSAg/6oPN/GuP47Z9hq2DELGDlbOKUCByKnIfLSbEhp961tP3XB3rYFHxbEYEfsrY4a0vrNkkYZ6Lq9JEFRfBCD2CTKX1oHyI8XM7xLMOAMh6WcPm3CXkvXJLH2h1wi8BMK8+RR4w/H1U3QoO0K39nLxpoag5BjBVNZ3dMClL6c/x+AuzqDH6vauMhXfrISoz/eFQ25bdPP2x3k+1F/RzUBN1X0uzLrzr+6uB6R+eiWbjVYpgpfFvLjaZF+dLmhXgtf4Z9g== 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=s/WBxikyjDTAI7mZnrXEdxFV5ugiZjp9vYBgnidbAAQ=; b=aLycI1AASeoKuB5A/HgifMcJBu0M4N9iGPaPxQxnHBAj39X++Ia1Z352IFdVjiPARuef1L5Vpjg3oF1C1yjeSfGi5vH8ITrcy+FGdooODwa0TpOdEc5x4r4kCQCU+LeGclMfURz+MnD2+TEq8dp6mrmJpTXeniBafwebCxf7o3eaqIm7sNzPwYW8tVGQ1BO5/n6q84gal1rRqYh42ZkYLgAjHVRklkGG/RNU4sy8JFx1UPmrmMCA2LzI8XT79ZQE0cM2RjTrZWHMxLrMGjULY2pnPW7w9EHAKXTQOoIBEEth3NDDYDWgl3rER8lR+Lhf7eGVcc4m2TIwsbz3c1OrqQ== 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=none 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=s/WBxikyjDTAI7mZnrXEdxFV5ugiZjp9vYBgnidbAAQ=; b=G+rp4mS6eDVbcTu4qq39AASDfTUNztTxSOX6WfWT/usKhJcKw1EMtrIlSxf0THHNGNfzGQ0xrnFRo9zHCoM7XVoOZcUpFUXZT7I33wYYV6Ia/6tiCoqV8EyI5GqTUkuR6zR5OrDS7HRG2zfEO8eNtEZOCeDbuGNiwpZW+VYMrml7YUeuoxKoZ/kwb0cQbUWW5jRyt7ReNj8N6COhGXAqsGhEIRSToTUNvQH70qfQxa0lweg9iuUIDEXIagFT6zV9t7U7TYN6ckqSyi1I4AMRpq733SLMf0jbBs/+454mD8+kq1iJoaQCfEiCINf1hwLd1DJapKCxG/3sYpBM2CJWng== Received: from MW4PR03CA0121.namprd03.prod.outlook.com (2603:10b6:303:8c::6) by MN2PR12MB3485.namprd12.prod.outlook.com (2603:10b6:208:c9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Fri, 8 Oct 2021 17:43:46 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::3d) by MW4PR03CA0121.outlook.office365.com (2603:10b6:303:8c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Fri, 8 Oct 2021 17:43:46 +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 CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4587.18 via Frontend Transport; Fri, 8 Oct 2021 17:43:46 +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; Fri, 8 Oct 2021 17:43:41 +0000 From: To: CC: Elena Agostini Date: Sat, 9 Oct 2021 01:53:48 +0000 Message-ID: <20211009015349.9694-9-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211009015349.9694-1-eagostini@nvidia.com> References: <20210602203531.2288645-1-thomas@monjalon.net> <20211009015349.9694-1-eagostini@nvidia.com> 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 HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 296d36d5-e2f5-4430-6a74-08d98a832dbd X-MS-TrafficTypeDiagnostic: MN2PR12MB3485: 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: BPx+UCI4Ug7vUdM8CRIdfoxwG/UMtY58XtwVDdWL9rT6ZQR0U4e2Qi9T6QVbakP48XlvLXxXX0YXvycDUyf8PlkkOOCOIJdCL7uA2piiVJveDiBwEYetWLjCtsvjSPulKaCRUe1thOmlymWWDgUIjt6uokTMau9o++ZwpJwEd0i6SuLuBpU1poZdAKLvrUl0yxd0DbhPDdbCG4KoUywVPGaJdALF5w88KI7VB7t2bU1FtO8WNzFBv6XnEW+AH2IxuCYS1VQ7EurT2F+6rYNWaAyAEADuaHTSSTtjydvaktrJYRDIxAxZuwjFsUO9q2WFm+CtoJQDkZ38DSGHVS0suyXVNnzfuQr31YMhudWwCC0SKGeW5E/I8N61qSsK1OD2WK+Ek+Ycd6waEQyMgbFLRhSe9e4V3KJFsFzS1npV8vw7xPmqjFAinmiw/p8HXQKTBX9ABCdpECwSlriGiuk6226NVvA1gGSTjIwDtsQycNrvzyPybAceiRYalhkt7QkA+lun6hyzIQGvkNLWw1rCRm1wN7xi7YLkq71pN27QAD9rkaU/JGhNCa25ebXggOwAP8HJGBb/UdOfQIQXwzGNn8sca0K2w8qM+mZpDPx41vVSng81/D2T1an1jJTnqfx1YJ7/JCJCIZA32QdMyC6bRylTksYyMNovTTbUWOyGrRhA7dOLLGjNnQvzqJV58c4DKoRrrl2AFiR6F3eesCHk3A== 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)(36860700001)(508600001)(86362001)(55016002)(7696005)(30864003)(316002)(8936002)(6286002)(70586007)(70206006)(107886003)(8676002)(426003)(83380400001)(336012)(36756003)(186003)(82310400003)(5660300002)(356005)(6916009)(7636003)(26005)(4326008)(16526019)(2616005)(47076005)(2876002)(2906002)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2021 17:43:46.1323 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 296d36d5-e2f5-4430-6a74-08d98a832dbd 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: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3485 Subject: [dpdk-dev] [PATCH v3 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 | 103 +++++++++++++++ doc/guides/prog_guide/gpudev.rst | 16 +++ doc/guides/rel_notes/release_21_11.rst | 2 +- lib/gpudev/gpudev.c | 165 +++++++++++++++++++++++++ lib/gpudev/meson.build | 2 + lib/gpudev/rte_gpudev.h | 129 +++++++++++++++++++ lib/gpudev/version.map | 4 + 7 files changed, 420 insertions(+), 1 deletion(-) diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c index 22f5c950b2..8f7ffa4c63 100644 --- a/app/test-gpudev/main.c +++ b/app/test-gpudev/main.c @@ -227,6 +227,108 @@ 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) { @@ -282,6 +384,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 59ab1a1920..0c6d92a269 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -66,7 +66,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 827e29d8f6..3cfde97e3c 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -737,3 +737,168 @@ 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; + } + + 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); + } + + 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->pkt_list[idx].opaque = 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) +{ + struct rte_mbuf *mbufs[RTE_GPU_COMM_LIST_PKTS_MAX]; + 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; + mbufs[idx] = (struct rte_mbuf *) comm_list_item->pkt_list[idx].opaque; + } + + rte_pktmbuf_free_bulk(mbufs, idx); + + 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 4a10a8bcf5..a13a4fc2c8 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; + /** Mbuf reference to release it in the rte_gpu_comm_cleanup_list(). */ + void *opaque; +}; + +/** 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 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