From patchwork Fri Apr 14 08:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Fialko X-Patchwork-Id: 126074 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 7478C4293E; Fri, 14 Apr 2023 10:53:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 628A0410FA; Fri, 14 Apr 2023 10:53:00 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id D89DA410FA for ; Fri, 14 Apr 2023 10:52:58 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33E6n4cP028158; Fri, 14 Apr 2023 01:52:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=mf2NnbOKjQyWmnNZWaUexoMV1PCREpC/i0fU+t3j1Xw=; b=NrFcjOP8IWtDxaY+u76RR5TsQA6uY1khq0oR3TNkfvWo0LbwYbdVpAaQI0m7k7rOVMRs mFXfWJmBOj8GgCflIPG/sP3CsWExQAiJZwQ96tByid++Z0fR/DKBYEjxggjerSkMj8RU JfYP6Zo9nKwwhIlrlWmSc1fYLJ7rDshZmgnoNCUytEKVpAH1zkOWTLH4zzUJYoClQa+2 LGcysLq15IPPVbKQKALu99f+GymCr91jELGXBv2bGbnA16OEt1bT6vbRRFthsnisxDQL gEFOuSd2PXGzkgtUyVOzOgD+H24VZUBNe0V9y96mw5ztM6t9t1sjn/VPvioLZozWpvZD IQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3px3fwg3k5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 14 Apr 2023 01:52:58 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 14 Apr 2023 01:52:55 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 14 Apr 2023 01:52:55 -0700 Received: from cavium-DT10.. (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id 08A5C3F7044; Fri, 14 Apr 2023 01:52:53 -0700 (PDT) From: Volodymyr Fialko To: , Reshma Pattan CC: , , Volodymyr Fialko Subject: [PATCH] reorder: introduce API to obtain memory footprint Date: Fri, 14 Apr 2023 10:52:51 +0200 Message-ID: <20230414085251.272062-1-vfialko@marvell.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: _7QUBueXhSC5uwfJSMagHKDOED4GXdU1 X-Proofpoint-GUID: _7QUBueXhSC5uwfJSMagHKDOED4GXdU1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-14_03,2023-04-13_01,2023-02-09_01 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 At present, it is not easy to determine the memory requirement for the reorder buffer without delving into its implementation details. To facilitate the use of reorder buffer with user allocation, a new API `rte_reorder_memory_footprint_get()` is introduced. This API will provide the amount of required memory for reorder buffer. Signed-off-by: Volodymyr Fialko --- app/test/test_reorder.c | 8 ++++---- lib/reorder/rte_reorder.c | 13 +++++++++---- lib/reorder/rte_reorder.h | 16 ++++++++++++++++ lib/reorder/version.map | 2 ++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/test/test_reorder.c b/app/test/test_reorder.c index f391597a78..6daa913ef9 100644 --- a/app/test/test_reorder.c +++ b/app/test/test_reorder.c @@ -68,12 +68,12 @@ test_reorder_init(void) struct rte_reorder_buffer *b = NULL; unsigned int size; /* - * The minimum memory area size that should be passed to library is, - * sizeof(struct rte_reorder_buffer) + (2 * size * sizeof(struct rte_mbuf *)); + * The minimum memory area size that should be passed to library determined + * by rte_reorder_memory_footprint_get(). * Otherwise error will be thrown */ - size = 100; + size = rte_reorder_memory_footprint_get(REORDER_BUFFER_SIZE) - 1; b = rte_reorder_init(b, size, "PKT1", REORDER_BUFFER_SIZE); TEST_ASSERT((b == NULL) && (rte_errno == EINVAL), "No error on init with NULL buffer."); @@ -84,7 +84,7 @@ test_reorder_init(void) "No error on init with invalid mem zone size."); rte_free(b); - size = 262336; + size = rte_reorder_memory_footprint_get(REORDER_BUFFER_SIZE); b = rte_malloc(NULL, size, 0); b = rte_reorder_init(b, size, "PKT1", REORDER_BUFFER_SIZE_INVALID); TEST_ASSERT((b == NULL) && (rte_errno == EINVAL), diff --git a/lib/reorder/rte_reorder.c b/lib/reorder/rte_reorder.c index 66d2cc07b7..f55f383700 100644 --- a/lib/reorder/rte_reorder.c +++ b/lib/reorder/rte_reorder.c @@ -54,12 +54,17 @@ struct rte_reorder_buffer { static void rte_reorder_free_mbufs(struct rte_reorder_buffer *b); +unsigned int +rte_reorder_memory_footprint_get(unsigned int size) +{ + return sizeof(struct rte_reorder_buffer) + (2 * size * sizeof(struct rte_mbuf *)); +} + struct rte_reorder_buffer * rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize, const char *name, unsigned int size) { - const unsigned int min_bufsize = sizeof(*b) + - (2 * size * sizeof(struct rte_mbuf *)); + const unsigned int min_bufsize = rte_reorder_memory_footprint_get(size); static const struct rte_mbuf_dynfield reorder_seqn_dynfield_desc = { .name = RTE_REORDER_SEQN_DYNFIELD_NAME, .size = sizeof(rte_reorder_seqn_t), @@ -148,8 +153,8 @@ rte_reorder_create(const char *name, unsigned socket_id, unsigned int size) { struct rte_reorder_buffer *b = NULL; struct rte_tailq_entry *te, *te_inserted; - const unsigned int bufsize = sizeof(struct rte_reorder_buffer) + - (2 * size * sizeof(struct rte_mbuf *)); + + const unsigned int bufsize = rte_reorder_memory_footprint_get(size); /* Check user arguments. */ if (!rte_is_power_of_2(size)) { diff --git a/lib/reorder/rte_reorder.h b/lib/reorder/rte_reorder.h index 9a5998f2f6..16dc4ee400 100644 --- a/lib/reorder/rte_reorder.h +++ b/lib/reorder/rte_reorder.h @@ -212,6 +212,22 @@ __rte_experimental unsigned int rte_reorder_min_seqn_set(struct rte_reorder_buffer *b, rte_reorder_seqn_t min_seqn); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Determine the amount of memory needed by the reorder buffer to accommodate a given number of + * elements. @see rte_reorder_init() + * + * @param size + * Number of elements that can be stored in reorder buffer. + * @return + * Reorder buffer footprint measured in bytes. + */ +__rte_experimental +unsigned int +rte_reorder_memory_footprint_get(unsigned int size); + #ifdef __cplusplus } #endif diff --git a/lib/reorder/version.map b/lib/reorder/version.map index e21b91f526..7ff6a622f4 100644 --- a/lib/reorder/version.map +++ b/lib/reorder/version.map @@ -19,4 +19,6 @@ EXPERIMENTAL { # added in 23.03 rte_reorder_drain_up_to_seqn; rte_reorder_min_seqn_set; + # added in 23.07 + rte_reorder_memory_footprint_get; };