summaryrefslogtreecommitdiffstats
path: root/src/vlibmemory
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
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')
-rw-r--r--src/vlibmemory/memory_api.c52
-rw-r--r--src/vlibmemory/memory_client.c14
-rw-r--r--src/vlibmemory/memory_shared.c15
3 files changed, 26 insertions, 55 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 */ );
}
diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c
index b5090636a7f..bd89526b696 100644
--- a/src/vlibmemory/memory_client.c
+++ b/src/vlibmemory/memory_client.c
@@ -160,7 +160,6 @@ void vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem);
int
vl_client_connect (const char *name, int ctx_quota, int input_queue_size)
{
- svm_region_t *svm;
vl_api_memclnt_create_t *mp;
vl_api_memclnt_create_reply_t *rp;
svm_queue_t *vl_input_queue;
@@ -181,7 +180,6 @@ vl_client_connect (const char *name, int ctx_quota, int input_queue_size)
return -1;
}
- svm = am->vlib_rp;
shmem_hdr = am->shmem_hdr;
if (shmem_hdr == 0 || shmem_hdr->vl_input_queue == 0)
@@ -193,12 +191,10 @@ vl_client_connect (const char *name, int ctx_quota, int input_queue_size)
CLIB_MEM_UNPOISON (shmem_hdr, sizeof (*shmem_hdr));
VL_MSG_API_SVM_QUEUE_UNPOISON (shmem_hdr->vl_input_queue);
- pthread_mutex_lock (&svm->mutex);
- oldheap = svm_push_data_heap (svm);
+ oldheap = vl_msg_push_heap ();
vl_input_queue = svm_queue_alloc_and_init (input_queue_size, sizeof (uword),
getpid ());
- svm_pop_heap (oldheap);
- pthread_mutex_unlock (&svm->mutex);
+ vl_msg_pop_heap (oldheap);
am->my_client_index = ~0;
am->my_registration = 0;
@@ -256,11 +252,9 @@ vl_api_memclnt_delete_reply_t_handler (vl_api_memclnt_delete_reply_t * mp)
void *oldheap;
api_main_t *am = vlibapi_get_main ();
- pthread_mutex_lock (&am->vlib_rp->mutex);
- oldheap = svm_push_data_heap (am->vlib_rp);
+ oldheap = vl_msg_push_heap ();
svm_queue_free (am->vl_input_queue);
- pthread_mutex_unlock (&am->vlib_rp->mutex);
- svm_pop_heap (oldheap);
+ vl_msg_pop_heap (oldheap);
am->my_client_index = ~0;
am->my_registration = 0;
diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c
index 0b232adf899..1716f271466 100644
--- a/src/vlibmemory/memory_shared.c
+++ b/src/vlibmemory/memory_shared.c
@@ -163,15 +163,13 @@ vl_msg_api_alloc_internal (svm_region_t * vlib_rp, int nbytes, int pool,
*/
am->ring_misses++;
- pthread_mutex_lock (&vlib_rp->mutex);
- oldheap = svm_push_data_heap (vlib_rp);
+ oldheap = vl_msg_push_heap_w_region (vlib_rp);
if (may_return_null)
{
rv = clib_mem_alloc_or_null (nbytes);
if (PREDICT_FALSE (rv == 0))
{
- svm_pop_heap (oldheap);
- pthread_mutex_unlock (&vlib_rp->mutex);
+ vl_msg_pop_heap_w_region (vlib_rp, oldheap);
return 0;
}
}
@@ -180,8 +178,7 @@ vl_msg_api_alloc_internal (svm_region_t * vlib_rp, int nbytes, int pool,
rv->q = 0;
rv->gc_mark_timestamp = 0;
- svm_pop_heap (oldheap);
- pthread_mutex_unlock (&vlib_rp->mutex);
+ vl_msg_pop_heap_w_region (vlib_rp, oldheap);
out:
#if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
@@ -296,8 +293,7 @@ vl_msg_api_free_w_region (svm_region_t * vlib_rp, void *a)
return;
}
- pthread_mutex_lock (&vlib_rp->mutex);
- oldheap = svm_push_data_heap (vlib_rp);
+ oldheap = vl_msg_push_heap_w_region (vlib_rp);
#if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
{
@@ -308,8 +304,7 @@ vl_msg_api_free_w_region (svm_region_t * vlib_rp, void *a)
#endif
clib_mem_free (rv);
- svm_pop_heap (oldheap);
- pthread_mutex_unlock (&vlib_rp->mutex);
+ vl_msg_pop_heap_w_region (vlib_rp, oldheap);
}
void