From 29a59c3ae18573043d9f9baa2796ab0b841bf6aa Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Thu, 2 May 2019 12:52:19 -0700 Subject: svm: store normalized head/tail for fifo If head/tail are stored as "absolute" values that are normalized to [0, fifo_size] interval, when fifo is shrunk/grown the consumer and producer have to independently update to the new fifo size and fix head and tail, respectively. If the head and tail are stored as normalized values, under the right conditions, they don't need to be fixed when fifo size changes. This reverts one of the changes in gerrit 18223. Change-Id: I55a908828afe90925cf7c20186a940b25e5805f9 Signed-off-by: Florin Coras --- src/plugins/unittest/svm_fifo_test.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/plugins/unittest/svm_fifo_test.c') diff --git a/src/plugins/unittest/svm_fifo_test.c b/src/plugins/unittest/svm_fifo_test.c index 99f0e5044d6..d2afc36e0d0 100644 --- a/src/plugins/unittest/svm_fifo_test.c +++ b/src/plugins/unittest/svm_fifo_test.c @@ -806,7 +806,7 @@ sfifo_test_fifo4 (vlib_main_t * vm, unformat_input_t * input) static u32 fifo_pos (svm_fifo_t * f, u32 pos) { - return pos; + return pos % f->size; } /* Avoids exposing svm_fifo.c internal function */ @@ -1194,6 +1194,7 @@ sfifo_test_fifo_grow (vlib_main_t * vm, unformat_input_t * input) svm_fifo_chunk_t *c, *next, *prev; u8 *test_data = 0, *data_buf = 0; svm_fifo_t *f; + u32 old_tail; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { @@ -1288,10 +1289,14 @@ sfifo_test_fifo_grow (vlib_main_t * vm, unformat_input_t * input) SFIFO_TEST (f->size == fifo_size + 200, "size expected %u is %u", fifo_size + 200, f->size); - svm_fifo_dequeue (f, 201, data_buf); + old_tail = f->tail; + svm_fifo_dequeue (f, 101, data_buf); SFIFO_TEST (f->size == fifo_size + 200 + 10 * 100, "size expected %u is %u", fifo_size + 200 + 10 * 100, f->size); + SFIFO_TEST (f->tail == old_tail, "new tail expected %u is %u", old_tail, + f->tail); + /* * Enqueue/dequeue tests */ -- cgit 1.2.3-korg