remove assert(current_sandbox->state == SANDBOX_RUNNING from software_interrupt.c and substract scheduling time from running time

main
xiaosuGW 3 years ago
parent 3dd9cbd722
commit 1eceb58278

@ -204,17 +204,24 @@ static inline void
scheduler_preempt(ucontext_t *user_context) scheduler_preempt(ucontext_t *user_context)
{ {
assert(user_context != NULL); 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(); struct sandbox *current = current_sandbox_get();
assert(current != NULL); assert(current != NULL);
assert(current->state == SANDBOX_RUNNING); 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(); struct sandbox *next = scheduler_get_next();
assert(next != NULL); 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 equals next, no switch is necessary, so resume execution */
if (current == next) return; if (current == next) return;

@ -109,7 +109,7 @@ sigalrm_propagate_workers(siginfo_t *signal_info)
static inline void static inline void
sigint_propagate_workers_listener(siginfo_t *signal_info) 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) { if (signal_info->si_code == SI_KERNEL || signal_info->si_code == SI_USER) {
for (int i = 0; i < runtime_worker_threads_count; i++) { for (int i = 0; i < runtime_worker_threads_count; i++) {
if (pthread_self() == runtime_worker_threads[i]) continue; 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); atomic_fetch_add(&software_interrupt_deferred_sigalrm, 1);
} else { } else {
/* A worker thread received a SIGALRM while running a preemptable sandbox, so preempt */ /* 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); scheduler_preempt(user_context);
} }
goto done; goto done;
@ -186,7 +186,6 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
case SIGUSR1: { case SIGUSR1: {
assert(current_sandbox); assert(current_sandbox);
assert(current_sandbox->ctxt.variant == ARCH_CONTEXT_VARIANT_SLOW); assert(current_sandbox->ctxt.variant == ARCH_CONTEXT_VARIANT_SLOW);
atomic_fetch_add(&software_interrupt_SIGUSR_count, 1); atomic_fetch_add(&software_interrupt_SIGUSR_count, 1);
#ifdef LOG_PREEMPTION #ifdef LOG_PREEMPTION
debuglog("Total SIGUSR1 Received: %d\n", software_interrupt_SIGUSR_count); 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; goto done;
} }
case SIGINT: { 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); sigint_propagate_workers_listener(signal_info);
dump_log_to_file(); dump_log_to_file();
/* terminate itself */ /* terminate itself */

Loading…
Cancel
Save