X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fsvm_fifo.c;h=47df22547ac077d214fbd9b3809087c72271b853;hb=10a0989a30f00e4705078ccfc0c03e8a7652eb2d;hp=8fe82f56abdc9acea4c39c51c5afbcd0e481747d;hpb=1f152cd6faf96b524b6b7071b5cffe1916f9c5cc;p=vpp.git diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c index 8fe82f56abd..47df22547ac 100644 --- a/src/svm/svm_fifo.c +++ b/src/svm/svm_fifo.c @@ -169,9 +169,13 @@ format_svm_fifo (u8 * s, va_list * args) svm_fifo_t *f = va_arg (*args, svm_fifo_t *); int verbose = va_arg (*args, int); + if (!s) + return s; + s = format (s, "cursize %u nitems %u has_event %d\n", f->cursize, f->nitems, f->has_event); - s = format (s, " head %d tail %d\n", f->head, f->tail); + s = format (s, " head %d tail %d segment manager %u\n", f->head, f->tail, + f->segment_manager); if (verbose > 1) s = format @@ -443,12 +447,13 @@ ooo_segment_try_collect (svm_fifo_t * f, u32 n_bytes_enqueued) } } - ASSERT (bytes >= 0 && bytes <= f->nitems); + ASSERT (bytes <= f->nitems); return bytes; } static int -svm_fifo_enqueue_internal (svm_fifo_t * f, u32 max_bytes, u8 * copy_from_here) +svm_fifo_enqueue_internal (svm_fifo_t * f, u32 max_bytes, + const u8 * copy_from_here) { u32 total_copy_bytes, first_copy_bytes, second_copy_bytes; u32 cursize, nitems; @@ -458,7 +463,7 @@ svm_fifo_enqueue_internal (svm_fifo_t * f, u32 max_bytes, u8 * copy_from_here) f->ooos_newest = OOO_SEGMENT_INVALID_INDEX; if (PREDICT_FALSE (cursize == f->nitems)) - return -2; /* fifo stuffed */ + return SVM_FIFO_FULL; nitems = f->nitems; @@ -520,7 +525,7 @@ svm_fifo_enqueue_internal (svm_fifo_t * f, u32 max_bytes, u8 * copy_from_here) static int svm_fifo_enqueue_nowait_ma (svm_fifo_t * f, u32 max_bytes, - u8 * copy_from_here) + const u8 * copy_from_here) { return svm_fifo_enqueue_internal (f, max_bytes, copy_from_here); } @@ -530,12 +535,13 @@ foreach_march_variant (SVM_ENQUEUE_CLONE_TEMPLATE, CLIB_MULTIARCH_SELECT_FN (svm_fifo_enqueue_nowait_ma); int -svm_fifo_enqueue_nowait (svm_fifo_t * f, u32 max_bytes, u8 * copy_from_here) +svm_fifo_enqueue_nowait (svm_fifo_t * f, u32 max_bytes, + const u8 * copy_from_here) { #if CLIB_DEBUG > 0 return svm_fifo_enqueue_nowait_ma (f, max_bytes, copy_from_here); #else - static int (*fp) (svm_fifo_t *, u32, u8 *); + static int (*fp) (svm_fifo_t *, u32, const u8 *); if (PREDICT_FALSE (fp == 0)) fp = (void *) svm_fifo_enqueue_nowait_ma_multiarch_select (); @@ -613,6 +619,20 @@ svm_fifo_enqueue_with_offset (svm_fifo_t * f, copy_from_here); } +void +svm_fifo_overwrite_head (svm_fifo_t * f, u8 * data, u32 len) +{ + u32 first_chunk; + first_chunk = f->nitems - f->head; + ASSERT (len <= f->nitems); + if (len <= first_chunk) + clib_memcpy (&f->data[f->head], data, len); + else + { + clib_memcpy (&f->data[f->head], data, first_chunk); + clib_memcpy (&f->data[0], data + first_chunk, len - first_chunk); + } +} static int svm_fifo_dequeue_internal (svm_fifo_t * f, u32 max_bytes, u8 * copy_here) @@ -808,6 +828,13 @@ svm_fifo_dequeue_drop (svm_fifo_t * f, u32 max_bytes) return total_drop_bytes; } +void +svm_fifo_dequeue_drop_all (svm_fifo_t * f) +{ + f->head = f->tail; + __sync_fetch_and_sub (&f->cursize, f->cursize); +} + u32 svm_fifo_number_ooo_segments (svm_fifo_t * f) {