aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/svm.am4
-rw-r--r--src/svm/memfd.c137
-rw-r--r--src/svm/memfd.h194
-rw-r--r--src/svm/ssvm.c117
-rw-r--r--src/svm/ssvm.h25
-rw-r--r--src/vat/api_format.c5
-rw-r--r--src/vlibmemory/memory_api.h1
-rw-r--r--src/vlibmemory/memory_client.c1
-rw-r--r--src/vlibmemory/socket_api.c18
-rw-r--r--src/vlibmemory/socket_api.h1
-rw-r--r--src/vlibmemory/socket_client.c6
-rw-r--r--src/vnet.am10
-rw-r--r--src/vnet/devices/ssvm/node.c345
-rw-r--r--src/vnet/devices/ssvm/ssvm_eth.c491
-rw-r--r--src/vnet/devices/ssvm/ssvm_eth.h140
-rw-r--r--src/vpp/api/api_format.c5
16 files changed, 157 insertions, 1343 deletions
diff --git a/src/svm.am b/src/svm.am
index 748ef147d0e..c29072e4f52 100644
--- a/src/svm.am
+++ b/src/svm.am
@@ -14,7 +14,6 @@
bin_PROGRAMS += svmtool svmdbtool
nobase_include_HEADERS += \
- svm/memfd.h \
svm/ssvm.h \
svm/svm_common.h \
svm/svmdb.h \
@@ -30,8 +29,7 @@ libsvm_la_SOURCES = \
svm/ssvm.c \
svm/svm_fifo.c \
svm/svm_fifo_segment.c \
- svm/queue.c \
- svm/memfd.c
+ svm/queue.c
libsvm_la_LIBADD = libvppinfra.la -lrt -lpthread
libsvm_la_DEPENDENCIES = libvppinfra.la
diff --git a/src/svm/memfd.c b/src/svm/memfd.c
deleted file mode 100644
index 9fe487db788..00000000000
--- a/src/svm/memfd.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "memfd.h"
-
-int
-memfd_master_init (memfd_private_t * memfd, u32 master_index)
-{
- int flags;
- memfd_shared_header_t *sh;
- u64 ticks = clib_cpu_time_now ();
- u64 randomize_baseva;
- void *oldheap;
-
- if (memfd->memfd_size == 0)
- return MEMFD_API_ERROR_NO_SIZE;
-
- ASSERT (vec_c_string_is_terminated (memfd->name));
- memfd->name = format (0, "memfd svm region %d", master_index);
-
- memfd->fd = memfd_create ((char *) memfd->name, MFD_ALLOW_SEALING);
- if (memfd->fd < 0)
- {
- clib_unix_warning ("create segment '%s'", memfd->name);
- return MEMFD_API_ERROR_CREATE_FAILURE;
- }
-
- if ((ftruncate (memfd->fd, memfd->memfd_size)) == -1)
- {
- clib_unix_warning ("set memfd size");
- return MEMFD_API_ERROR_SET_SIZE;
- }
-
- if ((fcntl (memfd->fd, F_ADD_SEALS, F_SEAL_SHRINK)) == -1)
- clib_unix_warning ("fcntl (F_ADD_SEALS, F_SEAL_SHRINK)");
-
- flags = MAP_SHARED;
- if (memfd->requested_va)
- flags |= MAP_FIXED;
-
- randomize_baseva = (ticks & 15) * MMAP_PAGESIZE;
-
- if (memfd->requested_va)
- memfd->requested_va += randomize_baseva;
-
- sh = memfd->sh =
- (memfd_shared_header_t *) mmap ((void *) memfd->requested_va,
- memfd->memfd_size, PROT_READ | PROT_WRITE,
- flags, memfd->fd, 0);
-
- if (memfd->sh == MAP_FAILED)
- {
- clib_unix_warning ("mmap");
- close (memfd->fd);
- return MEMFD_API_ERROR_MMAP;
- }
-
- memfd->my_pid = getpid ();
- sh->master_pid = memfd->my_pid;
- sh->memfd_size = memfd->memfd_size;
- sh->heap = mheap_alloc_with_flags
- (((u8 *) sh) + MMAP_PAGESIZE, memfd->memfd_size - MMAP_PAGESIZE,
- MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE);
-
- sh->memfd_va = pointer_to_uword (sh);
- sh->master_index = master_index;
-
- oldheap = memfd_push_heap (sh);
- sh->name = format (0, "%s%c", memfd->name, 0);
- memfd_pop_heap (oldheap);
-
- memfd->i_am_master = 1;
-
- /* 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
- */
-
-int
-memfd_slave_init (memfd_private_t * memfd)
-{
- memfd_shared_header_t *sh;
-
- memfd->i_am_master = 0;
-
- /* Map the segment once, to look at the shared header */
- sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
- memfd->fd, 0);
- if (sh == MAP_FAILED)
- {
- clib_unix_warning ("slave research mmap");
- close (memfd->fd);
- return MEMFD_API_ERROR_MMAP;
- }
-
- memfd->requested_va = (u64) sh->memfd_va;
- memfd->memfd_size = sh->memfd_size;
- munmap (sh, MMAP_PAGESIZE);
-
- sh = memfd->sh =
- (void *) mmap ((void *) memfd->requested_va, memfd->memfd_size,
- PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_FIXED, memfd->fd, 0);
-
- if (sh == MAP_FAILED)
- {
- clib_unix_warning ("slave final mmap");
- close (memfd->fd);
- return MEMFD_API_ERROR_MMAP;
- }
- sh->slave_pid = getpid ();
- return 0;
-}
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/svm/memfd.h b/src/svm/memfd.h
deleted file mode 100644
index 3ed4a9ab067..00000000000
--- a/src/svm/memfd.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __included_memfd_h__
-#define __included_memfd_h__
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <netinet/in.h>
-#include <signal.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <time.h>
-#include <fcntl.h>
-#include <string.h>
-#include <vppinfra/clib.h>
-#include <vppinfra/vec.h>
-#include <vppinfra/hash.h>
-#include <vppinfra/bitmap.h>
-#include <vppinfra/fifo.h>
-#include <vppinfra/time.h>
-#include <vppinfra/mheap.h>
-#include <vppinfra/heap.h>
-#include <vppinfra/pool.h>
-#include <vppinfra/format.h>
-/* DGMS, memfd syscall not in glibc... */
-#include <vppinfra/linux/syscall.h>
-
-#ifndef MMAP_PAGESIZE
-#define MMAP_PAGESIZE (clib_mem_get_page_size())
-#endif
-
-#define MEMFD_N_OPAQUE 7
-
-typedef struct
-{
- /* Spin-lock */
- volatile u32 lock;
- volatile u32 owner_pid;
- int recursion_count;
- u32 tag; /* for debugging */
-
- /* The allocation arena */
- void *heap;
-
- /* Segment must be mapped at this address, or no supper */
- u64 memfd_va;
- /* The actual mmap size */
- u64 memfd_size;
- u32 master_pid;
- u32 slave_pid;
- u8 *name;
- void *opaque[MEMFD_N_OPAQUE];
-
- /* 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;
-} memfd_shared_header_t;
-
-typedef struct
-{
- memfd_shared_header_t *sh;
- int fd;
- u64 memfd_size;
- u32 my_pid;
- u32 vlib_hw_if_index;
- uword requested_va;
- int i_am_master;
- u32 per_interface_next_index;
- u32 *rx_queue;
- u8 *name;
-} memfd_private_t;
-
-always_inline void
-memfd_lock (memfd_shared_header_t * h, u32 my_pid, u32 tag)
-{
- if (h->owner_pid == my_pid)
- {
- h->recursion_count++;
- return;
- }
-
- while (__sync_lock_test_and_set (&h->lock, 1))
- ;
-
- h->owner_pid = my_pid;
- h->recursion_count = 1;
- h->tag = tag;
-}
-
-always_inline void
-memfd_lock_non_recursive (memfd_shared_header_t * h, u32 tag)
-{
- while (__sync_lock_test_and_set (&h->lock, 1))
- ;
-
- h->tag = tag;
-}
-
-always_inline void
-memfd_unlock (memfd_shared_header_t * h)
-{
- if (--h->recursion_count == 0)
- {
- h->owner_pid = 0;
- h->tag = 0;
- CLIB_MEMORY_BARRIER ();
- h->lock = 0;
- }
-}
-
-always_inline void
-memfd_unlock_non_recursive (memfd_shared_header_t * h)
-{
- h->tag = 0;
- CLIB_MEMORY_BARRIER ();
- h->lock = 0;
-}
-
-static inline void *
-memfd_push_heap (memfd_shared_header_t * sh)
-{
- u8 *oldheap;
- oldheap = clib_mem_set_heap (sh->heap);
- return ((void *) oldheap);
-}
-
-static inline void
-memfd_pop_heap (void *oldheap)
-{
- clib_mem_set_heap (oldheap);
-}
-
-#define foreach_memfd_api_error \
-_(NO_NAME, "No shared segment name", -100) \
-_(NO_SIZE, "Size not set (master)", -101) \
-_(CREATE_FAILURE, "Create failed", -102) \
-_(SET_SIZE, "Set size failed", -103) \
-_(MMAP, "mmap failed", -104) \
-_(SLAVE_TIMEOUT, "Slave map timeout", -105)
-
-typedef enum
-{
-#define _(n,s,c) MEMFD_API_ERROR_##n = c,
- foreach_memfd_api_error
-#undef _
-} memfd_api_error_enum_t;
-
-#define MEMFD_API_ERROR_NO_NAME (-10)
-
-int memfd_master_init (memfd_private_t * memfd, u32 master_index);
-int memfd_slave_init (memfd_private_t * memfd);
-void memfd_delete (memfd_private_t * memfd);
-
-/* These do not belong here, but the original keeps running around... */
-/* $$$$ work w/ Damjan to fix properly */
-
-#ifndef F_LINUX_SPECIFIC_BASE
-#define F_LINUX_SPECIFIC_BASE 1024
-#endif
-#define MFD_ALLOW_SEALING 0x0002U
-#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
-#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
-
-#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
-#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
-#define F_SEAL_GROW 0x0004 /* prevent file from growing */
-#define F_SEAL_WRITE 0x0008 /* prevent writes */
-
-#endif /* __included_memfd_h__ */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c
index c04982de85a..9b935e4a3bd 100644
--- a/src/svm/ssvm.c
+++ b/src/svm/ssvm.c
@@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "ssvm.h"
-#include "svm_common.h"
+#include <svm/ssvm.h>
+#include <svm/svm_common.h>
int
ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
@@ -202,6 +202,119 @@ ssvm_delete (ssvm_private_t * ssvm)
munmap ((void *) ssvm->requested_va, ssvm->ssvm_size);
}
+int
+ssvm_master_init_memfd (ssvm_private_t * memfd, u32 master_index)
+{
+ int flags;
+ ssvm_shared_header_t *sh;
+ u64 ticks = clib_cpu_time_now ();
+ u64 randomize_baseva;
+ void *oldheap;
+
+ if (memfd->ssvm_size == 0)
+ return SSVM_API_ERROR_NO_SIZE;
+
+ ASSERT (vec_c_string_is_terminated (memfd->name));
+ memfd->name = format (0, "memfd svm region %d", master_index);
+
+ memfd->fd = memfd_create ((char *) memfd->name, MFD_ALLOW_SEALING);
+ if (memfd->fd < 0)
+ {
+ clib_unix_warning ("create segment '%s'", memfd->name);
+ return SSVM_API_ERROR_CREATE_FAILURE;
+ }
+
+ if ((ftruncate (memfd->fd, memfd->ssvm_size)) == -1)
+ {
+ clib_unix_warning ("set memfd size");
+ return SSVM_API_ERROR_SET_SIZE;
+ }
+
+ if ((fcntl (memfd->fd, F_ADD_SEALS, F_SEAL_SHRINK)) == -1)
+ clib_unix_warning ("fcntl (F_ADD_SEALS, F_SEAL_SHRINK)");
+
+ flags = MAP_SHARED;
+ if (memfd->requested_va)
+ flags |= MAP_FIXED;
+
+ randomize_baseva = (ticks & 15) * MMAP_PAGESIZE;
+
+ if (memfd->requested_va)
+ memfd->requested_va += randomize_baseva;
+
+ sh = memfd->sh =
+ (ssvm_shared_header_t *) mmap ((void *) memfd->requested_va,
+ memfd->ssvm_size, PROT_READ | PROT_WRITE,
+ flags, memfd->fd, 0);
+
+ if (memfd->sh == MAP_FAILED)
+ {
+ clib_unix_warning ("mmap");
+ close (memfd->fd);
+ return SSVM_API_ERROR_MMAP;
+ }
+
+ memfd->my_pid = getpid ();
+ sh->master_pid = memfd->my_pid;
+ sh->ssvm_size = memfd->ssvm_size;
+ sh->heap = mheap_alloc_with_flags
+ (((u8 *) sh) + MMAP_PAGESIZE, memfd->ssvm_size - MMAP_PAGESIZE,
+ MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE);
+
+ 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);
+ ssvm_pop_heap (oldheap);
+
+ memfd->i_am_master = 1;
+
+ /* 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
+ */
+
+int
+ssvm_slave_init_memfd (ssvm_private_t * memfd)
+{
+ ssvm_shared_header_t *sh;
+
+ memfd->i_am_master = 0;
+
+ /* Map the segment once, to look at the shared header */
+ sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
+ memfd->fd, 0);
+ if (sh == MAP_FAILED)
+ {
+ clib_unix_warning ("slave research mmap");
+ close (memfd->fd);
+ return SSVM_API_ERROR_MMAP;
+ }
+
+ memfd->requested_va = (u64) sh->ssvm_va;
+ memfd->ssvm_size = sh->ssvm_size;
+ munmap (sh, MMAP_PAGESIZE);
+
+ sh = (void *) mmap ((void *) memfd->requested_va, memfd->ssvm_size,
+ PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
+ memfd->fd, 0);
+
+ if (sh == MAP_FAILED)
+ {
+ clib_unix_warning ("slave final mmap");
+ close (memfd->fd);
+ return SSVM_API_ERROR_MMAP;
+ }
+ sh->slave_pid = getpid ();
+ memfd->sh = sh;
+ return 0;
+}
/*
* fd.io coding-style-patch-verification: ON
diff --git a/src/svm/ssvm.h b/src/svm/ssvm.h
index 8466e15579b..0295e302e72 100644
--- a/src/svm/ssvm.h
+++ b/src/svm/ssvm.h
@@ -37,6 +37,7 @@
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
+#include <vppinfra/linux/syscall.h>
#ifndef MMAP_PAGESIZE
#define MMAP_PAGESIZE (clib_mem_get_page_size())
@@ -76,12 +77,12 @@ typedef struct
ssvm_shared_header_t *sh;
u64 ssvm_size;
u32 my_pid;
- u32 vlib_hw_if_index;
u8 *name;
uword requested_va;
int i_am_master;
- u32 per_interface_next_index;
- u32 *rx_queue;
+
+ /* Needed by memfd segments */
+ int fd;
} ssvm_private_t;
always_inline void
@@ -165,6 +166,24 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index);
int ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds);
void ssvm_delete (ssvm_private_t * ssvm);
+int ssvm_master_init_memfd (ssvm_private_t * memfd, u32 master_index);
+int ssvm_slave_init_memfd (ssvm_private_t * memfd);
+void memfd_delete (ssvm_private_t * memfd);
+
+/* These do not belong here, but the original keeps running around... */
+/* $$$$ work w/ Damjan to fix properly */
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+#define MFD_ALLOW_SEALING 0x0002U
+#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
+#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
+
+#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
+#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
+#define F_SEAL_GROW 0x0004 /* prevent file from growing */
+#define F_SEAL_WRITE 0x0008 /* prevent writes */
+
#endif /* __included_ssvm_h__ */
/*
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index da1892a1580..3654cd663bd 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -19,7 +19,6 @@
#include <vat/vat.h>
#include <vppinfra/socket.h>
-#include <svm/memfd.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vnet/ip/ip.h>
@@ -2206,7 +2205,7 @@ static void vl_api_memfd_segment_create_reply_t_handler
socket_client_main_t *scm = vam->socket_client_main;
int my_fd = -1;
clib_error_t *error;
- memfd_private_t memfd;
+ ssvm_private_t memfd;
i32 retval = ntohl (mp->retval);
if (retval == 0)
@@ -2224,7 +2223,7 @@ static void vl_api_memfd_segment_create_reply_t_handler
vam->client_index_invalid = 1;
/* Note: this closes memfd.fd */
- retval = memfd_slave_init (&memfd);
+ retval = ssvm_slave_init_memfd (&memfd);
if (retval)
clib_warning ("WARNING: segment map returned %d", retval);
diff --git a/src/vlibmemory/memory_api.h b/src/vlibmemory/memory_api.h
index 9b87f5a18fd..58f47d1313a 100644
--- a/src/vlibmemory/memory_api.h
+++ b/src/vlibmemory/memory_api.h
@@ -19,6 +19,7 @@
#define SRC_VLIBMEMORY_MEMORY_API_H_
#include <svm/svm.h>
+#include <svm/ssvm.h>
#include <svm/queue.h>
#include <vlib/vlib.h>
#include <vlibapi/api.h>
diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c
index 1bb2fe86136..a0b5cc99cd4 100644
--- a/src/vlibmemory/memory_client.c
+++ b/src/vlibmemory/memory_client.c
@@ -20,6 +20,7 @@
#include <setjmp.h>
#include <svm/svm.h>
+#include <svm/ssvm.h>
#include <vppinfra/serialize.h>
#include <vppinfra/hash.h>
#include <vlibmemory/memory_client.h>
diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c
index 3d505359d3b..9c099b9b0b7 100644
--- a/src/vlibmemory/socket_api.c
+++ b/src/vlibmemory/socket_api.c
@@ -25,7 +25,7 @@
#include <sys/stat.h>
#include <vppinfra/byte_order.h>
-#include <svm/memfd.h>
+#include <svm/ssvm.h>
#include <vlibmemory/api.h>
#include <vlibmemory/vl_memory_msg_enum.h>
@@ -528,7 +528,7 @@ void
vl_api_sock_init_shm_t_handler (vl_api_sock_init_shm_t * mp)
{
vl_api_sock_init_shm_reply_t *rmp;
- memfd_private_t _memfd_private, *memfd = &_memfd_private;
+ ssvm_private_t _memfd_private, *memfd = &_memfd_private;
svm_map_region_args_t _args, *a = &_args;
vl_api_registration_t *regp;
api_main_t *am = &api_main;
@@ -554,12 +554,12 @@ vl_api_sock_init_shm_t_handler (vl_api_sock_init_shm_t * mp)
* shmem data structures will be initialized
*/
memset (memfd, 0, sizeof (*memfd));
- memfd->memfd_size = mp->requested_size;
+ memfd->ssvm_size = mp->requested_size;
memfd->requested_va = 0ULL;
memfd->i_am_master = 1;
memfd->name = format (0, "%s%c", regp->name, 0);
- if ((rv = memfd_master_init (memfd, mp->client_index)))
+ if ((rv = ssvm_master_init_memfd (memfd, mp->client_index)))
goto reply;
/* Remember to close this fd when the socket connection goes away */
@@ -569,8 +569,8 @@ vl_api_sock_init_shm_t_handler (vl_api_sock_init_shm_t * mp)
* Create a plausible svm_region in the memfd backed segment
*/
memset (a, 0, sizeof (*a));
- a->baseva = memfd->sh->memfd_va + MMAP_PAGESIZE;
- a->size = memfd->memfd_size - MMAP_PAGESIZE;
+ a->baseva = memfd->sh->ssvm_va + MMAP_PAGESIZE;
+ a->size = memfd->ssvm_size - MMAP_PAGESIZE;
/* $$$$ might want a different config parameter */
a->pvt_heap_size = am->api_pvt_heap_size;
a->flags = SVM_FLAGS_MHEAP;
@@ -622,7 +622,7 @@ vl_api_memfd_segment_create_t_handler (vl_api_memfd_segment_create_t * mp)
{
vl_api_memfd_segment_create_reply_t *rmp;
clib_file_t *cf;
- memfd_private_t _memfd_private, *memfd = &_memfd_private;
+ ssvm_private_t _memfd_private, *memfd = &_memfd_private;
vl_api_registration_t *regp;
int rv;
@@ -634,13 +634,13 @@ vl_api_memfd_segment_create_t_handler (vl_api_memfd_segment_create_t * mp)
}
memset (memfd, 0, sizeof (*memfd));
- memfd->memfd_size = mp->requested_size;
+ memfd->ssvm_size = mp->requested_size;
memfd->requested_va = 0ULL;
memfd->i_am_master = 1;
memfd->name = format (0, "%s%c", regp->name, 0);
/* Set up a memfd segment of the requested size */
- if ((rv = memfd_master_init (memfd, mp->client_index)))
+ if ((rv = ssvm_master_init_memfd (memfd, mp->client_index)))
goto reply;
/* Remember to close this fd when the socket connection goes away */
diff --git a/src/vlibmemory/socket_api.h b/src/vlibmemory/socket_api.h
index 69610e8997a..5cb3c058d5f 100644
--- a/src/vlibmemory/socket_api.h
+++ b/src/vlibmemory/socket_api.h
@@ -19,6 +19,7 @@
#define SRC_VLIBMEMORY_SOCKET_API_H_
#include <vlibapi/api_common.h>
+#include <svm/ssvm.h>
#include <vppinfra/file.h>
#define API_SOCKET_FILE "/run/vpp-api.sock"
diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c
index 4567f65e6e1..44d21228bfe 100644
--- a/src/vlibmemory/socket_client.c
+++ b/src/vlibmemory/socket_client.c
@@ -21,7 +21,7 @@
#define __USE_GNU
#include <sys/socket.h>
-#include <svm/memfd.h>
+#include <svm/ssvm.h>
#include <vlibmemory/socket_client.h>
#include <vlibmemory/memory_client.h>
@@ -231,7 +231,7 @@ static void vl_api_sock_init_shm_reply_t_handler
int my_fd = -1;
clib_error_t *error;
i32 retval = ntohl (mp->retval);
- memfd_private_t memfd;
+ ssvm_private_t memfd;
api_main_t *am = &api_main;
u8 *new_name;
@@ -255,7 +255,7 @@ static void vl_api_sock_init_shm_reply_t_handler
memfd.fd = my_fd;
/* Note: this closes memfd.fd */
- retval = memfd_slave_init (&memfd);
+ retval = ssvm_slave_init_memfd (&memfd);
if (retval)
clib_warning ("WARNING: segment map returned %d", retval);
diff --git a/src/vnet.am b/src/vnet.am
index 2bae8678c4b..84407bc1861 100644
--- a/src/vnet.am
+++ b/src/vnet.am
@@ -905,16 +905,6 @@ nobase_include_HEADERS += \
API_FILES += vnet/devices/tap/tapv2.api
########################################
-# ssvm ethernet
-########################################
-libvnet_la_SOURCES += \
- vnet/devices/ssvm/ssvm_eth.c \
- vnet/devices/ssvm/node.c
-
-nobase_include_HEADERS += \
- vnet/devices/ssvm/ssvm_eth.h
-
-########################################
# session managmeent
########################################
diff --git a/src/vnet/devices/ssvm/node.c b/src/vnet/devices/ssvm/node.c
deleted file mode 100644
index 344b357662c..00000000000
--- a/src/vnet/devices/ssvm/node.c
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ssvm_eth.h"
-
-vlib_node_registration_t ssvm_eth_input_node;
-
-typedef struct
-{
- u32 next_index;
- u32 sw_if_index;
-} ssvm_eth_input_trace_t;
-
-/* packet trace format function */
-static u8 *
-format_ssvm_eth_input_trace (u8 * s, va_list * args)
-{
- CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
- CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- ssvm_eth_input_trace_t *t = va_arg (*args, ssvm_eth_input_trace_t *);
-
- s = format (s, "SSVM_ETH_INPUT: sw_if_index %d, next index %d",
- t->sw_if_index, t->next_index);
- return s;
-}
-
-vlib_node_registration_t ssvm_eth_input_node;
-
-#define foreach_ssvm_eth_input_error \
-_(NO_BUFFERS, "Rx packet drops (no buffers)")
-
-typedef enum
-{
-#define _(sym,str) SSVM_ETH_INPUT_ERROR_##sym,
- foreach_ssvm_eth_input_error
-#undef _
- SSVM_ETH_INPUT_N_ERROR,
-} ssvm_eth_input_error_t;
-
-static char *ssvm_eth_input_error_strings[] = {
-#define _(sym,string) string,
- foreach_ssvm_eth_input_error
-#undef _
-};
-
-typedef enum
-{
- SSVM_ETH_INPUT_NEXT_DROP,
- SSVM_ETH_INPUT_NEXT_ETHERNET_INPUT,
- SSVM_ETH_INPUT_NEXT_IP4_INPUT,
- SSVM_ETH_INPUT_NEXT_IP6_INPUT,
- SSVM_ETH_INPUT_NEXT_MPLS_INPUT,
- SSVM_ETH_INPUT_N_NEXT,
-} ssvm_eth_input_next_t;
-
-static inline uword
-ssvm_eth_device_input (ssvm_eth_main_t * em,
- ssvm_private_t * intfc, vlib_node_runtime_t * node)
-{
- ssvm_shared_header_t *sh = intfc->sh;
- vlib_main_t *vm = em->vlib_main;
- svm_queue_t *q;
- ssvm_eth_queue_elt_t *elt, *elts;
- u32 elt_index;
- u32 my_pid = intfc->my_pid;
- int rx_queue_index;
- u32 n_to_alloc = VLIB_FRAME_SIZE * 2;
- u32 n_allocated, n_present_in_cache;
- u32 next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
- vlib_buffer_free_list_t *fl;
- u32 n_left_to_next, *to_next;
- u32 next0;
- u32 n_buffers;
- u32 n_available;
- u32 bi0, saved_bi0;
- vlib_buffer_t *b0, *prev;
- u32 saved_cache_size = 0;
- ethernet_header_t *eh0;
- u16 type0;
- u32 n_rx_bytes = 0, l3_offset0;
- u32 thread_index = vlib_get_thread_index ();
- u32 trace_cnt __attribute__ ((unused)) = vlib_get_trace_count (vm, node);
- volatile u32 *lock;
- u32 *elt_indices;
- uword n_trace = vlib_get_trace_count (vm, node);
-
- /* Either side down? buh-bye... */
- if (pointer_to_uword (sh->opaque[MASTER_ADMIN_STATE_INDEX]) == 0 ||
- pointer_to_uword (sh->opaque[SLAVE_ADMIN_STATE_INDEX]) == 0)
- return 0;
-
- if (intfc->i_am_master)
- q = (svm_queue_t *) (sh->opaque[TO_MASTER_Q_INDEX]);
- else
- q = (svm_queue_t *) (sh->opaque[TO_SLAVE_Q_INDEX]);
-
- /* Nothing to do? */
- if (q->cursize == 0)
- return 0;
-
- fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
-
- vec_reset_length (intfc->rx_queue);
-
- lock = (u32 *) q;
- while (__sync_lock_test_and_set (lock, 1))
- ;
- while (q->cursize > 0)
- {
- svm_queue_sub_raw (q, (u8 *) & elt_index);
- ASSERT (elt_index < 2048);
- vec_add1 (intfc->rx_queue, elt_index);
- }
- CLIB_MEMORY_BARRIER ();
- *lock = 0;
-
- n_present_in_cache = vec_len (em->buffer_cache);
-
- if (vec_len (em->buffer_cache) < vec_len (intfc->rx_queue) * 2)
- {
- vec_validate (em->buffer_cache,
- n_to_alloc + vec_len (em->buffer_cache) - 1);
- n_allocated =
- vlib_buffer_alloc (vm, &em->buffer_cache[n_present_in_cache],
- n_to_alloc);
-
- n_present_in_cache += n_allocated;
- _vec_len (em->buffer_cache) = n_present_in_cache;
- }
-
- elts = (ssvm_eth_queue_elt_t *) (sh->opaque[CHUNK_POOL_INDEX]);
-
- n_buffers = vec_len (intfc->rx_queue);
- rx_queue_index = 0;
-
- while (n_buffers > 0)
- {
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
- while (n_buffers > 0 && n_left_to_next > 0)
- {
- elt = elts + intfc->rx_queue[rx_queue_index];
-
- saved_cache_size = n_present_in_cache;
- if (PREDICT_FALSE (saved_cache_size == 0))
- {
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
- goto out;
- }
- saved_bi0 = bi0 = em->buffer_cache[--n_present_in_cache];
- b0 = vlib_get_buffer (vm, bi0);
- prev = 0;
-
- while (1)
- {
- vlib_buffer_init_for_free_list (b0, fl);
-
- b0->current_data = elt->current_data_hint;
- b0->current_length = elt->length_this_buffer;
- b0->total_length_not_including_first_buffer =
- elt->total_length_not_including_first_buffer;
-
- clib_memcpy (b0->data + b0->current_data, elt->data,
- b0->current_length);
-
- if (PREDICT_FALSE (prev != 0))
- prev->next_buffer = bi0;
-
- if (PREDICT_FALSE (elt->flags & SSVM_BUFFER_NEXT_PRESENT))
- {
- prev = b0;
- if (PREDICT_FALSE (n_present_in_cache == 0))
- {
- vlib_put_next_frame (vm, node, next_index,
- n_left_to_next);
- goto out;
- }
- bi0 = em->buffer_cache[--n_present_in_cache];
- b0 = vlib_get_buffer (vm, bi0);
- }
- else
- break;
- }
-
- saved_cache_size = n_present_in_cache;
-
- to_next[0] = saved_bi0;
- to_next++;
- n_left_to_next--;
-
- b0 = vlib_get_buffer (vm, saved_bi0);
- eh0 = vlib_buffer_get_current (b0);
-
- type0 = clib_net_to_host_u16 (eh0->type);
-
- next0 = SSVM_ETH_INPUT_NEXT_ETHERNET_INPUT;
-
- if (type0 == ETHERNET_TYPE_IP4)
- next0 = SSVM_ETH_INPUT_NEXT_IP4_INPUT;
- else if (type0 == ETHERNET_TYPE_IP6)
- next0 = SSVM_ETH_INPUT_NEXT_IP6_INPUT;
- else if (type0 == ETHERNET_TYPE_MPLS)
- next0 = SSVM_ETH_INPUT_NEXT_MPLS_INPUT;
-
- l3_offset0 = ((next0 == SSVM_ETH_INPUT_NEXT_IP4_INPUT ||
- next0 == SSVM_ETH_INPUT_NEXT_IP6_INPUT ||
- next0 == SSVM_ETH_INPUT_NEXT_MPLS_INPUT) ?
- sizeof (ethernet_header_t) : 0);
-
- n_rx_bytes += b0->current_length
- + b0->total_length_not_including_first_buffer;
-
- b0->current_data += l3_offset0;
- b0->current_length -= l3_offset0;
- b0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
-
- vnet_buffer (b0)->sw_if_index[VLIB_RX] = intfc->vlib_hw_if_index;
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
-
- /*
- * Turn this on if you run into
- * "bad monkey" contexts, and you want to know exactly
- * which nodes they've visited... See main.c...
- */
- VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
-
- if (PREDICT_FALSE (n_trace > 0))
- {
- ssvm_eth_input_trace_t *tr;
-
- vlib_trace_buffer (vm, node, next0, b0, /* follow_chain */ 1);
- vlib_set_trace_count (vm, node, --n_trace);
-
- tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
-
- tr->next_index = next0;
- tr->sw_if_index = intfc->vlib_hw_if_index;
- }
-
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, next0);
- n_buffers--;
- rx_queue_index++;
- }
-
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
- }
-
-out:
- if (em->buffer_cache)
- _vec_len (em->buffer_cache) = saved_cache_size;
- else
- ASSERT (saved_cache_size == 0);
-
- ssvm_lock (sh, my_pid, 2);
-
- ASSERT (vec_len (intfc->rx_queue) > 0);
-
- n_available = (u32) pointer_to_uword (sh->opaque[CHUNK_POOL_NFREE]);
- elt_indices = (u32 *) (sh->opaque[CHUNK_POOL_FREELIST_INDEX]);
-
- clib_memcpy (&elt_indices[n_available], intfc->rx_queue,
- vec_len (intfc->rx_queue) * sizeof (u32));
-
- n_available += vec_len (intfc->rx_queue);
- sh->opaque[CHUNK_POOL_NFREE] = uword_to_pointer (n_available, void *);
-
- ssvm_unlock (sh);
-
- vlib_error_count (vm, node->node_index, SSVM_ETH_INPUT_ERROR_NO_BUFFERS,
- n_buffers);
-
- vlib_increment_combined_counter
- (vnet_get_main ()->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX, thread_index,
- intfc->vlib_hw_if_index, rx_queue_index, n_rx_bytes);
-
- vnet_device_increment_rx_packets (thread_index, rx_queue_index);
-
- return rx_queue_index;
-}
-
-static uword
-ssvm_eth_input_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
-{
- ssvm_eth_main_t *em = &ssvm_eth_main;
- ssvm_private_t *intfc;
- uword n_rx_packets = 0;
-
- vec_foreach (intfc, em->intfcs)
- {
- n_rx_packets += ssvm_eth_device_input (em, intfc, node);
- }
-
- return n_rx_packets;
-}
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (ssvm_eth_input_node) = {
- .function = ssvm_eth_input_node_fn,
- .name = "ssvm_eth_input",
- .vector_size = sizeof (u32),
- .format_trace = format_ssvm_eth_input_trace,
- .type = VLIB_NODE_TYPE_INPUT,
- .state = VLIB_NODE_STATE_DISABLED,
-
- .n_errors = ARRAY_LEN(ssvm_eth_input_error_strings),
- .error_strings = ssvm_eth_input_error_strings,
-
- .n_next_nodes = SSVM_ETH_INPUT_N_NEXT,
-
- /* edit / add dispositions here */
- .next_nodes = {
- [SSVM_ETH_INPUT_NEXT_DROP] = "error-drop",
- [SSVM_ETH_INPUT_NEXT_ETHERNET_INPUT] = "ethernet-input",
- [SSVM_ETH_INPUT_NEXT_IP4_INPUT] = "ip4-input",
- [SSVM_ETH_INPUT_NEXT_IP6_INPUT] = "ip6-input",
- [SSVM_ETH_INPUT_NEXT_MPLS_INPUT] = "mpls-input",
- },
-};
-
-VLIB_NODE_FUNCTION_MULTIARCH (ssvm_eth_input_node, ssvm_eth_input_node_fn)
-/* *INDENT-ON* */
-
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vnet/devices/ssvm/ssvm_eth.c b/src/vnet/devices/ssvm/ssvm_eth.c
deleted file mode 100644
index 8a0cebe29d4..00000000000
--- a/src/vnet/devices/ssvm/ssvm_eth.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ssvm_eth.h"
-
-ssvm_eth_main_t ssvm_eth_main;
-
-#define foreach_ssvm_eth_tx_func_error \
-_(RING_FULL, "Tx packet drops (ring full)") \
-_(NO_BUFFERS, "Tx packet drops (no buffers)") \
-_(ADMIN_DOWN, "Tx packet drops (admin down)")
-
-typedef enum
-{
-#define _(f,s) SSVM_ETH_TX_ERROR_##f,
- foreach_ssvm_eth_tx_func_error
-#undef _
- SSVM_ETH_TX_N_ERROR,
-} ssvm_eth_tx_func_error_t;
-
-static u32 ssvm_eth_flag_change (vnet_main_t * vnm,
- vnet_hw_interface_t * hi, u32 flags);
-
-int
-ssvm_eth_create (ssvm_eth_main_t * em, u8 * name, int is_master)
-{
- ssvm_private_t *intfc;
- void *oldheap;
- clib_error_t *e;
- svm_queue_t *q;
- ssvm_shared_header_t *sh;
- ssvm_eth_queue_elt_t *elts;
- u32 *elt_indices;
- u8 enet_addr[6];
- int i, rv;
-
- vec_add2 (em->intfcs, intfc, 1);
-
- intfc->ssvm_size = em->segment_size;
- intfc->i_am_master = 1;
- intfc->name = name;
- intfc->my_pid = getpid ();
- if (is_master == 0)
- {
- rv = ssvm_slave_init (intfc, 20 /* timeout in seconds */ );
- if (rv < 0)
- return rv;
- goto create_vnet_interface;
- }
-
- intfc->requested_va = em->next_base_va;
- em->next_base_va += em->segment_size;
- rv = ssvm_master_init (intfc, intfc - em->intfcs /* master index */ );
-
- if (rv < 0)
- return rv;
-
- /* OK, segment created, set up queues and so forth. */
-
- sh = intfc->sh;
- oldheap = ssvm_push_heap (sh);
-
- q = svm_queue_init (em->queue_elts, sizeof (u32),
- 0 /* consumer pid not interesting */ ,
- 0 /* signal not sent */ );
- sh->opaque[TO_MASTER_Q_INDEX] = (void *) q;
- q = svm_queue_init (em->queue_elts, sizeof (u32),
- 0 /* consumer pid not interesting */ ,
- 0 /* signal not sent */ );
- sh->opaque[TO_SLAVE_Q_INDEX] = (void *) q;
-
- /*
- * Preallocate the requested number of buffer chunks
- * There must be a better way to do this, etc.
- * Add some slop to avoid pool reallocation, which will not go well
- */
- elts = 0;
- elt_indices = 0;
-
- vec_validate_aligned (elts, em->nbuffers - 1, CLIB_CACHE_LINE_BYTES);
- vec_validate_aligned (elt_indices, em->nbuffers - 1, CLIB_CACHE_LINE_BYTES);
-
- for (i = 0; i < em->nbuffers; i++)
- elt_indices[i] = i;
-
- sh->opaque[CHUNK_POOL_INDEX] = (void *) elts;
- sh->opaque[CHUNK_POOL_FREELIST_INDEX] = (void *) elt_indices;
- sh->opaque[CHUNK_POOL_NFREE] = (void *) (uword) em->nbuffers;
-
- ssvm_pop_heap (oldheap);
-
-create_vnet_interface:
-
- sh = intfc->sh;
-
- memset (enet_addr, 0, sizeof (enet_addr));
- enet_addr[0] = 2;
- enet_addr[1] = 0xFE;
- enet_addr[2] = is_master;
- enet_addr[5] = sh->master_index;
-
- e = ethernet_register_interface
- (em->vnet_main, ssvm_eth_device_class.index, intfc - em->intfcs,
- /* ethernet address */ enet_addr,
- &intfc->vlib_hw_if_index, ssvm_eth_flag_change);
-
- if (e)
- {
- clib_error_report (e);
- /* $$$$ unmap offending region? */
- return VNET_API_ERROR_INVALID_INTERFACE;
- }
-
- /* Declare link up */
- vnet_hw_interface_set_flags (em->vnet_main, intfc->vlib_hw_if_index,
- VNET_HW_INTERFACE_FLAG_LINK_UP);
-
- /* Let the games begin... */
- if (is_master)
- sh->ready = 1;
- return 0;
-}
-
-static clib_error_t *
-ssvm_config (vlib_main_t * vm, unformat_input_t * input)
-{
- u8 *name;
- int is_master = 1;
- int i, rv;
- ssvm_eth_main_t *em = &ssvm_eth_main;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "base-va %llx", &em->next_base_va))
- ;
- else if (unformat (input, "segment-size %lld", &em->segment_size))
- em->segment_size = 1ULL << (max_log2 (em->segment_size));
- else if (unformat (input, "nbuffers %lld", &em->nbuffers))
- ;
- else if (unformat (input, "queue-elts %lld", &em->queue_elts))
- ;
- else if (unformat (input, "slave"))
- is_master = 0;
- else if (unformat (input, "%s", &name))
- vec_add1 (em->names, name);
- else
- break;
- }
-
- /* No configured instances, we're done... */
- if (vec_len (em->names) == 0)
- return 0;
-
- for (i = 0; i < vec_len (em->names); i++)
- {
- rv = ssvm_eth_create (em, em->names[i], is_master);
- if (rv < 0)
- return clib_error_return (0, "ssvm_eth_create '%s' failed, error %d",
- em->names[i], rv);
- }
-
- vlib_node_set_state (vm, ssvm_eth_input_node.index,
- VLIB_NODE_STATE_POLLING);
-
- return 0;
-}
-
-VLIB_CONFIG_FUNCTION (ssvm_config, "ssvm_eth");
-
-
-static clib_error_t *
-ssvm_eth_init (vlib_main_t * vm)
-{
- ssvm_eth_main_t *em = &ssvm_eth_main;
-
- if (((sizeof (ssvm_eth_queue_elt_t) / CLIB_CACHE_LINE_BYTES)
- * CLIB_CACHE_LINE_BYTES) != sizeof (ssvm_eth_queue_elt_t))
- clib_warning ("ssvm_eth_queue_elt_t size %d not a multiple of %d",
- sizeof (ssvm_eth_queue_elt_t), CLIB_CACHE_LINE_BYTES);
-
- em->vlib_main = vm;
- em->vnet_main = vnet_get_main ();
- em->elog_main = &vm->elog_main;
-
- /* default config param values... */
-
- em->next_base_va = 0x600000000ULL;
- /*
- * Allocate 2 full superframes in each dir (256 x 2 x 2 x 2048 bytes),
- * 2mb; double that so we have plenty of space... 4mb
- */
- em->segment_size = 8 << 20;
- em->nbuffers = 1024;
- em->queue_elts = 512;
- return 0;
-}
-
-VLIB_INIT_FUNCTION (ssvm_eth_init);
-
-static char *ssvm_eth_tx_func_error_strings[] = {
-#define _(n,s) s,
- foreach_ssvm_eth_tx_func_error
-#undef _
-};
-
-static u8 *
-format_ssvm_eth_device_name (u8 * s, va_list * args)
-{
- u32 i = va_arg (*args, u32);
-
- s = format (s, "ssvmEthernet%d", i);
- return s;
-}
-
-static u8 *
-format_ssvm_eth_device (u8 * s, va_list * args)
-{
- s = format (s, "SSVM Ethernet");
- return s;
-}
-
-static u8 *
-format_ssvm_eth_tx_trace (u8 * s, va_list * args)
-{
- s = format (s, "Unimplemented...");
- return s;
-}
-
-
-static uword
-ssvm_eth_interface_tx (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * f)
-{
- ssvm_eth_main_t *em = &ssvm_eth_main;
- vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
- ssvm_private_t *intfc = vec_elt_at_index (em->intfcs, rd->dev_instance);
- ssvm_shared_header_t *sh = intfc->sh;
- svm_queue_t *q;
- u32 *from;
- u32 n_left;
- ssvm_eth_queue_elt_t *elts, *elt, *prev_elt;
- u32 my_pid = intfc->my_pid;
- vlib_buffer_t *b0;
- u32 bi0;
- u32 size_this_buffer;
- u32 chunks_this_buffer;
- u8 i_am_master = intfc->i_am_master;
- u32 elt_index;
- int is_ring_full, interface_down;
- int i;
- volatile u32 *queue_lock;
- u32 n_to_alloc = VLIB_FRAME_SIZE;
- u32 n_allocated, n_present_in_cache, n_available;
- u32 *elt_indices;
-
- if (i_am_master)
- q = (svm_queue_t *) sh->opaque[TO_SLAVE_Q_INDEX];
- else
- q = (svm_queue_t *) sh->opaque[TO_MASTER_Q_INDEX];
-
- queue_lock = (u32 *) q;
-
- from = vlib_frame_vector_args (f);
- n_left = f->n_vectors;
- is_ring_full = 0;
- interface_down = 0;
-
- n_present_in_cache = vec_len (em->chunk_cache);
-
- /* admin / link up/down check */
- if (sh->opaque[MASTER_ADMIN_STATE_INDEX] == 0 ||
- sh->opaque[SLAVE_ADMIN_STATE_INDEX] == 0)
- {
- interface_down = 1;
- goto out;
- }
-
- ssvm_lock (sh, my_pid, 1);
-
- elts = (ssvm_eth_queue_elt_t *) (sh->opaque[CHUNK_POOL_INDEX]);
- elt_indices = (u32 *) (sh->opaque[CHUNK_POOL_FREELIST_INDEX]);
- n_available = (u32) pointer_to_uword (sh->opaque[CHUNK_POOL_NFREE]);
-
- if (n_present_in_cache < n_left * 2)
- {
- vec_validate (em->chunk_cache, n_to_alloc + n_present_in_cache - 1);
-
- n_allocated = n_to_alloc < n_available ? n_to_alloc : n_available;
-
- if (PREDICT_TRUE (n_allocated > 0))
- {
- clib_memcpy (&em->chunk_cache[n_present_in_cache],
- &elt_indices[n_available - n_allocated],
- sizeof (u32) * n_allocated);
- }
-
- n_present_in_cache += n_allocated;
- n_available -= n_allocated;
- sh->opaque[CHUNK_POOL_NFREE] = uword_to_pointer (n_available, void *);
- _vec_len (em->chunk_cache) = n_present_in_cache;
- }
-
- ssvm_unlock (sh);
-
- while (n_left)
- {
- bi0 = from[0];
- b0 = vlib_get_buffer (vm, bi0);
-
- size_this_buffer = vlib_buffer_length_in_chain (vm, b0);
- chunks_this_buffer = (size_this_buffer + (SSVM_BUFFER_SIZE - 1))
- / SSVM_BUFFER_SIZE;
-
- /* If we're not going to be able to enqueue the buffer, tail drop. */
- if (q->cursize >= q->maxsize)
- {
- is_ring_full = 1;
- break;
- }
-
- prev_elt = 0;
- elt_index = ~0;
- for (i = 0; i < chunks_this_buffer; i++)
- {
- if (PREDICT_FALSE (n_present_in_cache == 0))
- goto out;
-
- elt_index = em->chunk_cache[--n_present_in_cache];
- elt = elts + elt_index;
-
- elt->type = SSVM_PACKET_TYPE;
- elt->flags = 0;
- elt->total_length_not_including_first_buffer =
- b0->total_length_not_including_first_buffer;
- elt->length_this_buffer = b0->current_length;
- elt->current_data_hint = b0->current_data;
- elt->owner = !i_am_master;
- elt->tag = 1;
-
- clib_memcpy (elt->data, b0->data + b0->current_data,
- b0->current_length);
-
- if (PREDICT_FALSE (prev_elt != 0))
- prev_elt->next_index = elt - elts;
-
- if (PREDICT_FALSE (i < (chunks_this_buffer - 1)))
- {
- elt->flags = SSVM_BUFFER_NEXT_PRESENT;
- ASSERT (b0->flags & VLIB_BUFFER_NEXT_PRESENT);
- b0 = vlib_get_buffer (vm, b0->next_buffer);
- }
- prev_elt = elt;
- }
-
- while (__sync_lock_test_and_set (queue_lock, 1))
- ;
-
- svm_queue_add_raw (q, (u8 *) & elt_index);
- CLIB_MEMORY_BARRIER ();
- *queue_lock = 0;
-
- from++;
- n_left--;
- }
-
-out:
- if (PREDICT_FALSE (n_left))
- {
- if (is_ring_full)
- vlib_error_count (vm, node->node_index, SSVM_ETH_TX_ERROR_RING_FULL,
- n_left);
- else if (interface_down)
- vlib_error_count (vm, node->node_index, SSVM_ETH_TX_ERROR_ADMIN_DOWN,
- n_left);
- else
- vlib_error_count (vm, node->node_index, SSVM_ETH_TX_ERROR_NO_BUFFERS,
- n_left);
-
- vlib_buffer_free (vm, from, n_left);
- }
- else
- vlib_buffer_free (vm, vlib_frame_vector_args (f), f->n_vectors);
-
- if (PREDICT_TRUE (vec_len (em->chunk_cache)))
- _vec_len (em->chunk_cache) = n_present_in_cache;
-
- return f->n_vectors;
-}
-
-static void
-ssvm_eth_clear_hw_interface_counters (u32 instance)
-{
- /* Nothing for now */
-}
-
-static clib_error_t *
-ssvm_eth_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
- u32 flags)
-{
- vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
- uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
- ssvm_eth_main_t *em = &ssvm_eth_main;
- ssvm_private_t *intfc = vec_elt_at_index (em->intfcs, hif->dev_instance);
- ssvm_shared_header_t *sh;
-
- /* publish link-state in shared-memory, to discourage buffer-wasting */
- sh = intfc->sh;
- if (intfc->i_am_master)
- sh->opaque[MASTER_ADMIN_STATE_INDEX] = (void *) is_up;
- else
- sh->opaque[SLAVE_ADMIN_STATE_INDEX] = (void *) is_up;
-
- return 0;
-}
-
-static clib_error_t *
-ssvm_eth_subif_add_del_function (vnet_main_t * vnm,
- u32 hw_if_index,
- struct vnet_sw_interface_t *st, int is_add)
-{
- /* Nothing for now */
- return 0;
-}
-
-/*
- * Dynamically redirect all pkts from a specific interface
- * to the specified node
- */
-static void
-ssvm_eth_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
- u32 node_index)
-{
- ssvm_eth_main_t *em = &ssvm_eth_main;
- vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
- ssvm_private_t *intfc = pool_elt_at_index (em->intfcs, hw->dev_instance);
-
- /* Shut off redirection */
- if (node_index == ~0)
- {
- intfc->per_interface_next_index = node_index;
- return;
- }
-
- intfc->per_interface_next_index =
- vlib_node_add_next (em->vlib_main, ssvm_eth_input_node.index, node_index);
-}
-
-static u32
-ssvm_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
-{
- /* nothing for now */
- return 0;
-}
-
-/* *INDENT-OFF* */
-VNET_DEVICE_CLASS (ssvm_eth_device_class) = {
- .name = "ssvm-eth",
- .tx_function = ssvm_eth_interface_tx,
- .tx_function_n_errors = SSVM_ETH_TX_N_ERROR,
- .tx_function_error_strings = ssvm_eth_tx_func_error_strings,
- .format_device_name = format_ssvm_eth_device_name,
- .format_device = format_ssvm_eth_device,
- .format_tx_trace = format_ssvm_eth_tx_trace,
- .clear_counters = ssvm_eth_clear_hw_interface_counters,
- .admin_up_down_function = ssvm_eth_interface_admin_up_down,
- .subif_add_del_function = ssvm_eth_subif_add_del_function,
- .rx_redirect_to_node = ssvm_eth_set_interface_next_node,
-};
-
-VLIB_DEVICE_TX_FUNCTION_MULTIARCH (ssvm_eth_device_class,
- ssvm_eth_interface_tx)
-/* *INDENT-ON* */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vnet/devices/ssvm/ssvm_eth.h b/src/vnet/devices/ssvm/ssvm_eth.h
deleted file mode 100644
index a506b4b7312..00000000000
--- a/src/vnet/devices/ssvm/ssvm_eth.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __included_ssvm_eth_h__
-#define __included_ssvm_eth_h__
-
-#include <vnet/vnet.h>
-
-#include <vppinfra/elog.h>
-#include <vppinfra/error.h>
-#include <vppinfra/format.h>
-#include <vppinfra/hash.h>
-#include <vppinfra/vec.h>
-#include <vppinfra/elog.h>
-#include <vlib/vlib.h>
-#include <vnet/ethernet/ethernet.h>
-#include <vnet/devices/devices.h>
-#include <vnet/ip/ip.h>
-#include <vnet/pg/pg.h>
-#include <svm/ssvm.h>
-#include <svm/queue.h>
-
-extern vnet_device_class_t ssvm_eth_device_class;
-extern vlib_node_registration_t ssvm_eth_input_node;
-
-#define SSVM_BUFFER_SIZE \
- (VLIB_BUFFER_DATA_SIZE + VLIB_BUFFER_PRE_DATA_SIZE)
-#define SSVM_PACKET_TYPE 1
-
-typedef struct
-{
- /* Type of queue element */
- u8 type;
- u8 flags;
-#define SSVM_BUFFER_NEXT_PRESENT (1<<0)
- u8 owner;
- u8 tag;
- i16 current_data_hint;
- u16 length_this_buffer;
- u16 total_length_not_including_first_buffer;
- u16 pad;
- u32 next_index;
- /* offset 16 */
- u8 data[SSVM_BUFFER_SIZE];
- /* pad to an even multiple of 64 octets */
- u8 pad2[CLIB_CACHE_LINE_BYTES - 16];
-} ssvm_eth_queue_elt_t;
-
-typedef struct
-{
- /* vector of point-to-point connections */
- ssvm_private_t *intfcs;
-
- u32 *buffer_cache;
- u32 *chunk_cache;
-
- /* Configurable parameters */
- /* base address for next placement */
- u64 next_base_va;
- u64 segment_size;
- u64 nbuffers;
- u64 queue_elts;
-
- /* Segment names */
- u8 **names;
-
- /* convenience */
- vlib_main_t *vlib_main;
- vnet_main_t *vnet_main;
- elog_main_t *elog_main;
-} ssvm_eth_main_t;
-
-extern ssvm_eth_main_t ssvm_eth_main;
-
-typedef enum
-{
- CHUNK_POOL_FREELIST_INDEX = 0,
- CHUNK_POOL_INDEX,
- CHUNK_POOL_NFREE,
- TO_MASTER_Q_INDEX,
- TO_SLAVE_Q_INDEX,
- MASTER_ADMIN_STATE_INDEX,
- SLAVE_ADMIN_STATE_INDEX,
-} ssvm_eth_opaque_index_t;
-
-/*
- * debug scaffolding.
- */
-static inline void
-ssvm_eth_validate_freelists (int need_lock)
-{
-#if CLIB_DEBUG > 0
- ssvm_eth_main_t *em = &ssvm_eth_main;
- ssvm_private_t *intfc;
- ssvm_shared_header_t *sh;
- u32 *elt_indices;
- u32 n_available;
- int i;
-
- for (i = 0; i < vec_len (em->intfcs); i++)
- {
- intfc = em->intfcs + i;
- sh = intfc->sh;
- u32 my_pid = intfc->my_pid;
-
- if (need_lock)
- ssvm_lock (sh, my_pid, 15);
-
- elt_indices = (u32 *) (sh->opaque[CHUNK_POOL_FREELIST_INDEX]);
- n_available = (u32) (uword) (sh->opaque[CHUNK_POOL_NFREE]);
-
- for (i = 0; i < n_available; i++)
- ASSERT (elt_indices[i] < 2048);
-
- if (need_lock)
- ssvm_unlock (sh);
- }
-#endif
-}
-
-#endif /* __included_ssvm_eth_h__ */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vpp/api/api_format.c b/src/vpp/api/api_format.c
index 4c13e11226f..33c3920d11d 100644
--- a/src/vpp/api/api_format.c
+++ b/src/vpp/api/api_format.c
@@ -19,7 +19,6 @@
#include <vat/vat.h>
#include <vppinfra/socket.h>
-#include <svm/memfd.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vnet/ip/ip.h>
@@ -2203,7 +2202,7 @@ static void vl_api_memfd_segment_create_reply_t_handler
socket_client_main_t *scm = vam->socket_client_main;
int my_fd = -1;
clib_error_t *error;
- memfd_private_t memfd;
+ ssvm_private_t memfd;
i32 retval = ntohl (mp->retval);
if (retval == 0)
@@ -2221,7 +2220,7 @@ static void vl_api_memfd_segment_create_reply_t_handler
vam->client_index_invalid = 1;
/* Note: this closes memfd.fd */
- retval = memfd_slave_init (&memfd);
+ retval = ssvm_slave_init_memfd (&memfd);
if (retval)
clib_warning ("WARNING: segment map returned %d", retval);