summaryrefslogtreecommitdiffstats
path: root/src/vcl/vppcom.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-11-13 15:52:38 -0800
committerDamjan Marion <dmarion@me.com>2018-11-18 19:46:38 +0000
commit053a0e44edb21713e0825f9c09ba4af12e686b38 (patch)
tree950e303daf1b367eab26cc823c0efc23ae170b1d /src/vcl/vppcom.c
parent0c4fec0134f32bc913299b37d048a99293b1a851 (diff)
vcl/session: apps with process workers
Allow apps to register child processes as app workers. In particular, on fork vcl now registers the child process with vpp as a new worker. Change-Id: I52a65fbc3292962b1f6e1fe0f6153f739e6e0d4a Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vcl/vppcom.c')
-rw-r--r--src/vcl/vppcom.c79
1 files changed, 63 insertions, 16 deletions
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index 99547377523..669f04fe1e3 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -688,6 +688,52 @@ vppcom_session_disconnect (u32 session_handle)
return VPPCOM_OK;
}
+static void
+vcl_cleanup_bapi (void)
+{
+ api_main_t *am = &api_main;
+
+ am->my_client_index = ~0;
+ am->my_registration = 0;
+ am->vl_input_queue = 0;
+ am->msg_index_by_name_and_crc = 0;
+
+ vl_client_api_unmap ();
+}
+
+void
+vcl_app_fork_child_handler (void)
+{
+ u8 *child_name;
+ int rv;
+
+ vcm->current_pid = getpid ();
+ vcl_set_worker_index (0);
+
+ VDBG (0, "initializing forked child");
+ 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)
+ {
+ VERR ("couldn't connect to VPP!");
+ return;
+ }
+
+ vcm->app_state = STATE_APP_ADDING_WORKER;
+ vcl_send_app_worker_add_del (1 /* is_add */ );
+ if (vcl_wait_for_app_state_change (STATE_APP_READY))
+ {
+ VERR ("failed to add worker to vpp");
+ return;
+ }
+ VDBG (0, "forked child main worker initialized");
+}
+
/*
* VPPCOM Public API functions
*/
@@ -704,12 +750,15 @@ vppcom_app_create (char *app_name)
vcl_cfg = &vcm->cfg;
vcm->main_cpu = pthread_self ();
+ vcm->main_pid = vcm->current_pid = getpid ();
+ vcm->app_name = format (0, "%s", app_name);
vppcom_init_error_string_table ();
svm_fifo_segment_main_init (vcl_cfg->segment_baseva,
20 /* timeout in secs */ );
pool_init_fixed (vcm->workers, vcl_cfg->max_workers);
clib_spinlock_init (&vcm->workers_lock);
vcl_worker_alloc_and_init ();
+ pthread_atfork (NULL, NULL, vcl_app_fork_child_handler);
}
if (vcm->my_client_index == ~0)
@@ -721,31 +770,28 @@ vppcom_app_create (char *app_name)
rv = vppcom_connect_to_vpp (app_name);
if (rv)
{
- clib_warning ("VCL<%d>: ERROR: couldn't connect to VPP!",
- getpid ());
+ VERR ("couldn't connect to VPP!");
return rv;
}
-
- VDBG (0, "VCL<%d>: sending session enable", getpid ());
+ vcm->main_api_client_index = vcm->my_client_index;
+ VDBG (0, "sending session enable");
rv = vppcom_app_session_enable ();
if (rv)
{
- clib_warning ("VCL<%d>: ERROR: vppcom_app_session_enable() "
- "failed!", getpid ());
+ VERR ("vppcom_app_session_enable() failed!");
return rv;
}
- VDBG (0, "VCL<%d>: sending app attach", getpid ());
+ VDBG (0, "sending app attach");
rv = vppcom_app_attach ();
if (rv)
{
- clib_warning ("VCL<%d>: ERROR: vppcom_app_attach() failed!",
- getpid ());
+ VERR ("vppcom_app_attach() failed!");
return rv;
}
- VDBG (0, "VCL<%d>: app_name '%s', my_client_index %d (0x%x)",
- getpid (), app_name, vcm->my_client_index, vcm->my_client_index);
+ VDBG (0, "app_name '%s', my_client_index %d (0x%x)",
+ app_name, vcm->my_client_index, vcm->my_client_index);
}
return VPPCOM_OK;
@@ -760,8 +806,8 @@ vppcom_app_destroy (void)
if (vcm->my_client_index == ~0)
return;
- VDBG (0, "VCL<%d>: detaching from VPP, my_client_index %d (0x%x)",
- getpid (), vcm->my_client_index, vcm->my_client_index);
+ VDBG (0, "detaching from VPP, my_client_index %d (0x%x)",
+ vcm->my_client_index, vcm->my_client_index);
vcl_evt (VCL_EVT_DETACH, vcm);
vppcom_app_send_detach ();
@@ -770,11 +816,12 @@ vppcom_app_destroy (void)
rv = vcl_wait_for_app_state_change (STATE_APP_ENABLED);
vcm->cfg.app_timeout = orig_app_timeout;
if (PREDICT_FALSE (rv))
- VDBG (0, "VCL<%d>: application detach timed out! returning %d (%s)",
- getpid (), rv, vppcom_retval_str (rv));
+ VDBG (0, "application detach timed out! returning %d (%s)",
+ rv, vppcom_retval_str (rv));
vcl_elog_stop (vcm);
vl_client_disconnect_from_vlib ();
+ vec_free (vcm->app_name);
vcm->my_client_index = ~0;
vcm->app_state = STATE_APP_START;
}
@@ -798,7 +845,7 @@ vppcom_session_create (u8 proto, u8 is_nonblocking)
vcl_evt (VCL_EVT_CREATE, session, session_type, session->session_state,
is_nonblocking, session_index);
- VDBG (0, "VCL<%d>: sid %u", getpid (), session->session_index);
+ VDBG (0, "created sid %u", session->session_index);
return vcl_session_handle (session);
}