summaryrefslogtreecommitdiffstats
path: root/src/svm/svm_fifo_segment.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-07-04 10:56:23 -0400
committerDamjan Marion <dmarion@me.com>2018-07-18 12:09:42 +0000
commit6a5adc369591fcac2447e9809deaa22f56b53911 (patch)
treec9a56b1ed0d5e8eb2f21a843552c6c0bc6df5597 /src/svm/svm_fifo_segment.c
parent2a3fb1a28b170ac1d37815983611e83d148811d4 (diff)
Add config option to use dlmalloc instead of mheap
Configure w/ --enable-dlmalloc, see .../build-data/platforms/vpp.mk src/vppinfra/dlmalloc.[ch] are slightly modified versions of the well-known Doug Lea malloc. Main advantage: dlmalloc mspaces have no inherent size limit. Change-Id: I19b3f43f3c65bcfb82c1a265a97922d01912446e Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/svm/svm_fifo_segment.c')
-rw-r--r--src/svm/svm_fifo_segment.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/svm/svm_fifo_segment.c b/src/svm/svm_fifo_segment.c
index 7c6d80229ad..ce1d5a0eab1 100644
--- a/src/svm/svm_fifo_segment.c
+++ b/src/svm/svm_fifo_segment.c
@@ -107,7 +107,12 @@ svm_fifo_segment_preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
/* Calculate space requirements */
pair_size = 2 * sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
+#if USE_DLMALLOC == 0
space_available = s->ssvm.ssvm_size - mheap_bytes (sh->heap);
+#else
+ space_available = s->ssvm.ssvm_size - mspace_usable_size (sh->heap);
+#endif
+
pairs_to_allocate = clib_min (space_available / pair_size, *n_fifo_pairs);
rx_fifos_size = (sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
tx_fifos_size = (sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
@@ -237,7 +242,6 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
svm_fifo_segment_private_t *s;
ssvm_shared_header_t *sh;
- mheap_t *heap_header;
u32 rnd_size = 0;
u8 *heap;
u32 pagesize = clib_mem_get_page_size ();
@@ -247,6 +251,7 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
rnd_size = (a->segment_size + (pagesize - 1)) & ~pagesize;
+#if USE_DLMALLOC == 0
heap = mheap_alloc (0, rnd_size);
if (heap == 0)
{
@@ -254,8 +259,14 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
pool_put (sm->segments, s);
return -1;
}
- heap_header = mheap_header (heap);
- heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
+ {
+ mheap_t *heap_header;
+ heap_header = mheap_header (heap);
+ heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
+ }
+#else
+ heap = create_mspace (rnd_size, 1 /* locked */ );
+#endif
s->ssvm.ssvm_size = rnd_size;
s->ssvm.i_am_master = 1;
@@ -572,11 +583,17 @@ svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
{
if (ssvm_type (&seg->ssvm) == SSVM_SEGMENT_PRIVATE)
{
+#if USE_DLMALLOC == 0
mheap_t *heap_header;
*address = pointer_to_uword (seg->ssvm.sh->heap);
heap_header = mheap_header (seg->ssvm.sh->heap);
*size = heap_header->max_size;
+#else
+ mspace_get_address_and_size (seg->ssvm.sh->heap,
+ (unsigned long long *) address,
+ (unsigned long long *) size);
+#endif
}
else
{
@@ -585,7 +602,7 @@ svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
}
}
-mheap_t *
+void *
svm_fifo_segment_heap (svm_fifo_segment_private_t * seg)
{
return seg->ssvm.sh->heap;
@@ -617,17 +634,19 @@ format_svm_fifo_segment (u8 * s, va_list * args)
{
svm_fifo_segment_private_t *sp
= va_arg (*args, svm_fifo_segment_private_t *);
- int verbose = va_arg (*args, int);
+ int verbose __attribute__ ((unused)) = va_arg (*args, int);
svm_fifo_segment_header_t *fsh = sp->h;
u32 count, indent;
svm_fifo_t *f;
int i;
indent = format_get_indent (s) + 2;
+#if USE_DLMALLOC == 0
s = format (s, "%U segment heap: %U\n", format_white_space, indent,
format_mheap, svm_fifo_segment_heap (sp), verbose);
s = format (s, "%U segment has %u active fifos\n",
format_white_space, indent, svm_fifo_segment_num_fifos (sp));
+#endif
for (i = 0; i < vec_len (fsh->free_fifos); i++)
{