diff options
author | Florin Coras <fcoras@cisco.com> | 2021-02-23 08:44:13 -0800 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2021-02-24 15:42:14 +0000 |
commit | 09bf91ad8d492763879303c9ff31dbcba5f9732b (patch) | |
tree | 57bd25ab42f053f21154f7532e3bb04612c13d42 /src/vnet | |
parent | 98874cda5853ea2d6b2dc32001b935d394b88430 (diff) |
session: init ctrl msg without mq lock
Type: improvement
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I755e6da1fcf6f3bf3c72d6d36c4243b0919b7209
Diffstat (limited to 'src/vnet')
-rw-r--r-- | src/vnet/session/session_api.c | 198 |
1 files changed, 96 insertions, 102 deletions
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c index e5021d4507c..8d82a7e4458 100644 --- a/src/vnet/session/session_api.c +++ b/src/vnet/session/session_api.c @@ -128,49 +128,41 @@ mq_send_session_accepted_cb (session_t * s) { app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); svm_msg_q_msg_t _msg, *msg = &_msg; + session_accepted_msg_t m = { 0 }; svm_msg_q_t *app_mq; fifo_segment_t *eq_seg; session_t *listener; - session_accepted_msg_t *mp; session_event_t *evt; application_t *app; app = application_get (app_wrk->app_index); - app_mq = app_wrk->event_queue; - if (mq_try_lock_and_alloc_msg (app_mq, msg)) - return SESSION_E_MQ_MSG_ALLOC; - evt = svm_msg_q_msg_data (app_mq, msg); - clib_memset (evt, 0, sizeof (*evt)); - evt->event_type = SESSION_CTRL_EVT_ACCEPTED; - mp = (session_accepted_msg_t *) evt->data; - clib_memset (mp, 0, sizeof (*mp)); - mp->context = app->app_index; - mp->server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); - mp->server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); - mp->segment_handle = session_segment_handle (s); - mp->flags = s->flags; + m.context = app->app_index; + m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); + m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); + m.segment_handle = session_segment_handle (s); + m.flags = s->flags; eq_seg = session_main_get_evt_q_segment (); if (session_has_transport (s)) { listener = listen_session_get_from_handle (s->listener_handle); - mp->listener_handle = app_listen_session_handle (listener); + m.listener_handle = app_listen_session_handle (listener); if (application_is_proxy (app)) { listener = app_worker_first_listener (app_wrk, session_get_fib_proto (s), session_get_transport_proto (s)); if (listener) - mp->listener_handle = listen_session_get_handle (listener); + m.listener_handle = listen_session_get_handle (listener); } - mp->vpp_event_queue_address = + m.vpp_event_queue_address = fifo_segment_msg_q_offset (eq_seg, s->thread_index); - mp->mq_index = s->thread_index; - mp->handle = session_handle (s); + m.mq_index = s->thread_index; + m.handle = session_handle (s); - session_get_endpoint (s, &mp->rmt, 0 /* is_lcl */ ); + session_get_endpoint (s, &m.rmt, 0 /* is_lcl */); } else { @@ -178,14 +170,23 @@ mq_send_session_accepted_cb (session_t * s) ct = (ct_connection_t *) session_get_transport (s); listener = listen_session_get_from_handle (s->listener_handle); - mp->listener_handle = app_listen_session_handle (listener); - mp->rmt.is_ip4 = session_type_is_ip4 (listener->session_type); - mp->rmt.port = ct->c_rmt_port; - mp->handle = session_handle (s); - mp->vpp_event_queue_address = + m.listener_handle = app_listen_session_handle (listener); + m.rmt.is_ip4 = session_type_is_ip4 (listener->session_type); + m.rmt.port = ct->c_rmt_port; + m.handle = session_handle (s); + m.vpp_event_queue_address = fifo_segment_msg_q_offset (eq_seg, s->thread_index); - mp->mq_index = s->thread_index; + m.mq_index = s->thread_index; } + + app_mq = app_wrk->event_queue; + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return SESSION_E_MQ_MSG_ALLOC; + + evt = svm_msg_q_msg_data (app_mq, msg); + clib_memset (evt, 0, sizeof (*evt)); + evt->event_type = SESSION_CTRL_EVT_ACCEPTED; + clib_memcpy_fast (evt->data, &m, sizeof (m)); svm_msg_q_add_and_unlock (app_mq, msg); return 0; @@ -264,34 +265,18 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context, session_t * s, session_error_t err) { svm_msg_q_msg_t _msg, *msg = &_msg; - session_connected_msg_t *mp; + session_connected_msg_t m = { 0 }; svm_msg_q_t *app_mq; transport_connection_t *tc; fifo_segment_t *eq_seg; app_worker_t *app_wrk; session_event_t *evt; - app_wrk = app_worker_get (app_wrk_index); - app_mq = app_wrk->event_queue; - if (!app_mq) - { - clib_warning ("app %u with api index: %u not attached", - app_wrk->app_index, app_wrk->api_client_index); - return -1; - } - - if (mq_try_lock_and_alloc_msg (app_mq, msg)) - return SESSION_E_MQ_MSG_ALLOC; - - evt = svm_msg_q_msg_data (app_mq, msg); - clib_memset (evt, 0, sizeof (*evt)); - evt->event_type = SESSION_CTRL_EVT_CONNECTED; - mp = (session_connected_msg_t *) evt->data; - clib_memset (mp, 0, sizeof (*mp)); - mp->context = api_context; + m.context = api_context; + m.retval = err; if (err) - goto done; + goto snd_msg; eq_seg = session_main_get_evt_q_segment (); @@ -301,19 +286,19 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context, if (!tc) { clib_warning ("failed to retrieve transport!"); - err = SESSION_E_REFUSED; - goto done; + m.retval = SESSION_E_REFUSED; + goto snd_msg; } - mp->handle = session_handle (s); - mp->vpp_event_queue_address = + m.handle = session_handle (s); + m.vpp_event_queue_address = fifo_segment_msg_q_offset (eq_seg, s->thread_index); - session_get_endpoint (s, &mp->lcl, 1 /* is_lcl */ ); + session_get_endpoint (s, &m.lcl, 1 /* is_lcl */); - mp->server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); - mp->server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); - mp->segment_handle = session_segment_handle (s); + m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); + m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); + m.segment_handle = session_segment_handle (s); } else { @@ -321,22 +306,32 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context, session_t *ss; cct = (ct_connection_t *) session_get_transport (s); - mp->handle = session_handle (s); - mp->lcl.port = cct->c_lcl_port; - mp->lcl.is_ip4 = cct->c_is_ip4; - mp->vpp_event_queue_address = + m.handle = session_handle (s); + m.lcl.port = cct->c_lcl_port; + m.lcl.is_ip4 = cct->c_is_ip4; + m.vpp_event_queue_address = fifo_segment_msg_q_offset (eq_seg, s->thread_index); - mp->server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); - mp->server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); - mp->segment_handle = session_segment_handle (s); + m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); + m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); + m.segment_handle = session_segment_handle (s); ss = ct_session_get_peer (s); - mp->ct_rx_fifo = fifo_segment_fifo_offset (ss->tx_fifo); - mp->ct_tx_fifo = fifo_segment_fifo_offset (ss->rx_fifo); - mp->ct_segment_handle = session_segment_handle (ss); + m.ct_rx_fifo = fifo_segment_fifo_offset (ss->tx_fifo); + m.ct_tx_fifo = fifo_segment_fifo_offset (ss->rx_fifo); + m.ct_segment_handle = session_segment_handle (ss); } -done: - mp->retval = err; +snd_msg: + + app_wrk = app_worker_get (app_wrk_index); + app_mq = app_wrk->event_queue; + + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return SESSION_E_MQ_MSG_ALLOC; + + evt = svm_msg_q_msg_data (app_mq, msg); + clib_memset (evt, 0, sizeof (*evt)); + evt->event_type = SESSION_CTRL_EVT_CONNECTED; + clib_memcpy_fast (evt->data, &m, sizeof (m)); svm_msg_q_add_and_unlock (app_mq, msg); return 0; @@ -347,59 +342,56 @@ mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context, session_handle_t handle, int rv) { svm_msg_q_msg_t _msg, *msg = &_msg; + session_bound_msg_t m = { 0 }; svm_msg_q_t *app_mq; transport_endpoint_t tep; - session_bound_msg_t *mp; fifo_segment_t *eq_seg; app_worker_t *app_wrk; session_event_t *evt; app_listener_t *al; session_t *ls = 0; - app_wrk = app_worker_get (app_wrk_index); - app_mq = app_wrk->event_queue; - if (!app_mq) - { - clib_warning ("app %u with api index: %u not attached", - app_wrk->app_index, app_wrk->api_client_index); - return -1; - } - - if (mq_try_lock_and_alloc_msg (app_mq, msg)) - return SESSION_E_MQ_MSG_ALLOC; - evt = svm_msg_q_msg_data (app_mq, msg); - clib_memset (evt, 0, sizeof (*evt)); - evt->event_type = SESSION_CTRL_EVT_BOUND; - mp = (session_bound_msg_t *) evt->data; - mp->context = api_context; + m.context = api_context; + m.retval = rv; if (rv) - goto done; + goto snd_msg; - mp->handle = handle; + m.handle = handle; al = app_listener_get_w_handle (handle); if (al->session_index != SESSION_INVALID_INDEX) ls = app_listener_get_session (al); else ls = app_listener_get_local_session (al); - session_get_endpoint (ls, &tep, 1 /* is_lcl */ ); - mp->lcl_port = tep.port; - mp->lcl_is_ip4 = tep.is_ip4; - clib_memcpy_fast (mp->lcl_ip, &tep.ip, sizeof (tep.ip)); + session_get_endpoint (ls, &tep, 1 /* is_lcl */); + m.lcl_port = tep.port; + m.lcl_is_ip4 = tep.is_ip4; + clib_memcpy_fast (m.lcl_ip, &tep.ip, sizeof (tep.ip)); eq_seg = session_main_get_evt_q_segment (); - mp->vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, ls->thread_index); + m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, ls->thread_index); if (session_transport_service_type (ls) == TRANSPORT_SERVICE_CL) { - mp->rx_fifo = fifo_segment_fifo_offset (ls->rx_fifo); - mp->tx_fifo = fifo_segment_fifo_offset (ls->tx_fifo); - mp->segment_handle = session_segment_handle (ls); + m.rx_fifo = fifo_segment_fifo_offset (ls->rx_fifo); + m.tx_fifo = fifo_segment_fifo_offset (ls->tx_fifo); + m.segment_handle = session_segment_handle (ls); } -done: - mp->retval = rv; +snd_msg: + + app_wrk = app_worker_get (app_wrk_index); + app_mq = app_wrk->event_queue; + + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return SESSION_E_MQ_MSG_ALLOC; + + evt = svm_msg_q_msg_data (app_mq, msg); + clib_memset (evt, 0, sizeof (*evt)); + evt->event_type = SESSION_CTRL_EVT_BOUND; + clib_memcpy_fast (evt->data, &m, sizeof (m)); + svm_msg_q_add_and_unlock (app_mq, msg); return 0; } @@ -431,7 +423,7 @@ static void mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh) { svm_msg_q_msg_t _msg, *msg = &_msg; - session_migrated_msg_t *mp; + session_migrated_msg_t m = { 0 }; fifo_segment_t *eq_seg; app_worker_t *app_wrk; session_event_t *evt; @@ -441,6 +433,12 @@ mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh) thread_index = session_thread_from_handle (new_sh); eq_seg = session_main_get_evt_q_segment (); + m.handle = session_handle (s); + m.new_handle = new_sh; + m.vpp_thread_index = thread_index; + m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, thread_index); + m.segment_handle = SESSION_INVALID_HANDLE; + app_wrk = app_worker_get (s->app_wrk_index); app_mq = app_wrk->event_queue; if (mq_try_lock_and_alloc_msg (app_mq, msg)) @@ -449,12 +447,8 @@ mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh) evt = svm_msg_q_msg_data (app_mq, msg); clib_memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_MIGRATED; - mp = (session_migrated_msg_t *) evt->data; - mp->handle = session_handle (s); - mp->new_handle = new_sh; - mp->vpp_thread_index = thread_index; - mp->vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, thread_index); - mp->segment_handle = SESSION_INVALID_HANDLE; + clib_memcpy_fast (evt->data, &m, sizeof (m)); + svm_msg_q_add_and_unlock (app_mq, msg); } |