diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 52a28a0..08eb932 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -13,10 +13,21 @@ #define RUNTIME_MAX_SANDBOX_REQUEST_COUNT (1 << 19) /* random! */ #define RUNTIME_READ_WRITE_VECTOR_LENGTH 16 -extern int runtime_epoll_file_descriptor; -extern float runtime_processor_speed_MHz; -extern uint32_t runtime_total_worker_processors; +/* + * Descriptor of the epoll instance used to monitor the socket descriptors of registered + * serverless modules. The listener cores listens for incoming client requests through this. + */ +extern int runtime_epoll_file_descriptor; + +/* + * Assumption: All cores are the same speed + * See runtime_get_processor_speed_MHz for further details + */ +extern float runtime_processor_speed_MHz; + +/* Count of worker threads and array of their pthread identifiers */ extern pthread_t runtime_worker_threads[]; +extern uint32_t runtime_worker_threads_count; void alloc_linear_memory(void); void expand_memory(void); @@ -36,7 +47,7 @@ static inline bool runtime_is_worker() { pthread_t self = pthread_self(); - for (int i = 0; i < runtime_total_worker_processors; i++) { + for (int i = 0; i < runtime_worker_threads_count; i++) { if (runtime_worker_threads[i] == self) return true; } diff --git a/runtime/src/main.c b/runtime/src/main.c index 27589d4..acb5145 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -23,7 +23,7 @@ int32_t debuglog_file_descriptor = -1; float runtime_processor_speed_MHz = 0; uint32_t runtime_total_online_processors = 0; -uint32_t runtime_total_worker_processors = 0; +uint32_t runtime_worker_threads_count = 0; uint32_t runtime_first_worker_processor = 0; int runtime_worker_threads_argument[WORKER_THREAD_CORE_COUNT] = { 0 }; /* The worker sets its argument to -1 on error */ pthread_t runtime_worker_threads[WORKER_THREAD_CORE_COUNT]; @@ -81,15 +81,14 @@ runtime_allocate_available_cores() runtime_first_worker_processor = 1; /* WORKER_THREAD_CORE_COUNT can be used as a cap on the number of cores to use, but if there are few * cores that WORKER_THREAD_CORE_COUNT, just use what is available */ - uint32_t max_possible_workers = runtime_total_online_processors - 1; - runtime_total_worker_processors = max_possible_workers; - if (max_possible_workers >= WORKER_THREAD_CORE_COUNT) - runtime_total_worker_processors = WORKER_THREAD_CORE_COUNT; + uint32_t max_possible_workers = runtime_total_online_processors - 1; + runtime_worker_threads_count = max_possible_workers; + if (max_possible_workers >= WORKER_THREAD_CORE_COUNT) runtime_worker_threads_count = WORKER_THREAD_CORE_COUNT; - assert(runtime_total_worker_processors == WORKER_THREAD_CORE_COUNT); + assert(runtime_worker_threads_count == WORKER_THREAD_CORE_COUNT); printf("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", - runtime_total_online_processors, runtime_total_worker_processors, runtime_first_worker_processor, + runtime_total_online_processors, runtime_worker_threads_count, runtime_first_worker_processor, LISTENER_THREAD_CORE_ID); } @@ -156,7 +155,7 @@ runtime_process_debug_log_behavior() void runtime_start_runtime_worker_threads() { - for (int i = 0; i < runtime_total_worker_processors; i++) { + for (int i = 0; i < runtime_worker_threads_count; i++) { int ret = pthread_create(&runtime_worker_threads[i], NULL, worker_thread_main, (void *)&runtime_worker_threads_argument[i]); if (ret) { @@ -173,7 +172,7 @@ runtime_start_runtime_worker_threads() } debuglog("Sandboxing environment ready!\n"); - for (int i = 0; i < runtime_total_worker_processors; i++) { + for (int i = 0; i < runtime_worker_threads_count; i++) { int ret = pthread_join(runtime_worker_threads[i], NULL); if (ret) { errno = ret; diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index b47de31..07642c1 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -54,7 +54,7 @@ sigalrm_propagate_workers(siginfo_t *signal_info) { /* Signal was sent directly by the kernel, so forward to other threads */ if (signal_info->si_code == SI_KERNEL) { - for (int i = 0; i < runtime_total_worker_processors; i++) { + for (int i = 0; i < runtime_worker_threads_count; i++) { if (pthread_self() == runtime_worker_threads[i]) continue; pthread_kill(runtime_worker_threads[i], SIGALRM);