summaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/memory_shared.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-01-05 03:20:25 -0800
committerDave Barach <openvpp@barachs.net>2018-01-09 18:33:08 +0000
commite86a8edd3c14fb41ace2a12efd17bc7772bf623f (patch)
tree480219864cadd743fdb95c21379aeaf88a985e23 /src/vlibmemory/memory_shared.c
parent4363ad6c96b5641fca1b16c5a6ec22e2364adcfd (diff)
api: refactor vlibmemory
- separate client/server code for both memory and socket apis - separate memory api code from generic vlib api code - move unix_shared_memory_fifo to svm and rename to svm_fifo_t - overall declutter Change-Id: I90cdd98ff74d0787d58825b914b0f1eafcfa4dc2 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vlibmemory/memory_shared.c')
-rw-r--r--src/vlibmemory/memory_shared.c109
1 files changed, 18 insertions, 91 deletions
diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c
index 0a3c23cbb3e..19285df9efe 100644
--- a/src/vlibmemory/memory_shared.c
+++ b/src/vlibmemory/memory_shared.c
@@ -25,22 +25,20 @@
#include <string.h>
#include <unistd.h>
#include <signal.h>
+
#include <vppinfra/format.h>
#include <vppinfra/byte_order.h>
#include <vppinfra/error.h>
+#include <svm/queue.h>
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
-#include <vlibmemory/api.h>
-#include <vlibmemory/unix_shared_memory_queue.h>
-
+#include <vlibmemory/memory_api.h>
#include <vlibmemory/vl_memory_msg_enum.h>
#define vl_typedefs
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_typedefs
-socket_main_t socket_main;
-
#define DEBUG_MESSAGE_BUFFER_OVERRUN 0
static inline void *
@@ -49,7 +47,7 @@ vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null)
int i;
msgbuf_t *rv;
ring_alloc_t *ap;
- unix_shared_memory_queue_t *q;
+ svm_queue_t *q;
void *oldheap;
vl_shmem_hdr_t *shmem_hdr;
api_main_t *am = &api_main;
@@ -376,13 +374,13 @@ vl_api_default_mem_config (vl_shmem_hdr_t * shmem_hdr)
vlib_input_queue_length = am->vlib_input_queue_length;
shmem_hdr->vl_input_queue =
- unix_shared_memory_queue_init (vlib_input_queue_length, sizeof (uword),
- getpid (), am->vlib_signal);
+ svm_queue_init (vlib_input_queue_length, sizeof (uword),
+ getpid (), am->vlib_signal);
#define _(sz,n) \
do { \
ring_alloc_t _rp; \
- _rp.rp = unix_shared_memory_queue_init ((n), (sz), 0, 0); \
+ _rp.rp = svm_queue_init ((n), (sz), 0, 0); \
_rp.size = (sz); \
_rp.nitems = n; \
_rp.hits = 0; \
@@ -396,7 +394,7 @@ vl_api_default_mem_config (vl_shmem_hdr_t * shmem_hdr)
#define _(sz,n) \
do { \
ring_alloc_t _rp; \
- _rp.rp = unix_shared_memory_queue_init ((n), (sz), 0, 0); \
+ _rp.rp = svm_queue_init ((n), (sz), 0, 0); \
_rp.size = (sz); \
_rp.nitems = n; \
_rp.hits = 0; \
@@ -427,10 +425,9 @@ vl_api_mem_config (vl_shmem_hdr_t * hdr, vl_api_shm_elem_config_t * config)
switch (c->type)
{
case VL_API_QUEUE:
- hdr->vl_input_queue = unix_shared_memory_queue_init (c->count,
- c->size,
- getpid (),
- am->vlib_signal);
+ hdr->vl_input_queue = svm_queue_init (c->count,
+ c->size,
+ getpid (), am->vlib_signal);
continue;
case VL_API_VLIB_RING:
vec_add2 (hdr->vl_rings, rp, 1);
@@ -444,7 +441,7 @@ vl_api_mem_config (vl_shmem_hdr_t * hdr, vl_api_shm_elem_config_t * config)
}
size = sizeof (ring_alloc_t) + c->size;
- rp->rp = unix_shared_memory_queue_init (c->count, size, 0, 0);
+ rp->rp = svm_queue_init (c->count, size, 0, 0);
rp->size = size;
rp->nitems = c->count;
rp->hits = 0;
@@ -493,7 +490,6 @@ vl_init_shmem (svm_region_t * vlib_rp, vl_api_shm_elem_config_t * config,
pthread_mutex_unlock (&vlib_rp->mutex);
}
-
int
vl_map_shmem (const char *region_name, int is_vlib)
{
@@ -548,7 +544,7 @@ vl_map_shmem (const char *region_name, int is_vlib)
am->our_pid = getpid ();
if (is_vlib)
{
- unix_shared_memory_queue_t *q;
+ svm_queue_t *q;
uword old_msg;
/*
* application restart. Reset cached pids, API message
@@ -581,9 +577,7 @@ vl_map_shmem (const char *region_name, int is_vlib)
mutex_ok:
am->vlib_rp = vlib_rp;
- while (unix_shared_memory_queue_sub (q,
- (u8 *) & old_msg,
- 1 /* nowait */ )
+ while (svm_queue_sub (q, (u8 *) & old_msg, 1 /* nowait */ )
!= -2 /* queue underflow */ )
{
vl_msg_api_free_nolock ((void *) old_msg);
@@ -676,7 +670,7 @@ vl_unmap_shmem (void)
}
void
-vl_msg_api_send_shmem (unix_shared_memory_queue_t * q, u8 * elem)
+vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem)
{
api_main_t *am = &api_main;
uword *trace = (uword *) elem;
@@ -684,11 +678,11 @@ vl_msg_api_send_shmem (unix_shared_memory_queue_t * q, u8 * elem)
if (am->tx_trace && am->tx_trace->enabled)
vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]);
- (void) unix_shared_memory_queue_add (q, elem, 0 /* nowait */ );
+ (void) svm_queue_add (q, elem, 0 /* nowait */ );
}
void
-vl_msg_api_send_shmem_nolock (unix_shared_memory_queue_t * q, u8 * elem)
+vl_msg_api_send_shmem_nolock (svm_queue_t * q, u8 * elem)
{
api_main_t *am = &api_main;
uword *trace = (uword *) elem;
@@ -696,74 +690,7 @@ vl_msg_api_send_shmem_nolock (unix_shared_memory_queue_t * q, u8 * elem)
if (am->tx_trace && am->tx_trace->enabled)
vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]);
- (void) unix_shared_memory_queue_add_nolock (q, elem);
-}
-
-u32
-vl_api_get_msg_index (u8 * name_and_crc)
-{
- api_main_t *am = &api_main;
- uword *p;
-
- if (am->msg_index_by_name_and_crc)
- {
- p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc);
- if (p)
- return p[0];
- }
- return ~0;
-}
-
-static inline vl_api_registration_t *
-vl_api_client_index_to_registration_internal (u32 handle)
-{
- vl_api_registration_t **regpp;
- vl_api_registration_t *regp;
- api_main_t *am = &api_main;
- u32 index;
-
- index = vl_msg_api_handle_get_index (handle);
- if ((am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK)
- != vl_msg_api_handle_get_epoch (handle))
- {
- vl_msg_api_increment_missing_client_counter ();
- return 0;
- }
-
- regpp = am->vl_clients + index;
-
- if (pool_is_free (am->vl_clients, regpp))
- {
- vl_msg_api_increment_missing_client_counter ();
- return 0;
- }
- regp = *regpp;
- return (regp);
-}
-
-vl_api_registration_t *
-vl_api_client_index_to_registration (u32 index)
-{
- if (PREDICT_FALSE (socket_main.current_rp != 0))
- return socket_main.current_rp;
-
- return (vl_api_client_index_to_registration_internal (index));
-}
-
-unix_shared_memory_queue_t *
-vl_api_client_index_to_input_queue (u32 index)
-{
- vl_api_registration_t *regp;
- api_main_t *am = &api_main;
-
- /* Special case: vlib trying to send itself a message */
- if (index == (u32) ~ 0)
- return (am->shmem_hdr->vl_input_queue);
-
- regp = vl_api_client_index_to_registration_internal (index);
- if (!regp)
- return 0;
- return (regp->vl_input_queue);
+ (void) svm_queue_add_nolock (q, elem);
}
/*