From 83ea669b2193a112ff1e3440efb9df78085b4616 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Fri, 12 Oct 2018 16:55:14 -0700 Subject: session: don't wait indefinitely for apps to consume evts (VPP-1454) Change-Id: I544b24d2b2c4a09829773cf180d1747f4b087d4c Signed-off-by: Florin Coras --- src/vnet/session/session_api.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c index fc63428277e..e82be560b1f 100755 --- a/src/vnet/session/session_api.c +++ b/src/vnet/session/session_api.c @@ -421,6 +421,23 @@ static session_cb_vft_t session_cb_vft = { .del_segment_callback = send_del_segment_callback, }; +static int +mq_try_lock_and_alloc_msg (svm_msg_q_t * app_mq, svm_msg_q_msg_t * msg) +{ + int rv; + u8 try = 0; + while (try < 100) + { + rv = svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, + SESSION_MQ_CTRL_EVT_RING, + SVM_Q_NOWAIT, msg); + if (!rv) + return 0; + try++; + } + return -1; +} + static int mq_send_session_accepted_cb (stream_session_t * s) { @@ -436,8 +453,8 @@ mq_send_session_accepted_cb (stream_session_t * s) app = application_get (app_wrk->app_index); app_mq = app_wrk->event_queue; - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return -1; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); @@ -523,8 +540,8 @@ mq_send_session_disconnected_cb (stream_session_t * s) app = application_get (app_wrk->app_index); app_mq = app_wrk->event_queue; - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_DISCONNECTED; @@ -544,8 +561,8 @@ mq_send_session_reset_cb (stream_session_t * s) session_event_t *evt; app_mq = app->event_queue; - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_RESET; @@ -576,8 +593,8 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context, return -1; } - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return -1; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_CONNECTED; @@ -656,8 +673,9 @@ mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context, return -1; } - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return -1; + evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_BOUND; -- cgit 1.2.3-korg