}
const char *
-vppcom_session_state_str (session_state_t state)
+vppcom_session_state_str (vcl_session_state_t state)
{
char *st;
st = "STATE_FAILED";
break;
+ case STATE_UPDATED:
+ st = "STATE_UPDATED";
+ break;
+
+ case STATE_LISTEN_NO_MQ:
+ st = "STATE_LISTEN_NO_MQ";
+ break;
+
default:
st = "UNKNOWN_STATE";
break;
mp->listener_handle);
if (!listen_session)
{
- svm_msg_q_t *evt_q;
evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *);
clib_warning ("VCL<%d>: ERROR: couldn't find listen session: "
"unknown vpp listener handle %llx",
rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
- if (mp->server_event_queue_address)
- {
- session->vpp_evt_q = uword_to_pointer (mp->client_event_queue_address,
- svm_msg_q_t *);
- session->our_evt_q = uword_to_pointer (mp->server_event_queue_address,
- svm_msg_q_t *);
- if (vcl_wait_for_segment (mp->segment_handle))
- {
- clib_warning ("segment for session %u couldn't be mounted!",
- session->session_index);
- return VCL_INVALID_SESSION_INDEX;
- }
- rx_fifo->master_session_index = session->session_index;
- tx_fifo->master_session_index = session->session_index;
- rx_fifo->master_thread_index = vcl_get_worker_index ();
- tx_fifo->master_thread_index = vcl_get_worker_index ();
- vec_validate (wrk->vpp_event_queues, 0);
- evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *);
- wrk->vpp_event_queues[0] = evt_q;
- }
- else
+ if (vcl_wait_for_segment (mp->segment_handle))
{
- session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
- svm_msg_q_t *);
- rx_fifo->client_session_index = session->session_index;
- tx_fifo->client_session_index = session->session_index;
- rx_fifo->client_thread_index = vcl_get_worker_index ();
- tx_fifo->client_thread_index = vcl_get_worker_index ();
- vpp_wrk_index = tx_fifo->master_thread_index;
- vec_validate (wrk->vpp_event_queues, vpp_wrk_index);
- wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q;
+ clib_warning ("segment for session %u couldn't be mounted!",
+ session->session_index);
+ return VCL_INVALID_SESSION_INDEX;
}
+ session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
+ svm_msg_q_t *);
+ rx_fifo->client_session_index = session->session_index;
+ tx_fifo->client_session_index = session->session_index;
+ rx_fifo->client_thread_index = vcl_get_worker_index ();
+ tx_fifo->client_thread_index = vcl_get_worker_index ();
+ vpp_wrk_index = tx_fifo->master_thread_index;
+ vec_validate (wrk->vpp_event_queues, vpp_wrk_index);
+ wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q;
+
session->vpp_handle = mp->handle;
session->vpp_thread_index = rx_fifo->master_thread_index;
session->client_context = mp->context;
u32 session_index, vpp_wrk_index;
svm_fifo_t *rx_fifo, *tx_fifo;
vcl_session_t *session = 0;
- svm_msg_q_t *evt_q;
session_index = mp->context;
session = vcl_session_get (wrk, session_index);
tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
if (vcl_wait_for_segment (mp->segment_handle))
{
- clib_warning ("segment for session %u couldn't be mounted!",
- session->session_index);
+ VDBG (0, "segment for session %u couldn't be mounted!",
+ session->session_index);
return VCL_INVALID_SESSION_INDEX;
}
rx_fifo->client_thread_index = vcl_get_worker_index ();
tx_fifo->client_thread_index = vcl_get_worker_index ();
- if (mp->client_event_queue_address)
- {
- session->vpp_evt_q = uword_to_pointer (mp->server_event_queue_address,
- svm_msg_q_t *);
- session->our_evt_q = uword_to_pointer (mp->client_event_queue_address,
- svm_msg_q_t *);
+ session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
+ svm_msg_q_t *);
+ vpp_wrk_index = tx_fifo->master_thread_index;
+ vec_validate (wrk->vpp_event_queues, vpp_wrk_index);
+ wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q;
- vec_validate (wrk->vpp_event_queues, 0);
- evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *);
- wrk->vpp_event_queues[0] = evt_q;
- }
- else
+ if (mp->ct_rx_fifo)
{
- session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
- svm_msg_q_t *);
- vpp_wrk_index = tx_fifo->master_thread_index;
- vec_validate (wrk->vpp_event_queues, vpp_wrk_index);
- wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q;
+ session->ct_rx_fifo = uword_to_pointer (mp->ct_rx_fifo, svm_fifo_t *);
+ session->ct_tx_fifo = uword_to_pointer (mp->ct_tx_fifo, svm_fifo_t *);
+ if (vcl_wait_for_segment (mp->ct_segment_handle))
+ {
+ VDBG (0, "ct segment for session %u couldn't be mounted!",
+ session->session_index);
+ return VCL_INVALID_SESSION_INDEX;
+ }
}
session->rx_fifo = rx_fifo;
return sid;
}
+static void
+vcl_session_unlisten_reply_handler (vcl_worker_t * wrk, void *data)
+{
+ session_unlisten_reply_msg_t *mp = (session_unlisten_reply_msg_t *) data;
+ vcl_session_t *s;
+
+ s = vcl_session_get_w_vpp_handle (wrk, mp->handle);
+ if (!s || s->session_state != STATE_DISCONNECT)
+ {
+ VDBG (0, "Unlisten reply with wrong handle %llx", mp->handle);
+ return;
+ }
+
+ if (mp->retval)
+ VDBG (0, "ERROR: session %u [0xllx]: unlisten failed: %U",
+ s->session_index, mp->handle, format_api_error, ntohl (mp->retval));
+
+ if (mp->context != wrk->wrk_index)
+ VDBG (0, "wrong context");
+
+ vcl_session_table_del_vpp_handle (wrk, mp->handle);
+ vcl_session_free (wrk, s);
+}
+
static vcl_session_t *
vcl_session_accepted (vcl_worker_t * wrk, session_accepted_msg_t * msg)
{
switch (e->event_type)
{
- case FIFO_EVENT_APP_RX:
- case FIFO_EVENT_APP_TX:
- case SESSION_IO_EVT_CT_RX:
- case SESSION_IO_EVT_CT_TX:
+ case SESSION_IO_EVT_RX:
+ case SESSION_IO_EVT_TX:
+ session = vcl_session_get (wrk, e->fifo->client_session_index);
+ if (!session || !(session->session_state & STATE_OPEN))
+ break;
vec_add1 (wrk->unhandled_evts_vector, *e);
break;
case SESSION_CTRL_EVT_ACCEPTED:
session = vcl_session_disconnected_handler (wrk, disconnected_msg);
if (!session)
break;
- session->session_state = STATE_DISCONNECT;
VDBG (0, "disconnected session %u [0x%llx]", session->session_index,
session->vpp_handle);
break;
case SESSION_CTRL_EVT_BOUND:
vcl_session_bound_handler (wrk, (session_bound_msg_t *) e->data);
break;
+ case SESSION_CTRL_EVT_UNLISTEN_REPLY:
+ vcl_session_unlisten_reply_handler (wrk, e->data);
+ break;
case SESSION_CTRL_EVT_REQ_WORKER_UPDATE:
vcl_session_req_worker_update_handler (wrk, e->data);
break;
static int
vppcom_wait_for_session_state_change (u32 session_index,
- session_state_t state,
+ vcl_session_state_t state,
f64 wait_for_time)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
static void
vcl_handle_pending_wrk_updates (vcl_worker_t * wrk)
{
- session_state_t state;
+ vcl_session_state_t state;
vcl_session_t *s;
u32 *sip;
return VPPCOM_EBADFD;
vpp_handle = session->vpp_handle;
- vcl_session_table_del_listener (wrk, vpp_handle);
session->vpp_handle = ~0;
session->session_state = STATE_DISCONNECT;
- VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending unbind msg! new state"
- " 0x%x (%s)", getpid (), vpp_handle, session_handle, STATE_DISCONNECT,
+ VDBG (1, "vpp handle 0x%llx, sid %u: sending unbind msg! new state"
+ " 0x%x (%s)", vpp_handle, session_handle, STATE_DISCONNECT,
vppcom_session_state_str (STATE_DISCONNECT));
vcl_evt (VCL_EVT_UNBIND, session);
- vppcom_send_unbind_sock (vpp_handle);
+ vppcom_send_unbind_sock (wrk, vpp_handle);
return VPPCOM_OK;
}
vcl_worker_t *wrk = vcl_worker_get_current ();
svm_msg_q_t *vpp_evt_q;
vcl_session_t *session;
- session_state_t state;
+ vcl_session_state_t state;
u64 vpp_handle;
session = vcl_session_get_w_handle (wrk, session_handle);
vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session,
vcl_session_handle_t sh, u8 do_disconnect)
{
- session_state_t state;
+ vcl_session_state_t state;
u32 next_sh, vep_sh;
int rv = VPPCOM_OK;
u64 vpp_handle;
if (!do_disconnect)
{
- VDBG (0, "session %u [0x%llx] disconnect skipped",
+ VDBG (1, "session %u [0x%llx] disconnect skipped",
session->session_index, vpp_handle);
goto cleanup;
}
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)
{
}
}
- if (vcl_session_is_ct (session))
- {
- vcl_cut_through_registration_t *ctr;
- uword mq_addr;
-
- mq_addr = pointer_to_uword (session->our_evt_q);
- ctr = vcl_ct_registration_lock_and_lookup (wrk, mq_addr);
- ASSERT (ctr);
- if (ctr->epoll_evt_conn_index != ~0)
- vcl_mq_epoll_del_evfd (wrk, ctr->epoll_evt_conn_index);
- VDBG (0, "Removing ct registration %u",
- vcl_ct_registration_index (wrk, ctr));
- vcl_ct_registration_del (wrk, ctr);
- vcl_ct_registration_lookup_del (wrk, mq_addr);
- vcl_ct_registration_unlock (wrk);
- }
+ VDBG (0, "session %u [0x%llx] removed", session->session_index, vpp_handle);
cleanup:
vcl_session_table_del_vpp_handle (wrk, vpp_handle);
vcl_session_free (wrk, session);
-
- VDBG (0, "session %u [0x%llx] removed", session->session_index, vpp_handle);
vcl_evt (VCL_EVT_CLOSE, session, rv);
return rv;
session_accepted_msg_t accepted_msg;
vcl_session_t *listen_session = 0;
vcl_session_t *client_session = 0;
- svm_msg_q_t *vpp_evt_q;
vcl_session_msg_t *evt;
u64 listen_vpp_handle;
svm_msg_q_msg_t msg;
sizeof (ip6_address_t));
}
- if (accepted_msg.server_event_queue_address)
- vpp_evt_q = uword_to_pointer (accepted_msg.vpp_event_queue_address,
- svm_msg_q_t *);
- else
- vpp_evt_q = client_session->vpp_evt_q;
-
- vcl_send_session_accepted_reply (vpp_evt_q, client_session->client_context,
+ vcl_send_session_accepted_reply (client_session->vpp_evt_q,
+ client_session->client_context,
client_session->vpp_handle, 0);
VDBG (0, "listener %u [0x%llx] accepted %u [0x%llx] peer: %U:%u "
static u8
vcl_is_rx_evt_for_session (session_event_t * e, u32 sid, u8 is_ct)
{
- if (!is_ct)
- return (e->event_type == FIFO_EVENT_APP_RX
- && e->fifo->client_session_index == sid);
- else
- return (e->event_type == SESSION_IO_EVT_CT_TX);
-}
-
-static inline u8
-vcl_session_is_readable (vcl_session_t * s)
-{
- return ((s->session_state & STATE_OPEN)
- || (s->session_state == STATE_LISTEN
- && s->session_type == VPPCOM_PROTO_UDP));
+ return (e->event_type == SESSION_IO_EVT_RX
+ && e->fifo->client_session_index == sid);
}
static inline int
u8 peek)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
- int n_read = 0, rv, is_nonblocking;
+ int n_read = 0, is_nonblocking;
vcl_session_t *s = 0;
svm_fifo_t *rx_fifo;
svm_msg_q_msg_t msg;
if (PREDICT_FALSE (!s || s->is_vep))
return VPPCOM_EBADFD;
- if (PREDICT_FALSE (!vcl_session_is_readable (s)))
+ if (PREDICT_FALSE (!vcl_session_is_open (s)))
{
- session_state_t state = s->session_state;
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
-
- VDBG (0, "session handle %u[0x%llx] is not open! state 0x%x (%s),"
- " returning %d (%s)", session_handle, s->vpp_handle, state,
- vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
- return rv;
+ VDBG (0, "session handle %u[0x%llx] is not open! state 0x%x (%s)",
+ s->session_index, s->vpp_handle, s->session_state,
+ vppcom_session_state_str (s->session_state));
+ return vcl_session_closed_error (s);
}
is_nonblocking = VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK);
is_ct = vcl_session_is_ct (s);
- mq = is_ct ? s->our_evt_q : wrk->app_event_queue;
- rx_fifo = s->rx_fifo;
+ mq = wrk->app_event_queue;
+ rx_fifo = is_ct ? s->ct_rx_fifo : s->rx_fifo;
s->has_rx_evt = 0;
+ if (is_ct)
+ svm_fifo_unset_event (s->rx_fifo);
+
if (svm_fifo_is_empty (rx_fifo))
{
+ svm_fifo_unset_event (rx_fifo);
if (is_nonblocking)
- {
- svm_fifo_unset_event (rx_fifo);
- return VPPCOM_EWOULDBLOCK;
- }
+ return VPPCOM_EWOULDBLOCK;
while (svm_fifo_is_empty (rx_fifo))
{
+ if (vcl_session_is_closing (s))
+ return vcl_session_closing_error (s);
+
svm_fifo_unset_event (rx_fifo);
svm_msg_q_lock (mq);
if (svm_msg_q_is_empty (mq))
e = svm_msg_q_msg_data (mq, &msg);
svm_msg_q_unlock (mq);
if (!vcl_is_rx_evt_for_session (e, s->session_index, is_ct))
- vcl_handle_mq_event (wrk, e);
+ {
+ clib_warning ("THIS ONE type %u", e->event_type);
+ vcl_handle_mq_event (wrk, e);
+ }
svm_msg_q_free_msg (mq, &msg);
-
- if (PREDICT_FALSE (s->session_state == STATE_DISCONNECT))
- return VPPCOM_ECONNRESET;
}
}
if (svm_fifo_is_empty (rx_fifo))
svm_fifo_unset_event (rx_fifo);
- if (is_ct && svm_fifo_needs_tx_ntf (rx_fifo, n_read))
- {
- svm_fifo_clear_tx_ntf (s->rx_fifo);
- app_send_io_evt_to_vpp (s->vpp_evt_q, s->rx_fifo, SESSION_IO_EVT_CT_RX,
- SVM_Q_WAIT);
- }
-
VDBG (2, "vpp handle 0x%llx, sid %u: read %d bytes from (%p)",
s->vpp_handle, session_handle, n_read, rx_fifo);
vppcom_data_segments_t ds)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
- int n_read = 0, rv, is_nonblocking;
+ int n_read = 0, is_nonblocking;
vcl_session_t *s = 0;
svm_fifo_t *rx_fifo;
svm_msg_q_msg_t msg;
if (PREDICT_FALSE (!s || s->is_vep))
return VPPCOM_EBADFD;
- if (PREDICT_FALSE (!vcl_session_is_readable (s)))
- {
- session_state_t state = s->session_state;
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
- return rv;
- }
+ if (PREDICT_FALSE (!vcl_session_is_open (s)))
+ return vcl_session_closed_error (s);
is_nonblocking = VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK);
is_ct = vcl_session_is_ct (s);
rx_fifo = s->rx_fifo;
s->has_rx_evt = 0;
+ if (is_ct)
+ svm_fifo_unset_event (s->rx_fifo);
+
if (svm_fifo_is_empty (rx_fifo))
{
if (is_nonblocking)
}
while (svm_fifo_is_empty (rx_fifo))
{
+ if (vcl_session_is_closing (s))
+ return vcl_session_closing_error (s);
+
svm_fifo_unset_event (rx_fifo);
svm_msg_q_lock (mq);
if (svm_msg_q_is_empty (mq))
if (!vcl_is_rx_evt_for_session (e, s->session_index, is_ct))
vcl_handle_mq_event (wrk, e);
svm_msg_q_free_msg (mq, &msg);
-
- if (PREDICT_FALSE (s->session_state == STATE_DISCONNECT))
- return VPPCOM_ECONNRESET;
}
}
n_read = svm_fifo_segments (rx_fifo, (svm_fifo_segment_t *) ds);
svm_fifo_unset_event (rx_fifo);
- if (is_ct && n_read + svm_fifo_max_dequeue (rx_fifo) == rx_fifo->nitems)
- {
- /* If the peer is not polling send notification */
- if (!svm_fifo_has_event (s->rx_fifo))
- app_send_io_evt_to_vpp (s->vpp_evt_q, s->rx_fifo,
- SESSION_IO_EVT_CT_RX, SVM_Q_WAIT);
- }
-
return n_read;
}
svm_fifo_segments_free (s->rx_fifo, (svm_fifo_segment_t *) ds);
}
-static inline int
-vppcom_session_read_ready (vcl_session_t * session)
-{
- /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
- if (PREDICT_FALSE (session->is_vep))
- {
- clib_warning ("VCL<%d>: ERROR: sid %u: cannot read from an "
- "epoll session!", getpid (), session->session_index);
- return VPPCOM_EBADFD;
- }
-
- if (PREDICT_FALSE (!(session->session_state & (STATE_OPEN | STATE_LISTEN))))
- {
- session_state_t state = session->session_state;
- int rv;
-
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
-
- VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session is not open!"
- " state 0x%x (%s), returning %d (%s)", getpid (),
- session->vpp_handle, session->session_index, state,
- vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
- return rv;
- }
-
- if (session->session_state & STATE_LISTEN)
- return clib_fifo_elts (session->accept_evts_fifo);
-
- return svm_fifo_max_dequeue (session->rx_fifo);
-}
-
int
vppcom_data_segment_copy (void *buf, vppcom_data_segments_t ds, u32 max_bytes)
{
static u8
vcl_is_tx_evt_for_session (session_event_t * e, u32 sid, u8 is_ct)
{
- if (!is_ct)
- return (e->event_type == FIFO_EVENT_APP_TX
- && e->fifo->client_session_index == sid);
- else
- return (e->event_type == SESSION_IO_EVT_CT_RX);
+ return (e->event_type == SESSION_IO_EVT_TX
+ && e->fifo->client_session_index == sid);
}
static inline int
u8 is_flush)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
- int rv, n_write, is_nonblocking;
+ int n_write, is_nonblocking;
vcl_session_t *s = 0;
svm_fifo_t *tx_fifo = 0;
session_evt_type_t et;
if (PREDICT_FALSE (s->is_vep))
{
- clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
- "cannot write to an epoll session!",
- getpid (), s->vpp_handle, session_handle);
-
+ VDBG (0, "ERROR: session %u [0x%llx]: cannot write to an epoll"
+ " session!", s->session_index, s->vpp_handle);
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (!(s->session_state & STATE_OPEN)))
+ if (PREDICT_FALSE (!vcl_session_is_open (s)))
{
- session_state_t state = s->session_state;
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
- VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session is not open! "
- "state 0x%x (%s)", getpid (), s->vpp_handle, session_handle,
- state, vppcom_session_state_str (state));
- return rv;
+ VDBG (1, "session %u [0x%llx]: is not open! state 0x%x (%s)",
+ s->session_index, s->vpp_handle, s->session_state,
+ vppcom_session_state_str (s->session_state));
+ return vcl_session_closed_error (s);;
}
- tx_fifo = s->tx_fifo;
is_ct = vcl_session_is_ct (s);
+ tx_fifo = is_ct ? s->ct_tx_fifo : s->tx_fifo;
is_nonblocking = VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK);
- mq = is_ct ? s->our_evt_q : wrk->app_event_queue;
+ mq = wrk->app_event_queue;
if (svm_fifo_is_full (tx_fifo))
{
if (is_nonblocking)
while (svm_fifo_is_full (tx_fifo))
{
svm_fifo_add_want_tx_ntf (tx_fifo, SVM_FIFO_WANT_TX_NOTIF);
+ if (vcl_session_is_closing (s))
+ return vcl_session_closing_error (s);
svm_msg_q_lock (mq);
if (svm_msg_q_is_empty (mq))
svm_msg_q_wait (mq);
if (!vcl_is_tx_evt_for_session (e, s->session_index, is_ct))
vcl_handle_mq_event (wrk, e);
svm_msg_q_free_msg (mq, &msg);
-
- if (PREDICT_FALSE (!(s->session_state & STATE_OPEN)))
- return VPPCOM_ECONNRESET;
}
}
- ASSERT (FIFO_EVENT_APP_TX + 1 == SESSION_IO_EVT_CT_TX);
- et = FIFO_EVENT_APP_TX + vcl_session_is_ct (s);
- if (is_flush && !vcl_session_is_ct (s))
+ et = SESSION_IO_EVT_TX;
+ if (is_flush && !is_ct)
et = SESSION_IO_EVT_TX_FLUSH;
if (s->is_dgram)
n_write = app_send_dgram_raw (tx_fifo, &s->transport,
- s->vpp_evt_q, buf, n, et, SVM_Q_WAIT);
+ s->vpp_evt_q, buf, n, et,
+ !is_ct /* do_evt */ , SVM_Q_WAIT);
else
n_write = app_send_stream_raw (tx_fifo, s->vpp_evt_q, buf, n, et,
- SVM_Q_WAIT);
+ !is_ct /* do_evt */ , SVM_Q_WAIT);
+
+ if (is_ct && svm_fifo_set_event (s->tx_fifo))
+ app_send_io_evt_to_vpp (s->vpp_evt_q, s->tx_fifo, et, SVM_Q_WAIT);
ASSERT (n_write > 0);
- VDBG (2, "VCL<%d>: vpp handle 0x%llx, sid %u: wrote %d bytes", getpid (),
- s->vpp_handle, session_handle, n_write);
+ VDBG (2, "session %u [0x%llx]: wrote %d bytes", s->session_index,
+ s->vpp_handle, n_write);
return n_write;
}
1 /* is_flush */ );
}
-
-static vcl_session_t *
-vcl_ct_session_get_from_fifo (vcl_worker_t * wrk, svm_fifo_t * f, u8 type)
-{
- vcl_session_t *s;
- s = vcl_session_get (wrk, f->client_session_index);
- if (s)
- {
- /* rx fifo */
- if (type == 0 && s->rx_fifo == f)
- return s;
- /* tx fifo */
- if (type == 1 && s->tx_fifo == f)
- return s;
- }
- s = vcl_session_get (wrk, f->master_session_index);
- if (s)
- {
- if (type == 0 && s->rx_fifo == f)
- return s;
- if (type == 1 && s->tx_fifo == f)
- return s;
- }
- return 0;
-}
-
-static inline int
-vppcom_session_write_ready (vcl_session_t * session)
-{
- /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
- if (PREDICT_FALSE (session->is_vep))
- {
- VDBG (0, "session %u [0x%llx]: cannot write to an epoll session!",
- session->session_index, session->vpp_handle);
- return VPPCOM_EBADFD;
- }
-
- if (PREDICT_FALSE (session->session_state & STATE_LISTEN))
- {
- if (session->tx_fifo)
- return svm_fifo_max_enqueue (session->tx_fifo);
- else
- return VPPCOM_EBADFD;
- }
-
- if (PREDICT_FALSE (!(session->session_state & STATE_OPEN)))
- {
- session_state_t state = session->session_state;
- int rv;
-
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
- VDBG (0, "session %u [0x%llx]: session is not open! state 0x%x (%s), "
- "returning %d (%s)", session->session_index, session->vpp_handle,
- state, vppcom_session_state_str (state), rv,
- vppcom_retval_str (rv));
- return rv;
- }
-
- return svm_fifo_max_enqueue (session->tx_fifo);
-}
-
#define vcl_fifo_rx_evt_valid_or_break(_fifo) \
if (PREDICT_FALSE (svm_fifo_is_empty (_fifo))) \
{ \
*bits_set += 1;
}
break;
- case SESSION_IO_EVT_CT_TX:
- vcl_fifo_rx_evt_valid_or_break (e->fifo);
- session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 0);
- if (!session)
- break;
- sid = session->session_index;
- if (sid < n_bits && read_map)
- {
- clib_bitmap_set_no_check ((uword *) read_map, sid, 1);
- *bits_set += 1;
- }
- break;
- case SESSION_IO_EVT_CT_RX:
- session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 1);
- if (!session)
- break;
- sid = session->session_index;
- if (sid < n_bits && write_map)
- {
- clib_bitmap_set_no_check ((uword *) write_map, sid, 1);
- *bits_set += 1;
- }
- break;
case SESSION_CTRL_EVT_ACCEPTED:
session = vcl_session_accepted (wrk,
(session_accepted_msg_t *) e->data);
*bits_set += 1;
}
break;
+ case SESSION_CTRL_EVT_UNLISTEN_REPLY:
+ vcl_session_unlisten_reply_handler (wrk, e->data);
+ break;
case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY:
vcl_session_worker_update_reply_handler (wrk, e->data);
break;
vcl_si_set * except_map, double time_to_wait,
u32 * bits_set)
{
- double total_wait = 0, wait_slice;
- vcl_cut_through_registration_t *cr;
-
time_to_wait = (time_to_wait == -1) ? 1e6 : time_to_wait;
- wait_slice = wrk->cut_through_registrations ? 10e-6 : time_to_wait;
- do
- {
- vcl_ct_registration_lock (wrk);
- /* *INDENT-OFF* */
- pool_foreach (cr, wrk->cut_through_registrations, ({
- vcl_select_handle_mq (wrk, cr->mq, n_bits, read_map, write_map, except_map,
- 0, bits_set);
- }));
- /* *INDENT-ON* */
- vcl_ct_registration_unlock (wrk);
-
- vcl_select_handle_mq (wrk, wrk->app_event_queue, n_bits, read_map,
- write_map, except_map, wait_slice, bits_set);
- total_wait += wait_slice;
- if (*bits_set)
- return *bits_set;
- }
- while (total_wait < time_to_wait);
-
- return 0;
+ return vcl_select_handle_mq (wrk, wrk->app_event_queue, n_bits, read_map,
+ write_map, except_map, time_to_wait, bits_set);
}
static int
continue;
}
- rv = vppcom_session_read_ready (session);
+ rv = vcl_session_read_ready (session);
if (rv)
{
clib_bitmap_set_no_check ((uword*)read_map, sid, 1);
" is_vep = %u\n"
" is_vep_session = %u\n"
" next_sid = 0x%x (%u)\n"
- " wait_cont_idx = 0x%x (%u)\n"
"}\n", getpid (), vep_idx,
session->is_vep, session->is_vep_session,
- vep->next_sh, vep->next_sh,
- session->wait_cont_idx, session->wait_cont_idx);
+ vep->next_sh, vep->next_sh);
for (sid = vep->next_sh; sid != ~0; sid = vep->next_sh)
{
vep_session->vep.vep_sh = ~0;
vep_session->vep.next_sh = ~0;
vep_session->vep.prev_sh = ~0;
- vep_session->wait_cont_idx = ~0;
vep_session->vpp_handle = ~0;
vcl_evt (VCL_EVT_EPOLL_CREATE, vep_session, vep_session->session_index);
goto done;
}
- vep_session->wait_cont_idx =
- (vep_session->wait_cont_idx == session_handle) ?
- session->vep.next_sh : vep_session->wait_cont_idx;
-
if (session->vep.prev_sh == vep_handle)
vep_session->vep.next_sh = session->vep.next_sh;
else
switch (e->event_type)
{
- case FIFO_EVENT_APP_RX:
+ case SESSION_IO_EVT_RX:
ASSERT (e->fifo->client_thread_index == vcl_get_worker_index ());
vcl_fifo_rx_evt_valid_or_break (e->fifo);
sid = e->fifo->client_session_index;
session_evt_data = session->vep.ev.data.u64;
session->has_rx_evt = 1;
break;
- case FIFO_EVENT_APP_TX:
+ case SESSION_IO_EVT_TX:
sid = e->fifo->client_session_index;
if (!(session = vcl_session_get (wrk, sid)))
break;
session_evt_data = session->vep.ev.data.u64;
svm_fifo_reset_tx_ntf (session->tx_fifo);
break;
- case SESSION_IO_EVT_CT_TX:
- vcl_fifo_rx_evt_valid_or_break (e->fifo);
- session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 0);
- if (PREDICT_FALSE (!session))
- break;
- sid = session->session_index;
- session_events = session->vep.ev.events;
- if (!(EPOLLIN & session->vep.ev.events) || session->has_rx_evt)
- break;
- add_event = 1;
- events[*num_ev].events |= EPOLLIN;
- session_evt_data = session->vep.ev.data.u64;
- session->has_rx_evt = 1;
- break;
- case SESSION_IO_EVT_CT_RX:
- session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 1);
- if (PREDICT_FALSE (!session))
- break;
- sid = session->session_index;
- session_events = session->vep.ev.events;
- if (!(EPOLLOUT & session_events))
- break;
- add_event = 1;
- events[*num_ev].events |= EPOLLOUT;
- session_evt_data = session->vep.ev.data.u64;
- svm_fifo_reset_tx_ntf (session->tx_fifo);
- break;
case SESSION_CTRL_EVT_ACCEPTED:
session = vcl_session_accepted (wrk,
(session_accepted_msg_t *) e->data);
events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP;
session_evt_data = session->vep.ev.data.u64;
break;
+ case SESSION_CTRL_EVT_UNLISTEN_REPLY:
+ vcl_session_unlisten_reply_handler (wrk, e->data);
+ break;
case SESSION_CTRL_EVT_REQ_WORKER_UPDATE:
vcl_session_req_worker_update_handler (wrk, e->data);
break;
vppcom_epoll_wait_condvar (vcl_worker_t * wrk, struct epoll_event *events,
int maxevents, u32 n_evts, double wait_for_time)
{
- vcl_cut_through_registration_t *cr;
- double total_wait = 0, wait_slice;
- int rv;
-
wait_for_time = (wait_for_time == -1) ? (double) 1e6 : wait_for_time;
- wait_slice = wrk->cut_through_registrations ? 10e-6 : wait_for_time;
-
- do
- {
- vcl_ct_registration_lock (wrk);
- /* *INDENT-OFF* */
- pool_foreach (cr, wrk->cut_through_registrations, ({
- vcl_epoll_wait_handle_mq (wrk, cr->mq, events, maxevents, 0, &n_evts);
- }));
- /* *INDENT-ON* */
- vcl_ct_registration_unlock (wrk);
-
- rv = vcl_epoll_wait_handle_mq (wrk, wrk->app_event_queue, events,
- maxevents, n_evts ? 0 : wait_slice,
- &n_evts);
- if (rv)
- total_wait += wait_slice;
- if (n_evts)
- return n_evts;
- }
- while (total_wait < wait_for_time);
- return n_evts;
+ return vcl_epoll_wait_handle_mq (wrk, wrk->app_event_queue, events,
+ maxevents, wait_for_time, &n_evts);
}
static int
switch (op)
{
case VPPCOM_ATTR_GET_NREAD:
- rv = vppcom_session_read_ready (session);
+ rv = vcl_session_read_ready (session);
VDBG (2, "VPPCOM_ATTR_GET_NREAD: sid %u, nread = %d", rv);
break;
case VPPCOM_ATTR_GET_NWRITE:
- rv = vppcom_session_write_ready (session);
+ rv = vcl_session_write_ready (session);
VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_NWRITE: sid %u, nwrite = %d",
getpid (), session_handle, rv);
break;
if (POLLIN & vp[i].events)
{
- rv = vppcom_session_read_ready (session);
+ rv = vcl_session_read_ready (session);
if (rv > 0)
{
vp[i].revents |= POLLIN;
if (POLLOUT & vp[i].events)
{
- rv = vppcom_session_write_ready (session);
+ rv = vcl_session_write_ready (session);
if (rv > 0)
{
vp[i].revents |= POLLOUT;
return vcl_get_worker_index ();
}
+int
+vppcom_worker_mqs_epfd (void)
+{
+ vcl_worker_t *wrk = vcl_worker_get_current ();
+ if (!vcm->cfg.use_mq_eventfd)
+ return -1;
+ return wrk->mqs_epfd;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*