<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hi Burakov,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
sure, will amend the changeset. currently I'm travelling, will get back by the end of this week if that's ok.</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Burakov, Anatoly <anatoly.burakov@intel.com><br>
<b>Sent:</b> 19 May 2023 22:15<br>
<b>To:</b> Vipin P R <vipinp@vmware.com><br>
<b>Cc:</b> dev@dpdk.org <dev@dpdk.org>; stable@dpdk.org <stable@dpdk.org><br>
<b>Subject:</b> Re: [PATCH 2/2] Memory Allocation: Alternative fix for ignore_msk during find_next_n() in fb_array library</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">!! External Email<br>
<br>
Hi,<br>
<br>
This is technically not a bug fix but an improvement to the lookahead<br>
algorithm, so I don't think this needs a Fixes: tag or a Cc to stable.<br>
<br>
On 1/13/2023 1:14 PM, Vipin P R wrote:<br>
> Ignore mask ignores essential bits WHICH could have been contiguous.<br>
> This commit aims to rectify that<br>
><br>
<br>
Suggested rewording:<br>
<br>
fbarray: improve lookahead ignore mask handling<br>
<br>
Currently, when lookahead mask does not have its first bit set but has<br>
other bits set, we do not set any ignore masks to avoid potentially<br>
ignoring useful bits.<br>
<br>
We can still ignore some bits, because we can rely on the fact that<br>
we're looking for `need` bits, and lookahead mask does give us<br>
information about whether there are other potential places we can start<br>
looking for runs in the next iteration.<br>
<br>
Address this by ignoring least significant clear bits in our lookahead<br>
mask on next iteration.<br>
<br>
> Cc: stable@dpdk.org<br>
><br>
> Signed-off-by: Vipin P R <vipinp@vmware.com><br>
> Acked-by: Kumara Parameshwaran <kparameshwar@vmware.com><br>
> ---<br>
> Depends-on: 0001-Memory-Allocation-Fixes-ms_idx-jump-lookahead-during.patch<br>
> Depends-on: 0002-Memory-Allocation-Fixes-ms_idx-jump-lookbehind-durin.patch<br>
> ---<br>
>   lib/eal/common/eal_common_fbarray.c | 21 ++++++++++++++++++---<br>
>   1 file changed, 18 insertions(+), 3 deletions(-)<br>
><br>
> diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c<br>
> index 313681a..29fffb6 100644<br>
> --- a/lib/eal/common/eal_common_fbarray.c<br>
> +++ b/lib/eal/common/eal_common_fbarray.c<br>
> @@ -138,7 +138,7 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,<br>
>       last_msk = ~(UINT64_MAX << last_mod);<br>
><br>
>       for (msk_idx = first; msk_idx < msk->n_masks; msk_idx++) {<br>
> -             uint64_t cur_msk, lookahead_msk;<br>
> +             uint64_t cur_msk, lookahead_msk, lookahead_msk_;<br>
<br>
`lookahead_msk_` doesn't need to be in the outer loop, IMO it can be<br>
moved inside the lookahead code. Also, `lookahead_msk_` is not a very<br>
informative name. Maybe change it to `lookahead_old` or similar?<br>
<br>
>               unsigned int run_start, clz, left;<br>
>               bool found = false;<br>
>               /*<br>
> @@ -215,12 +215,14 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,<br>
><br>
>               for (lookahead_idx = msk_idx + 1; lookahead_idx < msk->n_masks;<br>
>                               lookahead_idx++) {<br>
> -                     unsigned int s_idx, need;<br>
> +                     unsigned int s_idx, need, fsb_idx, fcb_idx, ignore_bits;<br>
>                       lookahead_msk = msk->data[lookahead_idx];<br>
><br>
>                       /* if we're looking for free space, invert the mask */<br>
>                       if (!used)<br>
>                               lookahead_msk = ~lookahead_msk;<br>
> +<br>
> +                     lookahead_msk_ = lookahead_msk;<br>
><br>
>                       /* figure out how many consecutive bits we need here */<br>
>                       need = RTE_MIN(left, MASK_ALIGN);<br>
> @@ -236,10 +238,23 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,<br>
>                                * as well, so skip that on next iteration.<br>
>                                */<br>
>                               if (!lookahead_msk) {<br>
> -                                     /* There aren't "need" number of contiguous bits anywhere in the mask.<br>
> +                                     /* There aren't "need" number of contiguous bits anywhere in the mask.<br>
>                                        * Ignore these many number of bits from LSB for the next iteration.<br>
>                                        */<br>
>                                       ignore_msk = ~((1ULL << need) - 1);<br>
> +                             } else {<br>
> +                                     /* Find the first clear bit */<br>
> +                                     fcb_idx = __builtin_ffsll((~lookahead_msk_));<br>
> +                                     /* clear all bits upto the first clear bit in lookahead_msk_. */<br>
> +                                     lookahead_msk_ = lookahead_msk_ & ((~0ULL) << fcb_idx);<br>
> +                                     /* find the first set bit in the modified mask */<br>
> +                                     fsb_idx = __builtin_ffsll(lookahead_msk_);<br>
> +                                     /* number of bits to ignore from the next iteration */<br>
> +                                     ignore_bits = fsb_idx - 1;<br>
> +                                     /* ignore all bits preceding the first set bit after the first clear bit<br>
> +                                      * starting from LSB of lookahead_msk_.<br>
> +                                      */<br>
> +                                     ignore_msk = ~((1ULL << ignore_bits) - 1);<br>
>                               }<br>
<br>
I don't quite understand what's happening here. Or rather, I kind of do,<br>
but I don't understand why we don't just 1) find first set bit in<br>
lookahead mask, and 2) ignore all preceding bits?<br>
<br>
E.g. something like:<br>
<br>
/* find first set bit */<br>
fsb_idx = __builtin_ffsll(lookahead_msk);<br>
/* ignore all preceding bits */<br>
ignore_msk = ~((1ULL << fsb_idx) - 1);<br>
<br>
would be much simpler and achieve the same result, would it not?<br>
<br>
>                               msk_idx = lookahead_idx - 1;<br>
>                               break;<br>
<br>
--<br>
Thanks,<br>
Anatoly<br>
<br>
<br>
!! External Email: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender.<br>
</div>
</span></font></div>
</body>
</html>