diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 83fc3b2..1e05489 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -91,3 +91,4 @@ print_runtime_scheduler(enum RUNTIME_SCHEDULER variant) extern enum RUNTIME_SCHEDULER runtime_scheduler; extern bool runtime_preemption_enabled; +extern uint32_t runtime_quantum_us; diff --git a/runtime/include/software_interrupt.h b/runtime/include/software_interrupt.h index fca97c8..b587e90 100644 --- a/runtime/include/software_interrupt.h +++ b/runtime/include/software_interrupt.h @@ -11,9 +11,6 @@ #include "debuglog.h" -#define SOFTWARE_INTERRUPT_TIME_TO_START_IN_USEC (2 * 1000) /* 2 ms */ -#define SOFTWARE_INTERRUPT_INTERVAL_DURATION_IN_USEC (1 * 1000) /* 1 ms */ - /************ * Externs * ***********/ diff --git a/runtime/src/main.c b/runtime/src/main.c index b9e7a97..6bd8866 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -41,7 +41,8 @@ enum RUNTIME_SCHEDULER runtime_scheduler = RUNTIME_SCHEDULER_FIFO; int runtime_worker_core_count; -bool runtime_preemption_enabled = true; +bool runtime_preemption_enabled = true; +uint32_t runtime_quantum_us = 5000; /* 5ms */ /** * Returns instructions on use of CLI if used incorrectly @@ -221,6 +222,17 @@ runtime_configure() if (preempt_disable != NULL && strcmp(preempt_disable, "false") != 0) runtime_preemption_enabled = false; printf("\tPreemption: %s\n", runtime_preemption_enabled ? "Enabled" : "Disabled"); + /* Runtime Quantum */ + char *quantum_raw = getenv("SLEDGE_QUANTUM_US"); + if (quantum_raw != NULL) { + long quantum = atoi(quantum_raw); + if (unlikely(quantum <= 0)) panic("SLEDGE_QUANTUM_US must be a positive integer, saw %ld\n", quantum); + if (unlikely(quantum > 999999)) + panic("SLEDGE_QUANTUM_US must be less than 999999 ms, saw %ld\n", quantum); + runtime_quantum_us = (uint32_t)quantum; + } + printf("\tQuantum: %u us\n", runtime_quantum_us); + /* Runtime Perf Log */ char *runtime_sandbox_perf_log_path = getenv("SLEDGE_SANDBOX_PERF_LOG"); if (runtime_sandbox_perf_log_path != NULL) { @@ -360,8 +372,7 @@ main(int argc, char **argv) runtime_processor_speed_MHz = runtime_get_processor_speed_MHz(); if (unlikely(runtime_processor_speed_MHz == 0)) panic("Failed to detect processor speed\n"); - software_interrupt_interval_duration_in_cycles = (uint64_t)SOFTWARE_INTERRUPT_INTERVAL_DURATION_IN_USEC - * runtime_processor_speed_MHz; + software_interrupt_interval_duration_in_cycles = (uint64_t)runtime_quantum_us * runtime_processor_speed_MHz; printf("\tProcessor Speed: %u MHz\n", runtime_processor_speed_MHz); runtime_set_resource_limits_to_max(); diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index 8fce230..5315dda 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -197,7 +197,7 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void *******************/ /** - * Arms the Interval Timer to start in 10ms and then trigger a SIGALRM every 5ms + * Arms the Interval Timer to start in one quantum and then trigger a SIGALRM every quantum */ void software_interrupt_arm_timer(void) @@ -207,8 +207,8 @@ software_interrupt_arm_timer(void) struct itimerval interval_timer; memset(&interval_timer, 0, sizeof(struct itimerval)); - interval_timer.it_value.tv_usec = SOFTWARE_INTERRUPT_TIME_TO_START_IN_USEC; - interval_timer.it_interval.tv_usec = SOFTWARE_INTERRUPT_INTERVAL_DURATION_IN_USEC; + interval_timer.it_value.tv_usec = runtime_quantum_us; + interval_timer.it_interval.tv_usec = runtime_quantum_us; int return_code = setitimer(ITIMER_REAL, &interval_timer, NULL); if (return_code) {