svm_fifo_copy_from_chunk (f, f->head_chunk, head, dst, len, &f->head_chunk);
head = head + len;
+ /* In order dequeues are not supported in combination with ooo peeking.
+ * Use svm_fifo_dequeue_drop instead. */
+ ASSERT (rb_tree_n_nodes (&f->ooo_deq_lookup) <= 1);
+
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));
}
int
-svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs)
+svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs, u32 n_segs,
+ u32 max_bytes)
{
- u32 cursize, head, tail, head_idx;
+ u32 cursize, to_read, head, tail, fs_index = 1, n_bytes, head_pos, len;
+ svm_fifo_chunk_t *c;
f_load_head_tail_cons (f, &head, &tail);
if (PREDICT_FALSE (cursize == 0))
return SVM_FIFO_EEMPTY;
- head_idx = head;
+ to_read = clib_min (cursize, max_bytes);
- if (tail < head)
- {
- fs[0].len = f->size - head_idx;
- fs[0].data = f->head_chunk->data + head_idx;
- fs[1].len = cursize - fs[0].len;
- fs[1].data = f->head_chunk->data;
- }
- else
+ c = f->head_chunk;
+ head_pos = head - c->start_byte;
+ fs[0].data = c->data + head_pos;
+ fs[0].len = c->length - head_pos;
+ n_bytes = fs[0].len;
+ c = c->next;
+
+ while (n_bytes < to_read && fs_index < n_segs)
{
- fs[0].len = cursize;
- fs[0].data = f->head_chunk->data + head_idx;
- fs[1].len = 0;
- fs[1].data = 0;
+ len = clib_min (c->length, to_read - n_bytes);
+ fs[fs_index].data = c->data;
+ fs[fs_index].len = len;
+ n_bytes += len;
+ c = c->next;
+ fs_index += 1;
}
- return cursize;
-}
-
-void
-svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs)
-{
- u32 head;
- /* consumer owned index */
- head = f->head;
-
- ASSERT (fs[0].data == f->head_chunk->data + head);
- head = (head + fs[0].len + fs[1].len);
- /* store-rel: consumer owned index (paired with load-acq in producer) */
- clib_atomic_store_rel_n (&f->head, head);
+ return n_bytes;
}
/**
u8 *data = 0;
svm_fifo_trace_elem_t *trace;
u32 offset;
- svm_fifo_t *dummy_fifo;
+ svm_fifo_t *placeholder_fifo;
if (!f)
return s;
trace_len = 0;
#endif
- dummy_fifo = svm_fifo_alloc (f->size);
+ placeholder_fifo = svm_fifo_alloc (f->size);
svm_fifo_init (f, f->size);
clib_memset (f->head_chunk->data, 0xFF, f->size);
vec_validate (data, f->size);
if (verbose)
s = format (s, "adding [%u, %u]:", trace[i].offset,
(trace[i].offset + trace[i].len));
- svm_fifo_enqueue_with_offset (dummy_fifo, trace[i].offset,
+ svm_fifo_enqueue_with_offset (placeholder_fifo, trace[i].offset,
trace[i].len, &data[offset]);
}
else if (trace[i].action == 2)
{
if (verbose)
s = format (s, "adding [%u, %u]:", 0, trace[i].len);
- svm_fifo_enqueue (dummy_fifo, trace[i].len, &data[offset]);
+ svm_fifo_enqueue (placeholder_fifo, trace[i].len, &data[offset]);
}
else if (!no_read)
{
if (verbose)
s = format (s, "read: %u", trace[i].len);
- svm_fifo_dequeue_drop (dummy_fifo, trace[i].len);
+ svm_fifo_dequeue_drop (placeholder_fifo, trace[i].len);
}
if (verbose)
- s = format (s, "%U", format_svm_fifo, dummy_fifo, 1);
+ s = format (s, "%U", format_svm_fifo, placeholder_fifo, 1);
}
- s = format (s, "result: %U", format_svm_fifo, dummy_fifo, 1);
+ s = format (s, "result: %U", format_svm_fifo, placeholder_fifo, 1);
return s;
}