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 96C434293E; Fri, 14 Apr 2023 10:39:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6EC74410F6; Fri, 14 Apr 2023 10:39:55 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 8CCE6400D5 for ; Fri, 14 Apr 2023 10:39:53 +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 33E0tCwF025323; Fri, 14 Apr 2023 01:39:52 -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=ycM8vuK3Ey8rp70sNcxE+E48av8t4f9E2Zp8ORQialc=; b=Jt2O4QR6Gd2liq/lL4AL2MFNPG14puQ4HQnfutPe6/5w5aXBG98x0aDn8xzoeLSE5MV4 IgVpGmm9358cPTjynnXKk4QVGTtoyAKCuT8xYB/aoooJ4CFMQtwNQ8sJFVw6fZJtafez fFVgnDWtuW5mJlfPeVgvUA9rXgxCaU3QjbYuz6kEBFKfim+VuV5botxocA1ZIU8IGUYz 1GIm76HTF+WP1ZbtDGYoCchoWHIgsaDk9cf3u33LsZTZsqIzM2RJV8tQDMe1YHRuekrX D8EqEUtlZNAa0KKZsSN1cmX5OGpt+YOEJZEPBhzUv+Q7uYH9fb+DSNvNf2RDQ/XXZ3Ok AQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3px3fwg2s8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 14 Apr 2023 01:39:52 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 14 Apr 2023 01:39:50 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 14 Apr 2023 01:39:50 -0700 Received: from cavium-DT10.. (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id 4EBFA3F7044; Fri, 14 Apr 2023 01:39:48 -0700 (PDT) From: Volodymyr Fialko To: , Cristian Dumitrescu CC: , , Volodymyr Fialko Subject: [PATCH] bitmap: add scan init at given position Date: Fri, 14 Apr 2023 10:39:43 +0200 Message-ID: <20230414083943.270651-1-vfialko@marvell.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: p2y03KXf3B5JMsYRv5QMrXt6_Trwl4Yk X-Proofpoint-GUID: p2y03KXf3B5JMsYRv5QMrXt6_Trwl4Yk 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 Currently, in the case when we search for a bit set after a particular value, the bitmap has to be scanned from the beginning and rte_bitmap_scan() has to be called multiple times until we hit the value. Add a new __rte_bitmap_scan_init_at() function to initialize scan state at the given position, this will allow getting the next bit set after some value within one rte_bitmap_scan() call. Signed-off-by: Volodymyr Fialko --- app/test/test_bitmap.c | 23 +++++++++++++++++++++++ lib/eal/include/rte_bitmap.h | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/app/test/test_bitmap.c b/app/test/test_bitmap.c index e9c61590ae..69ff7262f3 100644 --- a/app/test/test_bitmap.c +++ b/app/test/test_bitmap.c @@ -71,6 +71,29 @@ test_bitmap_scan_operations(struct rte_bitmap *bmp) return TEST_FAILED; } + /* Scan reset with count check. */ + __rte_bitmap_scan_init_at(bmp, pos + RTE_BITMAP_SLAB_BIT_SIZE); + if (!rte_bitmap_scan(bmp, &pos, &out_slab)) { + printf("Failed to get slab from bitmap.\n"); + return TEST_FAILED; + } + + if (slab2_magic != out_slab) { + printf("Scan init at operation failed.\n"); + return TEST_FAILED; + } + + __rte_bitmap_scan_init_at(bmp, pos + 2 * RTE_BITMAP_SLAB_BIT_SIZE); + if (!rte_bitmap_scan(bmp, &pos, &out_slab)) { + printf("Failed to get slab from bitmap.\n"); + return TEST_FAILED; + } + + if (slab1_magic != out_slab) { + printf("Scan init at operation failed.\n"); + return TEST_FAILED; + } + /* Test scan when a cline is half full */ rte_bitmap_reset(bmp); for (i = 0; i < MAX_BITS; i++) diff --git a/lib/eal/include/rte_bitmap.h b/lib/eal/include/rte_bitmap.h index 27ee3d18a4..54a986aa8f 100644 --- a/lib/eal/include/rte_bitmap.h +++ b/lib/eal/include/rte_bitmap.h @@ -137,6 +137,28 @@ __rte_bitmap_scan_init(struct rte_bitmap *bmp) bmp->go2 = 0; } +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Bitmap initialize internal scan pointers at the given position for the scan function. + * @see rte_bitmap_scan() + * + * @param bmp + * Handle to bitmap instance + * @param pos + * Bit position to start scan + */ +__rte_experimental +static inline void +__rte_bitmap_scan_init_at(struct rte_bitmap *bmp, uint32_t pos) +{ + bmp->index1 = pos >> (RTE_BITMAP_SLAB_BIT_SIZE_LOG2 + RTE_BITMAP_CL_BIT_SIZE_LOG2); + bmp->offset1 = (pos >> RTE_BITMAP_CL_BIT_SIZE_LOG2) & RTE_BITMAP_SLAB_BIT_MASK; + bmp->index2 = pos >> RTE_BITMAP_SLAB_BIT_SIZE_LOG2; + bmp->go2 = 1; +} + /** * Bitmap memory footprint calculation * -- 2.34.1