diff --git a/runtime/include/scheduler.h b/runtime/include/scheduler.h index 145ac25..fba923a 100644 --- a/runtime/include/scheduler.h +++ b/runtime/include/scheduler.h @@ -204,17 +204,24 @@ static inline void scheduler_preempt(ucontext_t *user_context) { assert(user_context != NULL); - - /* Process epoll to make sure that all runnable jobs are considered for execution */ - worker_thread_execute_epoll_loop(); - struct sandbox *current = current_sandbox_get(); assert(current != NULL); assert(current->state == SANDBOX_RUNNING); + /* This is for better state-change bookkeeping */ + uint64_t now = __getcycles(); + uint64_t duration_of_last_state = now - current->last_state_change_timestamp; + current->running_duration += duration_of_last_state; + + /* Process epoll to make sure that all runnable jobs are considered for execution */ + worker_thread_execute_epoll_loop(); + struct sandbox *next = scheduler_get_next(); assert(next != NULL); + /* This is for better state-change bookkeeping */ + current->last_state_change_timestamp = __getcycles(); + /* If current equals next, no switch is necessary, so resume execution */ if (current == next) return; diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index 54516e7..df7dd2f 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -109,7 +109,7 @@ sigalrm_propagate_workers(siginfo_t *signal_info) static inline void sigint_propagate_workers_listener(siginfo_t *signal_info) { - /* Signal was sent directly by the kernel, so forward to other threads */ + /* Signal was sent directly by the kernel user space, so forward to other threads */ if (signal_info->si_code == SI_KERNEL || signal_info->si_code == SI_USER) { for (int i = 0; i < runtime_worker_threads_count; i++) { if (pthread_self() == runtime_worker_threads[i]) continue; @@ -178,7 +178,7 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void atomic_fetch_add(&software_interrupt_deferred_sigalrm, 1); } else { /* A worker thread received a SIGALRM while running a preemptable sandbox, so preempt */ - assert(current_sandbox->state == SANDBOX_RUNNING); + //assert(current_sandbox->state == SANDBOX_RUNNING); scheduler_preempt(user_context); } goto done; @@ -186,7 +186,6 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void case SIGUSR1: { assert(current_sandbox); assert(current_sandbox->ctxt.variant == ARCH_CONTEXT_VARIANT_SLOW); - atomic_fetch_add(&software_interrupt_SIGUSR_count, 1); #ifdef LOG_PREEMPTION debuglog("Total SIGUSR1 Received: %d\n", software_interrupt_SIGUSR_count); @@ -197,7 +196,7 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void goto done; } case SIGINT: { - /* Only the thread that receives SIGINT from the kernel will broadcast SIGINT to other worker threads */ + /* Only the thread that receives SIGINT from the kernel or user space will broadcast SIGINT to other worker threads */ sigint_propagate_workers_listener(signal_info); dump_log_to_file(); /* terminate itself */