Recombine diags and minimum barrier open time changes (VPP-968)
[vpp.git] / src / vlibmemory / memory_vlib.c
index d2e0596..55a90d6 100644 (file)
@@ -136,6 +136,44 @@ vl_api_serialize_message_table (api_main_t * am, u8 * vector)
   return serialize_close_vector (sm);
 }
 
+/*
+ * vl_api_memclnt_create_internal
+ */
+
+u32
+vl_api_memclnt_create_internal (char *name, unix_shared_memory_queue_t * q)
+{
+  vl_api_registration_t **regpp;
+  vl_api_registration_t *regp;
+  svm_region_t *svm;
+  void *oldheap;
+  api_main_t *am = &api_main;
+
+  ASSERT (vlib_get_thread_index () == 0);
+  pool_get (am->vl_clients, regpp);
+
+  svm = am->vlib_rp;
+
+  pthread_mutex_lock (&svm->mutex);
+  oldheap = svm_push_data_heap (svm);
+  *regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
+
+  regp = *regpp;
+  memset (regp, 0, sizeof (*regp));
+  regp->registration_type = REGISTRATION_TYPE_SHMEM;
+  regp->vl_api_registration_pool_index = regpp - am->vl_clients;
+
+  regp->vl_input_queue = q;
+  regp->name = format (0, "%s%c", name, 0);
+
+  pthread_mutex_unlock (&svm->mutex);
+  svm_pop_heap (oldheap);
+  return vl_msg_api_handle_from_index_and_epoch
+    (regp->vl_api_registration_pool_index,
+     am->shmem_hdr->application_restarts);
+}
+
+
 /*
  * vl_api_memclnt_create_t_handler
  */
@@ -216,17 +254,26 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
      am->shmem_hdr->application_restarts);
   rp->context = mp->context;
   rp->response = ntohl (rv);
-  rp->message_table = (u64) am->serialized_message_table_in_shmem;
+  rp->message_table =
+    pointer_to_uword (am->serialized_message_table_in_shmem);
 
   vl_msg_api_send_shmem (q, (u8 *) & rp);
 }
 
-/* Application callback to clean up leftover registrations from this client */
-int vl_api_memclnt_delete_callback (u32 client_index) __attribute__ ((weak));
-
-int
-vl_api_memclnt_delete_callback (u32 client_index)
+static int
+call_reaper_functions (u32 client_index)
 {
+  clib_error_t *error = 0;
+  _vl_msg_api_function_list_elt_t *i;
+
+  i = api_main.reaper_function_registrations;
+  while (i)
+    {
+      error = i->f (client_index);
+      if (error)
+       clib_error_report (error);
+      i = i->next_init_function;
+    }
   return 0;
 }
 
@@ -246,7 +293,7 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
 
   handle = mp->index;
 
-  if (vl_api_memclnt_delete_callback (handle))
+  if (call_reaper_functions (handle))
     return;
 
   epoch = vl_msg_api_handle_get_epoch (handle);
@@ -353,7 +400,7 @@ _(GET_FIRST_MSG_ID, get_first_msg_id)
  * vl_api_init
  */
 static int
-memory_api_init (char *region_name)
+memory_api_init (const char *region_name)
 {
   int rv;
   vl_msg_api_msg_config_t cfg;
@@ -621,7 +668,7 @@ memclnt_process (vlib_main_t * vm,
 
                      handle = vl_msg_api_handle_from_index_and_epoch
                        (dead_indices[i], shm->application_restarts);
-                     (void) vl_api_memclnt_delete_callback (handle);
+                     (void) call_reaper_functions (handle);
                    }
                }
 
@@ -1194,7 +1241,7 @@ vlibmemory_init (vlib_main_t * vm)
 VLIB_INIT_FUNCTION (vlibmemory_init);
 
 void
-vl_set_memory_region_name (char *name)
+vl_set_memory_region_name (const char *name)
 {
   api_main_t *am = &api_main;
 
@@ -1267,7 +1314,7 @@ VLIB_CLI_COMMAND (cli_show_api_plugin_command, static) = {
 static void
 vl_api_rpc_call_t_handler (vl_api_rpc_call_t * mp)
 {
-  vl_api_rpc_reply_t *rmp;
+  vl_api_rpc_call_reply_t *rmp;
   int (*fp) (void *);
   i32 rv = 0;
   vlib_main_t *vm = vlib_get_main ();
@@ -1297,7 +1344,7 @@ vl_api_rpc_call_t_handler (vl_api_rpc_call_t * mp)
       if (q)
        {
          rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
-         rmp->_vl_msg_id = ntohs (VL_API_RPC_REPLY);
+         rmp->_vl_msg_id = ntohs (VL_API_RPC_CALL_REPLY);
          rmp->context = mp->context;
          rmp->retval = rv;
          vl_msg_api_send_shmem (q, (u8 *) & rmp);
@@ -1310,7 +1357,7 @@ vl_api_rpc_call_t_handler (vl_api_rpc_call_t * mp)
 }
 
 static void
-vl_api_rpc_reply_t_handler (vl_api_rpc_reply_t * mp)
+vl_api_rpc_call_reply_t_handler (vl_api_rpc_call_reply_t * mp)
 {
   clib_warning ("unimplemented");
 }
@@ -1324,7 +1371,7 @@ vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
   unix_shared_memory_queue_t *q;
 
   /* Main thread: call the function directly */
-  if (os_get_cpu_number () == 0)
+  if (vlib_get_thread_index () == 0)
     {
       vlib_main_t *vm = vlib_get_main ();
       void (*call_fp) (void *);
@@ -1407,7 +1454,7 @@ vl_api_trace_plugin_msg_ids_t_handler (vl_api_trace_plugin_msg_ids_t * mp)
 
 #define foreach_rpc_api_msg                     \
 _(RPC_CALL,rpc_call)                            \
-_(RPC_REPLY,rpc_reply)
+_(RPC_CALL_REPLY,rpc_call_reply)
 
 #define foreach_plugin_trace_msg               \
 _(TRACE_PLUGIN_MSG_IDS,trace_plugin_msg_ids)
@@ -1415,6 +1462,7 @@ _(TRACE_PLUGIN_MSG_IDS,trace_plugin_msg_ids)
 static clib_error_t *
 rpc_api_hookup (vlib_main_t * vm)
 {
+  api_main_t *am = &api_main;
 #define _(N,n)                                                  \
     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
                            vl_api_##n##_t_handler,              \
@@ -1434,6 +1482,10 @@ rpc_api_hookup (vlib_main_t * vm)
                            sizeof(vl_api_##n##_t), 1 /* do trace */);
   foreach_plugin_trace_msg;
 #undef _
+
+  /* No reason to halt the parade to create a trace record... */
+  am->is_mp_safe[VL_API_TRACE_PLUGIN_MSG_IDS] = 1;
+
   return 0;
 }
 
@@ -1908,6 +1960,32 @@ api_config_fn (vlib_main_t * vm, unformat_input_t * input)
 
 VLIB_CONFIG_FUNCTION (api_config_fn, "api-trace");
 
+static clib_error_t *
+api_queue_config_fn (vlib_main_t * vm, unformat_input_t * input)
+{
+  api_main_t *am = &api_main;
+  u32 nitems;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "length %d", &nitems) ||
+         (unformat (input, "len %d", &nitems)))
+       {
+         if (nitems >= 1024)
+           am->vlib_input_queue_length = nitems;
+         else
+           clib_warning ("vlib input queue length %d too small, ignored",
+                         nitems);
+       }
+      else
+       return clib_error_return (0, "unknown input `%U'",
+                                 format_unformat_error, input);
+    }
+  return 0;
+}
+
+VLIB_CONFIG_FUNCTION (api_queue_config_fn, "api-queue");
+
 /*
  * fd.io coding-style-patch-verification: ON
  *