From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7F7D745556; Mon, 8 Jul 2024 18:07:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C41CF4275A; Mon, 8 Jul 2024 18:07:43 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by mails.dpdk.org (Postfix) with ESMTP id DE12740265; Mon, 8 Jul 2024 18:07:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720454861; x=1751990861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kw3njbAWkTPQYFMcXwbYh/eSmEl1Lz6GLmYa9xT//mc=; b=A/ob4PcM8wC0R35De+0AlgZYKc3NWv3vaKSrTMYw7tTEhmPbjbeFWEEH v0aRFLYuftfdCjXk3o3i727lovEFeq61zmDYP98ZfCkeXii8ilgTxQuy/ v0WQ/4ZmWbb59p8QfcCuJ5qqbNC5jiK+aVXX7zDYKJHdPzY+nWIrzaExD pQRYbmJpqdrcVbqwOx/pLKzDDOGPtiYDfq6lP6sFzs1bM0m3bIGNgKkt/ CMCglrHFcKzntRpUR6kHDX5Yo3VcaNUkqoWG6VVyyKYfKr7e19Hec9zGO m3EZ1Q7i9flHpUAcNS6o9hOFqTPYwHNoK2U6IB9+FdkTSEUaumv+vbs6r w==; X-CSE-ConnectionGUID: 07Y4RM+6RZyKbydcgnHRyA== X-CSE-MsgGUID: OR/vC9h5SEG4P8r6YXBQsA== X-IronPort-AV: E=McAfee;i="6700,10204,11127"; a="28827520" X-IronPort-AV: E=Sophos;i="6.09,192,1716274800"; d="scan'208";a="28827520" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2024 09:07:40 -0700 X-CSE-ConnectionGUID: GObcjcjLRf+h5JytvUMCWw== X-CSE-MsgGUID: bjS4vLgYQKO0AVM795SCxw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,192,1716274800"; d="scan'208";a="51965477" Received: from silpixa00401119.ir.intel.com ([10.55.129.167]) by fmviesa005.fm.intel.com with ESMTP; 08 Jul 2024 09:07:39 -0700 From: Anatoly Burakov To: dev@dpdk.org, Tyler Retzlaff Cc: stable@dpdk.org Subject: [PATCH v1 1/4] fbarray: fix incorrect lookahead behavior Date: Mon, 8 Jul 2024 17:07:32 +0100 Message-ID: <62d5744a70ba1cde7d1dcf5311fdbc24d317b695.1720454625.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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@dpdk.org Signed-off-by: Vipin P R Signed-off-by: Anatoly Burakov --- 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