summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-09-25 15:18:13 -0700
committerDamjan Marion <dmarion@me.com>2020-09-29 09:02:48 +0000
commitd68faf8559da72aa6ad0526d5a86fb16587b1508 (patch)
tree8438ccf4ef312017465f073e5b7086abdd094cf3 /src/svm
parenta880b276d9998fa06c92355c4144fe3ca574c915 (diff)
vcl svm: provide apps access to fifo chunks
Type: feature Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I2191b8594b1e87ecc00f237316457db249f73603
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/svm_fifo.c49
-rw-r--r--src/svm/svm_fifo.h18
2 files changed, 36 insertions, 31 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index fda9481e721..2cce2bf50b3 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -1136,9 +1136,11 @@ svm_fifo_fill_chunk_list (svm_fifo_t * f)
}
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);
@@ -1148,37 +1150,26 @@ svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs)
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;
}
/**
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index f7503c8e900..93ef006fd48 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -348,8 +348,22 @@ int svm_fifo_dequeue_drop (svm_fifo_t * f, u32 len);
* @param f fifo
*/
void svm_fifo_dequeue_drop_all (svm_fifo_t * f);
-int svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs);
-void svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs);
+/**
+ * Get pointers to fifo chunks data in @ref svm_fifo_seg_t array
+ *
+ * Populates fifo segment array with pointers to fifo chunk data and lengths.
+ * Because this returns pointers to data, it must be paired with
+ * @ref svm_fifo_dequeue_drop to actually release the fifo chunks after the
+ * data is consumed.
+ *
+ * @param f fifo
+ * @param fs array of fifo segments allocated by caller
+ * @param n_segs number of fifo segments in array
+ * @param max_bytes max bytes to be mapped to fifo segments
+ * @return number of bytes in fifo segments or SVM_FIFO_EEMPTY
+ */
+int svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs, u32 n_segs,
+ u32 max_bytes);
/**
* Add io events subscriber to list
*