typedef struct vls_worker_
{
vcl_locked_session_t *vls_pool;
- uword *session_index_to_vlsh_table;
+ uword *session_handle_to_vlsh_table;
u32 wrk_index;
} vls_worker_t;
* vcl worker with vpp. Otherwise, all threads use the same vcl worker, so
* update the vcl worker's thread local worker index variable */
if (vls_mt_wrk_supported ())
- vls_register_vcl_worker ();
+ {
+ if (vppcom_worker_register () != VPPCOM_OK)
+ VERR ("failed to register worker");
+ }
else
vcl_set_worker_index (vlsl->vls_wrk_index);
}
static void
vls_worker_free (vls_worker_t * wrk)
{
- hash_free (wrk->session_index_to_vlsh_table);
+ hash_free (wrk->session_handle_to_vlsh_table);
pool_free (wrk->vls_pool);
pool_put (vlsm->workers, wrk);
}
vls->worker_index = vppcom_session_worker (sh);
vls->vls_index = vls - wrk->vls_pool;
vls->shared_data_index = ~0;
- hash_set (wrk->session_index_to_vlsh_table, vls->session_index,
- vls->vls_index);
+ hash_set (wrk->session_handle_to_vlsh_table, sh, vls->vls_index);
if (vls_mt_wrk_supported ())
{
hash_set (vls->vcl_wrk_index_to_session_index, vls->worker_index,
vls_worker_t *wrk = vls_worker_get_current ();
ASSERT (vls != 0);
- hash_unset (wrk->session_index_to_vlsh_table, vls->session_index);
+ hash_unset (wrk->session_handle_to_vlsh_table,
+ vcl_session_handle_from_index (vls->session_index));
clib_spinlock_free (&vls->lock);
pool_put (wrk->vls_pool, vls);
}
}
vls_handle_t
-vls_si_to_vlsh (u32 session_index)
+vls_si_wi_to_vlsh (u32 session_index, u32 vcl_wrk_index)
{
vls_worker_t *wrk = vls_worker_get_current ();
uword *vlshp;
- vlshp = hash_get (wrk->session_index_to_vlsh_table, session_index);
+ vlshp = hash_get (wrk->session_handle_to_vlsh_table,
+ vcl_session_handle_from_wrk_session_index (session_index,
+ vcl_wrk_index));
return vlshp ? *vlshp : VLS_INVALID_HANDLE;
}
vls_handle_t vlsh;
vls_mt_table_rlock ();
- vlsh = vls_si_to_vlsh (session_index);
+ vlsh = vls_si_wi_to_vlsh (session_index, vcl_get_worker_index ());
vls_mt_table_runlock ();
return vlsh;
wrk = vcl_worker_get (wrk_index);
s = vcl_session_get (wrk, vls->session_index);
- if (s->session_state != STATE_LISTEN)
+ if (s->session_state != VCL_STATE_LISTEN)
return;
vcl_send_session_unlisten (wrk, s);
- s->session_state = STATE_LISTEN_NO_MQ;
+ s->session_state = VCL_STATE_LISTEN_NO_MQ;
vls_listener_wrk_set (vls, wrk_index, 0 /* is_active */ );
}
return 0;
s = vcl_session_get (wrk, vls->session_index);
- if (s->session_state == STATE_LISTEN)
+ if (s->session_state == VCL_STATE_LISTEN)
vls_listener_wrk_set (vls, wrk->wrk_index, 0 /* is_active */ );
vls_shared_data_pool_rlock ();
* Cleanup vcl state
*/
n_subscribers = vec_len (vls_shd->workers_subscribed);
- do_disconnect = s->session_state == STATE_LISTEN || !n_subscribers;
+ do_disconnect = s->session_state == VCL_STATE_LISTEN || !n_subscribers;
vcl_session_cleanup (wrk, s, vcl_session_handle (s), do_disconnect);
/*
svm_fifo_add_subscriber (s->rx_fifo, vcl_wrk->vpp_wrk_index);
svm_fifo_add_subscriber (s->tx_fifo, vcl_wrk->vpp_wrk_index);
}
- else if (s->session_state == STATE_LISTEN)
+ else if (s->session_state == VCL_STATE_LISTEN)
{
- s->session_state = STATE_LISTEN_NO_MQ;
+ s->session_state = VCL_STATE_LISTEN_NO_MQ;
}
}
vcl_locked_session_t *vls, *parent_vls;
/* *INDENT-OFF* */
- pool_foreach (vls, vls_wrk->vls_pool, ({
+ pool_foreach (vls, vls_wrk->vls_pool) {
/* Initialize sharing on parent session */
if (vls->shared_data_index == ~0)
{
vls->shared_data_index = parent_vls->shared_data_index;
}
vls_share_session (vls_wrk, vls);
- }));
+ }
/* *INDENT-ON* */
}
{
vls_worker_t *vls_wrk = vls_worker_get_current (), *vls_parent_wrk;
vcl_worker_t *wrk = vcl_worker_get_current ();
+ u32 vls_index, session_index, wrk_index;
+ vcl_session_handle_t sh;
/*
* init vcl worker
*/
- wrk->vpp_event_queues = vec_dup (parent_wrk->vpp_event_queues);
wrk->sessions = pool_dup (parent_wrk->sessions);
wrk->session_index_by_vpp_handles =
hash_dup (parent_wrk->session_index_by_vpp_handles);
* init vls worker
*/
vls_parent_wrk = vls_worker_get (parent_wrk->wrk_index);
- vls_wrk->session_index_to_vlsh_table =
- hash_dup (vls_parent_wrk->session_index_to_vlsh_table);
+ /* *INDENT-OFF* */
+ hash_foreach (sh, vls_index, vls_parent_wrk->session_handle_to_vlsh_table,
+ ({
+ vcl_session_handle_parse (sh, &wrk_index, &session_index);
+ hash_set (vls_wrk->session_handle_to_vlsh_table,
+ vcl_session_handle_from_index (session_index), vls_index);
+ }));
+ /* *INDENT-ON* */
vls_wrk->vls_pool = pool_dup (vls_parent_wrk->vls_pool);
vls_share_sessions (vls_parent_wrk, vls_wrk);
s = vcl_session_get (wrk, vls->session_index);
if (PREDICT_FALSE (!s))
return;
- is_nonblk = VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK);
+ is_nonblk = vcl_session_has_attr (s, VCL_SESS_ATTR_NONBLOCK);
}
switch (op)
VDBG (1, "migrate session of worker (session): %u (%u) -> %u (%u)",
vls->owner_vcl_wrk_index, src_sid, wrk_index, sid);
- if (PREDICT_FALSE (session->is_vep && session->vep.next_sh != ~0))
+ if (PREDICT_FALSE ((session->flags & VCL_SESSION_F_IS_VEP)
+ && session->vep.next_sh != ~0))
{
/* TODO: rollback? */
VERR ("can't migrate nonempty epoll session");
ASSERT (0);
return;
}
- else if (PREDICT_FALSE (!session->is_vep &&
- session->session_state != STATE_CLOSED))
+ else if (PREDICT_FALSE (!(session->flags & VCL_SESSION_F_IS_VEP) &&
+ session->session_state != VCL_STATE_CLOSED))
{
/* TODO: rollback? */
VERR ("migrate NOT supported, session_status (%u)",
s = vcl_session_get (wrk, vls->session_index);
switch (s->session_state)
{
- case STATE_LISTEN:
+ case VCL_STATE_LISTEN:
if (is_add)
{
vls_listener_wrk_set (vls, vls->worker_index, 1 /* is_active */ );
}
vls_listener_wrk_stop_listen (vls, vls->worker_index);
break;
- case STATE_LISTEN_NO_MQ:
+ case VCL_STATE_LISTEN_NO_MQ:
if (!is_add)
break;
/* *INDENT-OFF* */
clib_bitmap_foreach (si, read_map, ({
s = vcl_session_get (wrk, si);
- if (s->session_state == STATE_LISTEN)
+ if (s->session_state == VCL_STATE_LISTEN)
{
vls = vls_get (vls_session_index_to_vlsh (si));
vls_mp_checks (vls, 1 /* is_add */);
is_current = current_wrk == wrk->wrk_index;
/* *INDENT-OFF* */
- pool_foreach (s, wrk->sessions, ({
- vls = vls_get (vls_si_to_vlsh (s->session_index));
+ pool_foreach (s, wrk->sessions) {
+ vls = vls_get (vls_si_wi_to_vlsh (s->session_index, wrk->wrk_index));
if (vls && (is_current || vls_is_shared_by_wrk (vls, current_wrk)))
vls_unshare_session (vls, wrk);
- }));
+ }
/* *INDENT-ON* */
}
vls_app_fork_child_handler (void)
{
vcl_worker_t *parent_wrk;
- int rv, parent_wrk_index;
- u8 *child_name;
+ int parent_wrk_index;
parent_wrk_index = vcl_get_worker_index ();
VDBG (0, "initializing forked child %u with parent wrk %u", getpid (),
parent_wrk_index);
/*
- * Allocate worker vcl
+ * Clear old state
*/
vcl_set_worker_index (~0);
- if (!vcl_worker_alloc_and_init ())
- VERR ("couldn't allocate new worker");
/*
- * Attach to binary api
+ * Allocate and register vcl worker with vpp
*/
- child_name = format (0, "%v-child-%u%c", vcm->app_name, getpid (), 0);
- vcl_cleanup_bapi ();
- vppcom_api_hookup ();
- vcm->app_state = STATE_APP_START;
- rv = vppcom_connect_to_vpp ((char *) child_name);
- vec_free (child_name);
- if (rv)
+ if (vppcom_worker_register ())
{
- VERR ("couldn't connect to VPP!");
+ VERR ("couldn't register new worker!");
return;
}
/*
- * Allocate/initialize vls worker
+ * Allocate/initialize vls worker and share sessions
*/
vls_worker_alloc ();
-
- /*
- * Register worker with vpp and share sessions
- */
- vcl_worker_register_with_vpp ();
parent_wrk = vcl_worker_get (parent_wrk_index);
vls_worker_copy_on_fork (parent_wrk);
parent_wrk->forked_child = vcl_get_worker_index ();
void
vls_register_vcl_worker (void)
{
- if (vppcom_worker_register () != VPPCOM_OK)
- {
- VERR ("failed to register worker");
- return;
- }
+ vls_mt_add ();
}
/*