From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 04577A0563; Tue, 10 Mar 2020 09:21:34 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F01B71C020; Tue, 10 Mar 2020 09:21:26 +0100 (CET) Received: from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130]) by dpdk.org (Postfix) with ESMTP id 377F81C002 for ; Tue, 10 Mar 2020 09:21:25 +0100 (CET) From: Suanming Mou To: cristian.dumitrescu@intel.com Cc: dev@dpdk.org Date: Tue, 10 Mar 2020 16:21:18 +0800 Message-Id: <1583828479-204084-2-git-send-email-suanmingm@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1583828479-204084-1-git-send-email-suanmingm@mellanox.com> References: <1583828479-204084-1-git-send-email-suanmingm@mellanox.com> Subject: [dpdk-dev] [PATCH 1/2] bitmap: add create bitmap with all bits set X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Currently, in the case to use bitmap as resource allocator, after bitmap creation, all the bitmap bits should be set to indicate the bit available. Every time when allocate one bit, search for the set bits and clear it to make it in use. Add a new rte_bitmap_init_with_all_set() function to have a quick fill up the bitmap bits. Comparing with the case create the bitmap as empty and set the bitmap one by one, the new function costs less cycles. Signed-off-by: Suanming Mou --- lib/librte_eal/common/include/rte_bitmap.h | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/librte_eal/common/include/rte_bitmap.h b/lib/librte_eal/common/include/rte_bitmap.h index 6b846f2..36b32e4 100644 --- a/lib/librte_eal/common/include/rte_bitmap.h +++ b/lib/librte_eal/common/include/rte_bitmap.h @@ -483,6 +483,38 @@ struct rte_bitmap { return 0; } +/** + * Bitmap initialization with all bits set + * + * @param n_bits + * Number of pre-allocated bits in array2. + * @param mem + * Base address of array1 and array2. + * @param mem_size + * Minimum expected size of bitmap. + * @return + * Handle to bitmap instance. + */ +static inline struct rte_bitmap * +rte_bitmap_init_with_all_set(uint32_t n_bits, uint8_t *mem, uint32_t mem_size) +{ + uint32_t i; + uint32_t slabs = n_bits / RTE_BITMAP_SLAB_BIT_SIZE; + struct rte_bitmap *bmp = rte_bitmap_init(n_bits, mem, mem_size); + + if (!bmp) + return NULL; + /* Fill the arry2 byte aligned bits. */ + memset(bmp->array2, 0xff, slabs * sizeof(bmp->array2[0])); + /* Fill the arry1 bits. */ + for (i = 0; i < n_bits; i += RTE_BITMAP_CL_BIT_SIZE) + rte_bitmap_set(bmp, i); + /* Fill the arry2 left not byte aligned bits. */ + for (i = slabs * RTE_BITMAP_SLAB_BIT_SIZE; i < n_bits; i++) + rte_bitmap_set(bmp, i); + return bmp; +} + #ifdef __cplusplus } #endif -- 1.8.3.1