From 6e998a81431718af1fa837f15907c2c9303c7a1f Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Tue, 9 Mar 2021 12:12:15 -0500 Subject: [PATCH] fix: Ensure workers init before softints --- runtime/src/main.c | 37 ++++++++++++++++---------------- runtime/src/software_interrupt.c | 3 +++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/runtime/src/main.c b/runtime/src/main.c index 761bc36..795f2c5 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -20,11 +20,12 @@ /* Conditionally used by debuglog when NDEBUG is not set */ int32_t debuglog_file_descriptor = -1; -uint32_t runtime_processor_speed_MHz = 0; -uint64_t runtime_relative_deadline_us_max = 0; /* a value higher than this will cause overflow on a uint64_t */ -uint32_t runtime_total_online_processors = 0; -uint32_t runtime_worker_threads_count = 0; -uint32_t runtime_first_worker_processor = 0; +uint32_t runtime_processor_speed_MHz = 0; +uint64_t runtime_relative_deadline_us_max = 0; /* a value higher than this will cause overflow on a uint64_t */ +uint32_t runtime_total_online_processors = 0; +uint32_t runtime_worker_threads_count = 0; +const uint32_t runtime_first_worker_processor = 1; +/* TODO: the worker never actually records state here */ 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]; @@ -85,8 +86,6 @@ runtime_allocate_available_cores() if (runtime_total_online_processors < 2) panic("Runtime requires at least two cores!"); - runtime_first_worker_processor = 1; - /* Number of Workers */ char *worker_count_raw = getenv("SLEDGE_NWORKERS"); if (worker_count_raw != NULL) { @@ -181,17 +180,6 @@ runtime_start_runtime_worker_threads() assert(ret == 0); } debuglog("Sandboxing environment ready!\n"); - - for (int i = 0; i < runtime_worker_threads_count; i++) { - int ret = pthread_join(runtime_worker_threads[i], NULL); - if (ret) { - errno = ret; - perror("pthread_join"); - exit(-1); - } - } - - exit(-1); } void @@ -251,6 +239,17 @@ main(int argc, char **argv) #endif if (module_new_from_json(argv[1])) panic("failed to parse modules file[%s]\n", argv[1]); - listener_thread_initialize(); runtime_start_runtime_worker_threads(); + listener_thread_initialize(); + + for (int i = 0; i < runtime_worker_threads_count; i++) { + int ret = pthread_join(runtime_worker_threads[i], NULL); + if (ret) { + errno = ret; + perror("pthread_join"); + exit(-1); + } + } + + exit(-1); } diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index a0dce8a..c102044 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -57,6 +57,9 @@ sigalrm_propagate_workers(siginfo_t *signal_info) for (int i = 0; i < runtime_worker_threads_count; i++) { if (pthread_self() == runtime_worker_threads[i]) continue; + /* All threads should have been initialized */ + assert(runtime_worker_threads[i] != 0); + pthread_kill(runtime_worker_threads[i], SIGALRM); } } else {