refactor: module pools

master
Sean McBride 3 years ago
parent 130617f406
commit 7d7224a6a9

@ -23,10 +23,7 @@ extern thread_local int worker_thread_idx;
INIT_POOL(wasm_memory, wasm_memory_free)
INIT_POOL(wasm_stack, wasm_stack_free)
/* TODO: Dynamically size based on number of threads */
#define MAX_WORKER_THREADS 64
struct module_pools {
struct module_pool {
struct wasm_memory_pool memory;
struct wasm_stack_pool stack;
} __attribute__((aligned(CACHE_PAD)));
@ -41,7 +38,7 @@ struct module {
_Atomic uint32_t reference_count; /* ref count how many instances exist here. */
struct sledge_abi__wasm_table *indirect_table;
struct module_pools pools[MAX_WORKER_THREADS];
struct module_pool *pools;
} __attribute__((aligned(CACHE_PAD)));
/********************************
@ -118,12 +115,21 @@ module_alloc_table(struct module *module)
static inline void
module_initialize_pools(struct module *module)
{
for (int i = 0; i < MAX_WORKER_THREADS; i++) {
for (int i = 0; i < runtime_worker_threads_count; i++) {
wasm_memory_pool_init(&module->pools[i].memory, false);
wasm_stack_pool_init(&module->pools[i].stack, false);
}
}
static inline void
module_deinitialize_pools(struct module *module)
{
for (int i = 0; i < runtime_worker_threads_count; i++) {
wasm_memory_pool_deinit(&module->pools[i].memory);
wasm_stack_pool_deinit(&module->pools[i].stack);
}
}
/**
* Invoke a module's initialize_memory
* @param module - the module whose memory we are initializing

@ -35,8 +35,6 @@ uint32_t runtime_total_online_processors = 0;
uint32_t runtime_worker_threads_count = 0;
enum RUNTIME_SIGALRM_HANDLER runtime_sigalrm_handler = RUNTIME_SIGALRM_HANDLER_BROADCAST;
int runtime_worker_core_count;
bool runtime_preemption_enabled = true;
uint32_t runtime_quantum_us = 5000; /* 5ms */

@ -39,6 +39,8 @@ module_init(struct module *module, IN char *path)
rc = sledge_abi_symbols_init(&module->abi, path);
if (rc != 0) goto err;
module->pools = calloc(runtime_worker_threads_count, sizeof(struct module_pool));
module->path = path;
module->stack_size = ((uint32_t)(round_up_to_page(stack_size == 0 ? WASM_STACK_SIZE : stack_size)));
@ -52,6 +54,19 @@ err:
goto done;
}
static inline void
module_deinit(struct module *module)
{
assert(module == NULL);
assert(module->reference_count == 0);
free(module->path);
sledge_abi_symbols_deinit(&module->abi);
/* TODO: Free indirect_table */
module_deinitialize_pools(module);
free(module->pools);
}
/***************************************
* Public Methods
***************************************/
@ -69,14 +84,11 @@ void
module_free(struct module *module)
{
if (module == NULL) return;
assert(module->reference_count == 0);
panic("Unimplemented!\n");
/* TODO: Should allocating routes increment reference */
/* Do not free if we still have oustanding references */
if (module->reference_count) return;
sledge_abi_symbols_deinit(&module->abi);
module_deinit(module);
free(module);
}

Loading…
Cancel
Save