summaryrefslogtreecommitdiffstats
path: root/src/svm/svm_fifo.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-04-25 12:58:46 -0700
committerDamjan Marion <dmarion@me.com>2019-04-26 10:23:38 +0000
commitb095a3cd221a142f7d2b4897b812b2781de05d29 (patch)
tree87a1cdc9872c91d46c771cd9b224c62a35d6af7d /src/svm/svm_fifo.c
parent403e3ba1507750df463d7179494c14d03864b810 (diff)
svm: fifo segment support for chunk allocation
Change-Id: Ie96706b4d8bcb32d2d5f065bc765f95f4e9369e7 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm/svm_fifo.c')
-rw-r--r--src/svm/svm_fifo.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index eafe497eec1..c8fd263c094 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -298,7 +298,9 @@ svm_fifo_init (svm_fifo_t * f, u32 size)
f->head_chunk = f->tail_chunk = f->ooo_enq = f->ooo_deq = f->start_chunk;
}
-/** create an svm fifo, in the current heap. Fails vs blow up the process */
+/**
+ * Creates a fifo in the current heap. Fails vs blow up the process
+ */
svm_fifo_t *
svm_fifo_create (u32 data_size_in_bytes)
{
@@ -317,6 +319,27 @@ svm_fifo_create (u32 data_size_in_bytes)
return f;
}
+/**
+ * Creates a fifo chunk in the current heap
+ */
+svm_fifo_chunk_t *
+svm_fifo_chunk_alloc (u32 size)
+{
+ svm_fifo_chunk_t *c;
+ u32 rounded_size;
+
+ /* round chunk size to the next highest power-of-two */
+ rounded_size = (1 << (max_log2 (size)));
+ c = clib_mem_alloc_aligned_or_null (sizeof (*c) + rounded_size,
+ CLIB_CACHE_LINE_BYTES);
+ if (c == 0)
+ return 0;
+
+ clib_memset (c, 0, sizeof (*c));
+ c->length = rounded_size;
+ return c;
+}
+
static inline void
svm_fifo_size_update (svm_fifo_t * f, svm_fifo_chunk_t * c)
{
@@ -462,13 +485,26 @@ svm_fifo_find_chunk (svm_fifo_t * f, u32 pos)
}
void
+svm_fifo_free_chunk_lookup (svm_fifo_t * f)
+{
+ rb_tree_free_nodes (&f->chunk_lookup);
+}
+
+void
+svm_fifo_free_ooo_data (svm_fifo_t * f)
+{
+ pool_free (f->ooo_segments);
+}
+
+void
svm_fifo_free (svm_fifo_t * f)
{
ASSERT (f->refcnt > 0);
if (--f->refcnt == 0)
{
- pool_free (f->ooo_segments);
+ /* ooo data is not allocated on segment heap */
+ svm_fifo_free_chunk_lookup (f);
clib_mem_free (f);
}
}