diff options
author | Florin Coras <fcoras@cisco.com> | 2019-12-19 16:10:58 -0800 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2020-02-25 19:18:49 +0000 |
commit | f22f4e562e1b922cff036ef628b77fd2d479d015 (patch) | |
tree | 4cbc3091a5ce89a73c94685dcee198dd583ca375 /src/svm/fifo_segment.h | |
parent | b020806806c0e6c54886cdb4347a5fd1f19504b0 (diff) |
svm: refactor fifo
Type: refactor
Switch from a wrapped byte space to a "continuous" one wherein fifo
chunks are appended to the fifo as more data is enqueued and chunks are
removed as data is dequeued.
The fifo is still subject to a maximum size, i.e., maximum number of
bytes that can be enqueued, so the max number of chunks associated to
the fifo is also constrained.
When enqueueing data, which must fit within the available free space, if
not enough "supporting" chunk memory is available, the fifo asks the
fifo segment for enough chunk memory to ensure that the write can
succeed. To avoid allocating large amounts of small chunks due to small
writes, if possible, the size of the chunks requested is lower capped by
min_alloc.
When dequeuing data, all the chunks that have been completely drained,
i.e., head moved beyond the chunks’ end bytes, are unlinked from the
fifo and returned to the fifo segment. The one exception to this is the
last chunk which is never unlinked.
Change-Id: I98c1dbd9135fb79650365c7e40c29238b96cd4ee
Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm/fifo_segment.h')
-rw-r--r-- | src/svm/fifo_segment.h | 44 |
1 files changed, 6 insertions, 38 deletions
diff --git a/src/svm/fifo_segment.h b/src/svm/fifo_segment.h index 02d45d3244d..85548063972 100644 --- a/src/svm/fifo_segment.h +++ b/src/svm/fifo_segment.h @@ -16,6 +16,7 @@ #define __included_fifo_segment_h__ #include <svm/ssvm.h> +#include <svm/fifo_types.h> #include <svm/svm_fifo.h> typedef enum @@ -38,26 +39,6 @@ typedef enum fifo_segment_flags_ FIFO_SEGMENT_F_MEM_LIMIT = 1 << 2, } fifo_segment_flags_t; -typedef struct fifo_segment_slice_ -{ - svm_fifo_t *fifos; /**< Linked list of active RX fifos */ - svm_fifo_t *free_fifos; /**< Freelists by fifo size */ - svm_fifo_chunk_t **free_chunks; /**< Freelists by chunk size */ - uword n_fl_chunk_bytes; /**< Chunk bytes on freelist */ -} fifo_segment_slice_t; - -typedef struct -{ - fifo_segment_slice_t *slices; /** Fixed array of slices */ - ssvm_shared_header_t *ssvm_sh; /**< Pointer to fs ssvm shared hdr */ - uword n_free_bytes; /**< Segment free bytes */ - u32 n_active_fifos; /**< Number of active fifos */ - u32 n_reserved_bytes; /**< Bytes not to be allocated */ - u32 max_log2_chunk_size; /**< Max log2(chunk size) for fs */ - u8 flags; /**< Segment flags */ - u8 n_slices; /**< Number of slices */ -} fifo_segment_header_t; - typedef struct { ssvm_private_t ssvm; /**< ssvm segment data */ @@ -158,25 +139,12 @@ void fifo_segment_preallocate_fifo_pairs (fifo_segment_t * fs, u32 rx_fifo_size, u32 tx_fifo_size, u32 * n_fifo_pairs); -/** - * Grow fifo size by adding an additional chunk of memory - * - * @param fs fifo segment for fifo - * @param f fifo to be grown - * @param chunk_size number of bytes to be added to fifo - * @return 0 on success or a negative number otherwise - */ -int fifo_segment_grow_fifo (fifo_segment_t * fs, svm_fifo_t * f, - u32 chunk_size); -/** - * Collect unused chunks for fifo - * - * @param fs fifo segment for fifo - * @param f fifo whose chunks are to be collected - * @return 0 on success, error otherwise - */ -int fifo_segment_collect_fifo_chunks (fifo_segment_t * fs, svm_fifo_t * f); +svm_fifo_chunk_t *fsh_alloc_chunk (fifo_segment_header_t * fsh, + u32 slice_index, u32 chunk_size); + +void fsh_collect_chunks (fifo_segment_header_t * fsh, u32 slice_index, + svm_fifo_chunk_t * cur); /** * Fifo segment estimate of number of free bytes |