[PATCH v2 1/4] eal: add bitset type

Mattias Rönnblom hofors at lysator.liu.se
Wed Oct 16 15:37:21 CEST 2024


On 2024-10-16 13:30, David Marchand wrote:
> On Thu, Oct 10, 2024 at 10:30 AM David Marchand
> <david.marchand at redhat.com> wrote:
>> diff --git a/lib/eal/include/rte_bitset.h b/lib/eal/include/rte_bitset.h
>> new file mode 100644
>> index 0000000000..b2d71aa7c6
>> --- /dev/null
>> +++ b/lib/eal/include/rte_bitset.h
> 
> [snip]
> 
>> +__rte_experimental
>> +static inline ssize_t
>> +__rte_bitset_find_nowrap(const uint64_t *bitset, size_t __rte_unused size, size_t start_bit,
>> +               size_t len, bool find_clear)
>> +{
>> +       size_t word_idx;
>> +       size_t offset;
>> +       size_t end_bit = start_bit + len;
>> +
>> +       RTE_ASSERT(end_bit <= size);
>> +
>> +       if (unlikely(len == 0))
>> +               return -1;
>> +
>> +       word_idx = __RTE_BITSET_WORD_IDX(start_bit);
>> +       offset = __RTE_BITSET_BIT_OFFSET(start_bit);
>> +
>> +       while (word_idx <= __RTE_BITSET_WORD_IDX(end_bit - 1)) {
>> +               uint64_t word;
>> +               int word_ffs;
>> +
>> +               word = bitset[word_idx];
>> +               if (find_clear)
>> +                       word = ~word;
>> +
>> +               word >>= offset;
>> +
>> +               word_ffs = __builtin_ffsll(word);
>> +
>> +               if (word_ffs != 0) {
>> +                       ssize_t ffs = start_bit + word_ffs - 1;
>> +
>> +                       /*
>> +                        * Check if set bit were among the last,
>> +                        * unused bits, in the last word.
>> +                        */
>> +                       if (unlikely(ffs >= (ssize_t)end_bit))
>> +                               return -1;
>> +
>> +                       return ffs;
>> +               }
>> +
>> +               start_bit += (RTE_BITSET_WORD_BITS - offset);
>> +               word_idx++;
>> +               offset = 0;
>> +       }
>> +
>> +       return -1;
>> +
>> +}
> 
> Now that the series is merged, we finally got one report from UNH and
> this patch breaks MSVC build.
> 
> FAILED: lib/librte_eal.a.p/eal_common_rte_bitset.c.obj
> "cl" "-Ilib\librte_eal.a.p" "-Ilib" "-I..\lib" "-I." "-I.." "-Iconfig"
> "-I..\config" "-Ilib\eal\include" "-I..\lib\eal\include"
> "-Ilib\eal\windows\include" "-I..\lib\eal\windows\include"
> "-Ilib\eal\x86\include" "-I..\lib\eal\x86\include" "-Ilib\eal\common"
> "-I..\lib\eal\common" "-Ilib\eal" "-I..\lib\eal" "-Ilib\log"
> "-I..\lib\log" "-Ilib\kvargs" "-I..\lib\kvargs" "-IC:\Program
> Files\Mellanox\MLNX_WinOF2_DevX_SDK\inc" "/MD" "/nologo"
> "/showIncludes" "/W3" "/WX" "/std:c11" "/O2" "/Gw" "/wd4244" "/wd4267"
> "/wd4146" "/experimental:c11atomics" "/d1experimental:typeof"
> "/experimental:statementExpressions" "/FI" "rte_config.h"
> "-D_GNU_SOURCE" "-D_WIN32_WINNT=0x0A00" "-DALLOW_EXPERIMENTAL_API"
> "-DALLOW_INTERNAL_API" "-DABI_VERSION=\"25.0\""
> "-DRTE_LOG_DEFAULT_LOGTYPE=lib.eal"
> "/Fdlib\librte_eal.a.p\eal_common_rte_bitset.c.pdb"
> /Folib/librte_eal.a.p/eal_common_rte_bitset.c.obj "/c"
> ../lib/eal/common/rte_bitset.c
> ..\lib\eal\include\rte_bitset.h(612): error C2220: the following
> warning is treated as an error
> ..\lib\eal\include\rte_bitset.h(612): warning C4013: '__builtin_ffsll'
> undefined; assuming extern returning int
> 
> 
> I see two options:
> - rewrite this code and use existing rte_ctz64 or rte_bsf64_safe,
> - introduce an additional rte_ffs64() in rte_bitops.h and implement it
> for MSVC and others,
> 
> And I would prefer we extend checkpatch, so that such issue is caught earlier.
> See:
> devtools/checkpatches.sh:               -v
> EXPRESSIONS='\\<__builtin_(clz|clzll|ctz|ctzll|popcount|popcountll)\\>'
> \
> 
> Please send a fix.
> 
> 

Will do.



More information about the dev mailing list