From: Suanming Mou <suanmingm@mellanox.com>
To: Thomas Monjalon <thomas@monjalon.net>, "dev@dpdk.org" <dev@dpdk.org>
Cc: "amo@semihalf.com" <amo@semihalf.com>,
Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Subject: Re: [dpdk-dev] [PATCH v4] bitmap: add init with all bits set
Date: Wed, 15 Apr 2020 14:22:50 +0000 [thread overview]
Message-ID: <HE1PR05MB3484BFF32847DB09149A2BEACCDB0@HE1PR05MB3484.eurprd05.prod.outlook.com> (raw)
In-Reply-To: <20200415141529.2057898-1-thomas@monjalon.net>
Hi Thomas,
Thanks for the update.
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Wednesday, April 15, 2020 10:15 PM
> To: dev@dpdk.org
> Cc: amo@semihalf.com; Suanming Mou <suanmingm@mellanox.com>; Cristian
> Dumitrescu <cristian.dumitrescu@intel.com>
> Subject: [PATCH v4] bitmap: add init with all bits set
>
> From: Suanming Mou <suanmingm@mellanox.com>
>
> 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 <suanmingm@mellanox.com>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Reviewed-by: Suanming Mou <suanmingm@mellanox.com>
> ---
>
> v4:
> - add experimental tags and comments
> - move functions near original init function
> - squash test patch
> - use "init" word in title
>
> v3 updates:
> 1. Implement individual rte_bitmap_init_with_all_set() function.
> 2. Add new function to clear the overhead bits.
>
> v2 updates:
> 1. Split the common part to __rte_bitmap_init().
> 2. Set the slab bits more customized.
>
> ---
> app/test/test_bitmap.c | 57 ++++++++++++++++++-
> lib/librte_eal/include/rte_bitmap.h | 85 +++++++++++++++++++++++++++++
> 2 files changed, 141 insertions(+), 1 deletion(-)
>
> diff --git a/app/test/test_bitmap.c b/app/test/test_bitmap.c index
> 95c5184882..a8204d329f 100644
> --- a/app/test/test_bitmap.c
> +++ b/app/test/test_bitmap.c
> @@ -146,7 +146,7 @@ test_bitmap_set_get_clear(struct rte_bitmap *bmp) }
>
> static int
> -test_bitmap(void)
> +test_bitmap_all_clear(void)
> {
> void *mem;
> uint32_t bmp_size;
> @@ -182,4 +182,59 @@ test_bitmap(void)
> return TEST_SUCCESS;
> }
>
> +static int
> +test_bitmap_all_set(void)
> +{
> + void *mem;
> + uint32_t i;
> + uint64_t slab;
> + uint32_t pos;
> + uint32_t bmp_size;
> + struct rte_bitmap *bmp;
> +
> + bmp_size =
> + rte_bitmap_get_memory_footprint(MAX_BITS);
> +
> + mem = rte_zmalloc("test_bmap", bmp_size, RTE_CACHE_LINE_SIZE);
> + if (mem == NULL) {
> + printf("Failed to allocate memory for bitmap\n");
> + return TEST_FAILED;
> + }
> +
> + bmp = rte_bitmap_init_with_all_set(MAX_BITS, mem, bmp_size);
> + if (bmp == NULL) {
> + printf("Failed to init bitmap\n");
> + return TEST_FAILED;
> + }
> +
> + for (i = 0; i < MAX_BITS; i++) {
> + pos = slab = 0;
> + if (!rte_bitmap_scan(bmp, &pos, &slab)) {
> + printf("Failed with init bitmap.\n");
> + return TEST_FAILED;
> + }
> + pos += (slab ? __builtin_ctzll(slab) : 0);
> + rte_bitmap_clear(bmp, pos);
> + }
> +
> + if (rte_bitmap_scan(bmp, &pos, &slab)) {
> + printf("Too much bits set.\n");
> + return TEST_FAILED;
> + }
> +
> + rte_bitmap_free(bmp);
> + rte_free(mem);
> +
> + return TEST_SUCCESS;
> +
> +}
> +
> +static int
> +test_bitmap(void)
> +{
> + if (test_bitmap_all_clear() != TEST_SUCCESS)
> + return TEST_FAILED;
> + return test_bitmap_all_set();
> +}
> +
> REGISTER_TEST_COMMAND(bitmap_test, test_bitmap); diff --git
> a/lib/librte_eal/include/rte_bitmap.h b/lib/librte_eal/include/rte_bitmap.h
> index 6b846f251b..7c90ef333f 100644
> --- a/lib/librte_eal/include/rte_bitmap.h
> +++ b/lib/librte_eal/include/rte_bitmap.h
> @@ -203,6 +203,91 @@ rte_bitmap_init(uint32_t n_bits, uint8_t *mem,
> uint32_t mem_size)
> return bmp;
> }
>
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this API may change without prior notice.
> + *
> + * Bitmap clear slab overhead bits.
> + *
> + * @param slabs
> + * Slab array.
> + * @param slab_size
> + * Number of 64-bit slabs in the slabs array.
> + * @param pos
> + * The start bit position in the slabs to be cleared.
> + */
> +__rte_experimental
> +static inline void
> +__rte_bitmap_clear_slab_overhead_bits(uint64_t *slabs, uint32_t slab_size,
> + uint32_t pos)
> +{
> + uint32_t i;
> + uint32_t index = pos / RTE_BITMAP_SLAB_BIT_SIZE;
> + uint32_t offset = pos & RTE_BITMAP_SLAB_BIT_MASK;
> +
> + if (offset) {
> + for (i = offset; i < RTE_BITMAP_SLAB_BIT_SIZE; i++)
> + slabs[index] &= ~(1llu << i);
> + index++;
> + }
> + if (index < slab_size)
> + memset(&slabs[index], 0, sizeof(slabs[0]) *
> + (slab_size - index));
> +}
> +
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this API may change without prior notice.
> + *
> + * 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.
> + */
> +__rte_experimental
> +static inline struct rte_bitmap *
> +rte_bitmap_init_with_all_set(uint32_t n_bits, uint8_t *mem, uint32_t
> +mem_size) {
> + struct rte_bitmap *bmp;
> + uint32_t array1_byte_offset, array1_slabs;
> + uint32_t array2_byte_offset, array2_slabs;
> + uint32_t size;
> +
> + /* Check input arguments */
> + if (!n_bits || !mem || (((uintptr_t) mem) & RTE_CACHE_LINE_MASK))
> + return NULL;
> +
> + size = __rte_bitmap_get_memory_footprint(n_bits,
> + &array1_byte_offset, &array1_slabs,
> + &array2_byte_offset, &array2_slabs);
> + if (size < mem_size)
> + return NULL;
> +
> + /* Setup bitmap */
> + bmp = (struct rte_bitmap *) mem;
> + bmp->array1 = (uint64_t *) &mem[array1_byte_offset];
> + bmp->array1_size = array1_slabs;
> + bmp->array2 = (uint64_t *) &mem[array2_byte_offset];
> + bmp->array2_size = array2_slabs;
> +
> + __rte_bitmap_scan_init(bmp);
> +
> + memset(bmp->array1, 0xff, bmp->array1_size * sizeof(bmp->array1[0]));
> + memset(bmp->array2, 0xff, bmp->array2_size * sizeof(bmp->array2[0]));
> + /* Clear overhead bits. */
> + __rte_bitmap_clear_slab_overhead_bits(bmp->array1, bmp-
> >array1_size,
> + bmp->array2_size >>
> RTE_BITMAP_CL_SLAB_SIZE_LOG2);
> + __rte_bitmap_clear_slab_overhead_bits(bmp->array2, bmp-
> >array2_size,
> + n_bits);
> + return bmp;
> +}
> +
> /**
> * Bitmap free
> *
> --
> 2.26.0
next prev parent reply other threads:[~2020-04-15 14:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-10 8:21 [dpdk-dev] [PATCH 0/2] bitmap: add create bitmap " Suanming Mou
2020-03-10 8:21 ` [dpdk-dev] [PATCH 1/2] " Suanming Mou
2020-04-03 14:49 ` Andrzej Ostruszka
2020-04-07 6:19 ` Suanming Mou
2020-04-07 15:00 ` Suanming Mou
2020-04-07 17:48 ` Dumitrescu, Cristian
2020-04-08 2:57 ` Suanming Mou
2020-03-10 8:21 ` [dpdk-dev] [PATCH 2/2] test/bitmap: add bitmap create with all bits set case Suanming Mou
2020-03-25 13:25 ` [dpdk-dev] [PATCH 0/2] bitmap: add create bitmap with all bits set Thomas Monjalon
2020-04-02 13:44 ` Suanming Mou
2020-04-08 3:05 ` [dpdk-dev] [PATCH v2 " Suanming Mou
2020-04-08 3:05 ` [dpdk-dev] [PATCH v2 1/2] " Suanming Mou
2020-04-09 14:16 ` Dumitrescu, Cristian
2020-04-10 10:34 ` Suanming Mou
2020-04-10 11:21 ` Dumitrescu, Cristian
2020-04-10 12:30 ` Suanming Mou
2020-04-08 3:05 ` [dpdk-dev] [PATCH v2 2/2] test/bitmap: add bitmap create with all bits set case Suanming Mou
2020-04-10 12:46 ` [dpdk-dev] [PATCH v3 0/2] bitmap: add create bitmap with all bits set Suanming Mou
2020-04-10 12:46 ` [dpdk-dev] [PATCH v3 1/2] " Suanming Mou
2020-04-10 16:04 ` Dumitrescu, Cristian
2020-04-10 12:46 ` [dpdk-dev] [PATCH v3 2/2] test/bitmap: add bitmap create with all bits set case Suanming Mou
2020-04-15 14:15 ` [dpdk-dev] [PATCH v4] bitmap: add init with all bits set Thomas Monjalon
2020-04-15 14:22 ` Suanming Mou [this message]
2020-04-15 14:42 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=HE1PR05MB3484BFF32847DB09149A2BEACCDB0@HE1PR05MB3484.eurprd05.prod.outlook.com \
--to=suanmingm@mellanox.com \
--cc=amo@semihalf.com \
--cc=cristian.dumitrescu@intel.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).