From cefd5d8806b9db7210192f53fdc2b8a60d4dc271 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Sun, 5 May 2019 13:19:57 -0700 Subject: svm: decouple fifo and default chunk allocation Default chunk is no longer embedded into the fifo and on free is returned to its respective chunk list. Change-Id: Ifc5d214eaa6eca44356eb79dd75650fb8569113f Signed-off-by: Florin Coras --- src/svm/svm_fifo.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/svm/svm_fifo.c') diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c index 3824d998866..6b4ea68ca17 100644 --- a/src/svm/svm_fifo.c +++ b/src/svm/svm_fifo.c @@ -400,9 +400,7 @@ svm_fifo_init (svm_fifo_t * f, u32 size) f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX; f->segment_index = SVM_FIFO_INVALID_INDEX; f->refcnt = 1; - f->default_chunk.start_byte = 0; - f->default_chunk.length = f->size; - f->default_chunk.next = f->start_chunk = f->end_chunk = &f->default_chunk; + f->flags = 0; f->head_chunk = f->tail_chunk = f->ooo_enq = f->ooo_deq = f->start_chunk; } @@ -412,17 +410,31 @@ svm_fifo_init (svm_fifo_t * f, u32 size) svm_fifo_t * svm_fifo_create (u32 data_size_in_bytes) { - svm_fifo_t *f; u32 rounded_data_size; + svm_fifo_chunk_t *c; + svm_fifo_t *f; - /* always round fifo data size to the next highest power-of-two */ - rounded_data_size = (1 << (max_log2 (data_size_in_bytes))); - f = clib_mem_alloc_aligned_or_null (sizeof (*f) + rounded_data_size, - CLIB_CACHE_LINE_BYTES); + f = clib_mem_alloc_aligned_or_null (sizeof (*f), CLIB_CACHE_LINE_BYTES); if (f == 0) return 0; clib_memset (f, 0, sizeof (*f)); + + /* always round fifo data size to the next highest power-of-two */ + rounded_data_size = (1 << (max_log2 (data_size_in_bytes))); + c = clib_mem_alloc_aligned_or_null (sizeof (*c) + rounded_data_size, + CLIB_CACHE_LINE_BYTES); + if (!c) + { + clib_mem_free (f); + return 0; + } + + c->next = c; + c->start_byte = 0; + c->length = data_size_in_bytes; + f->start_chunk = f->end_chunk = c; + svm_fifo_init (f, data_size_in_bytes); return f; } -- cgit 1.2.3-korg