summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-01-15 01:08:33 -0800
committerDave Barach <openvpp@barachs.net>2018-01-25 23:53:35 +0000
commitb384b543313b6b47a277c903e9d4fcd4343054fa (patch)
tree1996e3a25eb3a32fe5bbc405d75f38dd041a5a40 /src/svm
parent4e578068fc3fe8ba176d211123ddd88962dab315 (diff)
session: add support for memfd segments
- update segment manager and session api to work with both flavors of ssvm segments - added generic ssvm slave/master init and del functions - cleanup/refactor tcp_echo - fixed uses of svm fifo pool as vector Change-Id: Ieee8b163faa407da6e77e657a2322de213a9d2a0 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/ssvm.c129
-rw-r--r--src/svm/ssvm.h42
-rw-r--r--src/svm/svm_fifo_segment.c136
-rw-r--r--src/svm/svm_fifo_segment.h11
4 files changed, 214 insertions, 104 deletions
diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c
index 36abc208636..50552198137 100644
--- a/src/svm/ssvm.c
+++ b/src/svm/ssvm.c
@@ -15,17 +15,25 @@
#include <svm/ssvm.h>
#include <svm/svm_common.h>
+typedef int (*init_fn) (ssvm_private_t *);
+typedef void (*delete_fn) (ssvm_private_t *);
+
+static init_fn master_init_fns[SSVM_N_SEGMENT_TYPES] =
+ { ssvm_master_init_shm, ssvm_master_init_memfd };
+static init_fn slave_init_fns[SSVM_N_SEGMENT_TYPES] =
+ { ssvm_slave_init_shm, ssvm_slave_init_memfd };
+static delete_fn delete_fns[SSVM_N_SEGMENT_TYPES] =
+ { ssvm_delete_shm, ssvm_delete_memfd };
+
int
-ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
+ssvm_master_init_shm (ssvm_private_t * ssvm)
{
+ int ssvm_fd, mh_flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
svm_main_region_t *smr = svm_get_root_rp ()->data_base;
- int ssvm_fd;
- u8 *ssvm_filename;
- u8 junk = 0;
- int flags;
+ clib_mem_vm_map_t mapa = { 0 };
+ u8 junk = 0, *ssvm_filename;
ssvm_shared_header_t *sh;
- u64 ticks = clib_cpu_time_now ();
- u64 randomize_baseva;
+ uword page_size;
void *oldheap;
if (ssvm->ssvm_size == 0)
@@ -36,13 +44,10 @@ ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
ASSERT (vec_c_string_is_terminated (ssvm->name));
ssvm_filename = format (0, "/dev/shm/%s%c", ssvm->name, 0);
-
unlink ((char *) ssvm_filename);
-
vec_free (ssvm_filename);
ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR | O_CREAT | O_EXCL, 0777);
-
if (ssvm_fd < 0)
{
clib_unix_warning ("create segment '%s'", ssvm->name);
@@ -68,43 +73,35 @@ ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
return SSVM_API_ERROR_SET_SIZE;
}
- flags = MAP_SHARED;
- if (ssvm->requested_va)
- flags |= MAP_FIXED;
-
- randomize_baseva = (ticks & 15) * MMAP_PAGESIZE;
-
+ page_size = clib_mem_vm_get_page_size (ssvm_fd);
if (ssvm->requested_va)
- ssvm->requested_va += randomize_baseva;
-
- sh = ssvm->sh =
- (ssvm_shared_header_t *) mmap ((void *) ssvm->requested_va,
- ssvm->ssvm_size, PROT_READ | PROT_WRITE,
- flags, ssvm_fd, 0);
+ clib_mem_vm_randomize_va (&ssvm->requested_va, min_log2 (page_size));
- if (ssvm->sh == MAP_FAILED)
+ mapa.requested_va = ssvm->requested_va;
+ mapa.size = ssvm->ssvm_size;
+ mapa.fd = ssvm_fd;
+ if (clib_mem_vm_ext_map (&mapa))
{
clib_unix_warning ("mmap");
close (ssvm_fd);
return SSVM_API_ERROR_MMAP;
}
-
close (ssvm_fd);
- ssvm->my_pid = getpid ();
+ sh = mapa.addr;
sh->master_pid = ssvm->my_pid;
sh->ssvm_size = ssvm->ssvm_size;
- sh->heap = mheap_alloc_with_flags
- (((u8 *) sh) + MMAP_PAGESIZE, ssvm->ssvm_size - MMAP_PAGESIZE,
- MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE);
-
sh->ssvm_va = pointer_to_uword (sh);
- sh->master_index = master_index;
+ sh->type = SSVM_SEGMENT_SHM;
+ sh->heap = mheap_alloc_with_flags (((u8 *) sh) + page_size,
+ ssvm->ssvm_size - page_size, mh_flags);
oldheap = ssvm_push_heap (sh);
- sh->name = format (0, "%s%c", ssvm->name, 0);
+ sh->name = format (0, "%s", ssvm->name, 0);
ssvm_pop_heap (oldheap);
+ ssvm->sh = sh;
+ ssvm->my_pid = getpid ();
ssvm->i_am_master = 1;
/* The application has to set set sh->ready... */
@@ -112,7 +109,7 @@ ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
}
int
-ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds)
+ssvm_slave_init_shm (ssvm_private_t * ssvm)
{
struct stat stat;
int ssvm_fd = -1;
@@ -121,7 +118,7 @@ ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds)
ASSERT (vec_c_string_is_terminated (ssvm->name));
ssvm->i_am_master = 0;
- while (timeout_in_seconds-- > 0)
+ while (ssvm->attach_timeout-- > 0)
{
if (ssvm_fd < 0)
ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR, 0777);
@@ -152,7 +149,7 @@ map_it:
return SSVM_API_ERROR_MMAP;
}
- while (timeout_in_seconds-- > 0)
+ while (ssvm->attach_timeout-- > 0)
{
if (sh->ready)
goto re_map_it;
@@ -182,7 +179,7 @@ re_map_it:
}
void
-ssvm_delete (ssvm_private_t * ssvm)
+ssvm_delete_shm (ssvm_private_t * ssvm)
{
u8 *fn;
@@ -202,8 +199,11 @@ ssvm_delete (ssvm_private_t * ssvm)
munmap ((void *) ssvm->requested_va, ssvm->ssvm_size);
}
+/**
+ * Initialize memfd segment master
+ */
int
-ssvm_master_init_memfd (ssvm_private_t * memfd, u32 master_index)
+ssvm_master_init_memfd (ssvm_private_t * memfd)
{
uword page_size, flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
ssvm_shared_header_t *sh;
@@ -215,11 +215,11 @@ ssvm_master_init_memfd (ssvm_private_t * memfd, u32 master_index)
return SSVM_API_ERROR_NO_SIZE;
ASSERT (vec_c_string_is_terminated (memfd->name));
- memfd->name = format (0, "memfd svm region %d%c", master_index, 0);
alloc.name = (char *) memfd->name;
alloc.size = memfd->ssvm_size;
alloc.flags = CLIB_MEM_VM_F_SHARED;
+ alloc.requested_va = memfd->requested_va;
if ((err = clib_mem_vm_ext_alloc (&alloc)))
{
clib_error_report (err);
@@ -227,33 +227,34 @@ ssvm_master_init_memfd (ssvm_private_t * memfd, u32 master_index)
}
memfd->fd = alloc.fd;
- memfd->sh = alloc.addr;
+ memfd->sh = (ssvm_shared_header_t *) alloc.addr;
memfd->my_pid = getpid ();
memfd->i_am_master = 1;
page_size = 1 << alloc.log2_page_size;
- sh = (ssvm_shared_header_t *) memfd->sh;
+ sh = memfd->sh;
sh->master_pid = memfd->my_pid;
sh->ssvm_size = memfd->ssvm_size;
+ sh->ssvm_va = pointer_to_uword (sh);
+ sh->type = SSVM_SEGMENT_MEMFD;
sh->heap = mheap_alloc_with_flags (((u8 *) sh) + page_size,
memfd->ssvm_size - page_size, flags);
- sh->ssvm_va = pointer_to_uword (sh);
- sh->master_index = master_index;
oldheap = ssvm_push_heap (sh);
- sh->name = format (0, "%s%c", memfd->name, 0);
+ sh->name = format (0, "%s", memfd->name, 0);
ssvm_pop_heap (oldheap);
/* The application has to set set sh->ready... */
return 0;
}
-/*
- * Subtly different than svm_slave_init. The caller
- * needs to acquire a usable file descriptor for the memfd segment
- * e.g. via vppinfra/socket.c:default_socket_recvmsg
+/**
+ * Initialize memfd segment slave
+ *
+ * Subtly different than svm_slave_init. The caller needs to acquire
+ * a usable file descriptor for the memfd segment e.g. via
+ * vppinfra/socket.c:default_socket_recvmsg
*/
-
int
ssvm_slave_init_memfd (ssvm_private_t * memfd)
{
@@ -278,7 +279,7 @@ ssvm_slave_init_memfd (ssvm_private_t * memfd)
if (clib_mem_vm_ext_map (&mapa))
{
- clib_unix_warning ("slave research mmap");
+ clib_unix_warning ("slave research mmap (fd %d)", mapa.fd);
close (memfd->fd);
return SSVM_API_ERROR_MMAP;
}
@@ -286,7 +287,7 @@ ssvm_slave_init_memfd (ssvm_private_t * memfd)
sh = mapa.addr;
memfd->requested_va = sh->ssvm_va;
memfd->ssvm_size = sh->ssvm_size;
- munmap (sh, page_size);
+ clib_mem_vm_free (sh, page_size);
/*
* Remap the segment at the 'right' address
@@ -314,6 +315,36 @@ ssvm_delete_memfd (ssvm_private_t * memfd)
close (memfd->fd);
}
+int
+ssvm_master_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
+{
+ return (master_init_fns[type]) (ssvm);
+}
+
+int
+ssvm_slave_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
+{
+ return (slave_init_fns[type]) (ssvm);
+}
+
+void
+ssvm_delete (ssvm_private_t * ssvm)
+{
+ delete_fns[ssvm->sh->type] (ssvm);
+}
+
+ssvm_segment_type_t
+ssvm_type (const ssvm_private_t * ssvm)
+{
+ return ssvm->sh->type;
+}
+
+u8 *
+ssvm_name (const ssvm_private_t * ssvm)
+{
+ return ssvm->sh->name;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/svm/ssvm.h b/src/svm/ssvm.h
index a181f2ef864..9bf009e73d2 100644
--- a/src/svm/ssvm.h
+++ b/src/svm/ssvm.h
@@ -45,6 +45,13 @@
#define SSVM_N_OPAQUE 7
+typedef enum ssvm_segment_type_
+{
+ SSVM_SEGMENT_SHM = 0,
+ SSVM_SEGMENT_MEMFD,
+ SSVM_N_SEGMENT_TYPES /**< Private segments */
+} ssvm_segment_type_t;
+
typedef struct
{
/* Spin-lock */
@@ -68,8 +75,7 @@ typedef struct
/* Set when the master application thinks it's time to make the donuts */
volatile u32 ready;
- /* Needed to make unique MAC addresses, etc. */
- u32 master_index;
+ ssvm_segment_type_t type;
} ssvm_shared_header_t;
typedef struct
@@ -81,8 +87,11 @@ typedef struct
uword requested_va;
int i_am_master;
- /* Needed by memfd segments */
- int fd;
+ union
+ {
+ int fd; /**< memfd segments */
+ int attach_timeout; /**< shm segments attach timeout (sec) */
+ };
} ssvm_private_t;
always_inline void
@@ -145,6 +154,18 @@ ssvm_pop_heap (void *oldheap)
clib_mem_set_heap (oldheap);
}
+static inline void *
+ssvm_mem_alloc (ssvm_private_t * ssvm, uword size)
+{
+ u8 *oldheap;
+ void *rv;
+
+ oldheap = clib_mem_set_heap (ssvm->sh->heap);
+ rv = clib_mem_alloc (size);
+ clib_mem_set_heap (oldheap);
+ return (rv);
+}
+
#define foreach_ssvm_api_error \
_(NO_NAME, "No shared segment name", -100) \
_(NO_SIZE, "Size not set (master)", -101) \
@@ -162,14 +183,21 @@ typedef enum
#define SSVM_API_ERROR_NO_NAME (-10)
-int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index);
-int ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds);
+int ssvm_master_init (ssvm_private_t * ssvm, ssvm_segment_type_t type);
+int ssvm_slave_init (ssvm_private_t * ssvm, ssvm_segment_type_t type);
void ssvm_delete (ssvm_private_t * ssvm);
-int ssvm_master_init_memfd (ssvm_private_t * memfd, u32 master_index);
+int ssvm_master_init_shm (ssvm_private_t * ssvm);
+int ssvm_slave_init_shm (ssvm_private_t * ssvm);
+void ssvm_delete_shm (ssvm_private_t * ssvm);
+
+int ssvm_master_init_memfd (ssvm_private_t * memfd);
int ssvm_slave_init_memfd (ssvm_private_t * memfd);
void ssvm_delete_memfd (ssvm_private_t * memfd);
+ssvm_segment_type_t ssvm_type (const ssvm_private_t * ssvm);
+u8 *ssvm_name (const ssvm_private_t * ssvm);
+
#endif /* __included_ssvm_h__ */
/*
diff --git a/src/svm/svm_fifo_segment.c b/src/svm/svm_fifo_segment.c
index a56a714cc83..4d1833eee7e 100644
--- a/src/svm/svm_fifo_segment.c
+++ b/src/svm/svm_fifo_segment.c
@@ -58,7 +58,7 @@ allocate_new_fifo_chunk (svm_fifo_segment_header_t * fsh,
static void
preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
- svm_fifo_segment_create_args_t * a)
+ svm_fifo_segment_create_args_t * a, u32 protect_size)
{
svm_fifo_segment_header_t *fsh = s->h;
u32 rx_fifo_size, tx_fifo_size, pairs_to_allocate;
@@ -99,18 +99,17 @@ 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;
- pairs_to_allocate = clib_min (s->ssvm.ssvm_size / pair_size,
- a->preallocated_fifo_pairs);
+ if (protect_size)
+ protect_size += mheap_bytes (s->ssvm.sh->heap);
+ pairs_to_allocate =
+ clib_min ((s->ssvm.ssvm_size - protect_size) / pair_size,
+ a->preallocated_fifo_pairs);
rx_fifo_size = (sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
tx_fifo_size = (sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
vec_validate_init_empty (fsh->free_fifos,
clib_max (rx_freelist_index, tx_freelist_index),
0);
- if (0)
- clib_warning ("rx_fifo_size %u (%d mb), tx_fifo_size %u (%d mb)",
- rx_fifo_size, rx_fifo_size >> 20,
- tx_fifo_size, tx_fifo_size >> 20);
/* Allocate rx fifo space. May fail. */
rx_fifo_space = clib_mem_alloc_aligned_at_offset
@@ -164,16 +163,18 @@ preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
a->preallocated_fifo_pairs -= pairs_to_allocate;
}
-/** (master) create an svm fifo segment */
+/**
+ * Create an svm fifo segment and initialize as master
+ */
int
svm_fifo_segment_create (svm_fifo_segment_create_args_t * a)
{
- int rv;
- svm_fifo_segment_private_t *s;
svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
+ svm_fifo_segment_private_t *s;
ssvm_shared_header_t *sh;
svm_fifo_segment_header_t *fsh;
void *oldheap;
+ int rv;
/* Allocate a fresh segment */
pool_get (sm->segments, s);
@@ -185,16 +186,14 @@ svm_fifo_segment_create (svm_fifo_segment_create_args_t * a)
s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
s->ssvm.requested_va = sm->next_baseva;
- rv = ssvm_master_init (&s->ssvm, s - sm->segments);
-
- if (rv)
+ if ((rv = ssvm_master_init (&s->ssvm, a->segment_type)))
{
- _vec_len (s) = vec_len (s) - 1;
+ pool_put (sm->segments, s);
return (rv);
}
/* Note: requested_va updated due to seg base addr randomization */
- sm->next_baseva = s->ssvm.requested_va + a->segment_size;
+ sm->next_baseva = s->ssvm.sh->ssvm_va + a->segment_size;
sh = s->ssvm.sh;
oldheap = ssvm_push_heap (sh);
@@ -202,10 +201,8 @@ svm_fifo_segment_create (svm_fifo_segment_create_args_t * a)
/* Set up svm_fifo_segment shared header */
fsh = clib_mem_alloc (sizeof (*fsh));
memset (fsh, 0, sizeof (*fsh));
- sh->opaque[0] = fsh;
- s->h = fsh;
- fsh->segment_name = format (0, "%s%c", a->segment_name, 0);
- preallocate_fifo_pairs (s, a);
+ s->h = sh->opaque[0] = fsh;
+ preallocate_fifo_pairs (s, a, a->seg_protected_space);
ssvm_pop_heap (oldheap);
@@ -214,7 +211,9 @@ svm_fifo_segment_create (svm_fifo_segment_create_args_t * a)
return (0);
}
-/** Create an svm fifo segment in process-private memory */
+/**
+ * Create an svm fifo segment in process-private memory
+ */
int
svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
{
@@ -272,12 +271,10 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
/* Set up svm_fifo_segment shared header */
fsh = clib_mem_alloc (sizeof (*fsh));
memset (fsh, 0, sizeof (*fsh));
- sh->opaque[0] = fsh;
- s->h = fsh;
fsh->flags = FIFO_SEGMENT_F_IS_PRIVATE;
+ s->h = sh->opaque[0] = fsh;
if (!a->private_segment_count)
fsh->flags |= FIFO_SEGMENT_F_IS_MAIN_HEAP;
- fsh->segment_name = format (0, "%s%c", a->segment_name, 0);
if (a->private_segment_count)
{
@@ -285,7 +282,7 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
fsh->flags |= FIFO_SEGMENT_F_IS_PREALLOCATED;
oldheap = clib_mem_get_heap ();
clib_mem_set_heap (sh->heap);
- preallocate_fifo_pairs (s, a);
+ preallocate_fifo_pairs (s, a, i == 0 ? a->seg_protected_space : 0);
clib_mem_set_heap (oldheap);
}
sh->ready = 1;
@@ -295,15 +292,15 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
return (0);
}
-/** (slave) attach to an svm fifo segment */
+/**
+ * Attach as slave to an svm fifo segment
+ */
int
svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a)
{
- int rv;
- svm_fifo_segment_private_t *s;
svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
- ssvm_shared_header_t *sh;
- svm_fifo_segment_header_t *fsh;
+ svm_fifo_segment_private_t *s;
+ int rv;
/* Allocate a fresh segment */
pool_get (sm->segments, s);
@@ -313,19 +310,19 @@ svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a)
s->ssvm.my_pid = getpid ();
s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
s->ssvm.requested_va = sm->next_baseva;
+ if (a->segment_type == SSVM_SEGMENT_MEMFD)
+ s->ssvm.fd = a->memfd_fd;
+ else
+ s->ssvm.attach_timeout = sm->timeout_in_seconds;
- rv = ssvm_slave_init (&s->ssvm, sm->timeout_in_seconds);
-
- if (rv)
+ if ((rv = ssvm_slave_init (&s->ssvm, a->segment_type)))
{
_vec_len (s) = vec_len (s) - 1;
return (rv);
}
/* Fish the segment header */
- sh = s->ssvm.sh;
- fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
- s->h = fsh;
+ s->h = s->ssvm.sh->opaque[0];
vec_add1 (a->new_segment_indices, s - sm->segments);
return (0);
@@ -335,6 +332,7 @@ void
svm_fifo_segment_delete (svm_fifo_segment_private_t * s)
{
svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
+
if (s->h->flags & FIFO_SEGMENT_F_IS_PRIVATE)
{
/* Don't try to free vpp's heap! */
@@ -342,15 +340,18 @@ svm_fifo_segment_delete (svm_fifo_segment_private_t * s)
mheap_free (s->ssvm.sh->heap);
clib_mem_free (s->ssvm.sh);
clib_mem_free (s->h);
- pool_put (sm->segments, s);
}
else
{
ssvm_delete (&s->ssvm);
- pool_put (sm->segments, s);
}
+ memset (s, 0xfe, sizeof (*s));
+ pool_put (sm->segments, s);
}
+/**
+ * Allocate fifo in svm segment
+ */
svm_fifo_t *
svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
u32 data_size_in_bytes,
@@ -590,6 +591,53 @@ svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t * fifo_segment,
return count;
}
+void
+svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
+ u64 * size)
+{
+ if (seg->h->flags & FIFO_SEGMENT_F_IS_PRIVATE)
+ {
+ 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
+ {
+ *address = seg->ssvm.sh->ssvm_va;
+ *size = seg->ssvm.ssvm_size;
+ }
+}
+
+mheap_t *
+svm_fifo_segment_heap (svm_fifo_segment_private_t * seg)
+{
+ return seg->ssvm.sh->heap;
+}
+
+u8 *
+format_svm_fifo_segment_type (u8 * s, va_list * args)
+{
+ svm_fifo_segment_private_t *sp;
+ sp = va_arg (*args, svm_fifo_segment_private_t *);
+ ssvm_segment_type_t st = ssvm_type (&sp->ssvm);
+
+ if ((sp->h->flags & FIFO_SEGMENT_F_IS_PRIVATE)
+ && !(sp->h->flags & FIFO_SEGMENT_F_IS_MAIN_HEAP))
+ s = format (s, "%s", "private-heap");
+ else if ((sp->h->flags & FIFO_SEGMENT_F_IS_PRIVATE)
+ && (sp->h->flags & FIFO_SEGMENT_F_IS_MAIN_HEAP))
+ s = format (s, "%s", "main-heap");
+ else if (st == SSVM_SEGMENT_MEMFD)
+ s = format (s, "%s", "memfd");
+ else if (st == SSVM_SEGMENT_SHM)
+ s = format (s, "%s", "shm");
+ else
+ s = format (s, "%s", "unknown");
+ return s;
+}
+
/**
* Segment format function
*/
@@ -599,18 +647,14 @@ 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);
- ssvm_shared_header_t *sh;
- svm_fifo_segment_header_t *fsh;
+ svm_fifo_segment_header_t *fsh = sp->h;
+ u32 count, indent;
svm_fifo_t *f;
int i;
- u32 count;
- u32 indent = format_get_indent (s) + 2;
-
- sh = sp->ssvm.sh;
- fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
- s = format (s, "%USegment Heap: %U\n", format_white_space, indent,
- format_mheap, sh->heap, verbose);
+ indent = format_get_indent (s) + 2;
+ 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));
diff --git a/src/svm/svm_fifo_segment.h b/src/svm/svm_fifo_segment.h
index 405df934578..0e86c25deab 100644
--- a/src/svm/svm_fifo_segment.h
+++ b/src/svm/svm_fifo_segment.h
@@ -34,11 +34,11 @@ typedef enum
#define FIFO_SEGMENT_F_IS_PRIVATE 1 << 0 /* Private segment */
#define FIFO_SEGMENT_F_IS_MAIN_HEAP 1 << 1 /* Segment is main heap */
#define FIFO_SEGMENT_F_IS_PREALLOCATED 1 << 2 /* Segment is preallocated */
+#define FIFO_SEGMENT_F_WILL_DELETE 1 << 3 /* Segment will be removed */
typedef struct
{
svm_fifo_t *fifos; /**< Linked list of active RX fifos */
- u8 *segment_name; /**< Segment name */
svm_fifo_t **free_fifos; /**< Freelists, by fifo size */
u32 n_active_fifos; /**< Number of active fifos */
u8 flags; /**< Segment flags */
@@ -65,6 +65,7 @@ extern svm_fifo_segment_main_t svm_fifo_segment_main;
typedef struct
{
+ ssvm_segment_type_t segment_type;
char *segment_name;
u32 segment_size;
u32 *new_segment_indices;
@@ -72,13 +73,15 @@ typedef struct
u32 tx_fifo_size;
u32 preallocated_fifo_pairs;
u32 private_segment_count;
+ u32 seg_protected_space;
+ int memfd_fd;
} svm_fifo_segment_create_args_t;
static inline svm_fifo_segment_private_t *
svm_fifo_segment_get_segment (u32 segment_index)
{
svm_fifo_segment_main_t *ssm = &svm_fifo_segment_main;
- return vec_elt_at_index (ssm->segments, segment_index);
+ return pool_elt_at_index (ssm->segments, segment_index);
}
static inline u8
@@ -120,9 +123,13 @@ u32 svm_fifo_segment_index (svm_fifo_segment_private_t * s);
u32 svm_fifo_segment_num_fifos (svm_fifo_segment_private_t * fifo_segment);
u32 svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t *
fifo_segment, u32 fifo_size_in_bytes);
+void svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
+ u64 * size);
svm_fifo_segment_private_t *svm_fifo_segment_segments_pool (void);
+
format_function_t format_svm_fifo_segment;
+format_function_t format_svm_fifo_segment_type;
#endif /* __included_ssvm_fifo_segment_h__ */