Skip to contentSkip to conversation

test/bitmap: add test case to scan after half cline is cleared

PATCH Superseded Nithin Dabilpuram 3 participants 6 messages Dec 14, 2020 – Jan 17, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 test/bitmap: add test case to scan after half cline is cleared

Add a test case to test scan operation post clear of half cacheline of slabs.

Also fix meson.build to include test_bitmap.c in the compilation.

---
 app/test/meson.build   |  1 +
 app/test/test_bitmap.c | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
app/test/meson.build +1 -0
index 94fd39f..bb06a92 100644
@@ -13,6 +13,7 @@ test_sources = files('commands.c',
 	'test_atomic.c',
 	'test_barrier.c',
 	'test_bitops.c',
+	'test_bitmap.c',
 	'test_bpf.c',
 	'test_byteorder.c',
 	'test_cmdline.c',
app/test/test_bitmap.c +33 -1
index a8204d3..70d8fff 100644
@@ -16,9 +16,10 @@
 static int
 test_bitmap_scan_operations(struct rte_bitmap *bmp)
 {
-	uint32_t pos = 0;
 	uint64_t slab1_magic = 0xBADC0FFEEBADF00D;
 	uint64_t slab2_magic = 0xFEEDDEADDEADF00D;
+	uint32_t pos = 0, start_pos;
+	int i, nb_clear, nb_set;
 	uint64_t out_slab = 0;
 
 	rte_bitmap_reset(bmp);
@@ -70,6 +71,37 @@ test_bitmap_scan_operations(struct rte_bitmap *bmp)
 		return TEST_FAILED;
 	}
 
+	/* Test scan when a cline is half full */
+	rte_bitmap_reset(bmp);
+	for (i = 0; i < MAX_BITS; i++)
+		rte_bitmap_set(bmp, i);
+
+	nb_clear = RTE_MIN(RTE_BITMAP_CL_BIT_SIZE / 2, MAX_BITS);
+	for (i = 0; i < nb_clear; i++)
+		rte_bitmap_clear(bmp, i);
+
+	/* Find remaining bits set in bmp */
+	__rte_bitmap_scan_init(bmp);
+
+	if (rte_bitmap_scan(bmp, &pos, &out_slab) != 1) {
+		printf("Initial scan failed with half CL empty.\n");
+		return TEST_FAILED;
+	}
+
+	start_pos = pos;
+	nb_set = 0;
+	do {
+		nb_set += __builtin_popcountll(out_slab);
+		if (!rte_bitmap_scan(bmp, &pos, &out_slab))
+			break;
+	} while (pos != start_pos);
+
+	if ((nb_clear + nb_set) != MAX_BITS) {
+		printf("Scan failed to find all set bits. "
+		       "Expected %u, found %u.\n", MAX_BITS - nb_clear, nb_set);
+		return TEST_FAILED;
+	}
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
2.8.4
#1 lore raw

PATCH 2/2 bitmap: fix bitmap not empty API for 128B cacheline

Currently bitmap line not empty check API assumes cache line of 64B and only checks 8 slabs. Since in 128B cacheline, we have 16 slabs per cacheline, plt_bitmap_clear() will mark complete line as empty as soon as 8 slabs are full thereby breaking bitmap scan functionality. Fix it by defining new __plt_bitmap_line_not_empty() for 128B cacheline platform.

---
 lib/librte_eal/include/rte_bitmap.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
lib/librte_eal/include/rte_bitmap.h +25 -0
index 7c90ef3..d9a1b54 100644
@@ -417,6 +417,7 @@ rte_bitmap_set_slab(struct rte_bitmap *bmp, uint32_t pos, uint64_t slab)
 	*slab1 |= 1llu << offset1;
 }
 
+#if RTE_BITMAP_CL_SLAB_SIZE == 8
 static inline uint64_t
 __rte_bitmap_line_not_empty(uint64_t *slab2)
 {
@@ -432,6 +433,30 @@ __rte_bitmap_line_not_empty(uint64_t *slab2)
 	return v1 | v3;
 }
 
+#elif RTE_BITMAP_CL_SLAB_SIZE == 16
+static inline uint64_t
+__rte_bitmap_line_not_empty(uint64_t *slab2)
+{
+	uint64_t v1, v2, v3, v4, v5, v6, v7, v8;
+
+	v1 = slab2[0] | slab2[1];
+	v2 = slab2[2] | slab2[3];
+	v3 = slab2[4] | slab2[5];
+	v4 = slab2[6] | slab2[7];
+	v5 = slab2[8] | slab2[9];
+	v6 = slab2[10] | slab2[11];
+	v7 = slab2[12] | slab2[13];
+	v8 = slab2[14] | slab2[15];
+	v1 |= v2;
+	v3 |= v4;
+	v5 |= v6;
+	v7 |= v8;
+
+	return v1 | v3 | v5 | v7;
+}
+
+#endif
+
 /**
  * Bitmap bit clear
  *
Signature · 1 line
2.8.4
Acked-by on v1 2/2
#2 lore raw

Re: [dpdk-dev] [PATCH 2/2] bitmap: fix bitmap not empty API for 128B cacheline

Quoted 68 lines

-----Original Message-----
From: Nithin Dabilpuram <[email protected]>
Sent: Monday, December 14, 2020 10:29 AM
To: Dumitrescu, Cristian <[email protected]>
Cc: [email protected]; [email protected]; Nithin Dabilpuram <[email protected]>
Subject: [PATCH 2/2] bitmap: fix bitmap not empty API for 128B cacheline

Currently bitmap line not empty check API assumes cache line of 64B and only checks 8 slabs. Since in 128B cacheline, we have 16 slabs per cacheline, plt_bitmap_clear() will mark complete line as empty as soon as 8 slabs are full thereby breaking bitmap scan functionality. Fix it by defining new __plt_bitmap_line_not_empty() for 128B cacheline platform.

---
 lib/librte_eal/include/rte_bitmap.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
lib/librte_eal/include/rte_bitmap.h +1 -0
index 7c90ef3..d9a1b54 100644
@@ -417,6 +417,7 @@ rte_bitmap_set_slab(struct rte_bitmap *bmp,
 uint32_t pos, uint64_t slab)
 	*slab1 |= 1llu << offset1;
 }
 
+#if RTE_BITMAP_CL_SLAB_SIZE == 8
 static inline uint64_t
 __rte_bitmap_line_not_empty(uint64_t *slab2)

{

lib/librte_eal/include/rte_bitmap.h +24 -1
@@ -432,6 +433,30 @@ __rte_bitmap_line_not_empty(uint64_t *slab2)
 	return v1 | v3;
 }
 
+#elif RTE_BITMAP_CL_SLAB_SIZE == 16
+static inline uint64_t
+__rte_bitmap_line_not_empty(uint64_t *slab2)
+{
+	uint64_t v1, v2, v3, v4, v5, v6, v7, v8;
+
+	v1 = slab2[0] | slab2[1];
+	v2 = slab2[2] | slab2[3];
+	v3 = slab2[4] | slab2[5];
+	v4 = slab2[6] | slab2[7];
+	v5 = slab2[8] | slab2[9];
+	v6 = slab2[10] | slab2[11];
+	v7 = slab2[12] | slab2[13];
+	v8 = slab2[14] | slab2[15];
+	v1 |= v2;
+	v3 |= v4;
+	v5 |= v6;
+	v7 |= v8;
+
+	return v1 | v3 | v5 | v7;
+}
+
+#endif
+
 /**
  * Bitmap bit clear
  *
--
Quoted 1 line

2.8.4

#3 lore raw

PATCH v2 1/2 test/bitmap: test scan after half cline is cleared

In reply to Nithin Dabilpuram

Add a test case to test scan operation post clear of half cacheline of slabs.

Also fix meson.build to include test_bitmap.c in the compilation.

---

v2:
- No change

 app/test/meson.build   |  1 +
 app/test/test_bitmap.c | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
app/test/meson.build +1 -0
index 94fd39f..bb06a92 100644
@@ -13,6 +13,7 @@ test_sources = files('commands.c',
 	'test_atomic.c',
 	'test_barrier.c',
 	'test_bitops.c',
+	'test_bitmap.c',
 	'test_bpf.c',
 	'test_byteorder.c',
 	'test_cmdline.c',
app/test/test_bitmap.c +33 -1
index a8204d3..70d8fff 100644
@@ -16,9 +16,10 @@
 static int
 test_bitmap_scan_operations(struct rte_bitmap *bmp)
 {
-	uint32_t pos = 0;
 	uint64_t slab1_magic = 0xBADC0FFEEBADF00D;
 	uint64_t slab2_magic = 0xFEEDDEADDEADF00D;
+	uint32_t pos = 0, start_pos;
+	int i, nb_clear, nb_set;
 	uint64_t out_slab = 0;
 
 	rte_bitmap_reset(bmp);
@@ -70,6 +71,37 @@ test_bitmap_scan_operations(struct rte_bitmap *bmp)
 		return TEST_FAILED;
 	}
 
+	/* Test scan when a cline is half full */
+	rte_bitmap_reset(bmp);
+	for (i = 0; i < MAX_BITS; i++)
+		rte_bitmap_set(bmp, i);
+
+	nb_clear = RTE_MIN(RTE_BITMAP_CL_BIT_SIZE / 2, MAX_BITS);
+	for (i = 0; i < nb_clear; i++)
+		rte_bitmap_clear(bmp, i);
+
+	/* Find remaining bits set in bmp */
+	__rte_bitmap_scan_init(bmp);
+
+	if (rte_bitmap_scan(bmp, &pos, &out_slab) != 1) {
+		printf("Initial scan failed with half CL empty.\n");
+		return TEST_FAILED;
+	}
+
+	start_pos = pos;
+	nb_set = 0;
+	do {
+		nb_set += __builtin_popcountll(out_slab);
+		if (!rte_bitmap_scan(bmp, &pos, &out_slab))
+			break;
+	} while (pos != start_pos);
+
+	if ((nb_clear + nb_set) != MAX_BITS) {
+		printf("Scan failed to find all set bits. "
+		       "Expected %u, found %u.\n", MAX_BITS - nb_clear, nb_set);
+		return TEST_FAILED;
+	}
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
2.8.4
#4 lore raw

PATCH v2 2/2 bitmap: modify bitmap not empty API for 128B cacheline

Currently bitmap line not empty check API assumes cache line of 64B and only checks 8 slabs. Since in 128B cacheline, we have 16 slabs per cacheline, rte_bitmap_clear() will mark complete line as empty as soon as 8 slabs are empty thereby breaking bitmap scan functionality. Fix it by defining new __rte_bitmap_line_not_empty() for 128B cacheline platform.

---

v2:
- Fix issue with commit message and add acked-by from Cristian.

 lib/librte_eal/include/rte_bitmap.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
lib/librte_eal/include/rte_bitmap.h +25 -0
index 7c90ef3..d9a1b54 100644
@@ -417,6 +417,7 @@ rte_bitmap_set_slab(struct rte_bitmap *bmp, uint32_t pos, uint64_t slab)
 	*slab1 |= 1llu << offset1;
 }
 
+#if RTE_BITMAP_CL_SLAB_SIZE == 8
 static inline uint64_t
 __rte_bitmap_line_not_empty(uint64_t *slab2)
 {
@@ -432,6 +433,30 @@ __rte_bitmap_line_not_empty(uint64_t *slab2)
 	return v1 | v3;
 }
 
+#elif RTE_BITMAP_CL_SLAB_SIZE == 16
+static inline uint64_t
+__rte_bitmap_line_not_empty(uint64_t *slab2)
+{
+	uint64_t v1, v2, v3, v4, v5, v6, v7, v8;
+
+	v1 = slab2[0] | slab2[1];
+	v2 = slab2[2] | slab2[3];
+	v3 = slab2[4] | slab2[5];
+	v4 = slab2[6] | slab2[7];
+	v5 = slab2[8] | slab2[9];
+	v6 = slab2[10] | slab2[11];
+	v7 = slab2[12] | slab2[13];
+	v8 = slab2[14] | slab2[15];
+	v1 |= v2;
+	v3 |= v4;
+	v5 |= v6;
+	v7 |= v8;
+
+	return v1 | v3 | v5 | v7;
+}
+
+#endif
+
 /**
  * Bitmap bit clear
  *
Signature · 1 line
2.8.4
#5 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] bitmap: modify bitmap not empty API for 128B cacheline

05/01/2021 09:57, Nithin Dabilpuram:

Quoted 7 lines

Currently bitmap line not empty check API assumes cache line of 64B and only checks 8 slabs. Since in 128B cacheline, we have 16 slabs per cacheline, rte_bitmap_clear() will mark complete line as empty as soon as 8 slabs are empty thereby breaking bitmap scan functionality. Fix it by defining new __rte_bitmap_line_not_empty() for 128B cacheline platform.

Quoted 6 lines

---

v2:
- Fix issue with commit message and add acked-by from Cristian.

It seems you don't want to consider this patch as a fix, so no backport request.

Applied with title "bitmap: support 128-byte cacheline in empty check", thanks.