summaryrefslogtreecommitdiffstats
path: root/src/plugins/hs_apps/sapi/vpp_echo.c
diff options
context:
space:
mode:
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>2019-09-27 17:03:15 +0200
committerFlorin Coras <florin.coras@gmail.com>2019-09-30 16:48:21 +0000
commit46b91ebb5c350ceeccec97d8e09524f708512342 (patch)
treef4e054255a07e70db66d86fe6a1dacfb31a84142 /src/plugins/hs_apps/sapi/vpp_echo.c
parent0fc509343e43adf97f1b474254f601b3e55ac36f (diff)
hsa: fix vpp_echo mq locking
Type: fix Change-Id: I18d2cde0baaed4134e8378c09aaa88693fb997f8 Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/plugins/hs_apps/sapi/vpp_echo.c')
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/src/plugins/hs_apps/sapi/vpp_echo.c b/src/plugins/hs_apps/sapi/vpp_echo.c
index 79b71d1611e..407ab3f3816 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo.c
@@ -399,7 +399,7 @@ echo_handle_data (echo_main_t * em, echo_session_t * s, u8 * rx_buf)
static void *
echo_data_thread_fn (void *arg)
{
- clib_mem_set_thread_index ();
+ clib_mem_set_thread_index (); /* First thing to do in client thread */
echo_main_t *em = &echo_main;
u32 N = em->n_clients;
u32 n = (N + em->n_rx_threads - 1) / em->n_rx_threads;
@@ -661,44 +661,83 @@ echo_process_rpcs (echo_main_t * em)
{
echo_rpc_msg_t *rpc;
svm_msg_q_msg_t msg;
+ svm_msg_q_t *mq = em->rpc_msq_queue;
+
while (em->state < STATE_DATA_DONE && !em->time_to_stop)
{
- if (svm_msg_q_sub (em->rpc_msq_queue, &msg, SVM_Q_TIMEDWAIT, 1))
- continue;
- rpc = svm_msg_q_msg_data (em->rpc_msq_queue, &msg);
+ svm_msg_q_lock (mq);
+ if (svm_msg_q_is_empty (mq) && svm_msg_q_timedwait (mq, 1))
+ {
+ svm_msg_q_unlock (mq);
+ continue;
+ }
+ svm_msg_q_sub_w_lock (mq, &msg);
+ rpc = svm_msg_q_msg_data (mq, &msg);
+ svm_msg_q_unlock (mq);
((echo_rpc_t) rpc->fp) (rpc->arg, rpc->opaque);
- svm_msg_q_free_msg (em->rpc_msq_queue, &msg);
+ svm_msg_q_free_msg (mq, &msg);
+ }
+}
+
+static inline int
+echo_mq_dequeue_batch (svm_msg_q_t * mq, svm_msg_q_msg_t * msg_vec,
+ u32 n_max_msg)
+{
+ svm_msg_q_msg_t *msg;
+ u32 n_msgs;
+ int i;
+
+ n_msgs = clib_min (svm_msg_q_size (mq), n_max_msg);
+ for (i = 0; i < n_msgs; i++)
+ {
+ vec_add2 (msg_vec, msg, 1);
+ svm_msg_q_sub_w_lock (mq, msg);
}
+ return n_msgs;
}
static void *
echo_mq_thread_fn (void *arg)
{
- clib_mem_set_thread_index ();
+ clib_mem_set_thread_index (); /* First thing to do in client thread */
+ svm_msg_q_msg_t *msg_vec = 0;
echo_main_t *em = &echo_main;
session_event_t *e;
- svm_msg_q_msg_t msg;
- int rv;
+ svm_msg_q_msg_t *msg;
+ svm_msg_q_t *mq;
+ int i;
+
+ vec_validate (msg_vec, em->evt_q_size);
+ vec_reset_length (msg_vec);
wait_for_state_change (em, STATE_ATTACHED, 0);
- if (em->state < STATE_ATTACHED || !em->our_event_queue)
+ mq = em->our_event_queue;
+ if (em->state < STATE_ATTACHED || !mq)
{
ECHO_FAIL (ECHO_FAIL_APP_ATTACH, "Application failed to attach");
pthread_exit (0);
}
- while (1)
+ while (em->state < STATE_DETACHED && !em->time_to_stop)
{
- if (!(rv = svm_msg_q_sub (em->our_event_queue,
- &msg, SVM_Q_TIMEDWAIT, 1)))
+ svm_msg_q_lock (mq);
+ if (svm_msg_q_is_empty (mq) && svm_msg_q_timedwait (mq, 1))
{
- e = svm_msg_q_msg_data (em->our_event_queue, &msg);
+ svm_msg_q_unlock (mq);
+ continue;
+ }
+ echo_mq_dequeue_batch (mq, msg_vec, ~0);
+ svm_msg_q_unlock (mq);
+
+ for (i = 0; i < vec_len (msg_vec); i++)
+ {
+ msg = vec_elt_at_index (msg_vec, i);
+ e = svm_msg_q_msg_data (mq, msg);
handle_mq_event (e);
- svm_msg_q_free_msg (em->our_event_queue, &msg);
+ svm_msg_q_free_msg (mq, msg); /* No lock, single thread dequeuing */
}
- if (rv == ETIMEDOUT
- && (em->time_to_stop || em->state == STATE_DETACHED))
- break;
+ vec_reset_length (msg_vec);
}
+ vec_free (msg_vec);
pthread_exit (0);
}
@@ -744,6 +783,7 @@ print_usage_and_exit (void)
" use-svm-api Use SVM API to connect to VPP\n"
" test-bytes[:assert] Check data correctness when receiving (assert fails on first error)\n"
" fifo-size N Use N Kb fifos\n"
+ " mq-size N Use N event slots for vpp_echo <-> vpp events\n"
" rx-buf N[Kb|Mb|GB] Use N[Kb|Mb|GB] RX buffer\n"
" tx-buf N[Kb|Mb|GB] Use N[Kb|Mb|GB] TX test buffer\n"
" appns NAMESPACE Use the namespace NAMESPACE\n"
@@ -845,6 +885,8 @@ echo_process_opts (int argc, char **argv)
;
else if (unformat (a, "tx-buf %U", unformat_data, &em->tx_buf_size))
;
+ else if (unformat (a, "mq-size %d", &em->evt_q_size))
+ ;
else if (unformat (a, "nclients %d", &em->n_clients))
{
em->n_sessions = em->n_clients + 1;
@@ -969,6 +1011,7 @@ main (int argc, char **argv)
em->time_to_stop = 0;
em->i_am_master = 1;
em->n_rx_threads = 4;
+ em->evt_q_size = 256;
em->test_return_packets = RETURN_PACKETS_NOTEST;
em->timing.start_event = ECHO_EVT_FIRST_QCONNECT;
em->timing.end_event = ECHO_EVT_LAST_BYTE;