1 int 2 main (int argc, char *argv[]) 3 { 4 int i; 5 vlib_main_t *vm = &vlib_global_main; 6 void vl_msg_api_set_first_available_msg_id (u16); 7 uword main_heap_size = (1ULL << 30); 8 u8 *sizep; 9 u32 size; 10 int main_core = 1; 11 cpu_set_t cpuset; 12 13 .......... 14 15 /* 16 * Look for and parse the "heapsize" config parameter. 17 * Manual since none of the clib infra has been bootstrapped yet. 18 * 19 * Format: heapsize <nn>[mM][gG] 20 */ 21 22 for (i = 1; i < (argc - 1); i++) 23 { 24 if (!strncmp (argv[i], "plugin_path", 11)) 25 { 26 if (i < (argc - 1)) 27 vlib_plugin_path = argv[++i]; 28 } 29 if (!strncmp (argv[i], "test_plugin_path", 16)) 30 { 31 if (i < (argc - 1)) 32 vat_plugin_path = argv[++i]; 33 } 34 else if (!strncmp (argv[i], "heapsize", 8)) 35 { 36 sizep = (u8 *) argv[i + 1]; 37 size = 0; 38 while (*sizep >= ‘0‘ && *sizep <= ‘9‘) 39 { 40 size *= 10; 41 size += *sizep++ - ‘0‘; 42 } 43 if (size == 0) 44 { 45 fprintf 46 (stderr, 47 "warning: heapsize parse error ‘%s‘, use default %lld\n", 48 argv[i], (long long int) main_heap_size); 49 goto defaulted; 50 } 51 52 main_heap_size = size; 53 54 if (*sizep == ‘g‘ || *sizep == ‘G‘) 55 main_heap_size <<= 30; 56 else if (*sizep == ‘m‘ || *sizep == ‘M‘) 57 main_heap_size <<= 20; 58 } 59 else if (!strncmp (argv[i], "main-core", 9)) 60 { 61 if (i < (argc - 1)) 62 { 63 errno = 0; 64 unsigned long x = strtol (argv[++i], 0, 0); 65 if (errno == 0) 66 main_core = x; 67 } 68 } 69 } 70 71 defaulted: 72 73 /* set process affinity for main thread */ 74 CPU_ZERO (&cpuset); 75 CPU_SET (main_core, &cpuset); 76 pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset); 77 78 /* Set up the plugin message ID allocator right now... */ 79 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE); 80 81 /* Allocate main heap */ 82 if (clib_mem_init_thread_safe (0, main_heap_size)) 83 { 84 vm->init_functions_called = hash_create (0, /* value bytes */ 0); 85 vpe_main_init (vm); 86 return vlib_unix_main (argc, argv); 87 } 88 else 89 { 90 { 91 int rv __attribute__ ((unused)) = 92 write (2, "Main heap allocation failure!\r\n", 31); 93 } 94 return 1; 95 } 96 }
1 int 2 vlib_unix_main (int argc, char *argv[]) 3 { 4 vlib_main_t *vm = &vlib_global_main; /* one and only time for this! */ 5 unformat_input_t input; 6 clib_error_t *e; 7 int i; 8 9 vm->argv = (u8 **) argv; 10 vm->name = argv[0]; 11 vm->heap_base = clib_mem_get_heap (); 12 vm->heap_aligned_base = (void *) 13 (((uword) vm->heap_base) & ~(VLIB_FRAME_ALIGN - 1)); 14 ASSERT (vm->heap_base); 15 16 unformat_init_command_line (&input, (char **) vm->argv); 17 if ((e = vlib_plugin_config (vm, &input))) 18 { 19 clib_error_report (e); 20 return 1; 21 } 22 unformat_free (&input); 23 24 i = vlib_plugin_early_init (vm); 25 if (i) 26 return i; 27 28 unformat_init_command_line (&input, (char **) vm->argv); 29 if (vm->init_functions_called == 0) 30 vm->init_functions_called = hash_create (0, /* value bytes */ 0); 31 e = vlib_call_all_config_functions (vm, &input, 1 /* early */ ); 32 if (e != 0) 33 { 34 clib_error_report (e); 35 return 1; 36 } 37 unformat_free (&input); 38 39 /* always load symbols, for signal handler and mheap memory get/put backtrace */ 40 clib_elf_main_init (vm->name); 41 42 vec_validate (vlib_thread_stacks, 0); 43 vlib_thread_stack_init (0); 44 45 __os_thread_index = 0; 46 vm->thread_index = 0; 47 48 i = clib_calljmp (thread0, (uword) vm, 49 (void *) (vlib_thread_stacks[0] + 50 VLIB_THREAD_STACK_SIZE)); 51 return i; 52 }
原文:https://www.cnblogs.com/mysky007/p/12735682.html