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>
diff --git a/src/svm/ssvm.h b/src/svm/ssvm.h
index a181f2e..9bf009e 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 @@
/* 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 @@
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 @@
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 @@
#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__ */
/*