fifo_prepare (fifo_segment_t * fs, u32 fifo_size)
{
svm_fifo_t *f;
+ svm_fifo_chunk_t *c;
f = fifo_segment_alloc_fifo (fs, fifo_size, FIFO_SEGMENT_RX_FIFO);
- /* Paint fifo data vector with -1's */
- clib_memset (svm_fifo_head_chunk (f)->data, 0xFF, fifo_size);
+ /* Paint 1st fifo chunk with -1's */
+ c = svm_fifo_head_chunk (f);
+ clib_memset (c->data, 0xFF, c->length);
svm_fifo_init_ooo_lookup (f, 1 /* deq ooo */ );
return f;
SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
/*
- * Dequeue just a part of data
+ * Dequeue just a part of data. Because we're tracking ooo data, we can't
+ * call dequeue. Therefore, first peek and then dequeue drop
*/
- rv = svm_fifo_dequeue (f, fifo_inc, data_buf);
+ rv = svm_fifo_peek (f, 0, fifo_inc, data_buf);
+ SFIFO_TEST (rv == fifo_inc, "should dequeue all data");
+ rv = svm_fifo_dequeue_drop (f, fifo_inc);
SFIFO_TEST (rv == fifo_inc, "should dequeue all data");
rv = svm_fifo_n_chunks (f);
SFIFO_TEST (rv == 1, "should have %u chunks has %u", 1, rv);
SFIFO_TEST (c->length == 4096, "end chunk length should be %u", 4096);
/*
- * Dequeue all
+ * Dequeue all. Don't call dequeue see above
*/
- rv = svm_fifo_dequeue (f, fifo_size, data_buf + fifo_inc);
+ rv = svm_fifo_peek (f, 0, fifo_size, data_buf + fifo_inc);
SFIFO_TEST (rv == fifo_size, "should dequeue all data");
+ SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
rv = compare_data (data_buf, test_data, 0, vec_len (test_data),
(u32 *) & i);
vlib_cli_output (vm, "[%d] dequeued %u expected %u", i, data_buf[i],
test_data[i]);
SFIFO_TEST ((rv == 0), "dequeued compared to original returned %d", rv);
+
+ rv = svm_fifo_dequeue_drop (f, fifo_size);
+ SFIFO_TEST (rv == fifo_size, "should dequeue all data");
+
SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
/* fifo does not end on chunk boundary because of the - 100 */
SFIFO_TEST (f->head_chunk != 0, "should have head chunk");
/*
* Dequeue all
*/
- rv = svm_fifo_dequeue (f, fifo_size, data_buf);
+
+ /* Because we're tracking ooo data, we can't call dequeue. Therefore,
+ * first peek and then dequeue drop */
+ rv = svm_fifo_peek (f, 0, fifo_size, data_buf);
SFIFO_TEST (rv == fifo_size, "should dequeue all data");
rv = compare_data (data_buf, test_data, 0, vec_len (test_data),
test_data[i]);
SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
SFIFO_TEST ((rv == 0), "dequeued compared to original returned %d", rv);
+
+
+ rv = svm_fifo_dequeue_drop (f, fifo_size);
+ SFIFO_TEST ((rv == fifo_size), "all bytes should be dropped %u", rv);
+ SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
SFIFO_TEST (f->ooo_deq == 0, "should have no ooo deq chunk");
rv = svm_fifo_n_chunks (f);
SFIFO_TEST (rv == 1, "should have %u chunks has %u", 1, rv);
return 0;
}
+static int
+sfifo_test_fifo_make_rcv_wnd_zero (vlib_main_t * vm, unformat_input_t * input)
+{
+ int __clib_unused verbose = 0, fifo_size = 4096, deq_chunk;
+ fifo_segment_main_t _fsm = { 0 }, *fsm = &_fsm;
+ u8 *test_data = 0, *data_buf = 0;
+ fifo_segment_t *fs;
+ svm_fifo_t *f;
+ int rv;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "verbose"))
+ verbose = 1;
+ else
+ {
+ vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
+ input);
+ return -1;
+ }
+ }
+
+ /*
+ * Init fifo and enqueue data such that multiple 4096 chunks are allocated
+ */
+ fs = fifo_segment_prepare (fsm, "fifo-rcv-wnd-zero", 0);
+ f = fifo_prepare (fs, fifo_size);
+
+ /* Enqueue 3000 into 4KB chunk, so there'll be 1096 free space */
+ svm_fifo_set_size (f, 4096);
+ validate_test_and_buf_vecs (&test_data, &data_buf, fifo_size);
+ rv = svm_fifo_enqueue (f, 3000, test_data);
+ SFIFO_TEST (rv == 3000, "enqueued %u", rv);
+ rv = svm_fifo_max_enqueue (f);
+ SFIFO_TEST (rv == 1096, "svm_fifo_max_enqueue %u", rv);
+ SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
+
+ /* Shrink fifo size to the in-use size */
+ svm_fifo_set_size (f, 3000);
+ SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
+
+ /* In TCP, this should result in rcv-wnd = 0 */
+ rv = svm_fifo_max_enqueue (f);
+ SFIFO_TEST (rv == 0, "svm_fifo_max_enqueue %u", rv);
+ rv = svm_fifo_max_enqueue_prod (f);
+ SFIFO_TEST (rv == 0, "svm_fifo_max_enqueue_prod %u", rv);
+
+ /* Dequeue and ... */
+ rv = svm_fifo_dequeue (f, 3000, data_buf);
+ SFIFO_TEST (rv == 3000, "dequeued %u", rv);
+
+ /* Clean up */
+ ft_fifo_free (fs, f);
+ ft_fifo_segment_free (fsm, fs);
+ vec_free (test_data);
+ vec_free (data_buf);
+
+ return 0;
+}
+
+
static fifo_segment_main_t segment_main;
static int
fifo_segment_main_t *sm = &segment_main;
fifo_segment_create_args_t _a, *a = &_a;
u8 *test_data = 0, *data_buf = 0;
- u32 n_free_chunk_bytes;
+ u32 n_free_chunk_bytes, new_size;
fifo_segment_t *fs;
- svm_fifo_t *f;
+ svm_fifo_t *f, *tf;
clib_memset (a, 0, sizeof (*a));
a->segment_name = "fifo-test1";
n_free_chunk_bytes, rv);
/*
- * Allocate fifo that has all chunks
+ * Allocate fifo that has all chunks. Because we have a chunk size limit of
+ * segment_size / 2, allocate 2 fifos.
*/
- f = fifo_segment_alloc_fifo (fs, n_free_chunk_bytes, FIFO_SEGMENT_RX_FIFO);
+ tf = fifo_segment_alloc_fifo (fs, n_free_chunk_bytes / 2,
+ FIFO_SEGMENT_RX_FIFO);
+ SFIFO_TEST (tf != 0, "allocation should work");
+ SFIFO_TEST (svm_fifo_is_sane (tf), "fifo should be sane");
+
+ f = fifo_segment_alloc_fifo (fs, n_free_chunk_bytes / 2,
+ FIFO_SEGMENT_RX_FIFO);
SFIFO_TEST (f != 0, "allocation should work");
SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
+ fifo_segment_free_fifo (fs, tf);
fifo_segment_free_fifo (fs, f);
rv = fifo_segment_fl_chunk_bytes (fs);
/*
* Allocate fifo and try to grow beyond available space
*/
- f = fifo_segment_alloc_fifo (fs, fifo_size, FIFO_SEGMENT_RX_FIFO);
+ f = fifo_segment_alloc_fifo (fs, fifo_segment_free_bytes (fs),
+ FIFO_SEGMENT_RX_FIFO);
/* Try to force fifo growth */
- svm_fifo_set_size (f, svm_fifo_size (f) + n_free_chunk_bytes);
- validate_test_and_buf_vecs (&test_data, &data_buf, svm_fifo_size (f));
- rv = svm_fifo_enqueue (f, svm_fifo_size (f), test_data);
+ new_size = svm_fifo_size (f) + n_free_chunk_bytes + 1;
+ svm_fifo_set_size (f, new_size);
+ validate_test_and_buf_vecs (&test_data, &data_buf, new_size);
+ rv = svm_fifo_enqueue (f, new_size, test_data);
- SFIFO_TEST (rv != svm_fifo_size (f), "grow should fail size %u wrote %d",
- svm_fifo_size (f), rv);
+ SFIFO_TEST (rv != new_size, "grow should fail size %u wrote %d",
+ new_size, rv);
fifo_segment_free_fifo (fs, f);
return 0;
}
+static int
+approx_leq (uword a, uword b, u32 margin)
+{
+ if (a - margin <= b && b <= a)
+ return 1;
+ return 0;
+}
+
static int
sfifo_test_fifo_segment_prealloc (int verbose)
{
fifo_segment_create_args_t _a, *a = &_a;
fifo_segment_main_t *sm = &segment_main;
u32 max_pairs, pairs_req, free_space, pair_mem;
- svm_fifo_t *f, *old;
+ svm_fifo_t *f, *tf, *old;
fifo_segment_t *fs;
int rv, alloc;
SFIFO_TEST (rv == 50, "prealloc chunks expected %u is %u", 50, rv);
rv = fifo_segment_free_bytes (fs);
free_space -= (sizeof (svm_fifo_chunk_t) + 4096) * 50;
- SFIFO_TEST (rv == free_space, "free space expected %u is %u", free_space,
- rv);
+ /* Memory alloc alignment accounts for the difference */
+ SFIFO_TEST (approx_leq (free_space, rv, 16), "free space expected %u is %u",
+ free_space, rv);
+ free_space = rv;
rv = fifo_segment_fl_chunk_bytes (fs);
SFIFO_TEST (rv == 4096 * 50, "chunk free space expected %u is %u",
4096 * 50, rv);
SFIFO_TEST (rv == 50, "prealloc fifo hdrs expected %u is %u", 50, rv);
rv = fifo_segment_free_bytes (fs);
free_space -= sizeof (svm_fifo_t) * 50;
- SFIFO_TEST (rv == free_space, "free space expected %u is %u", free_space,
- rv);
+ /* Memory alloc alignment accounts for the difference */
+ SFIFO_TEST (approx_leq (free_space, rv, 16), "free space expected %u is %u",
+ free_space, rv);
+ free_space = rv;
- fifo_segment_update_free_bytes (fs);
rv = fifo_segment_free_bytes (fs);
SFIFO_TEST (clib_abs (rv - (int) free_space) < 512,
"free space expected %u is %u", free_space, rv);
- f = fifo_segment_alloc_fifo (fs, 200 << 10, FIFO_SEGMENT_RX_FIFO);
+ /* Use all free chunk memory */
+ f = fifo_segment_alloc_fifo (fs, 100 << 10, FIFO_SEGMENT_RX_FIFO);
SFIFO_TEST (f != 0, "fifo allocated");
+ SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
+
+ tf = fifo_segment_alloc_fifo (fs, 100 << 10, FIFO_SEGMENT_RX_FIFO);
+ SFIFO_TEST (tf != 0, "fifo allocated");
+ SFIFO_TEST (svm_fifo_is_sane (tf), "fifo should be sane");
+
rv = fifo_segment_num_free_chunks (fs, 4096);
SFIFO_TEST (rv == 0, "prealloc chunks expected %u is %u", 0, rv);
rv = fifo_segment_fl_chunk_bytes (fs);
SFIFO_TEST (rv == 0, "chunk free space expected %u is %u", 0, rv);
- SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane");
+
/*
* Multiple preallocs that consume the remaining space
*/
- fifo_segment_update_free_bytes (fs);
free_space = fifo_segment_free_bytes (fs);
pair_mem = 2 * (4096 + sizeof (*f) + sizeof (svm_fifo_chunk_t));
max_pairs = pairs_req = (free_space / pair_mem) - 1;
SFIFO_TEST (rv == max_pairs * 2, "prealloc chunks expected %u is %u",
max_pairs * 2, rv);
- fifo_segment_update_free_bytes (fs);
rv = fifo_segment_free_bytes (fs);
SFIFO_TEST (rv < 2 * pair_mem, "free bytes %u less than %u", rv,
2 * pair_mem);
* Cleanup
*/
fifo_segment_free_fifo (fs, old);
+ fifo_segment_free_fifo (fs, tf);
close (fs->ssvm.fd);
fifo_segment_delete (sm, fs);
return 0;
{
int rv, verbose = 0;
- fifo_segment_main_init (&segment_main, HIGH_SEGMENT_BASEVA, 5);
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "verbose"))
int res = 0;
char *str;
-
+ clib_warning ("high mem %lu", HIGH_SEGMENT_BASEVA);
+ fifo_segment_main_init (&segment_main, HIGH_SEGMENT_BASEVA, 5);
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "fifo1"))
res = sfifo_test_fifo_shrink (vm, input);
else if (unformat (input, "indirect"))
res = sfifo_test_fifo_indirect (vm, input);
+ else if (unformat (input, "zero"))
+ res = sfifo_test_fifo_make_rcv_wnd_zero (vm, input);
else if (unformat (input, "segment"))
res = sfifo_test_fifo_segment (vm, input);
else if (unformat (input, "all"))
if ((res = sfifo_test_fifo_indirect (vm, input)))
goto done;
+ if ((res = sfifo_test_fifo_make_rcv_wnd_zero (vm, input)))
+ goto done;
+
str = "all";
unformat_init_cstring (input, str);
if ((res = sfifo_test_fifo_segment (vm, input)))