[RFC v3] eal: add bitset type

Stephen Hemminger stephen at networkplumber.org
Wed Jan 31 17:02:31 CET 2024


On Wed, 31 Jan 2024 14:13:01 +0100
Mattias Rönnblom <mattias.ronnblom at ericsson.com> wrote:

> Introduce a set of functions and macros that operate on sets of bits,
> kept in arrays of 64-bit elements.
> 
> RTE bitset is designed for bitsets which are larger than what fits in
> a single machine word (i.e., 64 bits). For very large bitsets, the
> <rte_bitmap.h> API may be a more appropriate choice.
> 
> RFC v3:
>  * Split the bitset from the htimer patchset, where it was originally
>    hosted.
>  * Rebase to current DPDK main.
>  * Add note that rte_bitset_init() need not be called if bitset words
>    have already been zeroed.
>  * Use REGISTER_FAST_TEST instead of REGISTER_TEST_COMMAND.
>  * Use rte_popcount64() instead of compiler builtin.
> 
> RFC v2:
>  * Replaced <sys/types.h> with <stddef.h> include, to properly get
>    size_t typedef.
>  * Add <rte_compat.h> to get __rte_experimental in <rte_bitset.h>.
> 
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom at ericsson.com>
> ---
>  app/test/meson.build         |   1 +
>  app/test/test_bitset.c       | 645 +++++++++++++++++++++++++
>  lib/eal/common/meson.build   |   1 +
>  lib/eal/common/rte_bitset.c  |  29 ++
>  lib/eal/include/meson.build  |   1 +
>  lib/eal/include/rte_bitset.h | 884 +++++++++++++++++++++++++++++++++++
>  lib/eal/version.map          |   3 +
>  7 files changed, 1564 insertions(+)
>  create mode 100644 app/test/test_bitset.c
>  create mode 100644 lib/eal/common/rte_bitset.c
>  create mode 100644 lib/eal/include/rte_bitset.h
> 
> diff --git a/app/test/meson.build b/app/test/meson.build
> index dcc93f4a43..e218be11d8 100644
> --- a/app/test/meson.build
> +++ b/app/test/meson.build
> @@ -32,6 +32,7 @@ source_file_deps = {
>      'test_bitcount.c': [],
>      'test_bitmap.c': [],
>      'test_bitops.c': [],
> +    'test_bitset.c': [],
>      'test_bitratestats.c': ['metrics', 'bitratestats', 'ethdev'] + sample_packet_forward_deps,
>      'test_bpf.c': ['bpf', 'net'],
>      'test_byteorder.c': [],
> diff --git a/app/test/test_bitset.c b/app/test/test_bitset.c
> new file mode 100644
> index 0000000000..688349b03b
> --- /dev/null
> +++ b/app/test/test_bitset.c
> @@ -0,0 +1,645 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2023 Ericsson AB
> + */
> +
> +#include <stdlib.h>
> +#include <inttypes.h>
> +
> +#include <rte_random.h>
> +
> +#include <rte_bitset.h>
> +
> +#include "test.h"
> +
> +#define MAGIC UINT64_C(0xdeadbeefdeadbeef)
> +
> +static void
> +rand_buf(void *buf, size_t n)
> +{
> +	size_t i;
> +
> +	for (i = 0; i < n; i++)
> +		((char *)buf)[i] = (char)rte_rand();
Cast to char unneeded, and you don't want signed character here.
Use uint8_t


More information about the dev mailing list