diff --git a/runtime/Makefile b/runtime/Makefile index de58895..e69fce6 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -85,9 +85,6 @@ CFLAGS += -D${ARCH} CFLAGS += -DNCORES=${TOTAL_CORES} CFLAGS += -DPAGE_SIZE=$(PAGE_SIZE) -# Optionally Disable preemption -# CFLAGS += -DPREEMPT_DISABLE - # Sandboxes running on Sledge always use WebAssembly linear memory CFLAGS += -DUSE_MEM_VM diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index b0266fa..83fc3b2 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -90,3 +90,4 @@ print_runtime_scheduler(enum RUNTIME_SCHEDULER variant) }; extern enum RUNTIME_SCHEDULER runtime_scheduler; +extern bool runtime_preemption_enabled; diff --git a/runtime/src/main.c b/runtime/src/main.c index 7411dd6..b9e7a97 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -40,6 +40,9 @@ FILE *runtime_sandbox_perf_log = NULL; enum RUNTIME_SCHEDULER runtime_scheduler = RUNTIME_SCHEDULER_FIFO; int runtime_worker_core_count; + +bool runtime_preemption_enabled = true; + /** * Returns instructions on use of CLI if used incorrectly * @param cmd - The command the user entered @@ -213,6 +216,11 @@ runtime_configure() } printf("\tScheduler Policy: %s\n", print_runtime_scheduler(runtime_scheduler)); + /* Runtime Preemption Toggle */ + char *preempt_disable = getenv("SLEDGE_DISABLE_PREEMPTION"); + if (preempt_disable != NULL && strcmp(preempt_disable, "false") != 0) runtime_preemption_enabled = false; + printf("\tPreemption: %s\n", runtime_preemption_enabled ? "Enabled" : "Disabled"); + /* Runtime Perf Log */ char *runtime_sandbox_perf_log_path = getenv("SLEDGE_SANDBOX_PERF_LOG"); if (runtime_sandbox_perf_log_path != NULL) { diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index c102044..8fce230 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -165,9 +165,9 @@ software_interrupt_validate_worker() static inline void software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw) { -#ifdef PREEMPT_DISABLE - panic("Unexpectedly invoked signal handlers when PREEMPT_DISABLE set\n"); -#else + if (unlikely(!runtime_preemption_enabled)) { + panic("Unexpectedly invoked signal handlers with preemption disabled\n"); + } software_interrupt_validate_worker(); @@ -190,7 +190,6 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void } } } -#endif } /******************** @@ -203,7 +202,8 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void void software_interrupt_arm_timer(void) { -#ifndef PREEMPT_DISABLE + if (!runtime_preemption_enabled) return; + struct itimerval interval_timer; memset(&interval_timer, 0, sizeof(struct itimerval)); @@ -215,7 +215,6 @@ software_interrupt_arm_timer(void) perror("setitimer"); exit(1); } -#endif } /** diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index 0250401..5e6fe7a 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -317,10 +317,11 @@ worker_thread_main(void *return_code) /* Unmask signals */ -#ifndef PREEMPT_DISABLE - software_interrupt_unmask_signal(SIGALRM); - software_interrupt_unmask_signal(SIGUSR1); -#endif + if (runtime_preemption_enabled) { + software_interrupt_unmask_signal(SIGALRM); + software_interrupt_unmask_signal(SIGUSR1); + } + signal(SIGPIPE, SIG_IGN); /* Initialize epoll */