From 8164b5274f2910d76f46adc103d7674eee24a9d8 Mon Sep 17 00:00:00 2001 From: Xiaosu Lyu Date: Wed, 30 Nov 2022 17:25:01 -0500 Subject: [PATCH] add a flag to exit while loop for each worker thread --- runtime/include/scheduler.h | 3 ++- runtime/src/software_interrupt.c | 9 +++++---- runtime/src/worker_thread.c | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/runtime/include/scheduler.h b/runtime/include/scheduler.h index 69c96e7a..f691e97d 100644 --- a/runtime/include/scheduler.h +++ b/runtime/include/scheduler.h @@ -24,6 +24,7 @@ #include "sandbox_set_as_running_user.h" #include "scheduler_options.h" +extern thread_local bool pthread_stop; /** * This scheduler provides for cooperative and preemptive multitasking in a OS process's userspace. @@ -392,7 +393,7 @@ scheduler_switch_to_base_context(struct arch_context *current_context) static inline void scheduler_idle_loop() { - while (true) { + while (!pthread_stop) { /* Assumption: only called by the "base context" */ assert(current_sandbox_get() == NULL); diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index d7d27e8f..2c982e60 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -28,6 +28,7 @@ extern uint64_t total_held[1024]; extern uint64_t longest_held[1024]; +extern thread_local bool pthread_stop; thread_local _Atomic volatile sig_atomic_t handler_depth = 0; thread_local _Atomic volatile sig_atomic_t deferred_sigalrm = 0; @@ -232,19 +233,19 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void uint32_t total_sandboxes_error = atomic_load(&sandbox_state_totals[SANDBOX_ERROR]); printf("throughput is %f error request is %u global total request %d worker %d total requests is %u worker total_held %"PRIu64" longest_held %"PRIu64" listener total_held %"PRIu64" longest_held %"PRIu64"\n", throughput, total_sandboxes_error, atomic_load(&sandbox_state_totals[SANDBOX_COMPLETE]), worker_thread_idx, total_local_requests, total_held[worker_thread_idx], longest_held[worker_thread_idx], total_held[200], longest_held[200]); fflush(stdout); - pthread_exit(0); + pthread_stop = true; } default: { const char *signal_name = strsignal(signal_type); switch (signal_info->si_code) { case SI_TKILL: - panic("software_interrupt_handle_signals unexpectedly received signal %s from a thread kill\n", + printf("software_interrupt_handle_signals unexpectedly received signal %s from a thread kill\n", signal_name); case SI_KERNEL: - panic("software_interrupt_handle_signals unexpectedly received signal %s from the kernel\n", + printf("software_interrupt_handle_signals unexpectedly received signal %s from the kernel\n", signal_name); default: - panic("software_interrupt_handle_signals unexpectedly received signal %s with si_code %d\n", + printf("software_interrupt_handle_signals unexpectedly received signal %s with si_code %d\n", signal_name, signal_info->si_code); } } diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index 3828f060..de85b792 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -29,6 +29,8 @@ thread_local struct arch_context worker_thread_base_context; /* Used to index into global arguments and deadlines arrays */ thread_local int worker_thread_idx; +thread_local bool pthread_stop = false; + /* Used to track tenants' timeouts */ thread_local struct priority_queue *worker_thread_timeout_queue; /***********************