X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fvppcom.c;h=916ddf94f029ec278678b797d64c701a9fb7f8b9;hb=9ace36d0f9b04e2d4db410607ee33a8e72ef00c5;hp=4224a086a210f1a2dcf8e39915ccef04aae343c4;hpb=c4c4cf5066fbdceebd62a8819e3ecd0fc879f05d;p=vpp.git diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c index 4224a086a21..916ddf94f02 100644 --- a/src/vcl/vppcom.c +++ b/src/vcl/vppcom.c @@ -589,7 +589,7 @@ vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp) vec_validate (wrk->vpp_event_queues, 0); wrk->vpp_event_queues[0] = session->vpp_evt_q; - if (session->is_dgram) + if (vcl_session_is_cl (session)) { svm_fifo_t *rx_fifo, *tx_fifo; session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *); @@ -629,6 +629,36 @@ vcl_session_unlisten_reply_handler (vcl_worker_t * wrk, void *data) vcl_session_free (wrk, s); } +static void +vcl_session_migrated_handler (vcl_worker_t * wrk, void *data) +{ + session_migrated_msg_t *mp = (session_migrated_msg_t *) data; + vcl_session_t *s; + + s = vcl_session_get_w_vpp_handle (wrk, mp->handle); + if (!s) + { + VDBG (0, "Migrated notification with wrong handle %llx", mp->handle); + return; + } + + s->vpp_thread_index = mp->vpp_thread_index; + s->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *); + + vec_validate (wrk->vpp_event_queues, s->vpp_thread_index); + wrk->vpp_event_queues[s->vpp_thread_index] = s->vpp_evt_q; + + vcl_session_table_del_vpp_handle (wrk, mp->handle); + vcl_session_table_add_vpp_handle (wrk, mp->new_handle, s->session_index); + + /* Generate new tx event if we have outstanding data */ + if (svm_fifo_has_event (s->tx_fifo)) + app_send_io_evt_to_vpp (s->vpp_evt_q, s->tx_fifo->master_session_index, + SESSION_IO_EVT_TX, SVM_Q_WAIT); + + VDBG (0, "Migrated 0x%x to thread %u", mp->handle, s->vpp_thread_index); +} + static vcl_session_t * vcl_session_accepted (vcl_worker_t * wrk, session_accepted_msg_t * msg) { @@ -682,6 +712,24 @@ vcl_session_disconnected_handler (vcl_worker_t * wrk, return session; } +static void +vcl_session_cleanup_handler (vcl_worker_t * wrk, void *data) +{ + session_cleanup_msg_t *msg; + vcl_session_t *session; + + msg = (session_cleanup_msg_t *) data; + session = vcl_session_get_w_vpp_handle (wrk, msg->handle); + if (!session) + { + VDBG (0, "disconnect confirmed for unknown handle 0x%llx", msg->handle); + return; + } + + vcl_session_table_del_vpp_handle (wrk, msg->handle); + vcl_session_free (wrk, session); +} + static void vcl_session_req_worker_update_handler (vcl_worker_t * wrk, void *data) { @@ -812,6 +860,12 @@ vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e) case SESSION_CTRL_EVT_UNLISTEN_REPLY: vcl_session_unlisten_reply_handler (wrk, e->data); break; + case SESSION_CTRL_EVT_MIGRATED: + vcl_session_migrated_handler (wrk, e->data); + break; + case SESSION_CTRL_EVT_CLEANUP: + vcl_session_cleanup_handler (wrk, e->data); + break; case SESSION_CTRL_EVT_REQ_WORKER_UPDATE: vcl_session_req_worker_update_handler (wrk, e->data); break; @@ -1211,52 +1265,52 @@ vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session, next_sh = session->vep.next_sh; } + goto cleanup; } - else + + if (session->is_vep_session) { - if (session->is_vep_session) - { - rv = vppcom_epoll_ctl (vep_sh, EPOLL_CTL_DEL, sh, 0); - if (rv < 0) - VDBG (0, "session %u [0x%llx]: EPOLL_CTL_DEL vep_idx %u " - "failed! rv %d (%s)", session->session_index, vpp_handle, - vep_sh, rv, vppcom_retval_str (rv)); - } + rv = vppcom_epoll_ctl (vep_sh, EPOLL_CTL_DEL, sh, 0); + if (rv < 0) + VDBG (0, "session %u [0x%llx]: EPOLL_CTL_DEL vep_idx %u " + "failed! rv %d (%s)", session->session_index, vpp_handle, + vep_sh, rv, vppcom_retval_str (rv)); + } - if (!do_disconnect) - { - VDBG (1, "session %u [0x%llx] disconnect skipped", - session->session_index, vpp_handle); - goto cleanup; - } + if (!do_disconnect) + { + VDBG (1, "session %u [0x%llx] disconnect skipped", + session->session_index, vpp_handle); + goto cleanup; + } - if (state & STATE_LISTEN) - { - rv = vppcom_session_unbind (sh); - if (PREDICT_FALSE (rv < 0)) - VDBG (0, "session %u [0x%llx]: listener unbind failed! " - "rv %d (%s)", session->session_index, vpp_handle, rv, - vppcom_retval_str (rv)); - return rv; - } - else if ((state & STATE_OPEN) - || (vcl_session_is_connectable_listener (wrk, session))) - { - rv = vppcom_session_disconnect (sh); - if (PREDICT_FALSE (rv < 0)) - VDBG (0, "ERROR: session %u [0x%llx]: disconnect failed!" - " rv %d (%s)", session->session_index, vpp_handle, - rv, vppcom_retval_str (rv)); - } - else if (state == STATE_DISCONNECT) - { - svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, session); - vcl_send_session_reset_reply (mq, wrk->my_client_index, - session->vpp_handle, 0); - } + if (state & STATE_LISTEN) + { + rv = vppcom_session_unbind (sh); + if (PREDICT_FALSE (rv < 0)) + VDBG (0, "session %u [0x%llx]: listener unbind failed! " + "rv %d (%s)", session->session_index, vpp_handle, rv, + vppcom_retval_str (rv)); + return rv; + } + else if ((state & STATE_OPEN) + || (vcl_session_is_connectable_listener (wrk, session))) + { + rv = vppcom_session_disconnect (sh); + if (PREDICT_FALSE (rv < 0)) + VDBG (0, "ERROR: session %u [0x%llx]: disconnect failed!" + " rv %d (%s)", session->session_index, vpp_handle, + rv, vppcom_retval_str (rv)); + } + else if (state == STATE_DISCONNECT) + { + svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, session); + vcl_send_session_reset_reply (mq, wrk->my_client_index, + session->vpp_handle, 0); } - VDBG (0, "session %u [0x%llx] removed", session->session_index, vpp_handle); + /* Session is removed only after vpp confirms the disconnect */ + return rv; cleanup: vcl_session_table_del_vpp_handle (wrk, vpp_handle); @@ -2127,6 +2181,12 @@ vcl_select_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, case SESSION_CTRL_EVT_UNLISTEN_REPLY: vcl_session_unlisten_reply_handler (wrk, e->data); break; + case SESSION_CTRL_EVT_MIGRATED: + vcl_session_migrated_handler (wrk, e->data); + break; + case SESSION_CTRL_EVT_CLEANUP: + vcl_session_cleanup_handler (wrk, e->data); + break; case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY: vcl_session_worker_update_reply_handler (wrk, e->data); break; @@ -2518,6 +2578,23 @@ vppcom_epoll_ctl (uint32_t vep_handle, int op, uint32_t session_handle, svm_fifo_add_want_deq_ntf (session->tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL); + /* Generate EPOLLOUT if tx fifo not full */ + if ((event->events & EPOLLOUT) && + (vcl_session_write_ready (session) > 0)) + { + session_event_t e = { 0 }; + e.event_type = SESSION_IO_EVT_TX; + e.session_index = session->session_index; + vec_add1 (wrk->unhandled_evts_vector, e); + } + /* Generate EPOLLIN if rx fifo has data */ + if ((event->events & EPOLLIN) && (vcl_session_read_ready (session) > 0)) + { + session_event_t e = { 0 }; + e.event_type = SESSION_IO_EVT_RX; + e.session_index = session->session_index; + vec_add1 (wrk->unhandled_evts_vector, e); + } VDBG (1, "EPOLL_CTL_ADD: vep_sh %u, sh %u, events 0x%x, data 0x%llx!", vep_handle, session_handle, event->events, event->data.u64); vcl_evt (VCL_EVT_EPOLL_CTLADD, session, event->events, event->data.u64); @@ -2543,6 +2620,17 @@ vppcom_epoll_ctl (uint32_t vep_handle, int op, uint32_t session_handle, rv = VPPCOM_EINVAL; goto done; } + + /* Generate EPOLLOUT when tx_fifo/ct_tx_fifo not full */ + if ((event->events & EPOLLOUT) && + !(session->vep.ev.events & EPOLLOUT) && + (vcl_session_write_ready (session) > 0)) + { + session_event_t e = { 0 }; + e.event_type = SESSION_IO_EVT_TX; + e.session_index = session->session_index; + vec_add1 (wrk->unhandled_evts_vector, e); + } session->vep.et_mask = VEP_DEFAULT_ET_MASK; session->vep.ev = *event; VDBG (1, "EPOLL_CTL_MOD: vep_sh %u, sh %u, events 0x%x, data 0x%llx!", @@ -2691,8 +2779,6 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, if (!session) break; session_events = session->vep.ev.events; - if (!((EPOLLHUP | EPOLLRDHUP) & session_events)) - break; add_event = 1; events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; session_evt_data = session->vep.ev.data.u64; @@ -2702,8 +2788,6 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, if (!(session = vcl_session_get (wrk, sid))) break; session_events = session->vep.ev.events; - if (!((EPOLLHUP | EPOLLRDHUP) & session_events)) - break; add_event = 1; events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; session_evt_data = session->vep.ev.data.u64; @@ -2711,6 +2795,12 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, case SESSION_CTRL_EVT_UNLISTEN_REPLY: vcl_session_unlisten_reply_handler (wrk, e->data); break; + case SESSION_CTRL_EVT_MIGRATED: + vcl_session_migrated_handler (wrk, e->data); + break; + case SESSION_CTRL_EVT_CLEANUP: + vcl_session_cleanup_handler (wrk, e->data); + break; case SESSION_CTRL_EVT_REQ_WORKER_UPDATE: vcl_session_req_worker_update_handler (wrk, e->data); break;