aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-04-26 20:34:49 -0700
committerFlorin Coras <florin.coras@gmail.com>2019-04-27 20:05:06 +0000
commitde146e5d5f7e919b423feeff3159c4ecd564c353 (patch)
tree4e748c7f352e69623cda6935686067764f583a0f /src/svm
parentfdea5c6a00b74971dbb1b7ec4e25839a871006ca (diff)
svm: fix fifo tail/head/ooo logic for u32 wrap
These were introduced with the switch to unbound tail/head size, so they only affect master. Added unit tests to avoid future surprises. Change-Id: I83b6c9efbe31d8092ba59b8e2ed46f4da97f35db Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/svm_fifo.c4
-rw-r--r--src/svm/svm_fifo.h4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index c8fd263c094..4c84fce4c01 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -819,7 +819,7 @@ svm_fifo_enqueue_with_offset (svm_fifo_t * f, u32 offset, u32 len, u8 * src)
ooo_segment_add (f, offset, head, tail, len);
- tail_idx = (tail + offset) % f->size;
+ tail_idx = (tail % f->size + offset) % f->size;
if (!svm_fifo_chunk_includes_pos (f->ooo_enq, tail_idx))
f->ooo_enq = svm_fifo_find_chunk (f, tail_idx);
@@ -871,7 +871,7 @@ svm_fifo_peek (svm_fifo_t * f, u32 offset, u32 len, u8 * dst)
return -2; /* nothing in the fifo */
len = clib_min (cursize - offset, len);
- head_idx = (head + offset) % f->size;
+ head_idx = (head % f->size + offset) % f->size;
if (!svm_fifo_chunk_includes_pos (f->ooo_deq, head_idx))
f->ooo_deq = svm_fifo_find_chunk (f, head_idx);
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index 7c84fc82198..c9370955dfb 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -527,13 +527,13 @@ svm_fifo_newest_ooo_segment_reset (svm_fifo_t * f)
always_inline u32
ooo_segment_distance_from_tail (svm_fifo_t * f, u32 pos, u32 tail)
{
- return ((pos - tail) % f->size);
+ return ((f->size + pos - tail) % f->size);
}
always_inline u32
ooo_segment_distance_to_tail (svm_fifo_t * f, u32 pos, u32 tail)
{
- return ((tail - pos) % f->size);
+ return ((f->size + tail - pos) % f->size);
}
always_inline u32