[PATCH v1 1/4] fbarray: fix incorrect lookahead behavior
Anatoly Burakov
anatoly.burakov at intel.com
Mon Jul 8 18:07:32 CEST 2024
Currently, whenever last bit of current index mask is set (meaning, there is
potentially a run starting at the end of the mask), lookahead loop is entered.
In that loop, if the first bit of lookahead mask is not set, the lookahead is
stopped, and the current lookahead mask index is assigned to current index mask.
However, because at that point we are inside a for-loop that increments current
index mask after each iteration, this results in erroneous mask index
increment.
Fixlookahead to avoid erroneous increment, and add corresponding unit test.
Fixes: c44d09811b40 ("eal: add shared indexed file-backed array")
Cc: stable at dpdk.org
Signed-off-by: Vipin P R <vipinp at vmware.com>
Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
app/test/test_fbarray.c | 23 +++++++++++++++++++++++
lib/eal/common/eal_common_fbarray.c | 3 ++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/app/test/test_fbarray.c b/app/test/test_fbarray.c
index 26a51e2a3e..bf89b99e5b 100644
--- a/app/test/test_fbarray.c
+++ b/app/test/test_fbarray.c
@@ -103,6 +103,14 @@ static int empty_msk_test_setup(void)
return 0;
}
+static int lookahead_test_setup(void)
+{
+ /* set index 64 as used */
+ param.start = 64;
+ param.end = 64;
+ return init_array();
+}
+
static int test_invalid(void)
{
struct rte_fbarray dummy;
@@ -709,6 +717,20 @@ static int test_empty(void)
return TEST_SUCCESS;
}
+static int test_lookahead(void)
+{
+ int ret;
+
+ /* run regular test first */
+ ret = test_find();
+ if (ret != TEST_SUCCESS)
+ return ret;
+
+ /* test if we can find free chunk while not starting with 0 */
+ TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(¶m.arr, 1, param.start),
+ param.start + 1, "Free chunk index is wrong\n");
+ return TEST_SUCCESS;
+}
static struct unit_test_suite fbarray_test_suite = {
.suite_name = "fbarray autotest",
@@ -723,6 +745,7 @@ static struct unit_test_suite fbarray_test_suite = {
TEST_CASE_ST(last_msk_test_setup, reset_array, test_find),
TEST_CASE_ST(full_msk_test_setup, reset_array, test_find),
TEST_CASE_ST(empty_msk_test_setup, reset_array, test_empty),
+ TEST_CASE_ST(lookahead_test_setup, reset_array, test_lookahead),
TEST_CASES_END()
}
};
diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c
index 0fe5bcfe06..2680b34823 100644
--- a/lib/eal/common/eal_common_fbarray.c
+++ b/lib/eal/common/eal_common_fbarray.c
@@ -236,7 +236,8 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
* as well, so skip that on next iteration.
*/
ignore_msk = ~((1ULL << need) - 1);
- msk_idx = lookahead_idx;
+ /* outer loop will increment msk_idx so add 1 */
+ msk_idx = lookahead_idx - 1;
break;
}
--
2.43.0
More information about the dev
mailing list