bitmap: add scan init at given position

Message ID 20230414083943.270651-1-vfialko@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series bitmap: add scan init at given position |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Volodymyr Fialko April 14, 2023, 8:39 a.m. UTC
  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 <vfialko@marvell.com>
---
 app/test/test_bitmap.c       | 23 +++++++++++++++++++++++
 lib/eal/include/rte_bitmap.h | 22 ++++++++++++++++++++++
 2 files changed, 45 insertions(+)
  

Comments

Thomas Monjalon June 1, 2023, 3:26 p.m. UTC | #1
Cristian, please could you review this patch?

14/04/2023 10:39, Volodymyr Fialko:
> 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 <vfialko@marvell.com>
[...]
> +__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;
> +}

It is supposed to be an internal (inlined) function
but it is not used.
  
Cristian Dumitrescu June 8, 2023, 2:20 p.m. UTC | #2
Hi Volodymyr,

Thanks for your patch, comments below under your code:

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Thursday, June 1, 2023 4:26 PM
> To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Volodymyr Fialko
> <vfialko@marvell.com>
> Cc: dev@dpdk.org; jerinj@marvell.com; anoobj@marvell.com
> Subject: Re: [PATCH] bitmap: add scan init at given position
> 
> Cristian, please could you review this patch?
> 
> 14/04/2023 10:39, Volodymyr Fialko:
> > 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 <vfialko@marvell.com>
> [...]
> > +__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;
> > +}
> 
> It is supposed to be an internal (inlined) function
> but it is not used.
> 

My understanding is your proposed procedure for scanning starting at an offset is:
1. Call the new function: __rte_bitmap_scan_init_at()
2. Call the regular function: rte_bitmap_scan()

I think this procedure is not ideal, therefore I suggest we create a new API function which has an additional offset argument:

	rte_bitmap_scan_from_offset(struct rte_bitmap *bmp, uint32_t offset, uint32_t *pos, uint64_t *slab).

Under the hood, the new API should call an internal function similar to yours to start the scan at a given offset (while aborting any scan that might be in progress). Makes sense?

BTW, do we need to declare the experimental functions defined in a header file to the library map file? I don't see this in the patch, but the patch seems to compile and link fine ...

Regards,
Cristian
  
Bruce Richardson June 8, 2023, 2:50 p.m. UTC | #3
On Thu, Jun 08, 2023 at 02:20:13PM +0000, Dumitrescu, Cristian wrote:
> Hi Volodymyr,
> 
> Thanks for your patch, comments below under your code:
> 
> > -----Original Message-----
> > From: Thomas Monjalon <thomas@monjalon.net>
> > Sent: Thursday, June 1, 2023 4:26 PM
> > To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Volodymyr Fialko
> > <vfialko@marvell.com>
> > Cc: dev@dpdk.org; jerinj@marvell.com; anoobj@marvell.com
> > Subject: Re: [PATCH] bitmap: add scan init at given position
> > 
> > Cristian, please could you review this patch?
> > 
> > 14/04/2023 10:39, Volodymyr Fialko:
> > > 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 <vfialko@marvell.com>
> > [...]
> > > +__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;
> > > +}
> > 
> > It is supposed to be an internal (inlined) function
> > but it is not used.
> > 
> 
> My understanding is your proposed procedure for scanning starting at an offset is:
> 1. Call the new function: __rte_bitmap_scan_init_at()
> 2. Call the regular function: rte_bitmap_scan()
> 
> I think this procedure is not ideal, therefore I suggest we create a new API function which has an additional offset argument:
> 
> 	rte_bitmap_scan_from_offset(struct rte_bitmap *bmp, uint32_t offset, uint32_t *pos, uint64_t *slab).
> 
> Under the hood, the new API should call an internal function similar to yours to start the scan at a given offset (while aborting any scan that might be in progress). Makes sense?
> 
> BTW, do we need to declare the experimental functions defined in a header file to the library map file? I don't see this in the patch, but the patch seems to compile and link fine ...
> 
Inline functions in headers are not real "functions" in the output code, as
they get inlined into the caller. Therefore, they have no entries in the
version.map file, since they don't exist in the compiled object code.

/Bruce
  
Volodymyr Fialko June 12, 2023, 10:58 a.m. UTC | #4
Hi Cristian,

<snip>
> 
> My understanding is your proposed procedure for scanning starting at an offset is:
> 1. Call the new function: __rte_bitmap_scan_init_at() 2. Call the regular function: rte_bitmap_scan()
> 
> I think this procedure is not ideal, therefore I suggest we create a new API function which has an
> additional offset argument:
> 
> 	rte_bitmap_scan_from_offset(struct rte_bitmap *bmp, uint32_t offset, uint32_t *pos,
> uint64_t *slab).
> 
> Under the hood, the new API should call an internal function similar to yours to start the scan at a
> given offset (while aborting any scan that might be in progress). Makes sense?
> 
> BTW, do we need to declare the experimental functions defined in a header file to the library map
> file? I don't see this in the patch, but the patch seems to compile and link fine ...
> 
> Regards,
> Cristian

I like the suggested idea to add ` rte_bitmap_scan_from_offset ` API. I will implement it in the next version.
  

Patch

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
  *