summaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/memory_api.c
diff options
context:
space:
mode:
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>2019-11-25 16:29:38 +0100
committerFlorin Coras <florin.coras@gmail.com>2019-12-11 16:54:26 +0000
commit0aa4013e20471a7b23bc3252649c95c81b5d7519 (patch)
tree33fa625cc95b9feb23e512fc54a31152132e440d /src/vlibmemory/memory_api.c
parentcfdb109180cb01c17f92a465f925c244259ba06b (diff)
api: Use vl_msg_push/pop_heap
Type: refactor Change-Id: I0eb46676fc22ce6825b2d879498df344b5a855e8 Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/vlibmemory/memory_api.c')
-rw-r--r--src/vlibmemory/memory_api.c52
1 files changed, 17 insertions, 35 deletions
diff --git a/src/vlibmemory/memory_api.c b/src/vlibmemory/memory_api.c
index 8c633e20223..b5f3fae232e 100644
--- a/src/vlibmemory/memory_api.c
+++ b/src/vlibmemory/memory_api.c
@@ -121,31 +121,27 @@ vl_api_memclnt_create_internal (char *name, svm_queue_t * q)
{
vl_api_registration_t **regpp;
vl_api_registration_t *regp;
- svm_region_t *svm;
void *oldheap;
api_main_t *am = vlibapi_get_main ();
ASSERT (vlib_get_thread_index () == 0);
pool_get (am->vl_clients, regpp);
- svm = am->vlib_rp;
- pthread_mutex_lock (&svm->mutex);
- oldheap = svm_push_data_heap (svm);
+ oldheap = vl_msg_push_heap ();
*regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
regp = *regpp;
clib_memset (regp, 0, sizeof (*regp));
regp->registration_type = REGISTRATION_TYPE_SHMEM;
regp->vl_api_registration_pool_index = regpp - am->vl_clients;
- regp->vlib_rp = svm;
+ regp->vlib_rp = am->vlib_rp;
regp->shmem_hdr = am->shmem_hdr;
regp->vl_input_queue = q;
regp->name = format (0, "%s%c", name, 0);
- pthread_mutex_unlock (&svm->mutex);
- svm_pop_heap (oldheap);
+ vl_msg_pop_heap (oldheap);
return vl_msg_api_handle_from_index_and_epoch
(regp->vl_api_registration_pool_index,
am->shmem_hdr->application_restarts);
@@ -160,7 +156,6 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
vl_api_registration_t **regpp;
vl_api_registration_t *regp;
vl_api_memclnt_create_reply_t *rp;
- svm_region_t *svm;
svm_queue_t *q;
int rv = 0;
void *oldheap;
@@ -195,17 +190,14 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
pool_get (am->vl_clients, regpp);
- svm = am->vlib_rp;
-
- pthread_mutex_lock (&svm->mutex);
- oldheap = svm_push_data_heap (svm);
+ oldheap = vl_msg_push_heap ();
*regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
regp = *regpp;
clib_memset (regp, 0, sizeof (*regp));
regp->registration_type = REGISTRATION_TYPE_SHMEM;
regp->vl_api_registration_pool_index = regpp - am->vl_clients;
- regp->vlib_rp = svm;
+ regp->vlib_rp = am->vlib_rp;
regp->shmem_hdr = am->shmem_hdr;
regp->clib_file_index = am->shmem_hdr->clib_file_index;
@@ -224,8 +216,7 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
else
msg_table = am->serialized_message_table_in_shmem;
- pthread_mutex_unlock (&svm->mutex);
- svm_pop_heap (oldheap);
+ vl_msg_pop_heap (oldheap);
rp = vl_msg_api_alloc (sizeof (*rp));
rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE_REPLY);
@@ -266,7 +257,6 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
vl_api_registration_t **regpp;
vl_api_registration_t *regp;
vl_api_memclnt_delete_reply_t *rp;
- svm_region_t *svm;
void *oldheap;
api_main_t *am = vlibapi_get_main ();
u32 handle, client_index, epoch;
@@ -294,7 +284,6 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
{
int i;
regp = *regpp;
- svm = am->vlib_rp;
int private_registration = 0;
/* Send reply unless client asked us to do the cleanup */
@@ -327,11 +316,11 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
for (i = 0; i < vec_len (am->vlib_private_rps); i++)
{
/* Is this a pairwise / private API segment? */
- if (am->vlib_private_rps[i] == svm)
+ if (am->vlib_private_rps[i] == am->vlib_rp)
{
/* Note: account for the memfd header page */
- uword virtual_base = svm->virtual_base - MMAP_PAGESIZE;
- uword virtual_size = svm->virtual_size + MMAP_PAGESIZE;
+ uword virtual_base = am->vlib_rp->virtual_base - MMAP_PAGESIZE;
+ uword virtual_size = am->vlib_rp->virtual_size + MMAP_PAGESIZE;
/*
* Kill the registration pool element before we make
@@ -355,16 +344,14 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
{
pool_put_index (am->vl_clients,
regp->vl_api_registration_pool_index);
- pthread_mutex_lock (&svm->mutex);
- oldheap = svm_push_data_heap (svm);
+ oldheap = vl_msg_push_heap ();
if (mp->do_cleanup)
svm_queue_free (regp->vl_input_queue);
vec_free (regp->name);
/* Poison the old registration */
clib_memset (regp, 0xF1, sizeof (*regp));
clib_mem_free (regp);
- pthread_mutex_unlock (&svm->mutex);
- svm_pop_heap (oldheap);
+ vl_msg_pop_heap (oldheap);
/*
* These messages must be freed manually, since they're set up
* as "bounce" messages. In the private_registration == 1 case,
@@ -617,7 +604,6 @@ vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
if (PREDICT_FALSE (vec_len (dead_indices) > 0))
{
int i;
- svm_region_t *svm;
void *oldheap;
/* Allow the application to clean up its registrations */
@@ -634,9 +620,7 @@ vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
}
}
- svm = am->vlib_rp;
- pthread_mutex_lock (&svm->mutex);
- oldheap = svm_push_data_heap (svm);
+ oldheap = vl_msg_push_heap ();
for (i = 0; i < vec_len (dead_indices); i++)
{
@@ -644,7 +628,7 @@ vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
if (regpp)
{
/* Is this a pairwise SVM segment? */
- if ((*regpp)->vlib_rp != svm)
+ if ((*regpp)->vlib_rp != am->vlib_rp)
{
int i;
svm_region_t *dead_rp = (*regpp)->vlib_rp;
@@ -661,7 +645,7 @@ vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
}
svm_pop_heap (oldheap);
clib_warning ("private rp %llx AWOL", dead_rp);
- oldheap = svm_push_data_heap (svm);
+ oldheap = svm_push_data_heap (am->vlib_rp);
found:
/* Kill it, accounting for the memfd header page */
@@ -670,7 +654,7 @@ vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
clib_unix_warning ("munmap");
/* Reset the queue-length-address cache */
vec_reset_length (vl_api_queue_cursizes);
- oldheap = svm_push_data_heap (svm);
+ oldheap = svm_push_data_heap (am->vlib_rp);
}
else
{
@@ -686,14 +670,13 @@ vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
svm_pop_heap (oldheap);
clib_warning ("Duplicate free, client index %d",
regpp - am->vl_clients);
- oldheap = svm_push_data_heap (svm);
+ oldheap = svm_push_data_heap (am->vlib_rp);
}
}
svm_client_scan_this_region_nolock (am->vlib_rp);
- pthread_mutex_unlock (&svm->mutex);
- svm_pop_heap (oldheap);
+ vl_msg_pop_heap (oldheap);
for (i = 0; i < vec_len (dead_indices); i++)
pool_put_index (am->vl_clients, dead_indices[i]);
}
@@ -776,7 +759,6 @@ vl_mem_api_handle_msg_private (vlib_main_t * vm, vlib_node_runtime_t * node,
u32 reg_index)
{
api_main_t *am = vlibapi_get_main ();
-
return void_mem_api_handle_msg_i (am, am->vlib_private_rps[reg_index], vm,
node, 1 /* is_private */ );
}