static void erl_init(int ncpu) { init_benchmarking(); #ifdef ERTS_SMP erts_system_block_init(); #endif erts_init_monitors(); erts_init_gc(); erts_init_time(); erts_init_sys_common_misc(); erts_init_process(ncpu); erts_init_scheduling(use_multi_run_queue, no_schedulers, no_schedulers_online); erts_init_cpu_topology(); /* Must be after init_scheduling */ H_MIN_SIZE = erts_next_heap_size(H_MIN_SIZE, 0); BIN_VH_MIN_SIZE = erts_next_heap_size(BIN_VH_MIN_SIZE, 0); erts_init_trace(); erts_init_binary(); erts_init_bits(); erts_init_fun_table(); init_atom_table(); init_export_table(); init_module_table(); init_register_table(); init_message(); erts_bif_info_init(); erts_ddll_init(); init_emulator(); erts_bp_init(); init_db(); /* Must be after init_emulator */ erts_bif_timer_init(); erts_init_node_tables(); init_dist(); erl_drv_thr_init(); init_io(); init_copy(); init_load(); erts_init_bif(); erts_init_bif_chksum(); erts_init_bif_binary(); erts_init_bif_re(); erts_init_unicode(); /* after RE to get access to PCRE unicode */ erts_delay_trap = erts_export_put(am_erlang, am_delay_trap, 2); erts_late_init_process(); #if HAVE_ERTS_MSEG erts_mseg_late_init(); /* Must be after timer (erts_init_time()) and thread initializations */ #endif #ifdef HIPE hipe_mode_switch_init(); /* Must be after init_load/beam_catches/init */ #endif packet_parser_init(); erl_nif_init(); }
static void init_shared_memory(int argc, char **argv) { #ifdef HYBRID int arg_size = 0; global_heap_sz = erts_next_heap_size(global_heap_sz,0); /* Make sure arguments will fit on the heap, no one else will check! */ while (argc--) arg_size += 2 + strlen(argv[argc]); if (global_heap_sz < arg_size) global_heap_sz = erts_next_heap_size(arg_size,1); #ifndef INCREMENTAL global_heap = (Eterm *) ERTS_HEAP_ALLOC(ERTS_ALC_T_HEAP, sizeof(Eterm) * global_heap_sz); global_hend = global_heap + global_heap_sz; global_htop = global_heap; global_high_water = global_heap; global_old_hend = global_old_htop = global_old_heap = NULL; #endif global_gen_gcs = 0; global_max_gen_gcs = (Uint16) erts_smp_atomic32_read_nob(&erts_max_gen_gcs); global_gc_flags = erts_default_process_flags; erts_global_offheap.mso = NULL; #ifndef HYBRID /* FIND ME! */ erts_global_offheap.funs = NULL; #endif erts_global_offheap.overhead = 0; #endif #ifdef INCREMENTAL erts_init_incgc(); #endif }
Eterm erl_create_process(ErlProcess* parent, Eterm module, Eterm function, Eterm args, ErlSpawnOpts* opts) { int i; uint16_t last_proc; for(i=0; i<MAX_PROCESSES; i++) { if(proc_tab[i].active == 0) { last_proc = i; break; } } if(last_proc == MAX_PROCESSES) { erl_exit("maximum number of processes reached!"); //@todo return NIL; } ErlProcess* p = (ErlProcess*)&proc_tab[last_proc]; Eterm pid = pix2pid(last_proc); p->parent = parent; p->id = pid; p->timer.active = 0; p->timer.arg = NULL; p->timer.cancel = NULL; p->timer.count = 0; p->timer.next = NULL; p->timer.prev = NULL; p->timer.slot = 0; p->timer.timeout = NULL; //@todo throw an error if exported was not found p->arity = 3; p->arg_reg = p->def_arg_reg; p->max_arg_reg = sizeof(p->def_arg_reg)/sizeof(p->def_arg_reg[0]); for(i=0; i<p->max_arg_reg; i++) { p->def_arg_reg[i] = 0; } p->fcalls = REDUCTIONS; p->active = 1; p->flags = 0; p->msg.len = 0; p->msg.first = NULL; p->msg.last = &p->msg.first; p->msg.save = &p->msg.first; p->msg.saved_last = NULL; p->links = NULL; if(opts && (opts->flags & SPO_LINK)) { erts_add_link(&p->links, parent->id); erts_add_link(&parent->links, p->id); } // initialize heap unsigned int arg_size = size_object(args); unsigned int heap_need = arg_size; unsigned int sz = erts_next_heap_size(heap_need); p->heap = (Eterm*)pvPortMalloc(sz * sizeof(Eterm)); p->stop = p->hend = p->heap + sz; p->htop = p->heap; p->heap_sz = sz; p->i = (BeamInstr*)(beam_apply); p->cp = (BeamInstr*)(beam_apply + 1); p->saved_i = (BeamInstr*)(beam_apply + 2); p->arg_reg[0] = module; p->arg_reg[1] = function; p->arg_reg[2] = copy_struct(args, arg_size, &p->htop); //start process inside the FreeRTOS scheduler vTaskResume(*(p->handle)); return pid; }
static void erl_init(int ncpu, int proc_tab_sz, int legacy_proc_tab, int port_tab_sz, int port_tab_sz_ignore_files, int legacy_port_tab) { init_benchmarking(); erts_init_monitors(); erts_init_time(); erts_init_sys_common_misc(); erts_init_process(ncpu, proc_tab_sz, legacy_proc_tab); erts_init_scheduling(no_schedulers, no_schedulers_online); erts_init_cpu_topology(); /* Must be after init_scheduling */ erts_init_gc(); /* Must be after init_scheduling */ erts_alloc_late_init(); H_MIN_SIZE = erts_next_heap_size(H_MIN_SIZE, 0); BIN_VH_MIN_SIZE = erts_next_heap_size(BIN_VH_MIN_SIZE, 0); erts_init_trace(); erts_init_binary(); erts_init_bits(); erts_code_ix_init(); erts_init_fun_table(); init_atom_table(); init_export_table(); init_module_table(); init_register_table(); init_message(); erts_bif_info_init(); erts_ddll_init(); init_emulator(); erts_ptab_init(); /* Must be after init_emulator() */ erts_bp_init(); init_db(); /* Must be after init_emulator */ erts_bif_timer_init(); erts_init_node_tables(); init_dist(); erl_drv_thr_init(); erts_init_async(); erts_init_io(port_tab_sz, port_tab_sz_ignore_files, legacy_port_tab); init_load(); erts_init_bif(); erts_init_bif_chksum(); erts_init_bif_binary(); erts_init_bif_re(); erts_init_unicode(); /* after RE to get access to PCRE unicode */ erts_init_external(); erts_delay_trap = erts_export_put(am_erlang, am_delay_trap, 2); erts_late_init_process(); #if HAVE_ERTS_MSEG erts_mseg_late_init(); /* Must be after timer (erts_init_time()) and thread initializations */ #endif #ifdef HIPE hipe_mode_switch_init(); /* Must be after init_load/beam_catches/init */ #endif packet_parser_init(); erl_nif_init(); }