+ if (PREDICT_FALSE (f->ooo_deq != 0))
+ f->ooo_deq = 0;
+ }
+
+ /* Avoid unlinking the last chunk */
+ if (!prev)
+ return 0;
+
+ prev->next = 0;
+ start = f->start_chunk;
+ f->start_chunk = c;
+
+ return start;
+}
+
+int
+svm_fifo_dequeue (svm_fifo_t * f, u32 len, u8 * dst)
+{
+ u32 tail, head, cursize;
+
+ f_load_head_tail_cons (f, &head, &tail);
+
+ /* current size of fifo can only increase during dequeue: SPSC */
+ cursize = f_cursize (f, head, tail);
+
+ if (PREDICT_FALSE (cursize == 0))
+ return SVM_FIFO_EEMPTY;
+
+ len = clib_min (cursize, len);
+
+ if (!f->head_chunk)
+ f->head_chunk = svm_fifo_find_chunk (f, head);
+
+ svm_fifo_copy_from_chunk (f, f->head_chunk, head, dst, len, &f->head_chunk);
+ head = head + len;
+
+ if (f_pos_geq (head, f_chunk_end (f->start_chunk)))
+ fsh_collect_chunks (f->fs_hdr, f->slice_index,
+ f_unlink_chunks (f, head, 0));
+
+ /* store-rel: consumer owned index (paired with load-acq in producer) */
+ clib_atomic_store_rel_n (&f->head, head);
+
+ return len;
+}
+
+int
+svm_fifo_peek (svm_fifo_t * f, u32 offset, u32 len, u8 * dst)
+{
+ u32 tail, head, cursize, head_idx;
+
+ f_load_head_tail_cons (f, &head, &tail);
+
+ /* current size of fifo can only increase during peek: SPSC */
+ cursize = f_cursize (f, head, tail);
+
+ if (PREDICT_FALSE (cursize < offset))
+ return SVM_FIFO_EEMPTY;
+
+ len = clib_min (cursize - offset, len);
+ head_idx = head + offset;
+
+ if (!f->ooo_deq || !f_chunk_includes_pos (f->ooo_deq, head_idx))
+ f_update_ooo_deq (f, head_idx, head_idx + len);
+
+ svm_fifo_copy_from_chunk (f, f->ooo_deq, head_idx, dst, len, &f->ooo_deq);
+ return len;
+}
+
+int
+svm_fifo_dequeue_drop (svm_fifo_t * f, u32 len)
+{
+ u32 total_drop_bytes, tail, head, cursize;
+
+ f_load_head_tail_cons (f, &head, &tail);
+
+ /* number of bytes available */
+ cursize = f_cursize (f, head, tail);
+ if (PREDICT_FALSE (cursize == 0))
+ return SVM_FIFO_EEMPTY;
+
+ /* number of bytes we're going to drop */
+ total_drop_bytes = clib_min (cursize, len);
+
+ svm_fifo_trace_add (f, tail, total_drop_bytes, 3);
+
+ /* move head */
+ head = head + total_drop_bytes;
+
+ if (f_pos_geq (head, f_chunk_end (f->start_chunk)))
+ {
+ fsh_collect_chunks (f->fs_hdr, f->slice_index,
+ f_unlink_chunks (f, head, 1));
+ f->head_chunk =
+ f_chunk_includes_pos (f->start_chunk, head) ? f->start_chunk : 0;