X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp%2Fvnet%2Fmain.c;h=9d77a44c2ced642650590afabe6e579e05310678;hb=6a5adc369591fcac2447e9809deaa22f56b53911;hp=e4695e1ea4c78844b8410f8fde6448b2df769481;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c index e4695e1ea4c..9d77a44c2ce 100644 --- a/src/vpp/vnet/main.c +++ b/src/vpp/vnet/main.c @@ -13,74 +13,70 @@ * limitations under the License. */ +#define _GNU_SOURCE +#include +#include + #include #include #include #include #include - +#include #include - -#if DPDK -#include +#include /* - * Called by the dpdk driver's rte_delay_us() function. - * Return 0 to have the dpdk do a regular delay loop. - * Return 1 if to skip the delay loop because we are suspending - * the calling vlib process instead. + * Load plugins from /usr/lib/vpp_plugins by default */ -int -rte_delay_us_override (unsigned us) -{ - vlib_main_t *vm; - - /* Don't bother intercepting for short delays */ - if (us < 10) - return 0; - - /* - * Only intercept if we are in a vlib process. - * If we are called from a vlib worker thread or the vlib main - * thread then do not intercept. (Must not be called from an - * independent pthread). - */ - if (os_get_cpu_number () == 0) - { - /* - * We're in the vlib main thread or a vlib process. Make sure - * the process is running and we're not still initializing. - */ - vm = vlib_get_main (); - if (vlib_in_process_context (vm)) - { - /* Only suspend for the admin_down_process */ - vlib_process_t *proc = vlib_get_current_process (vm); - if (!(proc->flags & VLIB_PROCESS_IS_RUNNING) || - (proc->node_runtime.function != admin_up_down_process)) - return 0; - - f64 delay = 1e-6 * us; - vlib_process_suspend (vm, delay); - return 1; - } - } - return 0; // no override -} +char *vlib_plugin_path = "/usr/lib/vpp_plugins"; +char *vlib_plugin_app_version = VPP_BUILD_VER; -#if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) static void -rte_delay_us_override_cb (unsigned us) +vpp_find_plugin_path () { - if (rte_delay_us_override (us) == 0) - rte_delay_us_block (us); -} + extern char *vat_plugin_path; + char *p, path[PATH_MAX]; + int rv; + u8 *s; + + /* find executable path */ + if ((rv = readlink ("/proc/self/exe", path, PATH_MAX - 1)) == -1) + return; + + /* readlink doesn't provide null termination */ + path[rv] = 0; + + /* strip filename */ + if ((p = strrchr (path, '/')) == 0) + return; + *p = 0; + + /* strip bin/ */ + if ((p = strrchr (path, '/')) == 0) + return; + *p = 0; + + s = format (0, "%s/lib/vpp_plugins", path); +#if uword_bits == 64 + s = format (s, ":%s/lib64/vpp_plugins", path); #endif + vec_add1 (s, 0); + vlib_plugin_path = (char *) s; + + s = format (0, "%s/lib/vpp_api_test_plugins", path); +#if uword_bits == 64 + s = format (s, ":%s/lib64/vpp_api_test_plugins", path); #endif + vec_add1 (s, 0); + vat_plugin_path = (char *) s; +} static void vpe_main_init (vlib_main_t * vm) { + void vat_plugin_hash_create (void); + if (CLIB_DEBUG > 0) vlib_unix_cli_set_prompt ("DBGvpp# "); else @@ -89,28 +85,18 @@ vpe_main_init (vlib_main_t * vm) /* Turn off network stack components which we don't want */ vlib_mark_init_function_complete (vm, srp_init); -#if DPDK -#if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) - /* register custom delay function */ - rte_delay_us_callback_register (rte_delay_us_override_cb); -#endif -#endif + /* + * Create the binary api plugin hashes before loading plugins + */ + vat_plugin_hash_create (); + + vpp_find_plugin_path (); } /* - * Load plugins from /usr/lib/vpp_plugins by default + * Default path for runtime data */ -char *vlib_plugin_path = "/usr/lib/vpp_plugins"; - -void * -vnet_get_handoff_structure (void) -{ - static vnet_plugin_handoff_t _rv, *rv = &_rv; - - rv->vnet_main = vnet_get_main (); - rv->ethernet_main = ðernet_main; - return (void *) rv; -} +char *vlib_default_runtime_dir = "vpp"; int main (int argc, char *argv[]) @@ -121,7 +107,8 @@ main (int argc, char *argv[]) uword main_heap_size = (1ULL << 30); u8 *sizep; u32 size; - void vlib_set_get_handoff_structure_cb (void *cb); + int main_core = 1; + cpu_set_t cpuset; #if __x86_64__ CLIB_UNUSED (const char *msg) @@ -253,22 +240,33 @@ main (int argc, char *argv[]) else if (*sizep == 'm' || *sizep == 'M') main_heap_size <<= 20; } + else if (!strncmp (argv[i], "main-core", 9)) + { + if (i < (argc - 1)) + { + errno = 0; + unsigned long x = strtol (argv[++i], 0, 0); + if (errno == 0) + main_core = x; + } + } } defaulted: + /* set process affinity for main thread */ + CPU_ZERO (&cpuset); + CPU_SET (main_core, &cpuset); + pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset); + /* Set up the plugin message ID allocator right now... */ vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE); /* Allocate main heap */ - if (clib_mem_init (0, main_heap_size)) + if (clib_mem_init_thread_safe (0, main_heap_size)) { vm->init_functions_called = hash_create (0, /* value bytes */ 0); vpe_main_init (vm); -#if DPDK == 0 - unix_physmem_init (vm, 0 /* fail_if_physical_memory_not_present */ ); -#endif - vlib_set_get_handoff_structure_cb (&vnet_get_handoff_structure); return vlib_unix_main (argc, argv); } else @@ -323,11 +321,13 @@ plugin_path_config (vlib_main_t * vm, unformat_input_t * input) VLIB_CONFIG_FUNCTION (plugin_path_config, "plugin_path"); void vl_msg_api_post_mortem_dump (void); +void elog_post_mortem_dump (void); void os_panic (void) { vl_msg_api_post_mortem_dump (); + elog_post_mortem_dump (); abort (); } @@ -350,12 +350,21 @@ os_exit (int code) recursion_block = 1; vl_msg_api_post_mortem_dump (); + elog_post_mortem_dump (); vhost_user_unmap_all (); abort (); } exit (code); } +#ifdef BARRIER_TRACING +void +vl_msg_api_barrier_trace_context (const char *context) +{ + vlib_worker_threads[0].barrier_context = context; +} +#endif + void vl_msg_api_barrier_sync (void) { @@ -390,6 +399,12 @@ test_crash_command_fn (vlib_main_t * vm, { u64 *p = (u64 *) 0xdefec8ed; + ELOG_TYPE_DECLARE (e) = + { + .format = "deliberate crash: touching %x",.format_args = "i4",}; + + elog (&vm->elog_main, &e, 0xdefec8ed); + *p = 0xdeadbeef; /* Not so much... */