summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/svm_fifo.c47
-rw-r--r--src/svm/svm_fifo.h12
2 files changed, 57 insertions, 2 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index 018827e0343..0c258b4259c 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -835,6 +835,53 @@ svm_fifo_dequeue_drop_all (svm_fifo_t * f)
__sync_fetch_and_sub (&f->cursize, f->cursize);
}
+int
+svm_fifo_segments (svm_fifo_t * f, svm_fifo_segment_t * fs)
+{
+ u32 cursize, nitems;
+
+ /* read cursize, which can only increase while we're working */
+ cursize = svm_fifo_max_dequeue (f);
+ if (PREDICT_FALSE (cursize == 0))
+ return -2;
+
+ nitems = f->nitems;
+
+ fs[0].len = ((nitems - f->head) < cursize) ? (nitems - f->head) : cursize;
+ fs[0].data = f->data + f->head;
+
+ if (fs[0].len < cursize)
+ {
+ fs[1].len = cursize - fs[0].len;
+ fs[1].data = f->data;
+ }
+ else
+ {
+ fs[1].len = 0;
+ fs[1].data = 0;
+ }
+ return cursize;
+}
+
+void
+svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_segment_t * fs)
+{
+ u32 total_drop_bytes;
+
+ ASSERT (fs[0].data == f->data + f->head);
+ if (fs[1].len)
+ {
+ f->head = fs[1].len;
+ total_drop_bytes = fs[0].len + fs[1].len;
+ }
+ else
+ {
+ f->head = (f->head + fs[0].len) % f->nitems;
+ total_drop_bytes = fs[0].len;
+ }
+ __sync_fetch_and_sub (&f->cursize, total_drop_bytes);
+}
+
u32
svm_fifo_number_ooo_segments (svm_fifo_t * f)
{
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index a8aea00996e..ec32fd5f40d 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -85,6 +85,12 @@ typedef enum
SVM_FIFO_FULL = -2,
} svm_fifo_err_t;
+typedef struct svm_fifo_segment_
+{
+ u8 *data;
+ u32 len;
+} svm_fifo_segment_t;
+
#if SVM_FIFO_TRACE
#define svm_fifo_trace_add(_f, _s, _l, _t) \
{ \
@@ -147,8 +153,8 @@ svm_fifo_has_ooo_data (svm_fifo_t * f)
always_inline u8
svm_fifo_set_event (svm_fifo_t * f)
{
-// return __sync_lock_test_and_set (&f->has_event, 1) == 0;
-// return __sync_bool_compare_and_swap (&f->has_event, 0, 1);
+ /* return __sync_lock_test_and_set (&f->has_event, 1) == 0;
+ return __sync_bool_compare_and_swap (&f->has_event, 0, 1); */
return !__atomic_exchange_n (&f->has_event, 1, __ATOMIC_RELEASE);
}
@@ -175,6 +181,8 @@ int svm_fifo_dequeue_nowait (svm_fifo_t * f, u32 max_bytes, u8 * copy_here);
int svm_fifo_peek (svm_fifo_t * f, u32 offset, u32 max_bytes, u8 * copy_here);
int svm_fifo_dequeue_drop (svm_fifo_t * f, u32 max_bytes);
void svm_fifo_dequeue_drop_all (svm_fifo_t * f);
+int svm_fifo_segments (svm_fifo_t * f, svm_fifo_segment_t * fs);
+void svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_segment_t * fs);
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);