X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fsvm_fifo.h;h=39cdcc06a0cfcab297b54ffc21eed27b223fd841;hb=7fb0fe1;hp=84901d022d6aaf8a3a5f21770363cb38d78d89ff;hpb=818eb54de01459ed3d823f8a9781bbed0845db82;p=vpp.git diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h index 84901d022d6..39cdcc06a0c 100644 --- a/src/svm/svm_fifo.h +++ b/src/svm/svm_fifo.h @@ -80,6 +80,11 @@ typedef struct _svm_fifo CLIB_CACHE_LINE_ALIGN_MARK (data); } svm_fifo_t; +typedef enum +{ + SVM_FIFO_FULL = -2, +} svm_fifo_err_t; + #if SVM_FIFO_TRACE #define svm_fifo_trace_add(_f, _s, _l, _t) \ { \ @@ -140,7 +145,7 @@ svm_fifo_t *svm_fifo_create (u32 data_size_in_bytes); void svm_fifo_free (svm_fifo_t * f); int svm_fifo_enqueue_nowait (svm_fifo_t * f, u32 max_bytes, - u8 * copy_from_here); + const u8 * copy_from_here); int svm_fifo_enqueue_with_offset (svm_fifo_t * f, u32 offset, u32 required_bytes, u8 * copy_from_here); int svm_fifo_dequeue_nowait (svm_fifo_t * f, u32 max_bytes, u8 * copy_here); @@ -150,6 +155,7 @@ int svm_fifo_dequeue_drop (svm_fifo_t * f, u32 max_bytes); u32 svm_fifo_number_ooo_segments (svm_fifo_t * f); ooo_segment_t *svm_fifo_first_ooo_segment (svm_fifo_t * f); void svm_fifo_init_pointers (svm_fifo_t * f, u32 pointer); +void svm_fifo_overwrite_head (svm_fifo_t * f, u8 * data, u32 len); format_function_t format_svm_fifo; @@ -167,6 +173,49 @@ svm_fifo_newest_ooo_segment_reset (svm_fifo_t * f) f->ooos_newest = OOO_SEGMENT_INVALID_INDEX; } +/** + * Max contiguous chunk of data that can be read + */ +always_inline u32 +svm_fifo_max_read_chunk (svm_fifo_t * f) +{ + return ((f->tail > f->head) ? (f->tail - f->head) : (f->nitems - f->head)); +} + +/** + * Max contiguous chunk of data that can be written + */ +always_inline u32 +svm_fifo_max_write_chunk (svm_fifo_t * f) +{ + return ((f->tail >= f->head) ? (f->nitems - f->tail) : (f->head - f->tail)); +} + +/** + * Advance tail pointer + * + * Useful for moving tail pointer after external enqueue. + */ +always_inline void +svm_fifo_enqueue_nocopy (svm_fifo_t * f, u32 bytes) +{ + ASSERT (bytes <= svm_fifo_max_enqueue (f)); + f->tail = (f->tail + bytes) % f->nitems; + f->cursize += bytes; +} + +always_inline u8 * +svm_fifo_head (svm_fifo_t * f) +{ + return (f->data + f->head); +} + +always_inline u8 * +svm_fifo_tail (svm_fifo_t * f) +{ + return (f->data + f->tail); +} + always_inline u32 ooo_segment_distance_from_tail (svm_fifo_t * f, u32 pos) {