xref: /dpdk/lib/eal/include/rte_fbarray.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2017-2018 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef RTE_FBARRAY_H
699a2dd95SBruce Richardson #define RTE_FBARRAY_H
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * File-backed shared indexed array for DPDK.
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * Basic workflow is expected to be the following:
1499a2dd95SBruce Richardson  *  1) Allocate array either using ``rte_fbarray_init()`` or
1599a2dd95SBruce Richardson  *     ``rte_fbarray_attach()`` (depending on whether it's shared between
1699a2dd95SBruce Richardson  *     multiple DPDK processes)
1799a2dd95SBruce Richardson  *  2) find free spots using ``rte_fbarray_find_next_free()``
1899a2dd95SBruce Richardson  *  3) get pointer to data in the free spot using ``rte_fbarray_get()``, and
1999a2dd95SBruce Richardson  *     copy data into the pointer (element size is fixed)
2099a2dd95SBruce Richardson  *  4) mark entry as used using ``rte_fbarray_set_used()``
2199a2dd95SBruce Richardson  *
2299a2dd95SBruce Richardson  * Calls to ``rte_fbarray_init()`` and ``rte_fbarray_destroy()`` will have
2399a2dd95SBruce Richardson  * consequences for all processes, while calls to ``rte_fbarray_attach()`` and
2499a2dd95SBruce Richardson  * ``rte_fbarray_detach()`` will only have consequences within a single process.
2599a2dd95SBruce Richardson  * Therefore, it is safe to call ``rte_fbarray_attach()`` or
2699a2dd95SBruce Richardson  * ``rte_fbarray_detach()`` while another process is using ``rte_fbarray``,
2799a2dd95SBruce Richardson  * provided no other thread within the same process will try to use
2899a2dd95SBruce Richardson  * ``rte_fbarray`` before attaching or after detaching. It is not safe to call
2999a2dd95SBruce Richardson  * ``rte_fbarray_init()`` or ``rte_fbarray_destroy()`` while another thread or
3099a2dd95SBruce Richardson  * another process is using ``rte_fbarray``.
3199a2dd95SBruce Richardson  */
3299a2dd95SBruce Richardson 
3399a2dd95SBruce Richardson #include <stdio.h>
3499a2dd95SBruce Richardson 
3599a2dd95SBruce Richardson #include <rte_rwlock.h>
3699a2dd95SBruce Richardson 
37*719834a6SMattias Rönnblom #ifdef __cplusplus
38*719834a6SMattias Rönnblom extern "C" {
39*719834a6SMattias Rönnblom #endif
40*719834a6SMattias Rönnblom 
4199a2dd95SBruce Richardson #define RTE_FBARRAY_NAME_LEN 64
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson struct rte_fbarray {
4499a2dd95SBruce Richardson 	char name[RTE_FBARRAY_NAME_LEN]; /**< name associated with an array */
4599a2dd95SBruce Richardson 	unsigned int count;              /**< number of entries stored */
4699a2dd95SBruce Richardson 	unsigned int len;                /**< current length of the array */
4799a2dd95SBruce Richardson 	unsigned int elt_sz;             /**< size of each element */
4899a2dd95SBruce Richardson 	void *data;                      /**< data pointer */
4999a2dd95SBruce Richardson 	rte_rwlock_t rwlock;             /**< multiprocess lock */
5099a2dd95SBruce Richardson };
5199a2dd95SBruce Richardson 
5299a2dd95SBruce Richardson /**
5399a2dd95SBruce Richardson  * Set up ``rte_fbarray`` structure and allocate underlying resources.
5499a2dd95SBruce Richardson  *
5599a2dd95SBruce Richardson  * Call this function to correctly set up ``rte_fbarray`` and allocate
5699a2dd95SBruce Richardson  * underlying files that will be backing the data in the current process. Note
5799a2dd95SBruce Richardson  * that in order to use and share ``rte_fbarray`` between multiple processes,
5899a2dd95SBruce Richardson  * data pointed to by ``arr`` pointer must itself be allocated in shared memory.
5999a2dd95SBruce Richardson  *
6099a2dd95SBruce Richardson  * @param arr
6199a2dd95SBruce Richardson  *   Valid pointer to allocated ``rte_fbarray`` structure.
6299a2dd95SBruce Richardson  *
6399a2dd95SBruce Richardson  * @param name
6499a2dd95SBruce Richardson  *   Unique name to be assigned to this array.
6599a2dd95SBruce Richardson  *
6699a2dd95SBruce Richardson  * @param len
6799a2dd95SBruce Richardson  *   Number of elements initially available in the array.
6899a2dd95SBruce Richardson  *
6999a2dd95SBruce Richardson  * @param elt_sz
7099a2dd95SBruce Richardson  *   Size of each element.
7199a2dd95SBruce Richardson  *
7299a2dd95SBruce Richardson  * @return
7399a2dd95SBruce Richardson  *  - 0 on success.
7499a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
7599a2dd95SBruce Richardson  */
7699a2dd95SBruce Richardson int
7799a2dd95SBruce Richardson rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
7899a2dd95SBruce Richardson 		unsigned int elt_sz);
7999a2dd95SBruce Richardson 
8099a2dd95SBruce Richardson 
8199a2dd95SBruce Richardson /**
8299a2dd95SBruce Richardson  * Attach to a file backing an already allocated and correctly set up
8399a2dd95SBruce Richardson  * ``rte_fbarray`` structure.
8499a2dd95SBruce Richardson  *
8599a2dd95SBruce Richardson  * Call this function to attach to file that will be backing the data in the
8699a2dd95SBruce Richardson  * current process. The structure must have been previously correctly set up
8799a2dd95SBruce Richardson  * with a call to ``rte_fbarray_init()``. Calls to ``rte_fbarray_attach()`` are
8899a2dd95SBruce Richardson  * usually meant to be performed in a multiprocessing scenario, with data
8999a2dd95SBruce Richardson  * pointed to by ``arr`` pointer allocated in shared memory.
9099a2dd95SBruce Richardson  *
9199a2dd95SBruce Richardson  * @param arr
9299a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up rte_fbarray structure.
9399a2dd95SBruce Richardson  *
9499a2dd95SBruce Richardson  * @return
9599a2dd95SBruce Richardson  *  - 0 on success.
9699a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
9799a2dd95SBruce Richardson  */
9899a2dd95SBruce Richardson int
9999a2dd95SBruce Richardson rte_fbarray_attach(struct rte_fbarray *arr);
10099a2dd95SBruce Richardson 
10199a2dd95SBruce Richardson 
10299a2dd95SBruce Richardson /**
10399a2dd95SBruce Richardson  * Deallocate resources for an already allocated and correctly set up
10499a2dd95SBruce Richardson  * ``rte_fbarray`` structure, and remove the underlying file.
10599a2dd95SBruce Richardson  *
10699a2dd95SBruce Richardson  * Call this function to deallocate all resources associated with an
10799a2dd95SBruce Richardson  * ``rte_fbarray`` structure within the current process. This will also
10899a2dd95SBruce Richardson  * zero-fill data pointed to by ``arr`` pointer and remove the underlying file
10999a2dd95SBruce Richardson  * backing the data, so it is expected that by the time this function is called,
11099a2dd95SBruce Richardson  * all other processes have detached from this ``rte_fbarray``.
11199a2dd95SBruce Richardson  *
11299a2dd95SBruce Richardson  * @param arr
11399a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
11499a2dd95SBruce Richardson  *
11599a2dd95SBruce Richardson  * @return
11699a2dd95SBruce Richardson  *  - 0 on success.
11799a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
11899a2dd95SBruce Richardson  */
11999a2dd95SBruce Richardson int
12099a2dd95SBruce Richardson rte_fbarray_destroy(struct rte_fbarray *arr);
12199a2dd95SBruce Richardson 
12299a2dd95SBruce Richardson 
12399a2dd95SBruce Richardson /**
12499a2dd95SBruce Richardson  * Deallocate resources for an already allocated and correctly set up
12599a2dd95SBruce Richardson  * ``rte_fbarray`` structure.
12699a2dd95SBruce Richardson  *
12799a2dd95SBruce Richardson  * Call this function to deallocate all resources associated with an
12899a2dd95SBruce Richardson  * ``rte_fbarray`` structure within current process.
12999a2dd95SBruce Richardson  *
13099a2dd95SBruce Richardson  * @param arr
13199a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
13299a2dd95SBruce Richardson  *
13399a2dd95SBruce Richardson  * @return
13499a2dd95SBruce Richardson  *  - 0 on success.
13599a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
13699a2dd95SBruce Richardson  */
13799a2dd95SBruce Richardson int
13899a2dd95SBruce Richardson rte_fbarray_detach(struct rte_fbarray *arr);
13999a2dd95SBruce Richardson 
14099a2dd95SBruce Richardson 
14199a2dd95SBruce Richardson /**
14299a2dd95SBruce Richardson  * Get pointer to element residing at specified index.
14399a2dd95SBruce Richardson  *
14499a2dd95SBruce Richardson  * @param arr
14599a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
14699a2dd95SBruce Richardson  *
14799a2dd95SBruce Richardson  * @param idx
14899a2dd95SBruce Richardson  *   Index of an element to get a pointer to.
14999a2dd95SBruce Richardson  *
15099a2dd95SBruce Richardson  * @return
15199a2dd95SBruce Richardson  *  - non-NULL pointer on success.
15299a2dd95SBruce Richardson  *  - NULL on failure, with ``rte_errno`` indicating reason for failure.
15399a2dd95SBruce Richardson  */
15499a2dd95SBruce Richardson void *
15599a2dd95SBruce Richardson rte_fbarray_get(const struct rte_fbarray *arr, unsigned int idx);
15699a2dd95SBruce Richardson 
15799a2dd95SBruce Richardson 
15899a2dd95SBruce Richardson /**
15999a2dd95SBruce Richardson  * Find index of a specified element within the array.
16099a2dd95SBruce Richardson  *
16199a2dd95SBruce Richardson  * @param arr
16299a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
16399a2dd95SBruce Richardson  *
16499a2dd95SBruce Richardson  * @param elt
16599a2dd95SBruce Richardson  *   Pointer to element to find index to.
16699a2dd95SBruce Richardson  *
16799a2dd95SBruce Richardson  * @return
16899a2dd95SBruce Richardson  *  - non-negative integer on success.
16999a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
17099a2dd95SBruce Richardson  */
17199a2dd95SBruce Richardson int
17299a2dd95SBruce Richardson rte_fbarray_find_idx(const struct rte_fbarray *arr, const void *elt);
17399a2dd95SBruce Richardson 
17499a2dd95SBruce Richardson 
17599a2dd95SBruce Richardson /**
17699a2dd95SBruce Richardson  * Mark specified element as used.
17799a2dd95SBruce Richardson  *
17899a2dd95SBruce Richardson  * @param arr
17999a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
18099a2dd95SBruce Richardson  *
18199a2dd95SBruce Richardson  * @param idx
18299a2dd95SBruce Richardson  *   Element index to mark as used.
18399a2dd95SBruce Richardson  *
18499a2dd95SBruce Richardson  * @return
18599a2dd95SBruce Richardson  *  - 0 on success.
18699a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
18799a2dd95SBruce Richardson  */
18899a2dd95SBruce Richardson int
18999a2dd95SBruce Richardson rte_fbarray_set_used(struct rte_fbarray *arr, unsigned int idx);
19099a2dd95SBruce Richardson 
19199a2dd95SBruce Richardson 
19299a2dd95SBruce Richardson /**
19399a2dd95SBruce Richardson  * Mark specified element as free.
19499a2dd95SBruce Richardson  *
19599a2dd95SBruce Richardson  * @param arr
19699a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
19799a2dd95SBruce Richardson  *
19899a2dd95SBruce Richardson  * @param idx
19999a2dd95SBruce Richardson  *   Element index to mark as free.
20099a2dd95SBruce Richardson  *
20199a2dd95SBruce Richardson  * @return
20299a2dd95SBruce Richardson  *  - 0 on success.
20399a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
20499a2dd95SBruce Richardson  */
20599a2dd95SBruce Richardson int
20699a2dd95SBruce Richardson rte_fbarray_set_free(struct rte_fbarray *arr, unsigned int idx);
20799a2dd95SBruce Richardson 
20899a2dd95SBruce Richardson 
20999a2dd95SBruce Richardson /**
21099a2dd95SBruce Richardson  * Check whether element at specified index is marked as used.
21199a2dd95SBruce Richardson  *
21299a2dd95SBruce Richardson  * @param arr
21399a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
21499a2dd95SBruce Richardson  *
21599a2dd95SBruce Richardson  * @param idx
21699a2dd95SBruce Richardson  *   Element index to check as used.
21799a2dd95SBruce Richardson  *
21899a2dd95SBruce Richardson  * @return
21999a2dd95SBruce Richardson  *  - 1 if element is used.
22099a2dd95SBruce Richardson  *  - 0 if element is unused.
22199a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
22299a2dd95SBruce Richardson  */
22399a2dd95SBruce Richardson int
22499a2dd95SBruce Richardson rte_fbarray_is_used(struct rte_fbarray *arr, unsigned int idx);
22599a2dd95SBruce Richardson 
22699a2dd95SBruce Richardson 
22799a2dd95SBruce Richardson /**
22899a2dd95SBruce Richardson  * Find index of next free element, starting at specified index.
22999a2dd95SBruce Richardson  *
23099a2dd95SBruce Richardson  * @param arr
23199a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
23299a2dd95SBruce Richardson  *
23399a2dd95SBruce Richardson  * @param start
23499a2dd95SBruce Richardson  *   Element index to start search from.
23599a2dd95SBruce Richardson  *
23699a2dd95SBruce Richardson  * @return
23799a2dd95SBruce Richardson  *  - non-negative integer on success.
23899a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
23999a2dd95SBruce Richardson  */
24099a2dd95SBruce Richardson int
24199a2dd95SBruce Richardson rte_fbarray_find_next_free(struct rte_fbarray *arr, unsigned int start);
24299a2dd95SBruce Richardson 
24399a2dd95SBruce Richardson 
24499a2dd95SBruce Richardson /**
24599a2dd95SBruce Richardson  * Find index of next used element, starting at specified index.
24699a2dd95SBruce Richardson  *
24799a2dd95SBruce Richardson  * @param arr
24899a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
24999a2dd95SBruce Richardson  *
25099a2dd95SBruce Richardson  * @param start
25199a2dd95SBruce Richardson  *   Element index to start search from.
25299a2dd95SBruce Richardson  *
25399a2dd95SBruce Richardson  * @return
25499a2dd95SBruce Richardson  *  - non-negative integer on success.
25599a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
25699a2dd95SBruce Richardson  */
25799a2dd95SBruce Richardson int
25899a2dd95SBruce Richardson rte_fbarray_find_next_used(struct rte_fbarray *arr, unsigned int start);
25999a2dd95SBruce Richardson 
26099a2dd95SBruce Richardson 
26199a2dd95SBruce Richardson /**
26299a2dd95SBruce Richardson  * Find index of next chunk of ``n`` free elements, starting at specified index.
26399a2dd95SBruce Richardson  *
26499a2dd95SBruce Richardson  * @param arr
26599a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
26699a2dd95SBruce Richardson  *
26799a2dd95SBruce Richardson  * @param start
26899a2dd95SBruce Richardson  *   Element index to start search from.
26999a2dd95SBruce Richardson  *
27099a2dd95SBruce Richardson  * @param n
27199a2dd95SBruce Richardson  *   Number of free elements to look for.
27299a2dd95SBruce Richardson  *
27399a2dd95SBruce Richardson  * @return
27499a2dd95SBruce Richardson  *  - non-negative integer on success.
27599a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
27699a2dd95SBruce Richardson  */
27799a2dd95SBruce Richardson int
27899a2dd95SBruce Richardson rte_fbarray_find_next_n_free(struct rte_fbarray *arr, unsigned int start,
27999a2dd95SBruce Richardson 		unsigned int n);
28099a2dd95SBruce Richardson 
28199a2dd95SBruce Richardson 
28299a2dd95SBruce Richardson /**
28399a2dd95SBruce Richardson  * Find index of next chunk of ``n`` used elements, starting at specified index.
28499a2dd95SBruce Richardson  *
28599a2dd95SBruce Richardson  * @param arr
28699a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
28799a2dd95SBruce Richardson  *
28899a2dd95SBruce Richardson  * @param start
28999a2dd95SBruce Richardson  *   Element index to start search from.
29099a2dd95SBruce Richardson  *
29199a2dd95SBruce Richardson  * @param n
29299a2dd95SBruce Richardson  *   Number of used elements to look for.
29399a2dd95SBruce Richardson  *
29499a2dd95SBruce Richardson  * @return
29599a2dd95SBruce Richardson  *  - non-negative integer on success.
29699a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
29799a2dd95SBruce Richardson  */
29899a2dd95SBruce Richardson int
29999a2dd95SBruce Richardson rte_fbarray_find_next_n_used(struct rte_fbarray *arr, unsigned int start,
30099a2dd95SBruce Richardson 		unsigned int n);
30199a2dd95SBruce Richardson 
30299a2dd95SBruce Richardson 
30399a2dd95SBruce Richardson /**
30499a2dd95SBruce Richardson  * Find how many more free entries there are, starting at specified index.
30599a2dd95SBruce Richardson  *
30699a2dd95SBruce Richardson  * @param arr
30799a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
30899a2dd95SBruce Richardson  *
30999a2dd95SBruce Richardson  * @param start
31099a2dd95SBruce Richardson  *   Element index to start search from.
31199a2dd95SBruce Richardson  *
31299a2dd95SBruce Richardson  * @return
31399a2dd95SBruce Richardson  *  - non-negative integer on success.
31499a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
31599a2dd95SBruce Richardson  */
31699a2dd95SBruce Richardson int
31799a2dd95SBruce Richardson rte_fbarray_find_contig_free(struct rte_fbarray *arr,
31899a2dd95SBruce Richardson 		unsigned int start);
31999a2dd95SBruce Richardson 
32099a2dd95SBruce Richardson 
32199a2dd95SBruce Richardson /**
32299a2dd95SBruce Richardson  * Find how many more used entries there are, starting at specified index.
32399a2dd95SBruce Richardson  *
32499a2dd95SBruce Richardson  * @param arr
32599a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
32699a2dd95SBruce Richardson  *
32799a2dd95SBruce Richardson  * @param start
32899a2dd95SBruce Richardson  *   Element index to start search from.
32999a2dd95SBruce Richardson  *
33099a2dd95SBruce Richardson  * @return
33199a2dd95SBruce Richardson  *  - non-negative integer on success.
33299a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
33399a2dd95SBruce Richardson  */
33499a2dd95SBruce Richardson int
33599a2dd95SBruce Richardson rte_fbarray_find_contig_used(struct rte_fbarray *arr, unsigned int start);
33699a2dd95SBruce Richardson 
33799a2dd95SBruce Richardson /**
33899a2dd95SBruce Richardson  * Find index of previous free element, starting at specified index.
33999a2dd95SBruce Richardson  *
34099a2dd95SBruce Richardson  * @param arr
34199a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
34299a2dd95SBruce Richardson  *
34399a2dd95SBruce Richardson  * @param start
34499a2dd95SBruce Richardson  *   Element index to start search from.
34599a2dd95SBruce Richardson  *
34699a2dd95SBruce Richardson  * @return
34799a2dd95SBruce Richardson  *  - non-negative integer on success.
34899a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
34999a2dd95SBruce Richardson  */
35099a2dd95SBruce Richardson int
35199a2dd95SBruce Richardson rte_fbarray_find_prev_free(struct rte_fbarray *arr, unsigned int start);
35299a2dd95SBruce Richardson 
35399a2dd95SBruce Richardson 
35499a2dd95SBruce Richardson /**
35599a2dd95SBruce Richardson  * Find index of previous used element, starting at specified index.
35699a2dd95SBruce Richardson  *
35799a2dd95SBruce Richardson  * @param arr
35899a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
35999a2dd95SBruce Richardson  *
36099a2dd95SBruce Richardson  * @param start
36199a2dd95SBruce Richardson  *   Element index to start search from.
36299a2dd95SBruce Richardson  *
36399a2dd95SBruce Richardson  * @return
36499a2dd95SBruce Richardson  *  - non-negative integer on success.
36599a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
36699a2dd95SBruce Richardson  */
36799a2dd95SBruce Richardson int
36899a2dd95SBruce Richardson rte_fbarray_find_prev_used(struct rte_fbarray *arr, unsigned int start);
36999a2dd95SBruce Richardson 
37099a2dd95SBruce Richardson 
37199a2dd95SBruce Richardson /**
37299a2dd95SBruce Richardson  * Find lowest start index of chunk of ``n`` free elements, down from specified
37399a2dd95SBruce Richardson  * index.
37499a2dd95SBruce Richardson  *
37599a2dd95SBruce Richardson  * @param arr
37699a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
37799a2dd95SBruce Richardson  *
37899a2dd95SBruce Richardson  * @param start
37999a2dd95SBruce Richardson  *   Element index to start search from.
38099a2dd95SBruce Richardson  *
38199a2dd95SBruce Richardson  * @param n
38299a2dd95SBruce Richardson  *   Number of free elements to look for.
38399a2dd95SBruce Richardson  *
38499a2dd95SBruce Richardson  * @return
38599a2dd95SBruce Richardson  *  - non-negative integer on success.
38699a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
38799a2dd95SBruce Richardson  */
38899a2dd95SBruce Richardson int
38999a2dd95SBruce Richardson rte_fbarray_find_prev_n_free(struct rte_fbarray *arr, unsigned int start,
39099a2dd95SBruce Richardson 		unsigned int n);
39199a2dd95SBruce Richardson 
39299a2dd95SBruce Richardson 
39399a2dd95SBruce Richardson /**
39499a2dd95SBruce Richardson  * Find lowest start index of chunk of ``n`` used elements, down from specified
39599a2dd95SBruce Richardson  * index.
39699a2dd95SBruce Richardson  *
39799a2dd95SBruce Richardson  * @param arr
39899a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
39999a2dd95SBruce Richardson  *
40099a2dd95SBruce Richardson  * @param start
40199a2dd95SBruce Richardson  *   Element index to start search from.
40299a2dd95SBruce Richardson  *
40399a2dd95SBruce Richardson  * @param n
40499a2dd95SBruce Richardson  *   Number of used elements to look for.
40599a2dd95SBruce Richardson  *
40699a2dd95SBruce Richardson  * @return
40799a2dd95SBruce Richardson  *  - non-negative integer on success.
40899a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
40999a2dd95SBruce Richardson  */
41099a2dd95SBruce Richardson int
41199a2dd95SBruce Richardson rte_fbarray_find_prev_n_used(struct rte_fbarray *arr, unsigned int start,
41299a2dd95SBruce Richardson 		unsigned int n);
41399a2dd95SBruce Richardson 
41499a2dd95SBruce Richardson 
41599a2dd95SBruce Richardson /**
41699a2dd95SBruce Richardson  * Find how many more free entries there are before specified index (like
41799a2dd95SBruce Richardson  * ``rte_fbarray_find_contig_free`` but going in reverse).
41899a2dd95SBruce Richardson  *
41999a2dd95SBruce Richardson  * @param arr
42099a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
42199a2dd95SBruce Richardson  *
42299a2dd95SBruce Richardson  * @param start
42399a2dd95SBruce Richardson  *   Element index to start search from.
42499a2dd95SBruce Richardson  *
42599a2dd95SBruce Richardson  * @return
42699a2dd95SBruce Richardson  *  - non-negative integer on success.
42799a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
42899a2dd95SBruce Richardson  */
42999a2dd95SBruce Richardson int
43099a2dd95SBruce Richardson rte_fbarray_find_rev_contig_free(struct rte_fbarray *arr,
43199a2dd95SBruce Richardson 		unsigned int start);
43299a2dd95SBruce Richardson 
43399a2dd95SBruce Richardson 
43499a2dd95SBruce Richardson /**
43599a2dd95SBruce Richardson  * Find how many more used entries there are before specified index (like
43699a2dd95SBruce Richardson  * ``rte_fbarray_find_contig_used`` but going in reverse).
43799a2dd95SBruce Richardson  *
43899a2dd95SBruce Richardson  * @param arr
43999a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
44099a2dd95SBruce Richardson  *
44199a2dd95SBruce Richardson  * @param start
44299a2dd95SBruce Richardson  *   Element index to start search from.
44399a2dd95SBruce Richardson  *
44499a2dd95SBruce Richardson  * @return
44599a2dd95SBruce Richardson  *  - non-negative integer on success.
44699a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
44799a2dd95SBruce Richardson  */
44899a2dd95SBruce Richardson int
44999a2dd95SBruce Richardson rte_fbarray_find_rev_contig_used(struct rte_fbarray *arr, unsigned int start);
45099a2dd95SBruce Richardson 
45199a2dd95SBruce Richardson 
45299a2dd95SBruce Richardson /**
45399a2dd95SBruce Richardson  * Find index of biggest chunk of free elements, starting at specified index.
45499a2dd95SBruce Richardson  *
45599a2dd95SBruce Richardson  * @param arr
45699a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
45799a2dd95SBruce Richardson  *
45899a2dd95SBruce Richardson  * @param start
45999a2dd95SBruce Richardson  *   Element index to start search from.
46099a2dd95SBruce Richardson  *
46199a2dd95SBruce Richardson  * @return
46299a2dd95SBruce Richardson  *  - non-negative integer on success.
46399a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
46499a2dd95SBruce Richardson  */
46599a2dd95SBruce Richardson int
46699a2dd95SBruce Richardson rte_fbarray_find_biggest_free(struct rte_fbarray *arr, unsigned int start);
46799a2dd95SBruce Richardson 
46899a2dd95SBruce Richardson 
46999a2dd95SBruce Richardson /**
47099a2dd95SBruce Richardson  * Find index of biggest chunk of used elements, starting at specified index.
47199a2dd95SBruce Richardson  *
47299a2dd95SBruce Richardson  * @param arr
47399a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
47499a2dd95SBruce Richardson  *
47599a2dd95SBruce Richardson  * @param start
47699a2dd95SBruce Richardson  *   Element index to start search from.
47799a2dd95SBruce Richardson  *
47899a2dd95SBruce Richardson  * @return
47999a2dd95SBruce Richardson  *  - non-negative integer on success.
48099a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
48199a2dd95SBruce Richardson  */
48299a2dd95SBruce Richardson int
48399a2dd95SBruce Richardson rte_fbarray_find_biggest_used(struct rte_fbarray *arr, unsigned int start);
48499a2dd95SBruce Richardson 
48599a2dd95SBruce Richardson 
48699a2dd95SBruce Richardson /**
48799a2dd95SBruce Richardson  * Find index of biggest chunk of free elements before a specified index (like
48899a2dd95SBruce Richardson  * ``rte_fbarray_find_biggest_free``, but going in reverse).
48999a2dd95SBruce Richardson  *
49099a2dd95SBruce Richardson  * @param arr
49199a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
49299a2dd95SBruce Richardson  *
49399a2dd95SBruce Richardson  * @param start
49499a2dd95SBruce Richardson  *   Element index to start search from.
49599a2dd95SBruce Richardson  *
49699a2dd95SBruce Richardson  * @return
49799a2dd95SBruce Richardson  *  - non-negative integer on success.
49899a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
49999a2dd95SBruce Richardson  */
50099a2dd95SBruce Richardson int
50199a2dd95SBruce Richardson rte_fbarray_find_rev_biggest_free(struct rte_fbarray *arr, unsigned int start);
50299a2dd95SBruce Richardson 
50399a2dd95SBruce Richardson 
50499a2dd95SBruce Richardson /**
50599a2dd95SBruce Richardson  * Find index of biggest chunk of used elements before a specified index (like
50699a2dd95SBruce Richardson  * ``rte_fbarray_find_biggest_used``, but going in reverse).
50799a2dd95SBruce Richardson  *
50899a2dd95SBruce Richardson  * @param arr
50999a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
51099a2dd95SBruce Richardson  *
51199a2dd95SBruce Richardson  * @param start
51299a2dd95SBruce Richardson  *   Element index to start search from.
51399a2dd95SBruce Richardson  *
51499a2dd95SBruce Richardson  * @return
51599a2dd95SBruce Richardson  *  - non-negative integer on success.
51699a2dd95SBruce Richardson  *  - -1 on failure, with ``rte_errno`` indicating reason for failure.
51799a2dd95SBruce Richardson  */
51899a2dd95SBruce Richardson int
51999a2dd95SBruce Richardson rte_fbarray_find_rev_biggest_used(struct rte_fbarray *arr, unsigned int start);
52099a2dd95SBruce Richardson 
52199a2dd95SBruce Richardson 
52299a2dd95SBruce Richardson /**
52399a2dd95SBruce Richardson  * Dump ``rte_fbarray`` metadata.
52499a2dd95SBruce Richardson  *
52599a2dd95SBruce Richardson  * @param arr
52699a2dd95SBruce Richardson  *   Valid pointer to allocated and correctly set up ``rte_fbarray`` structure.
52799a2dd95SBruce Richardson  *
52899a2dd95SBruce Richardson  * @param f
52999a2dd95SBruce Richardson  *   File object to dump information into.
53099a2dd95SBruce Richardson  */
53199a2dd95SBruce Richardson void
53299a2dd95SBruce Richardson rte_fbarray_dump_metadata(struct rte_fbarray *arr, FILE *f);
53399a2dd95SBruce Richardson 
53499a2dd95SBruce Richardson #ifdef __cplusplus
53599a2dd95SBruce Richardson }
53699a2dd95SBruce Richardson #endif
53799a2dd95SBruce Richardson 
53899a2dd95SBruce Richardson #endif /* RTE_FBARRAY_H */
539