DPDK 22.11.6
Functions
rte_fbarray.h File Reference
#include <stdio.h>
#include <rte_rwlock.h>

Go to the source code of this file.

Functions

int rte_fbarray_init (struct rte_fbarray *arr, const char *name, unsigned int len, unsigned int elt_sz)
 
int rte_fbarray_attach (struct rte_fbarray *arr)
 
int rte_fbarray_destroy (struct rte_fbarray *arr)
 
int rte_fbarray_detach (struct rte_fbarray *arr)
 
void * rte_fbarray_get (const struct rte_fbarray *arr, unsigned int idx)
 
int rte_fbarray_find_idx (const struct rte_fbarray *arr, const void *elt)
 
int rte_fbarray_set_used (struct rte_fbarray *arr, unsigned int idx)
 
int rte_fbarray_set_free (struct rte_fbarray *arr, unsigned int idx)
 
int rte_fbarray_is_used (struct rte_fbarray *arr, unsigned int idx)
 
int rte_fbarray_find_next_free (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_next_used (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_next_n_free (struct rte_fbarray *arr, unsigned int start, unsigned int n)
 
int rte_fbarray_find_next_n_used (struct rte_fbarray *arr, unsigned int start, unsigned int n)
 
int rte_fbarray_find_contig_free (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_contig_used (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_prev_free (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_prev_used (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_prev_n_free (struct rte_fbarray *arr, unsigned int start, unsigned int n)
 
int rte_fbarray_find_prev_n_used (struct rte_fbarray *arr, unsigned int start, unsigned int n)
 
int rte_fbarray_find_rev_contig_free (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_rev_contig_used (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_biggest_free (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_biggest_used (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_rev_biggest_free (struct rte_fbarray *arr, unsigned int start)
 
int rte_fbarray_find_rev_biggest_used (struct rte_fbarray *arr, unsigned int start)
 
void rte_fbarray_dump_metadata (struct rte_fbarray *arr, FILE *f)
 

Detailed Description

File-backed shared indexed array for DPDK.

Basic workflow is expected to be the following: 1) Allocate array either using rte_fbarray_init() or rte_fbarray_attach() (depending on whether it's shared between multiple DPDK processes) 2) find free spots using rte_fbarray_find_next_free() 3) get pointer to data in the free spot using rte_fbarray_get(), and copy data into the pointer (element size is fixed) 4) mark entry as used using rte_fbarray_set_used()

Calls to rte_fbarray_init() and rte_fbarray_destroy() will have consequences for all processes, while calls to rte_fbarray_attach() and rte_fbarray_detach() will only have consequences within a single process. Therefore, it is safe to call rte_fbarray_attach() or rte_fbarray_detach() while another process is using rte_fbarray, provided no other thread within the same process will try to use rte_fbarray before attaching or after detaching. It is not safe to call rte_fbarray_init() or rte_fbarray_destroy() while another thread or another process is using rte_fbarray.

Definition in file rte_fbarray.h.

Function Documentation

◆ rte_fbarray_init()

int rte_fbarray_init ( struct rte_fbarray *  arr,
const char *  name,
unsigned int  len,
unsigned int  elt_sz 
)

Set up rte_fbarray structure and allocate underlying resources.

Call this function to correctly set up rte_fbarray and allocate underlying files that will be backing the data in the current process. Note that in order to use and share rte_fbarray between multiple processes, data pointed to by arr pointer must itself be allocated in shared memory.

Parameters
arrValid pointer to allocated rte_fbarray structure.
nameUnique name to be assigned to this array.
lenNumber of elements initially available in the array.
elt_szSize of each element.
Returns
  • 0 on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_attach()

int rte_fbarray_attach ( struct rte_fbarray *  arr)

Attach to a file backing an already allocated and correctly set up rte_fbarray structure.

Call this function to attach to file that will be backing the data in the current process. The structure must have been previously correctly set up with a call to rte_fbarray_init(). Calls to rte_fbarray_attach() are usually meant to be performed in a multiprocessing scenario, with data pointed to by arr pointer allocated in shared memory.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
Returns
  • 0 on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_destroy()

int rte_fbarray_destroy ( struct rte_fbarray *  arr)

Deallocate resources for an already allocated and correctly set up rte_fbarray structure, and remove the underlying file.

Call this function to deallocate all resources associated with an rte_fbarray structure within the current process. This will also zero-fill data pointed to by arr pointer and remove the underlying file backing the data, so it is expected that by the time this function is called, all other processes have detached from this rte_fbarray.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
Returns
  • 0 on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_detach()

int rte_fbarray_detach ( struct rte_fbarray *  arr)

Deallocate resources for an already allocated and correctly set up rte_fbarray structure.

Call this function to deallocate all resources associated with an rte_fbarray structure within current process.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
Returns
  • 0 on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_get()

void * rte_fbarray_get ( const struct rte_fbarray *  arr,
unsigned int  idx 
)

Get pointer to element residing at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
idxIndex of an element to get a pointer to.
Returns
  • non-NULL pointer on success.
  • NULL on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_idx()

int rte_fbarray_find_idx ( const struct rte_fbarray *  arr,
const void *  elt 
)

Find index of a specified element within the array.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
eltPointer to element to find index to.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_set_used()

int rte_fbarray_set_used ( struct rte_fbarray *  arr,
unsigned int  idx 
)

Mark specified element as used.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
idxElement index to mark as used.
Returns
  • 0 on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_set_free()

int rte_fbarray_set_free ( struct rte_fbarray *  arr,
unsigned int  idx 
)

Mark specified element as free.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
idxElement index to mark as free.
Returns
  • 0 on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_is_used()

int rte_fbarray_is_used ( struct rte_fbarray *  arr,
unsigned int  idx 
)

Check whether element at specified index is marked as used.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
idxElement index to check as used.
Returns
  • 1 if element is used.
  • 0 if element is unused.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_next_free()

int rte_fbarray_find_next_free ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of next free element, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_next_used()

int rte_fbarray_find_next_used ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of next used element, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_next_n_free()

int rte_fbarray_find_next_n_free ( struct rte_fbarray *  arr,
unsigned int  start,
unsigned int  n 
)

Find index of next chunk of n free elements, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
nNumber of free elements to look for.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_next_n_used()

int rte_fbarray_find_next_n_used ( struct rte_fbarray *  arr,
unsigned int  start,
unsigned int  n 
)

Find index of next chunk of n used elements, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
nNumber of used elements to look for.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_contig_free()

int rte_fbarray_find_contig_free ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find how many more free entries there are, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_contig_used()

int rte_fbarray_find_contig_used ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find how many more used entries there are, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_prev_free()

int rte_fbarray_find_prev_free ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of previous free element, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_prev_used()

int rte_fbarray_find_prev_used ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of previous used element, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_prev_n_free()

int rte_fbarray_find_prev_n_free ( struct rte_fbarray *  arr,
unsigned int  start,
unsigned int  n 
)

Find lowest start index of chunk of n free elements, down from specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
nNumber of free elements to look for.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_prev_n_used()

int rte_fbarray_find_prev_n_used ( struct rte_fbarray *  arr,
unsigned int  start,
unsigned int  n 
)

Find lowest start index of chunk of n used elements, down from specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
nNumber of used elements to look for.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_rev_contig_free()

int rte_fbarray_find_rev_contig_free ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find how many more free entries there are before specified index (like rte_fbarray_find_contig_free but going in reverse).

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_rev_contig_used()

int rte_fbarray_find_rev_contig_used ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find how many more used entries there are before specified index (like rte_fbarray_find_contig_used but going in reverse).

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_biggest_free()

int rte_fbarray_find_biggest_free ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of biggest chunk of free elements, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_biggest_used()

int rte_fbarray_find_biggest_used ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of biggest chunk of used elements, starting at specified index.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_rev_biggest_free()

int rte_fbarray_find_rev_biggest_free ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of biggest chunk of free elements before a specified index (like rte_fbarray_find_biggest_free, but going in reverse).

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_find_rev_biggest_used()

int rte_fbarray_find_rev_biggest_used ( struct rte_fbarray *  arr,
unsigned int  start 
)

Find index of biggest chunk of used elements before a specified index (like rte_fbarray_find_biggest_used, but going in reverse).

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
startElement index to start search from.
Returns
  • non-negative integer on success.
  • -1 on failure, with rte_errno indicating reason for failure.

◆ rte_fbarray_dump_metadata()

void rte_fbarray_dump_metadata ( struct rte_fbarray *  arr,
FILE *  f 
)

Dump rte_fbarray metadata.

Parameters
arrValid pointer to allocated and correctly set up rte_fbarray structure.
fFile object to dump information into.