summaryrefslogtreecommitdiffstats
path: root/src/svm/fifo_segment.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-07-02 13:07:37 -0700
committerDave Barach <openvpp@barachs.net>2019-07-03 11:26:36 +0000
commiteaacce4753c33342a6512039fe4153b15b476fb3 (patch)
treeb7465c6da3970f28db0aca7ab92b12b3c7fbaa5d /src/svm/fifo_segment.c
parentb5ef26d1ed524d1f2f59ffd5546d1c581f4c88a2 (diff)
svm: fix multi-chunk fifo alloc and add more tests
Type: fix - make sure that chunks and the rbtree are initialized if fifo segment allocates multiple chunks for the fifo. - ensure head/tail chunks are updated on all enqueue/dequeue events, including when dropping data. - more unit tests Also fixes dequeue drop updates of head chunk. Change-Id: I77f3550bc4e8b4e077f80ea87fe82b83ed013aeb Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm/fifo_segment.c')
-rw-r--r--src/svm/fifo_segment.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index d47c8534d14..eeb274636c1 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -394,6 +394,14 @@ fifo_segment_alloc_fifo (fifo_segment_t * fs, u32 data_bytes,
/* (re)initialize the fifo, as in svm_fifo_create */
svm_fifo_init (f, data_bytes);
+ /* Initialize chunks and rbtree for multi-chunk fifos */
+ if (f->start_chunk->next != f->start_chunk)
+ {
+ void *oldheap = ssvm_push_heap (fs->ssvm.sh);
+ svm_fifo_init_chunks (f);
+ ssvm_pop_heap (oldheap);
+ }
+
/* If rx fifo type add to active fifos list. When cleaning up segment,
* we need a list of active sessions that should be disconnected. Since
* both rx and tx fifos keep pointers to the session, it's enough to track
@@ -613,12 +621,16 @@ fifo_segment_preallocate_fifo_pairs (fifo_segment_t * fs,
/* Calculate space requirements */
pair_size = 2 * hdrs + rx_rounded_data_size + tx_rounded_data_size;
space_available = fs_free_space (fs);
- pairs_to_alloc = clib_min (space_available / pair_size, *n_fifo_pairs);
+ pairs_to_alloc = space_available / pair_size;
+ pairs_to_alloc = clib_min (pairs_to_alloc, *n_fifo_pairs);
+
+ if (!pairs_to_alloc)
+ return;
if (fs_try_alloc_fifo_batch (fs, rx_fl_index, pairs_to_alloc))
- clib_warning ("rx prealloc failed");
+ clib_warning ("rx prealloc failed: pairs %u", pairs_to_alloc);
if (fs_try_alloc_fifo_batch (fs, tx_fl_index, pairs_to_alloc))
- clib_warning ("tx prealloc failed");
+ clib_warning ("tx prealloc failed: pairs %u", pairs_to_alloc);
/* Account for the pairs allocated */
*n_fifo_pairs -= pairs_to_alloc;