aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2017-10-17 11:48:29 -0400
committerDamjan Marion <dmarion.lists@gmail.com>2017-10-18 11:47:29 +0000
commitcf5e848d69a4f14464c1e2d56896bc9f7e586951 (patch)
treecc74c2ba457b03a7dc75fabb1b1304e3e47342f0
parent965fec9089de96c2afbffc3dec3360d043e3eead (diff)
CSIT-844: fix binary api rx pthread heap push/pop
We need to push/pop the rx pthread's heap without affecting other thread(s). Search clib_per_cpu_mheaps, locate an unused slot. Duplicate the main thread heap pointer in that slot, and set __os_thread_index appropriately. Miscellaneous cleanups. Print exec_inband results as a vector, instead of as a format string. Don't bail out of vpp_api_test with results pending, e.g. at the end of a vpp_api_test script. Even though vpp will eventuallly garbage-collect them, We don't want to leave allocated reply messages lurking in the api message allocation rings... Change-Id: I0e8a25d1ff0d3700249dc330d079db16c2fcbc55 Signed-off-by: Dave Barach <dave@barachs.net>
-rw-r--r--src/vat/api_format.c2
-rw-r--r--src/vat/main.c13
-rw-r--r--src/vlibmemory/memory_client.c25
-rw-r--r--src/vlibmemory/memory_vlib.c8
4 files changed, 41 insertions, 7 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 24b6fb06a3a..d6af6984467 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -5884,7 +5884,7 @@ exec_inband (vat_main_t * vam)
W (ret);
/* json responses may or may not include a useful reply... */
if (vec_len (vam->cmd_reply))
- print (vam->ofp, (char *) (vam->cmd_reply));
+ print (vam->ofp, "%v", (char *) (vam->cmd_reply));
return ret;
}
diff --git a/src/vat/main.c b/src/vat/main.c
index e2c9b70889a..aa990a31d93 100644
--- a/src/vat/main.c
+++ b/src/vat/main.c
@@ -308,6 +308,7 @@ main (int argc, char **argv)
u8 *heap;
mheap_t *h;
int i;
+ f64 timeout;
clib_mem_init (0, 128 << 20);
@@ -432,6 +433,18 @@ main (int argc, char **argv)
fclose (vam->ifp);
}
+ /*
+ * Particularly when running a script, don't be in a hurry to leave.
+ * A reply message queued to this process will end up constipating
+ * the allocation rings.
+ */
+ timeout = vat_time_now (vam) + 2.0;
+ while (vam->result_ready == 0 && vat_time_now (vam) < timeout)
+ ;
+
+ if (vat_time_now (vam) > timeout)
+ clib_warning ("BUG: message reply spin-wait timeout");
+
vl_client_disconnect_from_vlib ();
exit (0);
}
diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c
index 3f8b799f41f..55913f59403 100644
--- a/src/vlibmemory/memory_client.c
+++ b/src/vlibmemory/memory_client.c
@@ -80,6 +80,7 @@ rx_thread_fn (void *arg)
unix_shared_memory_queue_t *q;
memory_client_main_t *mm = &memory_client_main;
api_main_t *am = &api_main;
+ int i;
q = am->vl_input_queue;
@@ -87,10 +88,27 @@ rx_thread_fn (void *arg)
if (setjmp (mm->rx_thread_jmpbuf) == 0)
{
mm->rx_thread_jmpbuf_valid = 1;
- while (1)
+ /*
+ * Find an unused slot in the per-cpu-mheaps array,
+ * and grab it for this thread. We need to be able to
+ * push/pop the thread heap without affecting other thread(s).
+ */
+ if (__os_thread_index == 0)
{
- vl_msg_api_queue_handler (q);
+ for (i = 0; i < ARRAY_LEN (clib_per_cpu_mheaps); i++)
+ {
+ if (clib_per_cpu_mheaps[i] == 0)
+ {
+ /* Copy the main thread mheap pointer */
+ clib_per_cpu_mheaps[i] = clib_per_cpu_mheaps[0];
+ __os_thread_index = i;
+ break;
+ }
+ }
+ ASSERT (__os_thread_index > 0);
}
+ while (1)
+ vl_msg_api_queue_handler (q);
}
pthread_exit (0);
}
@@ -138,7 +156,7 @@ vl_api_memclnt_create_reply_t_handler (vl_api_memclnt_create_reply_t * mp)
/* Recreate the vnet-side API message handler table */
tblv = uword_to_pointer (mp->message_table, u8 *);
- serialize_open_vector (sm, tblv);
+ unserialize_open_data (sm, tblv, vec_len (tblv));
unserialize_integer (sm, &nmsgs, sizeof (u32));
for (i = 0; i < nmsgs; i++)
@@ -311,6 +329,7 @@ vl_client_disconnect (void)
/* drain the queue */
if (ntohs (rp->_vl_msg_id) != VL_API_MEMCLNT_DELETE_REPLY)
{
+ clib_warning ("queue drain: %d", ntohs (rp->_vl_msg_id));
vl_msg_api_handler ((void *) rp);
continue;
}
diff --git a/src/vlibmemory/memory_vlib.c b/src/vlibmemory/memory_vlib.c
index 65d04dc266f..338fda45241 100644
--- a/src/vlibmemory/memory_vlib.c
+++ b/src/vlibmemory/memory_vlib.c
@@ -188,7 +188,6 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
int rv = 0;
void *oldheap;
api_main_t *am = &api_main;
- u8 *serialized_message_table_in_shmem;
/*
* This is tortured. Maintain a vlib-address-space private
@@ -237,7 +236,9 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
regp->name = format (0, "%s", mp->name);
vec_add1 (regp->name, 0);
- serialized_message_table_in_shmem = vl_api_serialize_message_table (am, 0);
+ if (am->serialized_message_table_in_shmem == 0)
+ am->serialized_message_table_in_shmem =
+ vl_api_serialize_message_table (am, 0);
pthread_mutex_unlock (&svm->mutex);
svm_pop_heap (oldheap);
@@ -250,7 +251,8 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
am->shmem_hdr->application_restarts);
rp->context = mp->context;
rp->response = ntohl (rv);
- rp->message_table = pointer_to_uword (serialized_message_table_in_shmem);
+ rp->message_table =
+ pointer_to_uword (am->serialized_message_table_in_shmem);
vl_msg_api_send_shmem (q, (u8 *) & rp);
}