aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/svm_fifo.c35
-rw-r--r--src/svm/svm_fifo.h28
-rw-r--r--src/svm/svm_fifo_segment.h4
3 files changed, 47 insertions, 20 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index e3f534b179c..07b0d2dfbe3 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include "svm_fifo.h"
+#include <svm/svm_fifo.h>
/** create an svm fifo, in the current heap. Fails vs blow up the process */
svm_fifo_t *
@@ -362,18 +362,19 @@ svm_fifo_enqueue_nowait (svm_fifo_t * f,
return svm_fifo_enqueue_internal (f, pid, max_bytes, copy_from_here);
}
-/** Enqueue a future segment.
+/**
+ * Enqueue a future segment.
+ *
* Two choices: either copies the entire segment, or copies nothing
* Returns 0 of the entire segment was copied
* Returns -1 if none of the segment was copied due to lack of space
*/
-
static int
-svm_fifo_enqueue_with_offset_internal2 (svm_fifo_t * f,
- int pid,
- u32 offset,
- u32 required_bytes,
- u8 * copy_from_here)
+svm_fifo_enqueue_with_offset_internal (svm_fifo_t * f,
+ int pid,
+ u32 offset,
+ u32 required_bytes,
+ u8 * copy_from_here)
{
u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
u32 cursize, nitems;
@@ -424,14 +425,14 @@ svm_fifo_enqueue_with_offset (svm_fifo_t * f,
u32 offset,
u32 required_bytes, u8 * copy_from_here)
{
- return svm_fifo_enqueue_with_offset_internal2
+ return svm_fifo_enqueue_with_offset_internal
(f, pid, offset, required_bytes, copy_from_here);
}
static int
-svm_fifo_dequeue_internal2 (svm_fifo_t * f,
- int pid, u32 max_bytes, u8 * copy_here)
+svm_fifo_dequeue_internal (svm_fifo_t * f,
+ int pid, u32 max_bytes, u8 * copy_here)
{
u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
u32 cursize, nitems;
@@ -484,7 +485,7 @@ int
svm_fifo_dequeue_nowait (svm_fifo_t * f,
int pid, u32 max_bytes, u8 * copy_here)
{
- return svm_fifo_dequeue_internal2 (f, pid, max_bytes, copy_here);
+ return svm_fifo_dequeue_internal (f, pid, max_bytes, copy_here);
}
int
@@ -492,7 +493,7 @@ svm_fifo_peek (svm_fifo_t * f, int pid, u32 offset, u32 max_bytes,
u8 * copy_here)
{
u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
- u32 cursize, nitems;
+ u32 cursize, nitems, real_head;
if (PREDICT_FALSE (f->cursize == 0))
return -2; /* nothing in the fifo */
@@ -500,6 +501,8 @@ svm_fifo_peek (svm_fifo_t * f, int pid, u32 offset, u32 max_bytes,
/* read cursize, which can only increase while we're working */
cursize = f->cursize;
nitems = f->nitems;
+ real_head = f->head + offset;
+ real_head = real_head >= nitems ? real_head - nitems : real_head;
/* Number of bytes we're going to copy */
total_copy_bytes = (cursize < max_bytes) ? cursize : max_bytes;
@@ -508,9 +511,9 @@ svm_fifo_peek (svm_fifo_t * f, int pid, u32 offset, u32 max_bytes,
{
/* Number of bytes in first copy segment */
first_copy_bytes =
- ((nitems - f->head + offset) < total_copy_bytes) ?
- (nitems - f->head + offset) : total_copy_bytes;
- clib_memcpy (copy_here, &f->data[f->head + offset], first_copy_bytes);
+ ((nitems - real_head) < total_copy_bytes) ?
+ (nitems - real_head) : total_copy_bytes;
+ clib_memcpy (copy_here, &f->data[real_head], first_copy_bytes);
/* Number of bytes in second copy segment, if any */
second_copy_bytes = total_copy_bytes - first_copy_bytes;
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index 70624b74ed1..39556173e4d 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -46,9 +46,11 @@ typedef struct
{
pthread_mutex_t mutex; /* 8 bytes */
pthread_cond_t condvar; /* 8 bytes */
- u32 owner_pid;
svm_lock_tag_t tag;
- volatile u32 cursize;
+
+ volatile u32 cursize; /**< current fifo size */
+ volatile u8 has_event; /**< non-zero if deq event exists */
+ u32 owner_pid;
u32 nitems;
/* Backpointers */
@@ -112,6 +114,28 @@ svm_fifo_has_ooo_data (svm_fifo_t * f)
return f->ooos_list_head != OOO_SEGMENT_INVALID_INDEX;
}
+/**
+ * Sets fifo event flag.
+ *
+ * @return 1 if flag was not set.
+ */
+always_inline u8
+svm_fifo_set_event (svm_fifo_t * f)
+{
+ /* Probably doesn't need to be atomic. Still, better avoid surprises */
+ return __sync_lock_test_and_set (&f->has_event, 1) == 0;
+}
+
+/**
+ * Unsets fifo event flag.
+ */
+always_inline void
+svm_fifo_unset_event (svm_fifo_t * f)
+{
+ /* Probably doesn't need to be atomic. Still, better avoid surprises */
+ __sync_lock_test_and_set (&f->has_event, 0);
+}
+
svm_fifo_t *svm_fifo_create (u32 data_size_in_bytes);
int svm_fifo_enqueue_nowait (svm_fifo_t * f, int pid, u32 max_bytes,
diff --git a/src/svm/svm_fifo_segment.h b/src/svm/svm_fifo_segment.h
index 793fa7c8a0e..ecb5653aa74 100644
--- a/src/svm/svm_fifo_segment.h
+++ b/src/svm/svm_fifo_segment.h
@@ -15,8 +15,8 @@
#ifndef __included_ssvm_fifo_segment_h__
#define __included_ssvm_fifo_segment_h__
-#include "svm_fifo.h"
-#include "ssvm.h"
+#include <svm/svm_fifo.h>
+#include <svm/ssvm.h>
typedef struct
{